Skip to content

Commit

Permalink
Merge pull request #59 from SWEET-DEVELOPERS/feature/#58-product
Browse files Browse the repository at this point in the history
[fix] 2030 ์ƒํ’ˆ API response์— ํ† ๋„ˆ๋จผํŠธ ์‹œ์ž‘ ์‹œ๊ฐ„ ์ถ”๊ฐ€
  • Loading branch information
ziiyouth authored Jan 13, 2024
2 parents 7375ab7 + 8dbcbfd commit 0f72743
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.sopt.sweet.domain.gift.dto.request.TournamentScoreRequestDto;
import org.sopt.sweet.domain.gift.dto.response.*;
import org.sopt.sweet.domain.gift.service.GiftService;
import org.sopt.sweet.domain.room.entity.Room;
import org.sopt.sweet.global.common.SuccessResponse;
import org.sopt.sweet.global.config.auth.UserId;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -35,14 +34,14 @@ public ResponseEntity<SuccessResponse<?>> getMyGift(@UserId Long userId, @Reques
return SuccessResponse.ok(myGiftsResponseDto);
}

@DeleteMapping ("/my/{giftId}")
@DeleteMapping("/my/{giftId}")
public ResponseEntity<SuccessResponse<?>> deleteMyGift(@UserId Long userId, @PathVariable Long giftId) {
giftService.deleteMyGift(userId, giftId);
return SuccessResponse.ok(null);
}

@GetMapping("/tonermant/{roomId}")
public ResponseEntity<SuccessResponse<?>> getTournamentGiftList(@UserId Long userId,@PathVariable Long roomId) {
public ResponseEntity<SuccessResponse<?>> getTournamentGiftList(@UserId Long userId, @PathVariable Long roomId) {
List<TournamentListsResponseDto> tournamentGiftList = giftService.getTournamentGiftList(roomId);
return SuccessResponse.ok(tournamentGiftList);
}
Expand Down Expand Up @@ -78,9 +77,4 @@ public ResponseEntity<SuccessResponse<?>> getFriendGift(@UserId Long userId, @Pa
}







}
3 changes: 0 additions & 3 deletions src/main/java/org/sopt/sweet/domain/gift/entity/Gift.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,4 @@ public void setScore(int score) {
this.score = score;
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ ResponseEntity<SuccessResponse<?>> getHotGift(
description = "authorization token์—์„œ ์–ป์€ userId, ์ž„์˜์ž…๋ ฅํ•˜๋ฉด ๋Œ€์ฒด๋ฉ๋‹ˆ๋‹ค.",
required = true,
example = "12345"
) @UserId Long userId
) @UserId Long userId,
@Parameter(
description = "์„ ๋ฌผ๋ฐฉ id",
required = true,
example = "1"
) @PathVariable Long roomId
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.sopt.sweet.global.config.auth.UserId;
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;

Expand All @@ -17,9 +18,9 @@ public class ProductController implements ProductApi {

private final ProductService productService;

@GetMapping("/hot")
public ResponseEntity<SuccessResponse<?>> getHotGift(@UserId Long userId) {
final HotProductsResponseDto hotProductsResponseDto = productService.getHotGift(userId);
@GetMapping("/hot/{roomId}")
public ResponseEntity<SuccessResponse<?>> getHotGift(@UserId Long userId, @PathVariable Long roomId) {
final HotProductsResponseDto hotProductsResponseDto = productService.getHotGift(userId, roomId);
return SuccessResponse.ok(hotProductsResponseDto);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

import lombok.Builder;

import java.time.LocalDateTime;
import java.util.List;

@Builder
public record HotProductsResponseDto(
LocalDateTime tournamentStartDate,
List<HotProductDto> hotProductDtoList
) {
public static HotProductsResponseDto of(List<HotProductDto> hotProductDtoList){
public static HotProductsResponseDto of(LocalDateTime tournamentStartDate,
List<HotProductDto> hotProductDtoList){
return HotProductsResponseDto.builder()
.tournamentStartDate(tournamentStartDate)
.hotProductDtoList(hotProductDtoList)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import org.sopt.sweet.domain.product.dto.response.HotProductsResponseDto;
import org.sopt.sweet.domain.product.entity.Product;
import org.sopt.sweet.domain.product.repository.ProductRepository;
import org.sopt.sweet.domain.room.entity.Room;
import org.sopt.sweet.domain.room.repository.RoomMemberRepository;
import org.sopt.sweet.domain.room.repository.RoomRepository;
import org.sopt.sweet.global.error.exception.EntityNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -17,6 +19,7 @@
import java.util.stream.Collectors;

import static org.sopt.sweet.global.error.ErrorCode.MEMBER_NOT_FOUND;
import static org.sopt.sweet.global.error.ErrorCode.ROOM_NOT_FOUND;

@RequiredArgsConstructor
@Service
Expand All @@ -25,19 +28,26 @@ public class ProductService {

private final MemberRepository memberRepository;
private final ProductRepository productRepository;
private final RoomRepository roomRepository;

public HotProductsResponseDto getHotGift(Long memberId){
public HotProductsResponseDto getHotGift(Long memberId, Long roomId){
Member member = findMemberByIdOrThrow(memberId);
Room room = findRoomByIdOrThrow(roomId);
List<Product> allProducts = productRepository.findAll();
List<HotProductDto> hotProductDtoList = mapToHotProductDtoList(allProducts);
return HotProductsResponseDto.of(hotProductDtoList);
return HotProductsResponseDto.of(room.getTournamentStartDate(), hotProductDtoList);
}

private Member findMemberByIdOrThrow(Long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(() -> new EntityNotFoundException(MEMBER_NOT_FOUND));
}

private Room findRoomByIdOrThrow(Long roomId) {
return roomRepository.findById(roomId)
.orElseThrow(() -> new EntityNotFoundException(ROOM_NOT_FOUND));
}

private List<HotProductDto> mapToHotProductDtoList(List<Product> products) {
return products.stream()
.map(product -> HotProductDto.of(
Expand Down

0 comments on commit 0f72743

Please sign in to comment.