1

Merge pull request #65 from hhu-propra2/updateGroupsAPI

Update groups api
This commit is contained in:
Max Oerter
2020-03-13 13:57:56 +01:00
committed by GitHub
7 changed files with 77 additions and 12 deletions

View File

@ -32,7 +32,7 @@ public class Gruppen2Application {
public Docket productAPI() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.paths(PathSelectors.ant("/products/**"))
.paths(PathSelectors.ant("/gruppen2/**"))
.apis(RequestHandlerSelectors.basePackage("mops.gruppen2"))
.build()
.apiInfo(apiMetadata());

View File

@ -1,19 +1,18 @@
package mops.gruppen2.controller;
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.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;
/**
@ -33,12 +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 List<Group> 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);
return groupService.projectEventList(events);
UpdatedGroupRequestMapper updatedGroupRequestMapper = APIFormatterService.wrapp(eventService.getMaxEvent_id(), groupService.projectEventList(events));
return updatedGroupRequestMapper;
}
@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 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);
}
}

View File

@ -0,0 +1,16 @@
package mops.gruppen2.domain.apiWrapper;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import mops.gruppen2.domain.Group;
import java.util.List;
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class UpdatedGroupRequestMapper {
private Long status;
private List<Group> groupList;
}

View File

@ -1,7 +1,6 @@
package mops.gruppen2.repository;
import mops.gruppen2.domain.EventDTO;
import mops.gruppen2.domain.event.Event;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
@ -16,6 +15,13 @@ 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 > ?#{[0]}")
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 List<EventDTO> findAllEventsOfGroups(@Param("groupIds") List<Long> groupIds);
@Query("SELECT MAX(event_id) FROM event")
public Long getHighesEvent_ID();
}

View File

@ -0,0 +1,14 @@
package mops.gruppen2.service;
import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.apiWrapper.UpdatedGroupRequestMapper;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class APIFormatterService {
static public UpdatedGroupRequestMapper wrapp(Long status, List<Group> groupList){
return new UpdatedGroupRequestMapper(status, groupList);
}
}

View File

@ -70,9 +70,10 @@ public class EventService {
* @return Liste von Events
*/
public List<Event> getNewEvents(Long status){
Iterable<EventDTO> eventDTOS = eventStore.findNewEventSinceStatus(status);
List<Long> groupIdsThatChanged = eventStore.findNewEventSinceStatus(status);
return translateEventDTOs(eventDTOS);
List<EventDTO> groupEventDTOS = eventStore.findAllEventsOfGroups(groupIdsThatChanged);
return translateEventDTOs(groupEventDTOS);
}
/** Erzeugt aus der Datenbank eine Liste von Events
@ -105,4 +106,17 @@ public class EventService {
}
}
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);
}
}

View File

@ -10,6 +10,7 @@ import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;