Skip to content

Commit

Permalink
added method that checks if user is participating in event
Browse files Browse the repository at this point in the history
  • Loading branch information
Teller501 committed Dec 4, 2023
1 parent dba2099 commit aac4469
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dk.kea.onav2ndproject_rest.api;

import dk.kea.onav2ndproject_rest.dto.EventDTO;
import dk.kea.onav2ndproject_rest.dto.UserDTO;
import dk.kea.onav2ndproject_rest.entity.User;
import dk.kea.onav2ndproject_rest.service.UserEventDetailsService;
Expand Down Expand Up @@ -27,4 +28,9 @@ public ResponseEntity<List<String>> getAdditionalNotesByUserIdAndEventId(@PathVa
return new ResponseEntity<>(userEventDetailService.getAdditionalNotesByUserIdAndEventId(userId, eventId), HttpStatus.OK);
}

@GetMapping("/participating/{userId}/{eventId}")
public ResponseEntity<Boolean> isUserParticipatingInEvent(@PathVariable int userId, @PathVariable int eventId) {
return new ResponseEntity<>(userEventDetailService.isUserParticipatingInEvent(userId, eventId), HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dk.kea.onav2ndproject_rest.repository;

import dk.kea.onav2ndproject_rest.entity.Event;
import dk.kea.onav2ndproject_rest.entity.User;
import dk.kea.onav2ndproject_rest.entity.UserEventDetails;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -17,5 +18,7 @@ public interface UserEventDetailsRepository extends JpaRepository<UserEventDetai
List<String> findAdditionalNotesByUserIdAndEventId(@Param("userId") int userId, @Param("eventId") int eventId);

Optional<UserEventDetails> findByEventIdAndUserId(Integer eventId, Long userId);
@Query("SELECT CASE WHEN COUNT(ued) > 0 THEN true ELSE false END FROM UserEventDetails ued WHERE ued.user.id = :userId AND ued.event.id = :eventId AND ued.participating = true")
boolean isUserParticipatingInEvent(int userId, int eventId);
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package dk.kea.onav2ndproject_rest.service;

import dk.kea.onav2ndproject_rest.dto.EventConverter;
import dk.kea.onav2ndproject_rest.dto.EventDTO;
import dk.kea.onav2ndproject_rest.dto.UserConverter;
import dk.kea.onav2ndproject_rest.dto.UserDTO;
import dk.kea.onav2ndproject_rest.entity.Event;
import dk.kea.onav2ndproject_rest.entity.User;
import dk.kea.onav2ndproject_rest.repository.UserEventDetailsRepository;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -16,6 +19,8 @@ public class UserEventDetailsService {
UserEventDetailsRepository userEventDetailsRepository;
@Autowired
UserConverter userConverter;
@Autowired
EventConverter eventConverter;

public List<UserDTO> getParticipatingUsersByEventId(int eventId) {
List<User> users = userEventDetailsRepository.findParticipatingUsersByEventId(eventId);
Expand All @@ -25,4 +30,8 @@ public List<UserDTO> getParticipatingUsersByEventId(int eventId) {
public List<String> getAdditionalNotesByUserIdAndEventId(int userId, int eventId) {
return userEventDetailsRepository.findAdditionalNotesByUserIdAndEventId(userId, eventId);
}

public boolean isUserParticipatingInEvent(int userId, int eventId) {
return userEventDetailsRepository.isUserParticipatingInEvent(userId, eventId);
}
}

0 comments on commit aac4469

Please sign in to comment.