1

Impletended the updategroup(status) method in the API

This commit is contained in:
LukasEttel
2020-03-12 16:11:32 +01:00
parent 3fcf8105f7
commit 9795c10c14
7 changed files with 46 additions and 27 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,13 +1,17 @@
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.EventService;
import mops.gruppen2.service.GroupService;
import mops.gruppen2.service.SerializationService;
@ -35,9 +39,11 @@ public class APIController {
@GetMapping("/updatedGroups/{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, JsonProcessingException {
List<Event> events = eventService.getNewEvents(status);
return groupService.projectEventList(events);
UpdatedGroupRequestMapper updatedGroupRequestMapper = APIFormatter.wrapp(eventService.getMaxEvent_id(), groupService.projectEventList(events));
return updatedGroupRequestMapper;
}

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

@ -10,9 +10,12 @@ import java.util.List;
@Repository
public interface EventRepository extends CrudRepository<EventDTO, Long> {
@Query("SELECT * FROM event WHERE event_id > @status")
@Query("SELECT * FROM event WHERE event_id > :status")
public Iterable<EventDTO> 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);
@Query("SELECT MAX(event_id) FROM event")
public Long getHighesEvent_ID();
}

View File

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

View File

@ -87,4 +87,8 @@ public class EventService {
return idsOfChangedGroups;
}
public Long getMaxEvent_id(){
return eventStore.getHighesEvent_ID();
}
}

View File

@ -38,26 +38,4 @@ class EventServiceTest {
when(eventRepositoryMock.findAll()).thenReturn(eventDTOS);
assertEquals(eventDTO1.getGroup_id()+1, eventService.checkGroup());
}
@Test
void checkGetAllGroupIdsWithRepeadedId(){
ArrayList<EventDTO> eventDTOS = new ArrayList<>();
EventDTO eventDTO1 = new EventDTO();
eventDTO1.setGroup_id(1L);
eventDTOS.add(eventDTO1);
EventDTO eventDTO2 = new EventDTO();
eventDTO2.setGroup_id(2L);
eventDTOS.add(eventDTO2);
EventDTO eventDTO3 = new EventDTO();
eventDTO3.setGroup_id(1L);
eventDTOS.add(eventDTO3);
List<Long> groupIds = eventService.getAllGroupIds(eventDTOS);
assertThat(groupIds.size()).isEqualTo(2);
}
}