Merge remote-tracking branch 'origin/master' into updateGroupsAPI
# Conflicts: # src/main/java/mops/gruppen2/service/EventService.java
This commit is contained in:
@ -80,7 +80,7 @@ public class Gruppen2Controller {
|
|||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
controllerService.createGroup(account, title, beschreibung);
|
controllerService.createGroup(account, title, beschreibung);
|
||||||
|
|
||||||
return "redirect:/gruppen2";
|
return "redirect:/gruppen2/";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
13
src/main/java/mops/gruppen2/controller/MopsController.java
Normal file
13
src/main/java/mops/gruppen2/controller/MopsController.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package mops.gruppen2.controller;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class MopsController {
|
||||||
|
|
||||||
|
@GetMapping("")
|
||||||
|
public String redirect(){
|
||||||
|
return "redirect:/gruppen2/";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -15,7 +15,11 @@ public class UpdateRoleEvent extends Event {
|
|||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UpdateRoleEvent(Long group_id, String user_id, Role newRole) {
|
||||||
|
super(group_id, user_id);
|
||||||
this.newRole = newRole;
|
this.newRole = newRole;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
import mops.gruppen2.domain.GroupType;
|
import mops.gruppen2.domain.GroupType;
|
||||||
|
import mops.gruppen2.domain.Role;
|
||||||
import mops.gruppen2.domain.Visibility;
|
import mops.gruppen2.domain.Visibility;
|
||||||
import mops.gruppen2.domain.event.*;
|
import mops.gruppen2.domain.event.*;
|
||||||
import mops.gruppen2.security.Account;
|
import mops.gruppen2.security.Account;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ControllerService {
|
public class ControllerService {
|
||||||
@ -15,15 +17,24 @@ public class ControllerService {
|
|||||||
this.eventService = eventService;
|
this.eventService = eventService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createGroup(Account account, String title, String beschreibung) {
|
/**
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(eventService.checkGroup(), account.getName(), null , GroupType.LECTURE, Visibility.PUBLIC);
|
* Erzeugt eine neue Gruppe, fügt den User, der die Gruppe erstellt hat, hinzu und setzt seine Rolle als Admin fest.
|
||||||
AddUserEvent addUserEvent = new AddUserEvent(eventService.checkGroup(), account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail());
|
* Zudem wird der Gruppentitel und die Gruppenbeschreibung erzeugt, welche vorher der Methode übergeben wurden.
|
||||||
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(eventService.checkGroup(), account.getName(), title);
|
* Aus diesen Event Objekten wird eine Liste erzeugt, welche daraufhin mithilfe des EventServices gesichert wird.
|
||||||
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(eventService.checkGroup(), account.getName(), beschreibung);
|
*
|
||||||
|
* @param account Keycloak-Account
|
||||||
|
* @param title Gruppentitel
|
||||||
|
* @param description Gruppenbeschreibung
|
||||||
|
*/
|
||||||
|
public void createGroup(Account account, String title, String description) {
|
||||||
|
|
||||||
eventService.saveEvent(createGroupEvent);
|
List<Event> eventList = new ArrayList<>();
|
||||||
eventService.saveEvent(addUserEvent);
|
Collections.addAll(eventList, new CreateGroupEvent(eventService.checkGroup(), account.getName(), null , GroupType.LECTURE, Visibility.PUBLIC),
|
||||||
eventService.saveEvent(updateGroupTitleEvent);
|
new AddUserEvent(eventService.checkGroup(), account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail()),
|
||||||
eventService.saveEvent(updateGroupDescriptionEvent);
|
new UpdateRoleEvent(eventService.checkGroup(), account.getName(), Role.ADMIN),
|
||||||
|
new UpdateGroupTitleEvent(eventService.checkGroup(), account.getName(), title),
|
||||||
|
new UpdateGroupDescriptionEvent(eventService.checkGroup(), account.getName(), description));
|
||||||
|
|
||||||
|
eventService.saveEventList(eventList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -95,6 +95,17 @@ public class EventService {
|
|||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sichert eine Liste von Event Objekten mithilfe der Methode saveEvent(Event event)
|
||||||
|
*
|
||||||
|
* @param createGroupEvents Liste von Event Objekten
|
||||||
|
*/
|
||||||
|
public void saveEventList(List<Event> createGroupEvents) {
|
||||||
|
for(Event event : createGroupEvents) {
|
||||||
|
saveEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Long getMaxEvent_id(){
|
public Long getMaxEvent_id(){
|
||||||
return eventStore.getHighesEvent_ID();
|
return eventStore.getHighesEvent_ID();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,11 +22,25 @@ public class SerializationService {
|
|||||||
this.eventStore = eventStore;
|
this.eventStore = eventStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Übersetzt mithilfe der Jackson-Library eine Java-Event-Repräsentation zu einem JSON-Event-Payload.
|
||||||
|
*
|
||||||
|
* @param event Java-Event-Repräsentation
|
||||||
|
* @return JSON-Event-Payload als String
|
||||||
|
* @throws JsonProcessingException
|
||||||
|
*/
|
||||||
public String serializeEvent(Event event) throws JsonProcessingException {
|
public String serializeEvent(Event event) throws JsonProcessingException {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
return mapper.writeValueAsString(event);
|
return mapper.writeValueAsString(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Übersetzt mithilfe der Jackson-Library einen JSON-Event-Payload zu einer Java-Event-Repräsentation.
|
||||||
|
*
|
||||||
|
* @param json JSON-Event-Payload als String
|
||||||
|
* @return Java-Event-Repräsentation
|
||||||
|
* @throws JsonProcessingException
|
||||||
|
*/
|
||||||
public Event deserializeEvent(String json) throws JsonProcessingException {
|
public Event deserializeEvent(String json) throws JsonProcessingException {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
return mapper.readValue(json, Event.class);
|
return mapper.readValue(json, Event.class);
|
||||||
|
|||||||
@ -19,6 +19,8 @@ public class UserService {
|
|||||||
this.groupService = groupService;
|
this.groupService = groupService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Test nötig??
|
||||||
|
|
||||||
public List<Group> getUserGroups(String user_id) throws EventException {
|
public List<Group> getUserGroups(String user_id) throws EventException {
|
||||||
List<Long> group_ids = eventRepository.findGroup_idsWhereUser_id(user_id);
|
List<Long> group_ids = eventRepository.findGroup_idsWhereUser_id(user_id);
|
||||||
List<Event> events = groupService.getGroupEvents(group_ids);
|
List<Event> events = groupService.getGroupEvents(group_ids);
|
||||||
|
|||||||
@ -35,12 +35,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="beschreibung">Beschreibung der Gruppe</label>
|
<label for="beschreibung">Beschreibung der Gruppe</label>
|
||||||
<textarea type="text" class="form-control" id="beschreibung" th:name="beschreibung">
|
<textarea th:name="beschreibung" class="form-control" id="beschreibung" rows="3"></textarea>
|
||||||
|
|
||||||
</textarea>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<button type="submit">Erstellen</button>
|
<button class="btn btn-primary" type="submit" style="background: #52a1eb; border-style: none">Erstellen</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@ -30,9 +30,12 @@
|
|||||||
<form action="/" method="get">
|
<form action="/" method="get">
|
||||||
<div th:each="gruppe: ${gruppen}">
|
<div th:each="gruppe: ${gruppen}">
|
||||||
<div style="border: 10px solid aliceblue; background: aliceblue">
|
<div style="border: 10px solid aliceblue; background: aliceblue">
|
||||||
<h4 th:href="url" style="color: dodgerblue; font-weight: bold" th:text="${gruppe.getTitle()}"></h4>
|
<h3>
|
||||||
|
<a href="url" style="color: dodgerblue; font-weight: bold" th:text="${gruppe.getTitle()}"></a>
|
||||||
|
</h3>
|
||||||
<p th:text="${gruppe.getDescription()}"></p>
|
<p th:text="${gruppe.getDescription()}"></p>
|
||||||
</div>
|
</div>
|
||||||
|
<br>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -35,16 +35,7 @@
|
|||||||
<label>Suchbegriff:</label>
|
<label>Suchbegriff:</label>
|
||||||
<input class="form-control" type="text" value="" name="suchbegriff" placeholder="z.B. Programmieren, Lerngruppe, ...">
|
<input class="form-control" type="text" value="" name="suchbegriff" placeholder="z.B. Programmieren, Lerngruppe, ...">
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<button type="button" class="btn btn-primary" style="background: #52a1eb; border-style: none">Suchen</button>
|
||||||
<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>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<br>
|
<br>
|
||||||
|
|||||||
@ -37,14 +37,6 @@ public class ControllerTest {
|
|||||||
.that().resideInAPackage("..controller..")
|
.that().resideInAPackage("..controller..")
|
||||||
.should().haveSimpleNameEndingWith("Controller");
|
.should().haveSimpleNameEndingWith("Controller");
|
||||||
|
|
||||||
@ArchTest
|
|
||||||
public static final ArchRule controllerClassesShouldHaveRequestMappingAnnotation = classes()
|
|
||||||
.that().resideInAPackage("..controller..")
|
|
||||||
.and().haveSimpleNameEndingWith("Controller")
|
|
||||||
.and().areAnnotatedWith(Controller.class)
|
|
||||||
.or().areAnnotatedWith(RestController.class)
|
|
||||||
.should().beAnnotatedWith(RequestMapping.class);
|
|
||||||
|
|
||||||
@ArchTest
|
@ArchTest
|
||||||
public static final ArchRule controllerClassesShouldNotDependOnEachOther = noClasses()
|
public static final ArchRule controllerClassesShouldNotDependOnEachOther = noClasses()
|
||||||
.that().haveSimpleNameEndingWith("Controller")
|
.that().haveSimpleNameEndingWith("Controller")
|
||||||
|
|||||||
Reference in New Issue
Block a user