From 609c0353d0f85015eb3582c774bfc3d1fa147aa4 Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Mon, 31 Jan 2022 20:52:30 +0100 Subject: [PATCH] Check isFullDay --- .../vpr/server/controller/EventController.java | 16 ++++++++++++++++ .../server/repository/UserEventRepository.java | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-) 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); }