Skip to content

Commit

Permalink
Merge pull request #121 from SWEET-DEVELOPERS/feature/#119
Browse files Browse the repository at this point in the history
[feat] response ์ถ”๊ฐ€ ๋ฐ ์ฝ”๋“œ ์ˆ˜์ •
  • Loading branch information
hysong4u authored Feb 23, 2024
2 parents 17995f9 + c254642 commit 6d250ab
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ public ResponseEntity<SuccessResponse<?>> createNewGift(@UserId Long userId, @Re

@GetMapping("/my/{roomId}")
public ResponseEntity<SuccessResponse<?>> getMyGift(@UserId Long userId, @PathVariable Long roomId) {
String gifteename = giftService.getGifteeName(roomId);
final MyGiftsResponseDto myGiftsResponseDto = giftService.getMyGift(userId, roomId);
return SuccessResponse.ok(myGiftsResponseDto);

Map<String, Object> result = new HashMap<>();
result.put("gifteeName", gifteename);
result.put("myGiftsResponseDto", myGiftsResponseDto);

return SuccessResponse.ok(result);
}


Expand All @@ -42,6 +48,18 @@ public ResponseEntity<SuccessResponse<?>> deleteMyGift(@UserId Long userId, @Pat
return SuccessResponse.ok(null);
}

@GetMapping("/friend/{roomId}")
public ResponseEntity<SuccessResponse<?>> getFriendGift(@UserId Long userId, @PathVariable Long roomId) {
RoomInfoResponseDto roomInfoResponseDto = giftService.getRoomInfo(roomId);
final List<FriendGiftDto> friendGiftList = giftService.getFriendGift(userId, roomId);

Map<String, Object> result = new HashMap<>();
result.put("roomInfoResponseDto", roomInfoResponseDto);
result.put("friendGiftDto", friendGiftList);
return SuccessResponse.ok(result);

}

@GetMapping("/tournament/{roomId}")
public ResponseEntity<SuccessResponse<?>> getTournamentGiftList(@UserId Long userId, @PathVariable Long roomId) {
Boolean isOwner = memberService.isOwner(userId, roomId);
Expand All @@ -55,7 +73,7 @@ public ResponseEntity<SuccessResponse<?>> getTournamentGiftList(@UserId Long use

@PostMapping("/tournament-score")
public ResponseEntity<SuccessResponse<?>> evaluateTournamentScore(@UserId Long userId, @RequestBody TournamentScoreRequestDto tournamentScoreRequestDto) {
giftService.evaluateTournamentScore(tournamentScoreRequestDto);
giftService.evaluateTournamentScore(userId,tournamentScoreRequestDto);
return SuccessResponse.created(null);
}

Expand All @@ -71,17 +89,7 @@ public ResponseEntity<SuccessResponse<?>> getRanking(@PathVariable Long roomId)
return SuccessResponse.ok(ranking);
}

@GetMapping("/friend/{roomId}")
public ResponseEntity<SuccessResponse<?>> getFriendGift(@UserId Long userId, @PathVariable Long roomId) {
RoomInfoResponseDto roomInfoResponseDto = giftService.getRoomInfo(roomId);
final List<FriendGiftDto> friendGiftList = giftService.getFriendGift(userId, roomId);

Map<String, Object> result = new HashMap<>();
result.put("roomInfoResponseDto", roomInfoResponseDto);
result.put("friendGiftDto", friendGiftList);
return SuccessResponse.ok(result);

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@

@Builder
public record TournamentInfoDto(

String firstplaceGiftName,
String firstplaceGiftImageUrl,
int firstplaceGiftCost,
LocalDateTime remainingTime,
int totalParticipantsCount,
int participantsCount

) {
public static TournamentInfoDto of(LocalDateTime remainingTime,
int TotalParticipantsCount,
int ParticipantsCount) {
public static TournamentInfoDto of( String firstplaceGiftName,
String firstplaceGiftImageUrl,
int firstplaceGiftCost,
LocalDateTime remainingTime,
int totalParticipantsCount,
int participantsCount) {
return TournamentInfoDto.builder()
.firstplaceGiftName(firstplaceGiftName)
.firstplaceGiftImageUrl(firstplaceGiftImageUrl)
.firstplaceGiftCost(firstplaceGiftCost)
.remainingTime(remainingTime)
.totalParticipantsCount(TotalParticipantsCount)
.participantsCount(ParticipantsCount)
.totalParticipantsCount(totalParticipantsCount)
.participantsCount(participantsCount)
.build();
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/sopt/sweet/domain/gift/entity/Gift.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import lombok.NoArgsConstructor;
import org.sopt.sweet.domain.member.entity.Member;
import org.sopt.sweet.domain.room.entity.Room;
import org.sopt.sweet.domain.room.entity.RoomMember;
import org.sopt.sweet.global.common.BaseTimeEntity;

import java.util.List;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "gift")
Expand Down Expand Up @@ -42,6 +45,10 @@ public class Gift extends BaseTimeEntity {
@JoinColumn(name = "member_id", nullable = false)
private Member member;

@OneToMany(mappedBy = "id")
private List<RoomMember> roomMembers;


@Builder
public Gift(String url, String name, int cost, String imageUrl, Room room, Member member) {
this.url = url;
Expand Down
31 changes: 26 additions & 5 deletions src/main/java/org/sopt/sweet/domain/gift/service/GiftService.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,18 @@ private List<TournamentListsResponseDto> mapGiftsToTournamentLists(List<Gift> gi
.collect(Collectors.toList());
}

public void evaluateTournamentScore(TournamentScoreRequestDto tournamentScoreRequestDto) {
public void evaluateTournamentScore(Long memberId, TournamentScoreRequestDto tournamentScoreRequestDto) {
Gift gift = findByIdOrThrow(tournamentScoreRequestDto.finalGiftId());
Room room = gift.getRoom();

//1๋“ฑ ์ƒํ’ˆ ์ €์žฅํ•˜๊ธฐ
RoomMember roomMember = roomMemberRepository.findByRoomIdAndMemberId(room.getId(), memberId);
roomMember.setFirstplaceGiftId(tournamentScoreRequestDto.finalGiftId());
roomMemberRepository.save(roomMember);

//ํ† ๋„ˆ๋จผํŠธ ์ฐธ์—ฌ ์—ฌ๋ถ€ ์—…๋ฐ์ดํŠธ
updateTournamentParticipation(memberId, room.getId());

Long firstGiftId = tournamentScoreRequestDto.firstGiftId();
Long secondGiftId = tournamentScoreRequestDto.secondGiftId();
Long finalGiftId = tournamentScoreRequestDto.finalGiftId();
Expand Down Expand Up @@ -190,23 +201,25 @@ private Gift updateScore(Long giftId, int score) {

public TournamentInfoDto getTournamentInfo(Long memberId, Long roomId) {
Room room = findRoomByIdOrThrow(roomId);
RoomMember roomMember = roomMemberRepository.findByRoomIdAndMemberId(roomId, memberId);
Gift firstPlaceGift = giftRepository.findById(roomMember.getFirstplaceGiftId())
.orElseThrow(() -> new EntityNotFoundException(GIFT_NOT_FOUND));

LocalDateTime tournamentStartDate = room.getTournamentStartDate();
TournamentDuration tournamentDuration = room.getTournamentDuration();

int totalParticipantsCount = room.getGifterNumber();

updateTournamentParticipation(memberId, roomId);

int participatingMembersCount = roomMemberRepository.countByRoomIdAndTournamentParticipationIsTrue(roomId);

LocalDateTime tournamentEndTime = getTournamentEndDate(tournamentStartDate, tournamentDuration);
LocalDateTime remainingTime =getTournamentRemainingTime(tournamentEndTime);

return new TournamentInfoDto(remainingTime, totalParticipantsCount, participatingMembersCount);
return new TournamentInfoDto(
firstPlaceGift.getName(), firstPlaceGift.getImageUrl(), firstPlaceGift.getCost(),
remainingTime, totalParticipantsCount, participatingMembersCount);
}


private LocalDateTime getTournamentEndDate(LocalDateTime tournamentStartDate, TournamentDuration tournamentDuration) {
LocalDateTime tournamentEndTime = tournamentStartDate.plusHours(tournamentDuration.getHours());
return tournamentEndTime;
Expand Down Expand Up @@ -285,4 +298,12 @@ public RoomInfoResponseDto getRoomInfo(Long roomId) {
LocalDateTime tournamentStartDate = room.getTournamentStartDate();
return new RoomInfoResponseDto(gifteeName,tournamentStartDate);
}


public String getGifteeName(Long roomId) {
Room room = findRoomByIdOrThrow(roomId);
String gifteeName = room.getGifteeName();
return gifteeName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class RoomMember extends BaseTimeEntity {
@Column(columnDefinition = "TINYINT(1) default 0")
private boolean tournamentParticipation;

@Column(name = "firstplace_gift_id")
private Long firstplaceGiftId;

@Builder
public RoomMember(Room room, Member member) {
this.room = room;
Expand All @@ -39,4 +42,7 @@ public void setTournamentParticipation(boolean tournamentParticipation) {
this.tournamentParticipation = tournamentParticipation;
}

public void setFirstplaceGiftId(Long firstplaceGiftId) {
this.firstplaceGiftId = firstplaceGiftId;
}
}

0 comments on commit 6d250ab

Please sign in to comment.