@ -22,10 +22,9 @@ import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Ein Beispiel für eine API mit Swagger.
|
||||
* Api zum Datenabgleich mit Gruppenfindung.
|
||||
*/
|
||||
//TODO: Testing
|
||||
//TODO: API-Service
|
||||
//TODO: API-Service?
|
||||
@RestController
|
||||
@RequestMapping("/gruppen2/api")
|
||||
public class APIController {
|
||||
@ -40,20 +39,20 @@ public class APIController {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@GetMapping("/updateGroups/{status}")
|
||||
@GetMapping("/updateGroups/{lastEventId}")
|
||||
@Secured("ROLE_api_user")
|
||||
@ApiOperation("Gibt alle Gruppen zurück, in denen sich etwas geändert hat")
|
||||
public GroupRequestWrapper updateGroup(@ApiParam("Letzter Status des Anfragestellers") @PathVariable Long status) throws EventException {
|
||||
List<Event> events = eventService.getNewEvents(status);
|
||||
public GroupRequestWrapper updateGroups(@ApiParam("Letzter Status des Anfragestellers") @PathVariable Long lastEventId) throws EventException {
|
||||
List<Event> events = eventService.getNewEvents(lastEventId);
|
||||
|
||||
return APIFormatterService.wrap(eventService.getMaxEventId(), groupService.projectEventList(events));
|
||||
}
|
||||
|
||||
@GetMapping("/getGroupIdsOfUser/{teilnehmer}")
|
||||
@GetMapping("/getGroupIdsOfUser/{userId}")
|
||||
@Secured("ROLE_api_user")
|
||||
@ApiOperation("Gibt alle Gruppen zurück, in denen sich ein Teilnehmer befindet")
|
||||
public List<String> getGroupsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String teilnehmer) {
|
||||
return userService.getUserGroups(teilnehmer).stream()
|
||||
public List<String> getGroupIdsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String userId) {
|
||||
return userService.getUserGroups(userId).stream()
|
||||
.map(group -> group.getId().toString())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
@ -61,10 +60,14 @@ public class APIController {
|
||||
@GetMapping("/getGroup/{groupId}")
|
||||
@Secured("ROLE_api_user")
|
||||
@ApiOperation("Gibt die Gruppe mit der als Parameter mitgegebenden groupId zurück")
|
||||
public Group getGroupFromId(@ApiParam("GruppenId der gefordeten Gruppe") @PathVariable String groupId) throws EventException {
|
||||
public Group getGroupById(@ApiParam("GruppenId der gefordeten Gruppe") @PathVariable String groupId) throws EventException {
|
||||
List<Event> eventList = eventService.getEventsOfGroup(UUID.fromString(groupId));
|
||||
List<Group> groups = groupService.projectEventList(eventList);
|
||||
|
||||
if (groups.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return groups.get(0);
|
||||
}
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ public final class APIFormatterService {
|
||||
|
||||
private APIFormatterService() {}
|
||||
|
||||
public static GroupRequestWrapper wrap(Long status, List<Group> groupList) {
|
||||
public static GroupRequestWrapper wrap(long status, List<Group> groupList) {
|
||||
return new GroupRequestWrapper(status, groupList);
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,11 +18,9 @@ import java.util.stream.Collectors;
|
||||
public class EventService {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(EventService.class);
|
||||
private final JsonService jsonService;
|
||||
private final EventRepository eventStore;
|
||||
|
||||
public EventService(JsonService jsonService, EventRepository eventStore) {
|
||||
this.jsonService = jsonService;
|
||||
public EventService(EventRepository eventStore) {
|
||||
this.eventStore = eventStore;
|
||||
}
|
||||
|
||||
@ -121,8 +119,16 @@ public class EventService {
|
||||
return events;
|
||||
}
|
||||
|
||||
public Long getMaxEventId() {
|
||||
return eventStore.getHighesEventID();
|
||||
public long getMaxEventId() {
|
||||
long highestEvent = 0;
|
||||
|
||||
try {
|
||||
highestEvent = eventStore.getHighesEventID();
|
||||
} catch (NullPointerException e) {
|
||||
LOG.debug("Eine maxId von 0 wurde zurückgegeben, da keine Events vorhanden sind.");
|
||||
}
|
||||
|
||||
return highestEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -25,7 +25,7 @@ public class UserService {
|
||||
|
||||
@Cacheable("groups")
|
||||
public List<Group> getUserGroups(String userId) throws EventException {
|
||||
return getUserGroups(new User(userId, null, null, null));
|
||||
return getUserGroups(new User(userId, "", "", ""));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -35,6 +35,7 @@ public class UserService {
|
||||
*
|
||||
* @return Liste aus Gruppen
|
||||
*/
|
||||
//TODO: Nur AddUserEvents + DeleteUserEvents betrachten
|
||||
@Cacheable("groups")
|
||||
public List<Group> getUserGroups(User user) {
|
||||
List<UUID> groupIds = eventService.findGroupIdsByUser(user.getId());
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
insert into event values
|
||||
(1,'8c15f614-fe04-4ac4-a2d7-d13e62ba8597','orga','CreateGroupEvent','{"type":"CreateGroupEvent","groupId":"8c15f614-fe04-4ac4-a2d7-d13e62ba8597","userId":"orga","groupVisibility":"PUBLIC","groupParent":null,"groupType":"SIMPLE","groupUserMaximum":2}'),
|
||||
(2,'8c15f614-fe04-4ac4-a2d7-d13e62ba8597','orga','AddUserEvent','{"type":"AddUserEvent","groupId":"8c15f614-fe04-4ac4-a2d7-d13e62ba8597","userId":"orga","givenname":"orga","familyname":"orga","email":"blorga@orga.org"}'),
|
||||
(3,'8c15f614-fe04-4ac4-a2d7-d13e62ba8597','orga','UpdateGroupTitleEvent','{"type":"UpdateGroupTitleEvent","groupId":"8c15f614-fe04-4ac4-a2d7-d13e62ba8597","userId":"orga","newGroupTitle":"sdsad"}'),
|
||||
(4,'8c15f614-fe04-4ac4-a2d7-d13e62ba8597','orga','UpdateGroupDescriptionEvent','{"type":"UpdateGroupDescriptionEvent","groupId":"8c15f614-fe04-4ac4-a2d7-d13e62ba8597","userId":"orga","newGroupDescription":"sadsad"}'),
|
||||
(5,'8c15f614-fe04-4ac4-a2d7-d13e62ba8597','orga','UpdateRoleEvent','{"type":"UpdateRoleEvent","groupId":"8c15f614-fe04-4ac4-a2d7-d13e62ba8597","userId":"orga","newRole":"ADMIN"}');
|
||||
Reference in New Issue
Block a user