Merge remote-tracking branch 'origin/event-db'
# Conflicts: # src/main/java/mops/gruppen2/domain/Aggregate.java # src/main/java/mops/gruppen2/service/GroupService.java # src/test/java/mops/gruppen2/domain/GroupTest.java
This commit is contained in:
@ -1,22 +1,29 @@
|
|||||||
package mops.gruppen2.controller;
|
package mops.gruppen2.controller;
|
||||||
|
|
||||||
|
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||||
|
import mops.gruppen2.service.EventService;
|
||||||
|
import mops.gruppen2.service.GroupService;
|
||||||
import mops.gruppen2.service.KeyCloakService;
|
import mops.gruppen2.service.KeyCloakService;
|
||||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
|
|
||||||
import javax.annotation.security.RolesAllowed;
|
import javax.annotation.security.RolesAllowed;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("/gruppen2")
|
@RequestMapping("/gruppen2")
|
||||||
public class Gruppen2Controller {
|
public class Gruppen2Controller {
|
||||||
|
|
||||||
private final KeyCloakService keyCloakService;
|
private final KeyCloakService keyCloakService;
|
||||||
|
private final EventService eventService;
|
||||||
|
private final GroupService groupService;
|
||||||
|
|
||||||
public Gruppen2Controller(KeyCloakService keyCloakService) {
|
public Gruppen2Controller(KeyCloakService keyCloakService, EventService eventService, GroupService groupService) {
|
||||||
this.keyCloakService = keyCloakService;
|
this.keyCloakService = keyCloakService;
|
||||||
|
this.eventService = eventService;
|
||||||
|
this.groupService = groupService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Zeigt die index.html an.
|
/**Zeigt die index.html an.
|
||||||
@ -31,4 +38,32 @@ public class Gruppen2Controller {
|
|||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
return "index";
|
return "index";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||||
|
@GetMapping("/createGroup")
|
||||||
|
public String createGroup(KeycloakAuthenticationToken token, Model model) {
|
||||||
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
|
return "create";
|
||||||
|
}
|
||||||
|
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||||
|
@GetMapping("/findGroup")
|
||||||
|
public String findGroup(KeycloakAuthenticationToken token, Model model) {
|
||||||
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
|
return "search";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/createGroup")
|
||||||
|
public String pCreateGroup(KeycloakAuthenticationToken token,
|
||||||
|
@RequestParam(value = "title") String title,
|
||||||
|
@RequestParam(value = "beschreibung") String beschreibung) {
|
||||||
|
|
||||||
|
//Hier muss alles in eine separate Klasse
|
||||||
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(eventService.checkGroup(), "faker", title, beschreibung);
|
||||||
|
eventService.saveEvent(createGroupEvent);
|
||||||
|
groupService.buildGroupFromEvent(createGroupEvent);
|
||||||
|
|
||||||
|
return "redirect:/";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,13 @@
|
|||||||
package mops.gruppen2.controller;
|
package mops.gruppen2.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.github.javafaker.Faker;
|
import com.github.javafaker.Faker;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import io.swagger.annotations.ApiParam;
|
import io.swagger.annotations.ApiParam;
|
||||||
import mops.gruppen2.domain.ProductSwaggerExample;
|
import mops.gruppen2.domain.ProductSwaggerExample;
|
||||||
|
import mops.gruppen2.domain.event.AddUserEvent;
|
||||||
|
import mops.gruppen2.service.SerializationService;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -19,6 +22,11 @@ public class SwaggerAPIController {
|
|||||||
|
|
||||||
private final Faker faker = new Faker();
|
private final Faker faker = new Faker();
|
||||||
private final List<ProductSwaggerExample> products = new ArrayList<>();
|
private final List<ProductSwaggerExample> products = new ArrayList<>();
|
||||||
|
private final SerializationService serializationService;
|
||||||
|
|
||||||
|
public SwaggerAPIControllerExample(SerializationService serializationService) {
|
||||||
|
this.serializationService = serializationService;
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/get/all")
|
@GetMapping("/get/all")
|
||||||
@ApiOperation(value = "Erzeugt eine Liste mit allen gespeicherten Produkten")
|
@ApiOperation(value = "Erzeugt eine Liste mit allen gespeicherten Produkten")
|
||||||
@ -44,4 +52,5 @@ public class SwaggerAPIController {
|
|||||||
|
|
||||||
return "Product saved successfully";
|
return "Product saved successfully";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/main/java/mops/gruppen2/domain/EventDTO.java
Normal file
15
src/main/java/mops/gruppen2/domain/EventDTO.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package mops.gruppen2.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.data.annotation.Id;
|
||||||
|
import org.springframework.data.relational.core.mapping.Table;
|
||||||
|
|
||||||
|
@Table("event")
|
||||||
|
@Data
|
||||||
|
public class EventDTO {
|
||||||
|
@Id
|
||||||
|
Long event_id;
|
||||||
|
Long group_id;
|
||||||
|
String user_id;
|
||||||
|
String event_payload;
|
||||||
|
}
|
||||||
@ -1,27 +1,29 @@
|
|||||||
package mops.gruppen2.domain.event;
|
package mops.gruppen2.domain.event;
|
||||||
|
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Value;
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import mops.gruppen2.domain.User;
|
import mops.gruppen2.domain.User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fügt einen einzelnen Nutzer einer Gruppe hinzu.
|
* Fügt einen einzelnen Nutzer einer Gruppe hinzu.
|
||||||
*/
|
*/
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@Getter
|
||||||
@Value
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class AddUserEvent extends Event {
|
public class AddUserEvent extends Event {
|
||||||
String givenname;
|
String givenname;
|
||||||
String familyname;
|
String familyname;
|
||||||
String email;
|
String email;
|
||||||
|
|
||||||
public AddUserEvent(long event_id, long group_id, String user_id, String givenname, String familyname, String email) {
|
public AddUserEvent(Long event_id, Long group_id, String user_id, String givenname, String familyname, String email) {
|
||||||
super(event_id, group_id, user_id);
|
super(event_id, group_id, user_id);
|
||||||
this.givenname = givenname;
|
this.givenname = givenname;
|
||||||
this.familyname = familyname;
|
this.familyname = familyname;
|
||||||
this.email = email;
|
this.email = email;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddUserEvent(long event_id, long group_id, User user) {
|
public AddUserEvent(Long event_id, Long group_id, User user) {
|
||||||
super(event_id, group_id, user.getUser_id());
|
super(event_id, group_id, user.getUser_id());
|
||||||
this.givenname = user.getGivenname();
|
this.givenname = user.getGivenname();
|
||||||
this.familyname = user.getFamilyname();
|
this.familyname = user.getFamilyname();
|
||||||
|
|||||||
@ -1,17 +1,24 @@
|
|||||||
package mops.gruppen2.domain.event;
|
package mops.gruppen2.domain.event;
|
||||||
|
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Value;
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@Getter
|
||||||
@Value
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class CreateGroupEvent extends Event {
|
public class CreateGroupEvent extends Event {
|
||||||
String groupTitle;
|
String groupTitle;
|
||||||
String groupDescription;
|
String groupDescription;
|
||||||
|
|
||||||
public CreateGroupEvent(long event_id, long group_id, String user_id, String groupTitle, String groupDescription) {
|
public CreateGroupEvent(long event_id, Long group_id, String user_id, String groupTitle, String groupDescription) {
|
||||||
super(event_id, group_id, user_id);
|
super(event_id, group_id, user_id);
|
||||||
this.groupTitle = groupTitle;
|
this.groupTitle = groupTitle;
|
||||||
this.groupDescription = groupDescription;
|
this.groupDescription = groupDescription;
|
||||||
}
|
}
|
||||||
|
public CreateGroupEvent(Long group_id, String user_id, String groupTitle, String groupDescription) {
|
||||||
|
super(group_id, user_id);
|
||||||
|
this.groupTitle = groupTitle;
|
||||||
|
this.groupDescription = groupDescription;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,14 @@
|
|||||||
package mops.gruppen2.domain.event;
|
package mops.gruppen2.domain.event;
|
||||||
|
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.*;
|
||||||
import lombok.Value;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entfernt ein einzelnes Mitglied einer Gruppe.
|
* Entfernt ein einzelnes Mitglied einer Gruppe.
|
||||||
*/
|
*/
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@Getter
|
||||||
@Value
|
|
||||||
public class DeleteUserEvent extends Event {
|
public class DeleteUserEvent extends Event {
|
||||||
|
|
||||||
public DeleteUserEvent(long event_id, long group_id, String user_id) {
|
public DeleteUserEvent(Long event_id, Long group_id, String user_id) {
|
||||||
super(event_id, group_id, user_id);
|
super(event_id, group_id, user_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,35 @@
|
|||||||
package mops.gruppen2.domain.event;
|
package mops.gruppen2.domain.event;
|
||||||
|
|
||||||
import lombok.Value;
|
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||||
import lombok.experimental.NonFinal;
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@Value
|
|
||||||
@NonFinal
|
@Getter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@JsonTypeInfo(
|
||||||
|
include = JsonTypeInfo.As.PROPERTY,
|
||||||
|
use = JsonTypeInfo.Id.NAME,
|
||||||
|
property = "type"
|
||||||
|
)
|
||||||
|
@JsonSubTypes({
|
||||||
|
@JsonSubTypes.Type(value = AddUserEvent.class, name = "AddUserEvent"),
|
||||||
|
@JsonSubTypes.Type(value = CreateGroupEvent.class, name = "CreateGroupEvent"),
|
||||||
|
@JsonSubTypes.Type(value = DeleteUserEvent.class, name = "DeleteUserEvent"),
|
||||||
|
@JsonSubTypes.Type(value = UpdateGroupDescriptionEvent.class, name = "UpdateGroupDescriptionEvent"),
|
||||||
|
@JsonSubTypes.Type(value = UpdateGroupTitleEvent.class, name = "UpdateGroupTitleEvent"),
|
||||||
|
@JsonSubTypes.Type(value = UpdateRoleEvent.class, name = "UpdateRoleEvent"),
|
||||||
|
})
|
||||||
public class Event {
|
public class Event {
|
||||||
long event_id;
|
Long event_id;
|
||||||
long group_id;
|
Long group_id;
|
||||||
String user_id;
|
String user_id;
|
||||||
|
|
||||||
|
public Event(Long group_id,String user_id){
|
||||||
|
this.group_id = group_id;
|
||||||
|
this.user_id = user_id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,19 @@
|
|||||||
package mops.gruppen2.domain.event;
|
package mops.gruppen2.domain.event;
|
||||||
|
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Value;
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ändert nur die Gruppenbeschreibung.
|
* Ändert nur die Gruppenbeschreibung.
|
||||||
*/
|
*/
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@Getter
|
||||||
@Value
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class UpdateGroupDescriptionEvent extends Event {
|
public class UpdateGroupDescriptionEvent extends Event {
|
||||||
String newGroupDescription;
|
String newGroupDescription;
|
||||||
|
|
||||||
public UpdateGroupDescriptionEvent(long event_id, long group_id, String user_id, String newGroupDescription) {
|
public UpdateGroupDescriptionEvent(Long event_id, Long group_id, String user_id, String newGroupDescription) {
|
||||||
super(event_id, group_id, user_id);
|
super(event_id, group_id, user_id);
|
||||||
this.newGroupDescription = newGroupDescription;
|
this.newGroupDescription = newGroupDescription;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,19 @@
|
|||||||
package mops.gruppen2.domain.event;
|
package mops.gruppen2.domain.event;
|
||||||
|
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Value;
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ändert nur den Gruppentitel.
|
* Ändert nur den Gruppentitel.
|
||||||
*/
|
*/
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@Getter
|
||||||
@Value
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class UpdateGroupTitleEvent extends Event {
|
public class UpdateGroupTitleEvent extends Event {
|
||||||
String newGroupTitle;
|
String newGroupTitle;
|
||||||
|
|
||||||
public UpdateGroupTitleEvent(long event_id, long group_id, String user_id, String newGroupTitle) {
|
public UpdateGroupTitleEvent(Long event_id, Long group_id, String user_id, String newGroupTitle) {
|
||||||
super(event_id, group_id, user_id);
|
super(event_id, group_id, user_id);
|
||||||
this.newGroupTitle = newGroupTitle;
|
this.newGroupTitle = newGroupTitle;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,19 +1,19 @@
|
|||||||
package mops.gruppen2.domain.event;
|
package mops.gruppen2.domain.event;
|
||||||
|
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.*;
|
||||||
import lombok.Value;
|
|
||||||
import mops.gruppen2.domain.Role;
|
import mops.gruppen2.domain.Role;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Aktualisiert die Gruppenrolle eines Teilnehmers.
|
* Aktualisiert die Gruppenrolle eines Teilnehmers.
|
||||||
*/
|
*/
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@Getter
|
||||||
@Value
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class UpdateRoleEvent extends Event {
|
public class UpdateRoleEvent extends Event {
|
||||||
|
|
||||||
Role newRole;
|
Role newRole;
|
||||||
|
|
||||||
public UpdateRoleEvent(long event_id, long group_id, String user_id, Role newRole) {
|
public UpdateRoleEvent(Long event_id, Long group_id, String user_id, Role newRole) {
|
||||||
super(event_id, group_id, user_id);
|
super(event_id, group_id, user_id);
|
||||||
|
|
||||||
this.newRole = newRole;
|
this.newRole = newRole;
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
package mops.gruppen2.repository;
|
package mops.gruppen2.repository;
|
||||||
|
|
||||||
import mops.gruppen2.domain.event.Event;
|
import mops.gruppen2.domain.EventDTO;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
public interface EventRepository extends CrudRepository<Event, Long> {
|
public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
||||||
}
|
}
|
||||||
|
|||||||
51
src/main/java/mops/gruppen2/service/EventService.java
Normal file
51
src/main/java/mops/gruppen2/service/EventService.java
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import mops.gruppen2.domain.EventDTO;
|
||||||
|
import mops.gruppen2.domain.event.Event;
|
||||||
|
import mops.gruppen2.repository.EventRepository;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class EventService {
|
||||||
|
private final SerializationService serializationService;
|
||||||
|
private final EventRepository eventStore;
|
||||||
|
|
||||||
|
public EventService(SerializationService serializationService, EventRepository eventStore) {
|
||||||
|
this.serializationService = serializationService;
|
||||||
|
this.eventStore = eventStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void saveEvent(Event event){
|
||||||
|
EventDTO eventDTO = getDTO(event);
|
||||||
|
eventStore.save(eventDTO);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public EventDTO getDTO(Event event){
|
||||||
|
EventDTO eventDTO = new EventDTO();
|
||||||
|
eventDTO.setGroup_id(event.getGroup_id());
|
||||||
|
eventDTO.setUser_id(event.getUser_id());
|
||||||
|
try {
|
||||||
|
eventDTO.setEvent_payload(serializationService.serializeEvent(event));
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return eventDTO;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long checkGroup() {
|
||||||
|
Long tmpId = 1L;
|
||||||
|
Iterable<EventDTO> eventDTOS = eventStore.findAll();
|
||||||
|
for (EventDTO event : eventDTOS) {
|
||||||
|
if (event.getGroup_id() == null) {
|
||||||
|
return tmpId;
|
||||||
|
}
|
||||||
|
if (tmpId <= event.getGroup_id()) {
|
||||||
|
tmpId++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tmpId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -13,7 +13,6 @@ public class GroupService {
|
|||||||
/**
|
/**
|
||||||
* Konstruiert eine vollständige Gruppe aus Events, welche dieselbe Gruppe betreffen.
|
* Konstruiert eine vollständige Gruppe aus Events, welche dieselbe Gruppe betreffen.
|
||||||
*
|
*
|
||||||
* @param event Initiales CreateGroup-Event
|
|
||||||
* @param eventList Die restlichen Events für diese Gruppe
|
* @param eventList Die restlichen Events für diese Gruppe
|
||||||
* @return Gruppe auf aktuellem Stand
|
* @return Gruppe auf aktuellem Stand
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -1,5 +1,12 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import mops.gruppen2.domain.EventDTO;
|
||||||
|
import mops.gruppen2.domain.event.Event;
|
||||||
|
import mops.gruppen2.repository.EventRepository;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -7,4 +14,21 @@ import org.springframework.stereotype.Service;
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class SerializationService {
|
public class SerializationService {
|
||||||
|
|
||||||
|
private final EventRepository eventStore;
|
||||||
|
private final Logger log = LoggerFactory.getLogger(SerializationService.class);
|
||||||
|
|
||||||
|
public SerializationService(EventRepository eventStore) {
|
||||||
|
this.eventStore = eventStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String serializeEvent(Event event) throws JsonProcessingException {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
return mapper.writeValueAsString(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Event deserializeEvent(String json) throws JsonProcessingException {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
return mapper.readValue(json, Event.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
50
src/main/resources/templates/create.html
Normal file
50
src/main/resources/templates/create.html
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en" xmlns:th="http://www.thymeleaf.org"
|
||||||
|
th:replace="~{mopslayout :: html(name='Gruppenbildung', headcontent=~{:: headcontent}, navigation=~{:: navigation}, bodycontent=~{:: bodycontent})}">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Name des Subsystems</title>
|
||||||
|
<th:block th:fragment="headcontent">
|
||||||
|
<!-- Links, Skripts, Styles hier einfügen! -->
|
||||||
|
</th:block>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation">
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a th:href="@{/gruppen2}" href="/">Gruppen</a>
|
||||||
|
</li>
|
||||||
|
<li class="active">
|
||||||
|
<a th:href="@{/gruppen2/createGroup}" href="/createGroup">Erstellen</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
</header>
|
||||||
|
<main th:fragment="bodycontent">
|
||||||
|
<h1>Gruppenerstellung</h1>
|
||||||
|
<div class="container-fluid">
|
||||||
|
<form method="post" action="/gruppen2/createGroup">
|
||||||
|
<div style="border: 10px solid aliceblue; background: aliceblue">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="titel">Name der Gruppe</label>
|
||||||
|
<input type="text" class="form-control" id="titel" th:name="title">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="beschreibung">Beschreibung der Gruppe</label>
|
||||||
|
<textarea type="text" class="form-control" id="beschreibung" th:name="beschreibung">
|
||||||
|
|
||||||
|
</textarea>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<button type="submit">Erstellen</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -1,6 +1,6 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en" xmlns:th="http://www.thymeleaf.org"
|
<html lang="en" xmlns:th="http://www.thymeleaf.org"
|
||||||
th:replace="~{mopslayout :: html(name='Name des Subsystems', headcontent=~{:: headcontent}, navigation=~{:: navigation}, bodycontent=~{:: bodycontent})}">
|
th:replace="~{mopslayout :: html(name='Gruppenbildung', headcontent=~{:: headcontent}, navigation=~{:: navigation}, bodycontent=~{:: bodycontent})}">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>Name des Subsystems</title>
|
<title>Name des Subsystems</title>
|
||||||
@ -10,12 +10,30 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation">
|
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation">
|
||||||
<!-- Navigation als ungeordnete Liste mit einfachen Links hier einfügen! -->
|
<ul>
|
||||||
</nav>
|
<li class="active">
|
||||||
|
<a th:href="@{/gruppen2}" href="/">Gruppen</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a th:href="@{/gruppen2/createGroup}" href="/createGroup">Erstellen</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
<main th:fragment="bodycontent">
|
<main th:fragment="bodycontent">
|
||||||
<!-- Restlichen Inhalt hier einfügen! -->
|
<h1>Meine Gruppen</h1>
|
||||||
|
<div class="container-fluid">
|
||||||
|
<form action="/" method="get">
|
||||||
|
<div style="border: 10px solid aliceblue; background: aliceblue">
|
||||||
|
<h4 style="color: dodgerblue; font-weight: bold">Titel der Gruppe</h4>
|
||||||
|
<p>Beschreibung der Gruppe ...</p>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
81
src/main/resources/templates/search.html
Normal file
81
src/main/resources/templates/search.html
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en" xmlns:th="http://www.thymeleaf.org"
|
||||||
|
th:replace="~{mopslayout :: html(name='Gruppenbildung', headcontent=~{:: headcontent}, navigation=~{:: navigation}, bodycontent=~{:: bodycontent})}">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Name des Subsystems</title>
|
||||||
|
<th:block th:fragment="headcontent">
|
||||||
|
<!-- Links, Skripts, Styles hier einfügen! -->
|
||||||
|
</th:block>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation">
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a th:href="@{/gruppen2}" href="/">Gruppen</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a th:href="@{/gruppen2/createGroup}" href="/createGroup">Erstellen</a>
|
||||||
|
</li>
|
||||||
|
<li class="active">
|
||||||
|
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
</header>
|
||||||
|
<main th:fragment="bodycontent">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
<h1>Gruppensuche</h1>
|
||||||
|
<div class="container-fluid">
|
||||||
|
<form action="/findGroup" method="get">
|
||||||
|
<div style="border: 10px solid aliceblue; background: aliceblue">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Suchbegriff:</label>
|
||||||
|
<input class="form-control" type="text" value="" name="suchbegriff" placeholder="z.B. Programmieren, Lerngruppe, ...">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<input type="checkbox" style="margin-left: 10px;"> Öffentliche Gruppen
|
||||||
|
<input type="checkbox" style="margin-left: 24px;"> Private Gruppen
|
||||||
|
<br>
|
||||||
|
<input type="checkbox" style="margin-left: 10px;"> Suchbegriff im Namen
|
||||||
|
<input type="checkbox" style="margin-left: 10px;"> Suchbegriff in der Beschreibung
|
||||||
|
<input type="checkbox" style="margin-left: 10px;"> Suchbegriff in der Veranstaltung
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<button type="button" class="btn btn-primary" style="background: dodgerblue">Suchen</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<br>
|
||||||
|
<table class="table">
|
||||||
|
<!-- Erscheint dann, wenn man "Suchen" Button klickt und Ergebnisse angezeigt werden, aber so solls aussehen -->
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">Gruppenname</th>
|
||||||
|
<th scope="col">Beschreibung</th>
|
||||||
|
<th scope="col">Öffentlich/Privat</th>
|
||||||
|
<th scope="col">Mitgliederanzahl</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">LA1 Kursgruppe</th>
|
||||||
|
<td>Gruppe für den Kurs LA1</td>
|
||||||
|
<td>Öffentlich</td>
|
||||||
|
<td>318</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Lerngruppe LA1</th>
|
||||||
|
<td>Lerngruppe zur Bearbeitung von Übungszetteln</td>
|
||||||
|
<td>Privat</td>
|
||||||
|
<td>6</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
92
src/test/java/mops/gruppen2/builder/EventBuilder.java
Normal file
92
src/test/java/mops/gruppen2/builder/EventBuilder.java
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
package mops.gruppen2.builder;
|
||||||
|
|
||||||
|
import com.github.javafaker.Faker;
|
||||||
|
import mops.gruppen2.domain.Role;
|
||||||
|
import mops.gruppen2.domain.event.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class EventBuilder {
|
||||||
|
|
||||||
|
public static CreateGroupEvent randomCreateGroupEvent() {
|
||||||
|
Faker faker = new Faker();
|
||||||
|
|
||||||
|
return new CreateGroupEvent(
|
||||||
|
faker.random().nextLong(),
|
||||||
|
faker.random().nextLong(),
|
||||||
|
faker.random().hex(),
|
||||||
|
faker.leagueOfLegends().champion(),
|
||||||
|
faker.leagueOfLegends().quote()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AddUserEvent randomAddUserEvent() {
|
||||||
|
Faker faker = new Faker();
|
||||||
|
|
||||||
|
String firstname = faker.name().firstName();
|
||||||
|
String lastname = faker.name().lastName();
|
||||||
|
|
||||||
|
return new AddUserEvent(
|
||||||
|
faker.random().nextLong(),
|
||||||
|
faker.random().nextLong(),
|
||||||
|
faker.random().hex(),
|
||||||
|
firstname,
|
||||||
|
lastname,
|
||||||
|
firstname + "." + lastname + "@mail.de"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Event> randomAddUserEvents(int count) {
|
||||||
|
List<Event> eventList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
eventList.add(EventBuilder.randomAddUserEvent());
|
||||||
|
}
|
||||||
|
|
||||||
|
return eventList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DeleteUserEvent randomDeleteUserEvent(long group_id, String user_id) {
|
||||||
|
Faker faker = new Faker();
|
||||||
|
|
||||||
|
return new DeleteUserEvent(
|
||||||
|
faker.random().nextLong(),
|
||||||
|
group_id,
|
||||||
|
user_id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UpdateGroupDescriptionEvent randomUpdateGroupDescriptionEvent(long group_id) {
|
||||||
|
Faker faker = new Faker();
|
||||||
|
|
||||||
|
return new UpdateGroupDescriptionEvent(
|
||||||
|
faker.random().nextLong(),
|
||||||
|
group_id,
|
||||||
|
faker.random().hex(),
|
||||||
|
faker.leagueOfLegends().quote()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UpdateGroupTitleEvent randomUpdateGroupTitleEvent(long group_id) {
|
||||||
|
Faker faker = new Faker();
|
||||||
|
|
||||||
|
return new UpdateGroupTitleEvent(
|
||||||
|
faker.random().nextLong(),
|
||||||
|
group_id,
|
||||||
|
faker.random().hex(),
|
||||||
|
faker.leagueOfLegends().champion()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UpdateRoleEvent randomUpdateRoleEvent(long group_id, String user_id, Role role) {
|
||||||
|
Faker faker = new Faker();
|
||||||
|
|
||||||
|
return new UpdateRoleEvent(
|
||||||
|
faker.random().nextLong(),
|
||||||
|
group_id,
|
||||||
|
user_id,
|
||||||
|
role
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class EventServiceTest {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import mops.gruppen2.builder.EventBuilder;
|
||||||
|
import mops.gruppen2.domain.event.AddUserEvent;
|
||||||
|
import mops.gruppen2.domain.event.Event;
|
||||||
|
import mops.gruppen2.repository.EventRepository;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
class SerializationServiceTest {
|
||||||
|
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setUp() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void serializeEventTest() {
|
||||||
|
event = new Event(1L,1L,"1");
|
||||||
|
|
||||||
|
SerializationService serializationService = new SerializationService(eventRepository);
|
||||||
|
|
||||||
|
try {
|
||||||
|
assertThat(serializationService.serializeEvent(event)).isEqualTo("{\"type\":\"Event\",\"event_id\":1,\"group_id\":1,\"user_id\":\"1\"}");
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void deserializeAddUserEvent() throws JsonProcessingException {
|
||||||
|
SerializationService serializationService = new SerializationService(mock(EventRepository.class));
|
||||||
|
|
||||||
|
String json = "{\"type\":\"Event\",\"event_id\":1,\"group_id\":1,\"user_id\":\"1\"}";
|
||||||
|
|
||||||
|
Event event = serializationService.deserializeEvent(json);
|
||||||
|
|
||||||
|
assertThat(event).isInstanceOf(Event.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void serializeEventTestAddUserEvent(){
|
||||||
|
AddUserEvent event = new AddUserEvent(1,1,"user_id","peter","mueller","a@a");
|
||||||
|
SerializationService serializationService = new SerializationService(mock(EventRepository.class));
|
||||||
|
try {
|
||||||
|
assertThat(serializationService.serializeEvent(event)).isEqualTo("{\"type\":\"AddUserEvent\",\"event_id\":1,\"group_id\":1,\"user_id\":\"user_id\",\"givenname\":\"peter\",\"familyname\":\"mueller\",\"email\":\"a@a\"}");
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user