Check isFullDay

This commit is contained in:
Marc Beyer 2022-01-31 20:52:30 +01:00
parent 2918bc46b5
commit 609c0353d0
2 changed files with 20 additions and 1 deletions

View File

@ -160,6 +160,22 @@ public class EventController {
userEvent.setEvent(event);
userEvent.setUser(user);
List<UserEvent> 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){

View File

@ -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<UserEvent, Integer> {
List<UserEvent> findByUserIdAndDate(long userId, Date date);
}