diff --git a/server/src/main/java/com/vpr/server/controller/EventController.java b/server/src/main/java/com/vpr/server/controller/EventController.java index 3cc7b29..28cee56 100644 --- a/server/src/main/java/com/vpr/server/controller/EventController.java +++ b/server/src/main/java/com/vpr/server/controller/EventController.java @@ -160,6 +160,22 @@ public class EventController { userEvent.setEvent(event); userEvent.setUser(user); + List userEvents = userEventRepository.findByUserIdAndDate(user.getId(), userEvent.getDate()); + System.out.println(userEvents.size() + ""); + if(event.isFullDay() && userEvents.size() > 0){ + return new ResponseEntity<>("Es gibt bereits Termine am " + userEvent.getDate(), HttpStatus.BAD_REQUEST); + }else{ + for(UserEvent ue : userEvents){ + if(ue.getEvent().isFullDay()){ + return new ResponseEntity<>( + "Der Tag " + userEvent.getDate() + " ist schon mit '" + + ue.getEvent().getName() + "' belegt", + HttpStatus.BAD_REQUEST + ); + } + } + } + eventRepository.save(event); userEventRepository.save(userEvent); }catch (IllegalArgumentException exception){ diff --git a/server/src/main/java/com/vpr/server/repository/UserEventRepository.java b/server/src/main/java/com/vpr/server/repository/UserEventRepository.java index f34219c..b47fc19 100644 --- a/server/src/main/java/com/vpr/server/repository/UserEventRepository.java +++ b/server/src/main/java/com/vpr/server/repository/UserEventRepository.java @@ -3,9 +3,12 @@ package com.vpr.server.repository; import com.vpr.server.data.UserEvent; import org.springframework.data.repository.CrudRepository; +import java.sql.Date; +import java.util.List; + // This will be AUTO IMPLEMENTED by Spring into a Bean called eventListRepository // CRUD refers Create, Read, Update, Delete public interface UserEventRepository extends CrudRepository { - + List findByUserIdAndDate(long userId, Date date); }