Impletended SwaggerApi with all provisionally funktiontionallitys
This commit is contained in:
@ -1,23 +1,18 @@
|
|||||||
package mops.gruppen2.controller;
|
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.ApiOperation;
|
||||||
import io.swagger.annotations.ApiParam;
|
import io.swagger.annotations.ApiParam;
|
||||||
import mops.gruppen2.domain.Exceptions.EventException;
|
import mops.gruppen2.domain.Exceptions.EventException;
|
||||||
import mops.gruppen2.domain.Group;
|
import mops.gruppen2.domain.Group;
|
||||||
import mops.gruppen2.domain.ProductSwaggerExample;
|
|
||||||
import mops.gruppen2.domain.apiWrapper.UpdatedGroupRequestMapper;
|
import mops.gruppen2.domain.apiWrapper.UpdatedGroupRequestMapper;
|
||||||
import mops.gruppen2.domain.event.Event;
|
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.EventService;
|
||||||
import mops.gruppen2.service.GroupService;
|
import mops.gruppen2.service.GroupService;
|
||||||
import mops.gruppen2.service.SerializationService;
|
import mops.gruppen2.service.SerializationService;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,22 +32,27 @@ public class APIController {
|
|||||||
this.groupService = groupService;
|
this.groupService = groupService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/updatedGroups/{status}")
|
@GetMapping("/updateGroups/{status}")
|
||||||
@ApiOperation(value = "Gibt alle Gruppen zurück in denen sich etwas geändert hat")
|
@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 {
|
public UpdatedGroupRequestMapper updateGroup(@ApiParam("Status des Anfragestellers") @PathVariable Long status) throws EventException {
|
||||||
List<Event> events = eventService.getNewEvents(status);
|
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;
|
return updatedGroupRequestMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/getGroups/{teilnehme}")
|
@GetMapping("/getGroupIdsOfUser/{teilnehmer}")
|
||||||
@ApiOperation(value = "Gibt alle Gruppen zurück in denen sich ein Teilnehmer befindet")
|
@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 {
|
public List<Long> getGroupsOfUser(@ApiParam("Der Teilnehmer") @PathVariable String teilnehmer) throws EventException {
|
||||||
List<Long> asd = new ArrayList<>();
|
return eventService.getGroupsOfUser(teilnehmer);
|
||||||
|
|
||||||
return asd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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")
|
@Query("select * from event where group_id =:id")
|
||||||
List<EventDTO> findEventDTOByGroup_id(@Param("id") Long group_id);
|
List<EventDTO> findEventDTOByGroup_id(@Param("id") Long group_id);
|
||||||
|
|
||||||
@Query("SELECT * FROM event WHERE event_id > :status")
|
@Query("SELECT DISTINCT group_id FROM event WHERE event_id > :status")
|
||||||
public Iterable<EventDTO> findNewEventSinceStatus(@Param("status") Long status);
|
public List<Long> findNewEventSinceStatus(@Param("status") Long status);
|
||||||
|
|
||||||
@Query("SELECT * FROM event WHERE group_id IN (:groupIds) ")
|
@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")
|
@Query("SELECT MAX(event_id) FROM event")
|
||||||
public Long getHighesEvent_ID();
|
public Long getHighesEvent_ID();
|
||||||
|
|||||||
@ -2,10 +2,12 @@ package mops.gruppen2.service;
|
|||||||
|
|
||||||
import mops.gruppen2.domain.Group;
|
import mops.gruppen2.domain.Group;
|
||||||
import mops.gruppen2.domain.apiWrapper.UpdatedGroupRequestMapper;
|
import mops.gruppen2.domain.apiWrapper.UpdatedGroupRequestMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class APIFormatter {
|
@Service
|
||||||
|
public class APIFormatterService {
|
||||||
static public UpdatedGroupRequestMapper wrapp(Long status, List<Group> groupList){
|
static public UpdatedGroupRequestMapper wrapp(Long status, List<Group> groupList){
|
||||||
return new UpdatedGroupRequestMapper(status, groupList);
|
return new UpdatedGroupRequestMapper(status, groupList);
|
||||||
}
|
}
|
||||||
@ -70,10 +70,9 @@ public class EventService {
|
|||||||
* @return Liste von Events
|
* @return Liste von Events
|
||||||
*/
|
*/
|
||||||
public List<Event> getNewEvents(Long status){
|
public List<Event> getNewEvents(Long status){
|
||||||
Iterable<EventDTO> newEventDTOS = eventStore.findNewEventSinceStatus(status);
|
List<Long> groupIdsThatChanged = eventStore.findNewEventSinceStatus(status);
|
||||||
List<Long> groupIdsThatChanged = this.getAllGroupIds(newEventDTOS);
|
|
||||||
|
|
||||||
Iterable<EventDTO> groupEventDTOS = eventStore.findAllEventsOfGroups(groupIdsThatChanged);
|
List<EventDTO> groupEventDTOS = eventStore.findAllEventsOfGroups(groupIdsThatChanged);
|
||||||
return translateEventDTOs(groupEventDTOS);
|
return translateEventDTOs(groupEventDTOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,19 +95,17 @@ public class EventService {
|
|||||||
return events;
|
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(){
|
public Long getMaxEvent_id(){
|
||||||
return eventStore.getHighesEvent_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