-
Notifications
You must be signed in to change notification settings - Fork 0
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
[feat] 선물 토너먼트 점수 입력 API & 토너먼트 정보 조회 API 구현 #50
Merged
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ff19134
[feat] 토너먼트 점수 등록 API swagger 구현
hysong4u 190bb69
[feat] 토너먼트 점수 등록 API controller 구현
hysong4u db3343f
[feat] 토너먼트 점수 등록 API repository 구현
hysong4u 81fd4ff
[feat] 토너먼트 점수 등록 API service 구현
hysong4u 789d338
[feat] 토너먼트 점수 등록 API Dto 구현
hysong4u 6a9a13a
[feat] score 관련 메서드 추가
hysong4u d7ac650
[feat] 토너먼트 관련 정보 추출 API Controller 구현
hysong4u cf730dd
[feat] 토너먼트 관련 정보 추출 API Service 구현
hysong4u d3843a1
[feat] 토너먼트 관련 정보 추출 API Repository 구현
hysong4u f14eeee
[feat] 토너먼트 관련 정보 추출 API Repository 구현
hysong4u a7dc373
[feat] 토너먼트 관련 정보 추출 API Dto 구현
hysong4u 3115ab2
[feat] 토너먼트 참여자 관련 메서드 추가
hysong4u 63d0093
[feat] 토너먼트 관련 정보 추출 API swagger구현
hysong4u c2c97c1
[refactor] 불필요한 코드 삭제
hysong4u 65d2733
[refactor] 상수 변수 명 수정
hysong4u File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/org/sopt/sweet/domain/gift/dto/request/TournamentScoreRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.sopt.sweet.domain.gift.dto.request; | ||
|
||
import lombok.Builder; | ||
import org.sopt.sweet.domain.gift.dto.response.TournamentListsResponseDto; | ||
|
||
@Builder | ||
public record TournamentScoreRequestDto( | ||
Long firstPlaceGiftId, | ||
Long secondPlaceGiftId | ||
) { | ||
public static TournamentScoreRequestDto of(Long firstPlaceGiftId, Long secondPlaceGiftId) { | ||
return TournamentScoreRequestDto.builder() | ||
.firstPlaceGiftId(firstPlaceGiftId) | ||
.secondPlaceGiftId(secondPlaceGiftId) | ||
.build(); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/org/sopt/sweet/domain/gift/dto/response/TournamentInfoDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.sopt.sweet.domain.gift.dto.response; | ||
|
||
import lombok.Builder; | ||
import org.sopt.sweet.domain.room.constant.TournamentDuration; | ||
|
||
import java.time.LocalDateTime; | ||
@Builder | ||
public record TournamentInfoDto( | ||
LocalDateTime tournamentStartDate, | ||
TournamentDuration tournamentDuration, | ||
|
||
int TotalParticipantsCount, | ||
int ParticipantsCount | ||
|
||
) { | ||
public static TournamentInfoDto of(LocalDateTime tournamentStartDate, | ||
TournamentDuration tournamentDuration, | ||
int TotalParticipantsCount, | ||
int ParticipantsCount) { | ||
return TournamentInfoDto.builder() | ||
.tournamentStartDate(tournamentStartDate) | ||
.tournamentDuration(tournamentDuration) | ||
.TotalParticipantsCount(TotalParticipantsCount) | ||
.ParticipantsCount(ParticipantsCount) | ||
.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,16 @@ | |
import lombok.RequiredArgsConstructor; | ||
import org.sopt.sweet.domain.gift.dto.request.CreateGiftRequestDto; | ||
import org.sopt.sweet.domain.gift.dto.request.MyGiftsRequestDto; | ||
import org.sopt.sweet.domain.gift.dto.request.TournamentScoreRequestDto; | ||
import org.sopt.sweet.domain.gift.dto.response.MyGiftDto; | ||
import org.sopt.sweet.domain.gift.dto.response.MyGiftsResponseDto; | ||
import org.sopt.sweet.domain.gift.dto.response.TournamentListsResponseDto; | ||
import org.sopt.sweet.domain.gift.dto.response.TournamentInfoDto; | ||
import org.sopt.sweet.domain.gift.entity.Gift; | ||
import org.sopt.sweet.domain.gift.repository.GiftRepository; | ||
import org.sopt.sweet.domain.member.entity.Member; | ||
import org.sopt.sweet.domain.member.repository.MemberRepository; | ||
import org.sopt.sweet.domain.room.constant.TournamentDuration; | ||
import org.sopt.sweet.domain.room.entity.Room; | ||
import org.sopt.sweet.domain.room.entity.RoomMember; | ||
import org.sopt.sweet.domain.room.repository.RoomMemberRepository; | ||
|
@@ -36,6 +39,8 @@ public class GiftService { | |
private final RoomRepository roomRepository; | ||
private final RoomMemberRepository roomMemberRepository; | ||
private static final int MAX_GIFT_COUNT = 2; | ||
private static final int FirstPlaceScore = 10; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기서는 final로 상수를 정의한 거니까 두 가지 변수 명만 규칙에 맞게 대문자로 바꿔주면 좋을 거 같아요!!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네~~~꼼꼼한 리뷰 감사합니당 |
||
private static final int SecondPlaceScore = 5; | ||
|
||
public void createNewGift(Long memberId, CreateGiftRequestDto createGiftRequestDto) { | ||
Member member = findMemberByIdOrThrow(memberId); | ||
|
@@ -57,7 +62,7 @@ public MyGiftsResponseDto getMyGift(Long memberId, MyGiftsRequestDto myGiftsRequ | |
return new MyGiftsResponseDto(myGiftsDtoList); | ||
} | ||
|
||
public void deleteMyGift(Long memberId, Long giftId){ | ||
public void deleteMyGift(Long memberId, Long giftId) { | ||
Member member = findMemberByIdOrThrow(memberId); | ||
Gift gift = findByIdOrThrow(giftId); | ||
validateMemberGiftOwner(member, gift); | ||
|
@@ -123,11 +128,17 @@ private Room findRoomByIdOrThrow(Long roomId) { | |
.orElseThrow(() -> new EntityNotFoundException(ROOM_NOT_FOUND)); | ||
} | ||
|
||
|
||
private Gift findByIdOrThrow(Long giftId) { | ||
return giftRepository.findById(giftId) | ||
.orElseThrow(() -> new EntityNotFoundException(GIFT_NOT_FOUND)); | ||
} | ||
|
||
private Room findGiftByIdOrThrow(Long roomId) { | ||
return roomRepository.findById(roomId) | ||
.orElseThrow(() -> new EntityNotFoundException(GIFT_NOT_FOUND)); | ||
} | ||
|
||
|
||
@Transactional(readOnly = true) | ||
public List<TournamentListsResponseDto> getTournamentGiftList(Long roomId) { | ||
|
@@ -142,4 +153,44 @@ private List<TournamentListsResponseDto> mapGiftsToTournamentLists(List<Gift> gi | |
.collect(Collectors.toList()); | ||
} | ||
|
||
public void evaluateTournamentScore(TournamentScoreRequestDto tournamentScoreRequestDto) { | ||
|
||
Gift firstPlaceGift = updateScore(tournamentScoreRequestDto.firstPlaceGiftId(), FirstPlaceScore); | ||
Gift secondPlaceGift = updateScore(tournamentScoreRequestDto.secondPlaceGiftId(), SecondPlaceScore); | ||
|
||
giftRepository.save(firstPlaceGift); | ||
giftRepository.save(secondPlaceGift); | ||
} | ||
|
||
|
||
private Gift updateScore(Long giftId, int score) { | ||
Gift gift = findByIdOrThrow(giftId); | ||
int newScore = gift.getScore() + score; | ||
gift.setScore(newScore); | ||
return gift; | ||
} | ||
|
||
public TournamentInfoDto getTournamentInfo(Long memberId, Long roomId) { | ||
Room room = findRoomByIdOrThrow(roomId); | ||
|
||
LocalDateTime tournamentStartDate = room.getTournamentStartDate(); | ||
TournamentDuration tournamentDuration = room.getTournamentDuration(); | ||
int totalParticipantsCount = room.getGifterNumber(); | ||
|
||
updateTournamentParticipation(memberId, roomId); | ||
|
||
int participatingMembersCount = roomMemberRepository.countByRoomIdAndTournamentParticipationIsTrue(roomId); | ||
|
||
return new TournamentInfoDto(tournamentStartDate, tournamentDuration, totalParticipantsCount, participatingMembersCount); | ||
} | ||
|
||
public void updateTournamentParticipation(Long memberId, Long roomId) { | ||
RoomMember roomMember = roomMemberRepository.findByRoomIdAndMemberId(roomId, memberId); | ||
roomMember.setTournamentParticipation(true); | ||
roomMemberRepository.save(roomMember); | ||
} | ||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
토너먼트 점수 변경할 때 (결과 API) roommember 테이블에 있는 토너먼트 참여 여부도 변경해줘야 할 것 같아요! 기본값 false(DB에는 tinyint 라서 0, 1)로 되어 있는 걸 true로 반환해줘야 토너먼트 완료한 사람 수 보내줄 수 있을 거 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넹넹 확인!!