finish controller refactoring
This commit is contained in:
@ -4,6 +4,7 @@ package mops.gruppen2.controller;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import mops.gruppen2.aspect.annotation.TraceMethodCalls;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.api.GroupRequestWrapper;
|
||||
@ -24,6 +25,7 @@ import java.util.UUID;
|
||||
* Api zum Datenabgleich.
|
||||
*/
|
||||
@Log4j2
|
||||
@TraceMethodCalls
|
||||
@RestController
|
||||
@RequestMapping("/gruppen2/api")
|
||||
public class APIController {
|
||||
@ -48,8 +50,6 @@ public class APIController {
|
||||
public GroupRequestWrapper update(@ApiParam("Letzte gespeicherte EventId des Anfragestellers")
|
||||
@PathVariable("id") long eventId) {
|
||||
|
||||
log.info("ApiRequest to /updateGroups (Event-ID: {})\n", eventId);
|
||||
|
||||
return APIService.wrap(eventStoreService.findMaxEventId(),
|
||||
projectionService.projectNewGroups(eventId));
|
||||
}
|
||||
@ -63,8 +63,6 @@ public class APIController {
|
||||
public List<String> usergroups(@ApiParam("Nutzer-Id")
|
||||
@PathVariable("id") String userId) {
|
||||
|
||||
log.info("ApiRequest to /getGroupIdsOfUser (Nutzer-ID: {})\n", userId);
|
||||
|
||||
return IdService.uuidsToString(eventStoreService.findExistingUserGroups(new User(userId)));
|
||||
}
|
||||
|
||||
@ -77,8 +75,6 @@ public class APIController {
|
||||
public Group getGroupById(@ApiParam("Gruppen-Id der gefordeten Gruppe")
|
||||
@PathVariable("id") String groupId) {
|
||||
|
||||
log.info("ApiRequest to /getGroup (Gruppen-ID: {})\n", groupId);
|
||||
|
||||
return projectionService.projectSingleGroup(UUID.fromString(groupId));
|
||||
}
|
||||
|
||||
|
@ -128,6 +128,7 @@ public class GroupDetailsController {
|
||||
|
||||
User user = new User(token);
|
||||
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
||||
|
||||
ValidationService.throwIfNoAdmin(group, user);
|
||||
|
||||
model.addAttribute("group", group);
|
||||
@ -162,6 +163,7 @@ public class GroupDetailsController {
|
||||
|
||||
User user = new User(token);
|
||||
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
||||
|
||||
ValidationService.throwIfNoAdmin(group, user);
|
||||
|
||||
model.addAttribute("group", group);
|
||||
@ -213,6 +215,7 @@ public class GroupDetailsController {
|
||||
|
||||
User user = new User(token);
|
||||
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
||||
|
||||
ValidationService.throwIfNoAdmin(group, user);
|
||||
|
||||
groupService.toggleMemberRole(new User(userId), group);
|
||||
@ -236,7 +239,9 @@ public class GroupDetailsController {
|
||||
User user = new User(token);
|
||||
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
||||
|
||||
// Der eingeloggte User kann sich nicht selbst entfernen
|
||||
ValidationService.throwIfNoAdmin(group, user);
|
||||
|
||||
// Der eingeloggte User kann sich nicht selbst entfernen (er kann aber verlassen)
|
||||
if (!userId.equals(user.getId())) {
|
||||
groupService.deleteUser(new User(userId), group);
|
||||
}
|
||||
|
@ -23,12 +23,12 @@ public class UpdateGroupDescriptionEvent extends Event {
|
||||
|
||||
public UpdateGroupDescriptionEvent(UUID groupId, String userId, String newGroupDescription) {
|
||||
super(groupId, userId);
|
||||
this.newGroupDescription = newGroupDescription.trim();
|
||||
this.newGroupDescription = newGroupDescription;
|
||||
}
|
||||
|
||||
public UpdateGroupDescriptionEvent(Group group, User user, String newGroupDescription) {
|
||||
super(group.getId(), user.getId());
|
||||
this.newGroupDescription = newGroupDescription.trim();
|
||||
this.newGroupDescription = newGroupDescription;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,12 +23,12 @@ public class UpdateGroupTitleEvent extends Event {
|
||||
|
||||
public UpdateGroupTitleEvent(UUID groupId, String userId, String newGroupTitle) {
|
||||
super(groupId, userId);
|
||||
this.newGroupTitle = newGroupTitle.trim();
|
||||
this.newGroupTitle = newGroupTitle;
|
||||
}
|
||||
|
||||
public UpdateGroupTitleEvent(Group group, User user, String newGroupTitle) {
|
||||
super(group.getId(), user.getId());
|
||||
this.newGroupTitle = newGroupTitle.trim();
|
||||
this.newGroupTitle = newGroupTitle;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -82,6 +82,7 @@ public class GroupService {
|
||||
* Fügt eine Liste von Usern zu einer Gruppe hinzu.
|
||||
* Duplikate werden übersprungen, die erzeugten Events werden gespeichert.
|
||||
* Dabei wird das Teilnehmermaximum eventuell angehoben.
|
||||
* Prüft, ob der User Admin ist.
|
||||
*
|
||||
* @param newUsers Userliste
|
||||
* @param group Gruppe
|
||||
@ -109,6 +110,7 @@ public class GroupService {
|
||||
|
||||
/**
|
||||
* Wechselt die Rolle eines Teilnehmers von Admin zu Member oder andersherum.
|
||||
* Überprüft, ob der User Mitglied ist und ob er der letzte Admin ist.
|
||||
*
|
||||
* @param user Teilnehmer, welcher geändert wird
|
||||
* @param group Gruppe, in welcher sih der Teilnehmer befindet
|
||||
@ -145,6 +147,10 @@ public class GroupService {
|
||||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt, speichert ein AddUserEvent und wendet es auf eine Gruppe an.
|
||||
* Prüft, ob der Nutzer schon Mitglied ist und ob Gruppe voll ist.
|
||||
*/
|
||||
public void addUser(User user, Group group) {
|
||||
ValidationService.throwIfMember(group, user);
|
||||
ValidationService.throwIfGroupFull(group);
|
||||
@ -166,6 +172,10 @@ public class GroupService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt, speichert ein DeleteUserEvent und wendet es auf eine Gruppe an.
|
||||
* Prüft, ob der Nutzer Mitglied ist und ob er der letzte Admin ist.
|
||||
*/
|
||||
public void deleteUser(User user, Group group) throws EventException {
|
||||
ValidationService.throwIfNoMember(group, user);
|
||||
ValidationService.throwIfLastAdmin(user, group);
|
||||
@ -180,6 +190,10 @@ public class GroupService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt, speichert ein DeleteGroupEvent und wendet es auf eine Gruppe an.
|
||||
* Prüft, ob der Nutzer Admin ist.
|
||||
*/
|
||||
public void deleteGroup(User user, Group group) {
|
||||
ValidationService.throwIfNoAdmin(group, user);
|
||||
|
||||
@ -190,35 +204,67 @@ public class GroupService {
|
||||
eventStoreService.saveEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt, speichert ein UpdateTitleEvent und wendet es auf eine Gruppe an.
|
||||
* Prüft, ob der Nutzer Admin ist und ob der Titel valide ist.
|
||||
* Bei keiner Änderung wird nichts erzeugt.
|
||||
*/
|
||||
public void updateTitle(User user, Group group, String title) {
|
||||
ValidationService.throwIfNoAdmin(group, user);
|
||||
ValidationService.validateTitle(title);
|
||||
ValidationService.validateTitle(title.trim());
|
||||
|
||||
Event event = new UpdateGroupTitleEvent(group, user, title);
|
||||
if (title.trim().equals(group.getTitle())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Event event = new UpdateGroupTitleEvent(group, user, title.trim());
|
||||
event.apply(group);
|
||||
|
||||
eventStoreService.saveEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt, speichert ein UpdateDescriptiopnEvent und wendet es auf eine Gruppe an.
|
||||
* Prüft, ob der Nutzer Admin ist und ob die Beschreibung valide ist.
|
||||
* Bei keiner Änderung wird nichts erzeugt.
|
||||
*/
|
||||
public void updateDescription(User user, Group group, String description) {
|
||||
ValidationService.throwIfNoAdmin(group, user);
|
||||
ValidationService.validateDescription(description);
|
||||
ValidationService.validateDescription(description.trim());
|
||||
|
||||
Event event = new UpdateGroupDescriptionEvent(group, user, description);
|
||||
if (description.trim().equals(group.getDescription())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Event event = new UpdateGroupDescriptionEvent(group, user, description.trim());
|
||||
event.apply(group);
|
||||
|
||||
eventStoreService.saveEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt, speichert ein UpdateRoleEvent und wendet es auf eine Gruppe an.
|
||||
* Prüft, ob der Nutzer Mitglied ist.
|
||||
* Bei keiner Änderung wird nichts erzeugt.
|
||||
*/
|
||||
private void updateRole(User user, Group group, Role role) {
|
||||
ValidationService.throwIfNoMember(group, user);
|
||||
|
||||
if (role == group.getRoles().get(user.getId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Event event = new UpdateRoleEvent(group, user, role);
|
||||
event.apply(group);
|
||||
|
||||
eventStoreService.saveEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt, speichert ein UpdateUserLimitEvent und wendet es auf eine Gruppe an.
|
||||
* Prüft, ob der Nutzer Admin ist und ob das Limit valide ist.
|
||||
* Bei keiner Änderung wird nichts erzeugt.
|
||||
*/
|
||||
public void updateUserLimit(User user, Group group, long userLimit) {
|
||||
ValidationService.throwIfNoAdmin(group, user);
|
||||
ValidationService.validateUserLimit(userLimit, group);
|
||||
|
Reference in New Issue
Block a user