Refactor ControllerService and add an UpdateRoleEvent to createGroup
This commit is contained in:
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -94,4 +94,15 @@ 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user