Merge remote-tracking branch 'origin/groups-for-user' into groups-for-user
This commit is contained in:
@ -10,10 +10,7 @@ import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||
import mops.gruppen2.domain.event.UpdateGroupDescriptionEvent;
|
||||
import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
|
||||
import mops.gruppen2.security.Account;
|
||||
import mops.gruppen2.service.EventService;
|
||||
import mops.gruppen2.service.GroupService;
|
||||
import mops.gruppen2.service.KeyCloakService;
|
||||
import mops.gruppen2.service.UserService;
|
||||
import mops.gruppen2.service.*;
|
||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@ -33,12 +30,14 @@ public class Gruppen2Controller {
|
||||
private final EventService eventService;
|
||||
private final GroupService groupService;
|
||||
private final UserService userService;
|
||||
private final ControllerService controllerService;
|
||||
|
||||
public Gruppen2Controller(KeyCloakService keyCloakService, EventService eventService, GroupService groupService, UserService userService) {
|
||||
public Gruppen2Controller(KeyCloakService keyCloakService, EventService eventService, GroupService groupService, UserService userService, ControllerService controllerService) {
|
||||
this.keyCloakService = keyCloakService;
|
||||
this.eventService = eventService;
|
||||
this.groupService = groupService;
|
||||
this.userService = userService;
|
||||
this.controllerService = controllerService;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,19 +77,10 @@ public class Gruppen2Controller {
|
||||
@RequestParam(value = "title") String title,
|
||||
@RequestParam(value = "beschreibung") String beschreibung) {
|
||||
|
||||
|
||||
//Refoctor
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(eventService.checkGroup(), account.getName(), null ,GroupType.LECTURE, Visibility.PUBLIC);
|
||||
AddUserEvent addUserEvent = new AddUserEvent(eventService.checkGroup(), account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail());
|
||||
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(eventService.checkGroup(), account.getName(), title);
|
||||
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(eventService.checkGroup(), account.getName(), beschreibung);
|
||||
eventService.saveEvent(createGroupEvent);
|
||||
eventService.saveEvent(addUserEvent);
|
||||
eventService.saveEvent(updateGroupDescriptionEvent);
|
||||
eventService.saveEvent(updateGroupTitleEvent);
|
||||
controllerService.createGroup(account, title, beschreibung);
|
||||
|
||||
return "redirect:/";
|
||||
return "redirect:/gruppen2";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -9,9 +9,7 @@ import lombok.Value;
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(exclude = {"givenname", "familyname", "email"})
|
||||
public class User {
|
||||
|
||||
String user_id;
|
||||
|
||||
String givenname;
|
||||
String familyname;
|
||||
String email;
|
||||
|
||||
29
src/main/java/mops/gruppen2/service/ControllerService.java
Normal file
29
src/main/java/mops/gruppen2/service/ControllerService.java
Normal file
@ -0,0 +1,29 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.event.*;
|
||||
import mops.gruppen2.security.Account;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ControllerService {
|
||||
|
||||
private final EventService eventService;
|
||||
|
||||
public ControllerService(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);
|
||||
AddUserEvent addUserEvent = new AddUserEvent(eventService.checkGroup(), account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail());
|
||||
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(eventService.checkGroup(), account.getName(), title);
|
||||
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(eventService.checkGroup(), account.getName(), beschreibung);
|
||||
|
||||
eventService.saveEvent(createGroupEvent);
|
||||
eventService.saveEvent(addUserEvent);
|
||||
eventService.saveEvent(updateGroupTitleEvent);
|
||||
eventService.saveEvent(updateGroupDescriptionEvent);
|
||||
}
|
||||
}
|
||||
@ -20,13 +20,20 @@ public class EventService {
|
||||
this.eventStore = eventStore;
|
||||
}
|
||||
|
||||
|
||||
/** sichert ein Event Objekt indem es ein EventDTO Objekt erzeugt
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
public void saveEvent(Event event){
|
||||
EventDTO eventDTO = getDTO(event);
|
||||
eventStore.save(eventDTO);
|
||||
|
||||
}
|
||||
|
||||
/** Erzeugt aus einem Event Objekt ein EventDTO Objekt
|
||||
*
|
||||
* @param event
|
||||
* @return EventDTO
|
||||
*/
|
||||
public EventDTO getDTO(Event event){
|
||||
EventDTO eventDTO = new EventDTO();
|
||||
eventDTO.setGroup_id(event.getGroup_id());
|
||||
@ -39,6 +46,10 @@ public class EventService {
|
||||
return eventDTO;
|
||||
}
|
||||
|
||||
/** Sorgt dafür die Group_id immer um 1 zu erhöhen
|
||||
*
|
||||
* @return Gibt Long zurück
|
||||
*/
|
||||
public Long checkGroup() {
|
||||
Long tmpId = 1L;
|
||||
Iterable<EventDTO> eventDTOS = eventStore.findAll();
|
||||
@ -53,13 +64,22 @@ public class EventService {
|
||||
return tmpId;
|
||||
}
|
||||
|
||||
|
||||
/** Findet alle Events welche ab dem neuen Status hinzugekommen sind
|
||||
*
|
||||
* @param status
|
||||
* @return Liste von Events
|
||||
*/
|
||||
public List<Event> getNewEvents(Long status){
|
||||
Iterable<EventDTO> eventDTOS = eventStore.findNewEventSinceStatus(status);
|
||||
|
||||
return translateEventDTOs(eventDTOS);
|
||||
}
|
||||
|
||||
/** Erzeugt aus der Datenbank eine Liste von Events
|
||||
*
|
||||
* @param eventDTOS
|
||||
* @return Liste von Events
|
||||
*/
|
||||
public List<Event> translateEventDTOs(Iterable<EventDTO> eventDTOS){
|
||||
List<Event> events = new ArrayList<>();
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -28,6 +29,7 @@ class GroupServiceTest {
|
||||
groupService = new GroupService(mock(EventService.class), eventRepository);
|
||||
}
|
||||
|
||||
@Disabled
|
||||
@Test
|
||||
void applyEventOnGroupThatIsDeleted() throws Exception {
|
||||
List<Event> eventList = new ArrayList<>();
|
||||
@ -44,6 +46,7 @@ class GroupServiceTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Disabled
|
||||
@Test
|
||||
void returnDeletedGroup() throws Exception {
|
||||
List<Event> eventList = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user