Impletended SwaggerApi with all provisionally funktiontionallitys
This commit is contained in:
@ -1,23 +1,18 @@
|
||||
package mops.gruppen2.controller;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.github.javafaker.Faker;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import mops.gruppen2.domain.Exceptions.EventException;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.ProductSwaggerExample;
|
||||
import mops.gruppen2.domain.apiWrapper.UpdatedGroupRequestMapper;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.service.APIFormatter;
|
||||
import mops.gruppen2.service.APIFormatterService;
|
||||
import mops.gruppen2.service.EventService;
|
||||
import mops.gruppen2.service.GroupService;
|
||||
import mops.gruppen2.service.SerializationService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -37,22 +32,27 @@ public class APIController {
|
||||
this.groupService = groupService;
|
||||
}
|
||||
|
||||
@GetMapping("/updatedGroups/{status}")
|
||||
@GetMapping("/updateGroups/{status}")
|
||||
@ApiOperation(value = "Gibt alle Gruppen zurück in denen sich etwas geändert hat")
|
||||
public UpdatedGroupRequestMapper updateGroup(@ApiParam("Status des Anfragestellers") @PathVariable Long status) throws EventException {
|
||||
List<Event> events = eventService.getNewEvents(status);
|
||||
UpdatedGroupRequestMapper updatedGroupRequestMapper = APIFormatter.wrapp(eventService.getMaxEvent_id(), groupService.projectEventList(events));
|
||||
UpdatedGroupRequestMapper updatedGroupRequestMapper = APIFormatterService.wrapp(eventService.getMaxEvent_id(), groupService.projectEventList(events));
|
||||
|
||||
return updatedGroupRequestMapper;
|
||||
}
|
||||
|
||||
@GetMapping("/getGroups/{teilnehme}")
|
||||
@GetMapping("/getGroupIdsOfUser/{teilnehmer}")
|
||||
@ApiOperation(value = "Gibt alle Gruppen zurück in denen sich ein Teilnehmer befindet")
|
||||
public List<Long> getGroupsOfUser(@ApiParam("Der Teilnehmer") @PathVariable String userId) throws EventException {
|
||||
List<Long> asd = new ArrayList<>();
|
||||
|
||||
return asd;
|
||||
public List<Long> getGroupsOfUser(@ApiParam("Der Teilnehmer") @PathVariable String teilnehmer) throws EventException {
|
||||
return eventService.getGroupsOfUser(teilnehmer);
|
||||
}
|
||||
|
||||
@GetMapping("/getGroup/{groupId}")
|
||||
@ApiOperation(value = "Gibt alle die Gruppe mit der als Parameter mitgegebenden groupId zurück")
|
||||
public Group getGroupFromId(@ApiParam("Die GruppenId der gefordeten Gruppe") @PathVariable Long groupId) throws EventException{
|
||||
List<Event> eventList = eventService.getEventsOfGroup(groupId);
|
||||
|
||||
List<Group> groups = groupService.projectEventList(eventList);
|
||||
return groups.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,11 +16,11 @@ public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
||||
@Query("select * from event where group_id =:id")
|
||||
List<EventDTO> findEventDTOByGroup_id(@Param("id") Long group_id);
|
||||
|
||||
@Query("SELECT * FROM event WHERE event_id > :status")
|
||||
public Iterable<EventDTO> findNewEventSinceStatus(@Param("status") Long status);
|
||||
@Query("SELECT DISTINCT group_id FROM event WHERE event_id > :status")
|
||||
public List<Long> findNewEventSinceStatus(@Param("status") Long status);
|
||||
|
||||
@Query("SELECT * FROM event WHERE group_id IN (:groupIds) ")
|
||||
public Iterable<EventDTO> findAllEventsOfGroups(@Param("groupIds") List<Long> groupIds);
|
||||
public List<EventDTO> findAllEventsOfGroups(@Param("groupIds") List<Long> groupIds);
|
||||
|
||||
@Query("SELECT MAX(event_id) FROM event")
|
||||
public Long getHighesEvent_ID();
|
||||
|
||||
@ -2,10 +2,12 @@ package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.apiWrapper.UpdatedGroupRequestMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class APIFormatter {
|
||||
@Service
|
||||
public class APIFormatterService {
|
||||
static public UpdatedGroupRequestMapper wrapp(Long status, List<Group> groupList){
|
||||
return new UpdatedGroupRequestMapper(status, groupList);
|
||||
}
|
||||
@ -70,10 +70,9 @@ public class EventService {
|
||||
* @return Liste von Events
|
||||
*/
|
||||
public List<Event> getNewEvents(Long status){
|
||||
Iterable<EventDTO> newEventDTOS = eventStore.findNewEventSinceStatus(status);
|
||||
List<Long> groupIdsThatChanged = this.getAllGroupIds(newEventDTOS);
|
||||
List<Long> groupIdsThatChanged = eventStore.findNewEventSinceStatus(status);
|
||||
|
||||
Iterable<EventDTO> groupEventDTOS = eventStore.findAllEventsOfGroups(groupIdsThatChanged);
|
||||
List<EventDTO> groupEventDTOS = eventStore.findAllEventsOfGroups(groupIdsThatChanged);
|
||||
return translateEventDTOs(groupEventDTOS);
|
||||
}
|
||||
|
||||
@ -96,19 +95,17 @@ public class EventService {
|
||||
return events;
|
||||
}
|
||||
|
||||
private List<Long> getAllGroupIds(Iterable<EventDTO> eventDTOS){
|
||||
List<Long> idsOfChangedGroups = new ArrayList<>();
|
||||
for (EventDTO eventDTO : eventDTOS){
|
||||
if (!idsOfChangedGroups.contains(eventDTO.getGroup_id())) {
|
||||
idsOfChangedGroups.add(eventDTO.getGroup_id());
|
||||
|
||||
}
|
||||
}
|
||||
return idsOfChangedGroups;
|
||||
}
|
||||
|
||||
public Long getMaxEvent_id(){
|
||||
return eventStore.getHighesEvent_ID();
|
||||
}
|
||||
|
||||
public List<Long> getGroupsOfUser(String userID) {
|
||||
return eventStore.findGroup_idsWhereUser_id(userID);
|
||||
}
|
||||
|
||||
public List<Event> getEventsOfGroup(Long groupId) {
|
||||
List<EventDTO> eventDTOList = eventStore.findEventDTOByGroup_id(groupId);
|
||||
return translateEventDTOs(eventDTOList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user