Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added method that checks if user is participating in event #8

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}