Skip to content

Commit

Permalink
Merge pull request #120 from SWEET-DEVELOPERS/feature/#119
Browse files Browse the repository at this point in the history
[fix] 예외 처리 & response 추가
  • Loading branch information
hysong4u authored Feb 22, 2024
2 parents 40cb736 + defbf22 commit 6322a7c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ public ResponseEntity<SuccessResponse<?>> getRanking(@PathVariable Long roomId)

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import java.time.LocalDateTime;

public record TournamentStartDateResponseDto(
public record RoomInfoResponseDto(
String gifteeName,
LocalDateTime tournamentStartDate
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
Expand Down Expand Up @@ -280,9 +279,10 @@ private List<FriendGiftDto> mapGiftsToFriendGiftDtoList(List<Gift> gifts) {
.collect(Collectors.toList());
}

public TournamentStartDateResponseDto getTournamentStartDate(Long roomId) {
public RoomInfoResponseDto getRoomInfo(Long roomId) {
Room room = findRoomByIdOrThrow(roomId);
String gifteeName = room.getGifteeName();
LocalDateTime tournamentStartDate = room.getTournamentStartDate();
return new TournamentStartDateResponseDto(tournamentStartDate);
return new RoomInfoResponseDto(gifteeName,tournamentStartDate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public String sendDiscordNotification(String nickname) {
RestTemplate restTemplate = new RestTemplate();
Long totalMembers = memberRepository.count();

String message = nickname + "님이 회원가입했습니다! (누적 회원수: " + totalMembers + "명)\n";
String message = totalMembers + "번째 유저가 회원가입했습니다!\n";

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@

@Builder
public record HotProductsResponseDto(
String gifteeName,
LocalDateTime tournamentStartDate,
List<HotProductDto> hotProductDtoList
) {
public static HotProductsResponseDto of(LocalDateTime tournamentStartDate,
public static HotProductsResponseDto of( String gifteeName,
LocalDateTime tournamentStartDate,
List<HotProductDto> hotProductDtoList) {
return HotProductsResponseDto.builder()
.gifteeName(gifteeName)
.tournamentStartDate(tournamentStartDate)
.hotProductDtoList(hotProductDtoList)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public HotProductsResponseDto getHotGift(Long memberId, Long roomId) {
Room room = findRoomByIdOrThrow(roomId);
List<Product> allProducts = productRepository.findAll();
List<HotProductDto> hotProductDtoList = mapToHotProductDtoList(allProducts);
return HotProductsResponseDto.of(room.getTournamentStartDate(), hotProductDtoList);
return HotProductsResponseDto.of(room.getGifteeName(), room.getTournamentStartDate(), hotProductDtoList);
}

private Member findMemberByIdOrThrow(Long memberId) {
Expand Down

0 comments on commit 6322a7c

Please sign in to comment.