Merge branch 'groups-for-user' of https://github.com/hhu-propra2/abschlussprojekt-it-bois into groups-for-user
This commit is contained in:
@ -17,10 +17,4 @@ public class Gruppen2Config {
|
|||||||
GroupService groupService;
|
GroupService groupService;
|
||||||
@Autowired
|
@Autowired
|
||||||
EventService eventService;
|
EventService eventService;
|
||||||
|
|
||||||
@Bean
|
|
||||||
public List<Group> groups() throws EventException {
|
|
||||||
return groupService.projectEventList(eventService.findAllEvents());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
44
src/main/java/mops/gruppen2/controller/APIController.java
Normal file
44
src/main/java/mops/gruppen2/controller/APIController.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
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.event.Event;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ein Beispiel für eine API mit Swagger.
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/gruppen2")
|
||||||
|
public class APIController {
|
||||||
|
|
||||||
|
private final SerializationService serializationService;
|
||||||
|
private final EventService eventService;
|
||||||
|
private final GroupService groupService;
|
||||||
|
|
||||||
|
public APIController(SerializationService serializationService, EventService eventService, GroupService groupService) {
|
||||||
|
this.serializationService = serializationService;
|
||||||
|
this.eventService = eventService;
|
||||||
|
this.groupService = groupService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 {
|
||||||
|
List<Event> events = eventService.getNewEvents(status);
|
||||||
|
return groupService.projectEventList(events);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,54 +0,0 @@
|
|||||||
package mops.gruppen2.controller;
|
|
||||||
|
|
||||||
|
|
||||||
import com.github.javafaker.Faker;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import io.swagger.annotations.ApiParam;
|
|
||||||
import mops.gruppen2.domain.ProductSwaggerExample;
|
|
||||||
import mops.gruppen2.service.SerializationService;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ein Beispiel für eine API mit Swagger.
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/products")
|
|
||||||
public class SwaggerAPIController {
|
|
||||||
|
|
||||||
private final Faker faker = new Faker();
|
|
||||||
private final List<ProductSwaggerExample> products = new ArrayList<>();
|
|
||||||
private final SerializationService serializationService;
|
|
||||||
|
|
||||||
public SwaggerAPIController(SerializationService serializationService) {
|
|
||||||
this.serializationService = serializationService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/get/all")
|
|
||||||
@ApiOperation(value = "Erzeugt eine Liste mit allen gespeicherten Produkten")
|
|
||||||
public List<ProductSwaggerExample> getProducts() {
|
|
||||||
return products;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/get/{index}")
|
|
||||||
public ProductSwaggerExample getProduct(@ApiParam("Produkt Index") @PathVariable int index) {
|
|
||||||
return products.get(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/save")
|
|
||||||
public String saveProduct(@RequestBody ProductSwaggerExample product) {
|
|
||||||
products.add(product);
|
|
||||||
|
|
||||||
return "Product saved successfully";
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/random")
|
|
||||||
public String saveRandomProduct() {
|
|
||||||
products.add(new ProductSwaggerExample(faker.food().ingredient(), "Empty"));
|
|
||||||
|
|
||||||
return "Product saved successfully";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package mops.gruppen2.repository;
|
package mops.gruppen2.repository;
|
||||||
|
|
||||||
import mops.gruppen2.domain.EventDTO;
|
import mops.gruppen2.domain.EventDTO;
|
||||||
|
import mops.gruppen2.domain.event.Event;
|
||||||
import org.springframework.data.jdbc.repository.query.Query;
|
import org.springframework.data.jdbc.repository.query.Query;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
@ -15,4 +16,6 @@ public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
|||||||
|
|
||||||
@Query("select * where group_id =:id")
|
@Query("select * 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 > ?#{[0]}")
|
||||||
|
public Iterable<EventDTO> findNewEventSinceStatus(@Param("status") Long status);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||||||
import mops.gruppen2.domain.EventDTO;
|
import mops.gruppen2.domain.EventDTO;
|
||||||
import mops.gruppen2.domain.event.Event;
|
import mops.gruppen2.domain.event.Event;
|
||||||
import mops.gruppen2.repository.EventRepository;
|
import mops.gruppen2.repository.EventRepository;
|
||||||
|
import org.bouncycastle.jcajce.provider.asymmetric.ec.KeyFactorySpi;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -52,16 +53,24 @@ public class EventService {
|
|||||||
return tmpId;
|
return tmpId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Event> findAllEvents() {
|
|
||||||
Iterable<EventDTO> eventDTOS = eventStore.findAll();
|
public List<Event> getNewEvents(Long status){
|
||||||
|
Iterable<EventDTO> eventDTOS = eventStore.findNewEventSinceStatus(status);
|
||||||
|
|
||||||
|
return translateEventDTOs(eventDTOS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Event> translateEventDTOs(Iterable<EventDTO> eventDTOS){
|
||||||
List<Event> events = new ArrayList<>();
|
List<Event> events = new ArrayList<>();
|
||||||
eventDTOS.forEach(eventDTO -> {
|
|
||||||
|
for (EventDTO eventDTO : eventDTOS) {
|
||||||
try {
|
try {
|
||||||
events.add(serializationService.deserializeEvent(eventDTO.getEvent_payload()));
|
events.add(serializationService.deserializeEvent(eventDTO.getEvent_payload()));
|
||||||
|
|
||||||
}catch (JsonProcessingException e) {
|
}catch (JsonProcessingException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user