diff --git a/src/main/java/com/ODG/ODG_back/controller/MeetingController.java b/src/main/java/com/ODG/ODG_back/controller/MeetingController.java index dc695fc..96fe2e0 100644 --- a/src/main/java/com/ODG/ODG_back/controller/MeetingController.java +++ b/src/main/java/com/ODG/ODG_back/controller/MeetingController.java @@ -4,6 +4,13 @@ import com.ODG.ODG_back.dto.meeting.response.MeetingCreateResponseDto; import com.ODG.ODG_back.dto.meeting.response.MeetingInfoResponseDto; import com.ODG.ODG_back.service.MeetingService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -11,16 +18,55 @@ @RestController @RequestMapping("/meetings") @RequiredArgsConstructor +@Tag(name = "Meeting", description = "모임 관리 API") public class MeetingController { private final MeetingService meetingService; + @Operation( + summary = "새 모임 생성", + description = "새로운 모임을 생성하고 고유한 링크 코드를 발급합니다. " + + "생성된 링크 코드로 참가자들이 모임에 참여할 수 있습니다." + + "인증이 필요하지 않는 공개 API입니다." + ) + @ApiResponses(value = { + @ApiResponse( + responseCode = "200", + description = "모임 생성 성공", + content = @Content(schema = @Schema(implementation = MeetingCreateResponseDto.class)) + ), + @ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content) + }) @PostMapping("/") - public ResponseEntity createMeeting(@RequestBody MeetingCreateRequestDto dto) { + public ResponseEntity createMeeting( + @Parameter( + description = "모임 생성 정보", + required = true, + content = @Content(schema = @Schema(implementation = MeetingCreateRequestDto.class)) + )@RequestBody MeetingCreateRequestDto dto + ) { return ResponseEntity.ok(meetingService.addMeeting(dto)); } + @Operation( + summary = "모임 정보 조회", + description = "링크 코드를 사용하여 모임의 기본 정보를 조회합니다. " + + "모임 제목, 목적 정보를 확인할 수 있습니다. " + + "인증이 필요하지 않는 공개 API입니다." + ) + @ApiResponses(value = { + @ApiResponse( + responseCode = "200", + description = "모임 정보 조회 성공", + content = @Content(schema = @Schema(implementation = MeetingInfoResponseDto.class)) + ), + @ApiResponse(responseCode = "404", description = "존재하지 않는 모임", content = @Content), + @ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content) + }) @GetMapping("/{linkCode}/info") - public ResponseEntity getMeeting(@PathVariable String linkCode) { + public ResponseEntity getMeeting( + @Parameter(description = "모임 링크 코드") + @PathVariable String linkCode + ) { return ResponseEntity.ok(meetingService.getMeeting(linkCode)); } } diff --git a/src/main/java/com/ODG/ODG_back/controller/MidpointController.java b/src/main/java/com/ODG/ODG_back/controller/MidpointController.java index ee28e31..b55f30d 100644 --- a/src/main/java/com/ODG/ODG_back/controller/MidpointController.java +++ b/src/main/java/com/ODG/ODG_back/controller/MidpointController.java @@ -1,8 +1,16 @@ package com.ODG.ODG_back.controller; import com.ODG.ODG_back.dto.midpoint.response.MidpointResponseDto; +import com.ODG.ODG_back.security.jwt.JwtTokenProvider; import com.ODG.ODG_back.service.MidpointService; import com.ODG.ODG_back.strategy.MidpointStrategyType; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -10,14 +18,37 @@ @RestController @RequestMapping("/meetings/{inviteCode}/midpoint") @RequiredArgsConstructor +@Tag(name = "Midpoint", description = "중간 지점 추천 API") public class MidpointController { private final MidpointService midpointService; + private final JwtTokenProvider jwtTokenProvider; + @Operation( + summary = "중간 지점 조회", + description = "모임 참가자들의 위치를 기반으로 중간 지점을 조회합니다. " + + "전략은 쿼리 파라미터로 전달됩니다." + ) + @ApiResponses(value = { + @ApiResponse( + responseCode = "200", + description = "중간 지점 조회 성공", + content = @Content(schema = @Schema(implementation = MidpointResponseDto.class)) + ), + @ApiResponse(responseCode = "403", description = "인증 실패 (토큰 없음 또는 유효하지 않음)", content = @Content), + @ApiResponse(responseCode = "404", description = "존재하지 않는 모임", content = @Content), + @ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content) + }) @GetMapping - public ResponseEntity getRecommendedMidpoints(@PathVariable String inviteCode, - @RequestParam MidpointStrategyType strategyType) { - return ResponseEntity.ok(midpointService.getRecommendedMidpoints(inviteCode, strategyType)); + public ResponseEntity getRecommendedMidpoints( + @Parameter(description = "모임 링크 코드") + @PathVariable String inviteCode, + @Parameter(description = "JWT 토큰 (쿠키에서 자동 추출, 아무 값 입력)") + @CookieValue("access_token") String jwtToken, + @Parameter(description = "전략 타입") + @RequestParam MidpointStrategyType strategyType) { + String userId = jwtTokenProvider.getUserId(jwtToken); + return ResponseEntity.ok(midpointService.getRecommendedMidpoints(inviteCode, strategyType, userId)); } } diff --git a/src/main/java/com/ODG/ODG_back/controller/ParticipantController.java b/src/main/java/com/ODG/ODG_back/controller/ParticipantController.java index ef92129..5e5d06b 100644 --- a/src/main/java/com/ODG/ODG_back/controller/ParticipantController.java +++ b/src/main/java/com/ODG/ODG_back/controller/ParticipantController.java @@ -7,6 +7,13 @@ import com.ODG.ODG_back.security.jwt.JwtCookieUtil; import com.ODG.ODG_back.security.jwt.JwtTokenProvider; import com.ODG.ODG_back.service.ParticipantService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -20,14 +27,35 @@ @RequestMapping("/meetings/{linkCode}/participants") @RequiredArgsConstructor @Slf4j +@Tag(name = "Participant", description = "모임 참가자 관리 API") public class ParticipantController { private final ParticipantService participantService; private final JwtTokenProvider jwtTokenProvider; + @Operation( + summary = "모임 참가자 등록", + description = "모임에 새로운 참가자를 등록하고 JWT 토큰을 쿠키로 설정합니다. " + + "등록 성공 시 access_token 쿠키가 자동으로 브라우저에 저장됩니다. " + + "뿐만 아니라 json으로 access_token을 반환합니다. " + + "인증이 필요한 타 api에선 쿠키에서 access_token을 받으니 유의하십시오. " + + "인증이 필요하지 않는 공개 API입니다." + ) + @ApiResponses(value = { + @ApiResponse( + responseCode = "200", + description = "참가자 등록 성공", + content = @Content(schema = @Schema(implementation = ParticipantRegisterResponseDto.class)) + ), + @ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content), + @ApiResponse(responseCode = "404", description = "존재하지 않는 모임", content = @Content), + @ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content) + }) @PostMapping("/register") public ResponseEntity addParticipant( + @Parameter(description = "모임 링크 코드") @PathVariable String linkCode, + @Parameter(description = "참가자 등록 정보") @RequestBody ParticipantRegisterRequestDto requestDto, HttpServletResponse response ){ @@ -45,9 +73,22 @@ public ResponseEntity addParticipant( return ResponseEntity.ok(responseDto); } + @Operation( + summary = "모임 참가자 삭제", + description = "현재 로그인한 참가자를 모임에서 제거합니다. " + + "쿠키의 JWT 토큰을 사용하여 인증을 수행합니다." + ) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "참가자 삭제 성공"), + @ApiResponse(responseCode = "403", description = "인증 실패 (토큰 없음 또는 유효하지 않음)", content = @Content), + @ApiResponse(responseCode = "404", description = "존재하지 않는 모임 또는 참가자", content = @Content), + @ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content) + }) @DeleteMapping("/delete") public ResponseEntity deleteParticipant( + @Parameter(description = "모임 링크 코드") @PathVariable String linkCode, + @Parameter(description = "JWT 토큰 (쿠키에서 자동 추출, 아무 값 입력)") @CookieValue("access_token") String jwtToken ) { String userId = jwtTokenProvider.getUserId(jwtToken); @@ -55,10 +96,24 @@ public ResponseEntity deleteParticipant( return ResponseEntity.ok().build(); } + @Operation( + summary = "참가자 정보 수정", + description = "현재 로그인한 참가자의 정보를 수정합니다. " + + "쿠키의 JWT 토큰을 사용하여 본인 인증을 수행합니다." + ) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "참가자 정보 수정 성공"), + @ApiResponse(responseCode = "403", description = "인증 실패 (토큰 없음 또는 유효하지 않음)", content = @Content), + @ApiResponse(responseCode = "404", description = "존재하지 않는 모임 또는 참가자", content = @Content), + @ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content) + }) @PutMapping("/update") public ResponseEntity updateParticipant( + @Parameter(description = "모임 링크 코드") @PathVariable String linkCode, + @Parameter(description = "수정할 참가자 정보") @RequestBody ParticipantUpdateRequestDto participantUpdateRequestDto, + @Parameter(description = "JWT 토큰 (쿠키에서 자동 추출, 아무 값 입력)") @CookieValue("access_token") String jwtToken // 쿠키에서 jwt 추출 ){ String userId = jwtTokenProvider.getUserId(jwtToken); @@ -66,9 +121,29 @@ public ResponseEntity updateParticipant( return ResponseEntity.ok().build(); } + @Operation( + summary = "모임 참가자 목록 조회", + description = "특정 모임의 모든 참가자 목록과 투표 상태를 조회합니다. " + ) + @ApiResponses(value = { + @ApiResponse( + responseCode = "200", + description = "참가자 목록 조회 성공", + content = @Content(schema = @Schema(implementation = ParticipantListResponseDto.class)) + ), + @ApiResponse(responseCode = "403", description = "인증 실패 (토큰 없음 또는 유효하지 않음)", content = @Content), + @ApiResponse(responseCode = "404", description = "존재하지 않는 모임", content = @Content), + @ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content) + }) @GetMapping("/") - public ResponseEntity> getParticipants(@PathVariable String linkCode){ - List participants = participantService.getParticipantsWithVoteStatus(linkCode); + public ResponseEntity> getParticipants( + @Parameter(description = "모임 링크 코드") + @PathVariable String linkCode, + @Parameter(description = "JWT 토큰 (쿠키에서 자동 추출, 아무 값 입력)") + @CookieValue("access_token") String jwtToken + ){ + String userId = jwtTokenProvider.getUserId(jwtToken); + List participants = participantService.getParticipantsWithVoteStatus(linkCode, userId); return ResponseEntity.ok(participants); } } diff --git a/src/main/java/com/ODG/ODG_back/controller/PlaceController.java b/src/main/java/com/ODG/ODG_back/controller/PlaceController.java index 217d5ca..71bcad4 100644 --- a/src/main/java/com/ODG/ODG_back/controller/PlaceController.java +++ b/src/main/java/com/ODG/ODG_back/controller/PlaceController.java @@ -1,26 +1,53 @@ package com.ODG.ODG_back.controller; import com.ODG.ODG_back.dto.place.response.PlaceResponseDto; +import com.ODG.ODG_back.security.jwt.JwtTokenProvider; import com.ODG.ODG_back.service.PlaceService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @RestController @RequestMapping("/meetings/{inviteCode}") @RequiredArgsConstructor +@Tag(name = "Place", description = "추천 장소 조회 API") public class PlaceController { private final PlaceService placeService; + private final JwtTokenProvider jwtTokenProvider; + @Operation( + summary = "추천 장소 조회", + description = "모임 중간 지점을 기반으로 추천 장소 목록을 조회합니다. " + ) + @ApiResponses(value = { + @ApiResponse( + responseCode = "200", + description = "추천 장소 조회 성공", + content = @Content(schema = @Schema(implementation = PlaceResponseDto.class)) + ), + @ApiResponse(responseCode = "403", description = "인증 실패 (토큰 없음 또는 유효하지 않음)", content = @Content), + @ApiResponse(responseCode = "404", description = "존재하지 않는 모임 또는 중간지점", content = @Content), + @ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content) + }) @GetMapping("/places") - public ResponseEntity> getPlacesByMidpoint(@PathVariable String inviteCode) { - return ResponseEntity.ok(placeService.getPlacesByMidpoint(inviteCode)); + public ResponseEntity> getPlacesByMidpoint( + @Parameter(description = "모임 초대 코드") + @PathVariable String inviteCode, + @Parameter(description = "JWT 토큰 (쿠키에서 자동 추출, 아무 값 입력)") + @CookieValue("access_token") String jwtToken + ) { + String userId = jwtTokenProvider.getUserId(jwtToken); + return ResponseEntity.ok(placeService.getPlacesByMidpoint(inviteCode, userId)); } } diff --git a/src/main/java/com/ODG/ODG_back/controller/VoteController.java b/src/main/java/com/ODG/ODG_back/controller/VoteController.java index 578fb2f..4428187 100644 --- a/src/main/java/com/ODG/ODG_back/controller/VoteController.java +++ b/src/main/java/com/ODG/ODG_back/controller/VoteController.java @@ -4,6 +4,13 @@ import com.ODG.ODG_back.dto.vote.response.VoteResultDto; import com.ODG.ODG_back.security.jwt.JwtTokenProvider; import com.ODG.ODG_back.service.VoteService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -13,23 +20,58 @@ @RestController @RequestMapping("/meetings/{inviteCode}") @RequiredArgsConstructor +@Tag(name = "Vote", description = "투표 관리 API") public class VoteController { private final VoteService voteService; private final JwtTokenProvider jwtTokenProvider; + @Operation( + summary = "투표 토글", + description = "참가자가 특정 장소에 대해 투표를 생성하거나 이미 투표가 된 장소라면 삭제합니다. " + ) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "투표 토글 성공"), + @ApiResponse(responseCode = "403", description = "인증 실패 (토큰 없음 또는 유효하지 않음)", content = @Content), + @ApiResponse(responseCode = "404", description = "존재하지 않는 모임 또는 참가자 또는 장소", content = @Content), + @ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content) + }) @PostMapping("/vote") - public ResponseEntity vote(@PathVariable String inviteCode, - @RequestBody VoteRequestDto voteRequestDto, - @CookieValue("access_token") String jwtToken) { + public ResponseEntity vote( + @Parameter(description = "모임 초대 코드") + @PathVariable String inviteCode, + @Parameter(description = "투표 요청 데이터") + @RequestBody VoteRequestDto voteRequestDto, + @Parameter(description = "JWT 토큰 (쿠키에서 자동 추출, 아무 값 입력)") + @CookieValue("access_token") String jwtToken) { String userId = jwtTokenProvider.getUserId(jwtToken); voteService.vote(inviteCode, userId, voteRequestDto); return ResponseEntity.ok().build(); } + @Operation( + summary = "투표 결과 조회", + description = "특정 모임의 투표 결과를 조회합니다." + ) + @ApiResponses(value = { + @ApiResponse( + responseCode = "200", + description = "투표 결과 조회 성공", + content = @Content(schema = @Schema(implementation = VoteResultDto.class)) + ), + @ApiResponse(responseCode = "403", description = "인증 실패 (토큰 없음 또는 유효하지 않음)", content = @Content), + @ApiResponse(responseCode = "404", description = "존재하지 않는 모임", content = @Content), + @ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content) + }) @GetMapping("/result") - public ResponseEntity> getVoteResults(@PathVariable String inviteCode) { - List voteResults = voteService.getVoteResults(inviteCode); + public ResponseEntity> getVoteResults( + @Parameter(description = "모임 초대 코드") + @PathVariable String inviteCode, + @Parameter(description = "JWT 토큰 (쿠키에서 자동 추출, 아무 값 입력)") + @CookieValue("access_token") String jwtToken + ) { + String userId = jwtTokenProvider.getUserId(jwtToken); + List voteResults = voteService.getVoteResults(inviteCode, userId); return ResponseEntity.ok(voteResults); } diff --git a/src/main/java/com/ODG/ODG_back/service/MidpointService.java b/src/main/java/com/ODG/ODG_back/service/MidpointService.java index 2b5745d..efbd027 100644 --- a/src/main/java/com/ODG/ODG_back/service/MidpointService.java +++ b/src/main/java/com/ODG/ODG_back/service/MidpointService.java @@ -1,12 +1,16 @@ package com.ODG.ODG_back.service; +import com.ODG.ODG_back.domain.Meeting; import com.ODG.ODG_back.dto.midpoint.response.MidpointResponseDto; +import com.ODG.ODG_back.exception.ErrorCode; +import com.ODG.ODG_back.exception.custom.NotFoundException; +import com.ODG.ODG_back.repository.MeetingRepository; +import com.ODG.ODG_back.repository.ParticipantRepository; import com.ODG.ODG_back.strategy.MidpointStrategy; import com.ODG.ODG_back.strategy.MidpointStrategyType; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import java.util.List; import java.util.Map; @Service @@ -15,8 +19,14 @@ public class MidpointService { // 전략 빈 자동 주입 private final Map strategyMap; + private final MeetingRepository meetingRepository; + private final ParticipantRepository participantRepository; - public MidpointResponseDto getRecommendedMidpoints(String inviteCode, MidpointStrategyType strategyType) { + public MidpointResponseDto getRecommendedMidpoints(String inviteCode, MidpointStrategyType strategyType, String userId) { + Meeting meeting = meetingRepository.findByInviteCode(inviteCode) + .orElseThrow(() -> new NotFoundException(ErrorCode.MEETING_NOT_FOUND)); + participantRepository.findByUserIdAndMeeting(userId, meeting) + .orElseThrow(() -> new NotFoundException(ErrorCode.PARTICIPANT_NOT_FOUND)); MidpointStrategy strategy = strategyMap.get(strategyType.getBeanName()); return strategy.calculateMidpoints(inviteCode); diff --git a/src/main/java/com/ODG/ODG_back/service/ParticipantService.java b/src/main/java/com/ODG/ODG_back/service/ParticipantService.java index b568584..99adcfe 100644 --- a/src/main/java/com/ODG/ODG_back/service/ParticipantService.java +++ b/src/main/java/com/ODG/ODG_back/service/ParticipantService.java @@ -76,7 +76,12 @@ public void deleteParticipant(String linkCode, String userId) { participantRepository.delete(participant); } - public List getParticipantsWithVoteStatus(String linkCode) { + public List getParticipantsWithVoteStatus(String linkCode, String userId) { + Meeting meeting = meetingRepository.findByInviteCode(linkCode) + .orElseThrow(() -> new NotFoundException(ErrorCode.MEETING_NOT_FOUND)); + participantRepository.findByUserIdAndMeeting(userId, meeting) + .orElseThrow(() -> new NotFoundException(ErrorCode.PARTICIPANT_NOT_FOUND)); + return participantRepository.findParticipantsWithVoteStatus(linkCode); } } diff --git a/src/main/java/com/ODG/ODG_back/service/PlaceService.java b/src/main/java/com/ODG/ODG_back/service/PlaceService.java index 61ef516..e3c699b 100644 --- a/src/main/java/com/ODG/ODG_back/service/PlaceService.java +++ b/src/main/java/com/ODG/ODG_back/service/PlaceService.java @@ -1,9 +1,6 @@ package com.ODG.ODG_back.service; -import com.ODG.ODG_back.domain.Meeting; -import com.ODG.ODG_back.domain.Midpoint; -import com.ODG.ODG_back.domain.Place; -import com.ODG.ODG_back.domain.RecommendedMidpoint; +import com.ODG.ODG_back.domain.*; import com.ODG.ODG_back.domain.enums.MeetingType; import com.ODG.ODG_back.domain.enums.PlaceCategory; import com.ODG.ODG_back.dto.place.response.PlaceResponseDto; @@ -11,6 +8,7 @@ import com.ODG.ODG_back.exception.custom.NotFoundException; import com.ODG.ODG_back.mapper.PlaceMapper; import com.ODG.ODG_back.repository.MeetingRepository; +import com.ODG.ODG_back.repository.ParticipantRepository; import com.ODG.ODG_back.repository.PlaceRepository; import com.ODG.ODG_back.repository.RecommendedMidpointRepository; import lombok.RequiredArgsConstructor; @@ -25,13 +23,15 @@ public class PlaceService { private final MeetingRepository meetingRepository; private final RecommendedMidpointRepository recommendedMidpointRepository; private final PlaceRepository placeRepository; + private final ParticipantRepository participantRepository; private final PlaceMapper placeMapper; - public List getPlacesByMidpoint(String inviteCode) { + public List getPlacesByMidpoint(String inviteCode, String userId) { Meeting meeting = meetingRepository.findByInviteCode(inviteCode) .orElseThrow(() -> new NotFoundException(ErrorCode.MEETING_NOT_FOUND)); - + participantRepository.findByUserIdAndMeeting(userId, meeting) + .orElseThrow(() -> new NotFoundException(ErrorCode.PARTICIPANT_NOT_FOUND)); RecommendedMidpoint recommendedMidpoint = recommendedMidpointRepository.findByMeeting(meeting) .orElseThrow(() -> new NotFoundException(ErrorCode.RECOMMENDED_MIDPOINT_NOT_FOUND)); Midpoint midpoint = recommendedMidpoint.getMidpoint(); diff --git a/src/main/java/com/ODG/ODG_back/service/VoteService.java b/src/main/java/com/ODG/ODG_back/service/VoteService.java index 1ab5e9b..de224b7 100644 --- a/src/main/java/com/ODG/ODG_back/service/VoteService.java +++ b/src/main/java/com/ODG/ODG_back/service/VoteService.java @@ -34,7 +34,7 @@ public void vote(String inviteCode, String userId, VoteRequestDto voteRequestDto .orElseThrow(() -> new NotFoundException(ErrorCode.MEETING_NOT_FOUND)); Place place = placeRepository.findById(voteRequestDto.getPlaceId()) .orElseThrow(() -> new NotFoundException(ErrorCode.PLACE_NOT_FOUND)); - Participant participant = participantRepository.findByUserId(userId) + Participant participant = participantRepository.findByUserIdAndMeeting(userId, meeting) .orElseThrow(() -> new NotFoundException(ErrorCode.PARTICIPANT_NOT_FOUND)); Optional existingVote = voteRepository.findByMeetingAndPlaceAndParticipant(meeting, place, participant); @@ -47,10 +47,11 @@ public void vote(String inviteCode, String userId, VoteRequestDto voteRequestDto } } - public List getVoteResults(String inviteCode) { + public List getVoteResults(String inviteCode, String userId) { Meeting meeting = meetingRepository.findByInviteCode(inviteCode) .orElseThrow(() -> new NotFoundException(ErrorCode.MEETING_NOT_FOUND)); - + participantRepository.findByUserIdAndMeeting(userId, meeting) + .orElseThrow(() -> new NotFoundException(ErrorCode.PARTICIPANT_NOT_FOUND)); return voteRepository.findVoteCountsByMeeting(meeting); } }