Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into NABI-124--beommo-feat-…
Browse files Browse the repository at this point in the history
…-jjim-CD

# Conflicts:
#	src/main/java/org/prgrms/nabimarketbe/domain/card/api/CardController.java
  • Loading branch information
BeommoKoo-dev committed Nov 11, 2023
2 parents d70e905 + f92f168 commit 7d4b834
Show file tree
Hide file tree
Showing 35 changed files with 1,171 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
package org.prgrms.nabimarketbe.domain.card.api;

import java.util.List;
import lombok.RequiredArgsConstructor;

import org.prgrms.nabimarketbe.domain.card.dto.request.CardCreateRequestDTO;
import org.prgrms.nabimarketbe.domain.card.dto.response.CardCreateResponseDTO;
import org.prgrms.nabimarketbe.domain.card.dto.response.CardListReadPagingResponseDTO;
import org.prgrms.nabimarketbe.domain.card.dto.response.CardListResponseDTO;
import org.prgrms.nabimarketbe.domain.card.dto.response.CardSingleReadResponseDTO;
import org.prgrms.nabimarketbe.domain.card.dto.response.SuggestionAvailableCardResponseDTO;
import org.prgrms.nabimarketbe.domain.card.entity.CardStatus;
import org.prgrms.nabimarketbe.domain.card.service.CardService;
import org.prgrms.nabimarketbe.domain.category.entity.CategoryEnum;
import org.prgrms.nabimarketbe.domain.item.entity.PriceRange;
import org.prgrms.nabimarketbe.global.util.ResponseFactory;
import org.prgrms.nabimarketbe.global.util.model.SingleResult;

import org.springframework.http.MediaType;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

import lombok.RequiredArgsConstructor;

@RestController
Expand All @@ -40,7 +34,7 @@ public class CardController {
MediaType.APPLICATION_JSON_VALUE
}, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SingleResult<CardCreateResponseDTO>> createCard(
@RequestHeader(name = "authorization") String token,
@RequestHeader(name = "Authorization") String token,
@RequestPart("thumbnail") MultipartFile thumbnail,
@RequestPart("dto") CardCreateRequestDTO cardCreateRequestDTO,
@RequestPart("files") List<MultipartFile> files
Expand Down Expand Up @@ -85,12 +79,54 @@ public ResponseEntity<SingleResult<CardListReadPagingResponseDTO>> getCardsByCon

@GetMapping("/{cardId}/available-cards")
public ResponseEntity<SingleResult<CardListResponseDTO<SuggestionAvailableCardResponseDTO>>> getSuggestionAvailableCards(
@RequestHeader(name = "authorization") String token,
@RequestHeader(name = "Authorization") String token,
@PathVariable Long cardId
) {
CardListResponseDTO<SuggestionAvailableCardResponseDTO> cardListResponseDTO
= cardService.getSuggestionAvailableCards(token, cardId);

return ResponseEntity.ok(ResponseFactory.getSingleResult(cardListResponseDTO));
}

@PutMapping("/status/{cardId}")
public ResponseEntity<CommonResult> updateCardStatusById(
@RequestHeader(name = "authorization") String token,
@PathVariable Long cardId,
@RequestBody CardStatusUpdateRequestDTO cardStatusUpdateRequestDTO
) {
cardService.updateCardStatusById(
token,
cardId,
cardStatusUpdateRequestDTO
);

return ResponseEntity.ok(ResponseFactory.getSuccessResult());
}

@GetMapping("/{status}/my-cards")
public ResponseEntity<SingleResult<CardListReadPagingResponseDTO>> getMyCardsByStatus(
@RequestHeader(name = "authorization") String token,
@PathVariable CardStatus status,
@RequestParam(required = false) String cursorId,
@RequestParam Integer size
) {
CardListReadPagingResponseDTO cardListReadPagingResponseDTO = cardService.getMyCardsByStatus(
token,
status,
cursorId,
size
);

return ResponseEntity.ok(ResponseFactory.getSingleResult(cardListReadPagingResponseDTO));
}

@DeleteMapping("/{cardId}")
public ResponseEntity<CommonResult> deleteCardById(
@RequestHeader(name = "authorization") String token,
@PathVariable Long cardId
) {
cardService.deleteCardById(token, cardId);

return ResponseEntity.ok(ResponseFactory.getSuccessResult());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.prgrms.nabimarketbe.domain.card.dto.request;

import org.prgrms.nabimarketbe.domain.card.entity.CardStatus;
import org.prgrms.nabimarketbe.global.annotation.ValidEnum;

public record CardStatusUpdateRequestDTO(
@ValidEnum(enumClass = CardStatus.class, message = "유효하지 않은 상태입니다.")
CardStatus cardStatus
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.prgrms.nabimarketbe.domain.card.dto.response;

import lombok.Getter;

import org.prgrms.nabimarketbe.domain.item.entity.PriceRange;

@Getter
public class CardSummaryResponseDTO{
private Long cardId;

private String itemName;

private String thumbnail;

private PriceRange priceRange;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class Card extends BaseEntity {
@Column(name = "card_title", nullable = false)
private String cardTitle;

// @NotBlank(message = "공백을 허용하지 않습니다.")
@Column(name = "thumbnail_image")
private String thumbNailImage;

Expand Down Expand Up @@ -131,4 +130,16 @@ public void increaseDibCount() {
public void decreaseDibCount() {
this.dibCount -= 1;
}

public void updateCardStatusToTradeAvailable() {
this.status = CardStatus.TRADE_AVAILABLE;
}

public void updateCardStatusToReserved() {
this.status = CardStatus.RESERVED;
}

public void updateCardStatusToTradeComplete() {
this.status = CardStatus.TRADE_COMPLETE;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.prgrms.nabimarketbe.domain.card.repository;

import org.prgrms.nabimarketbe.domain.card.entity.Card;
import org.prgrms.nabimarketbe.domain.user.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface CardRepository extends JpaRepository<Card, Long>, CardRepositoryCustom {
Optional<Card> findByCardIdAndUser(Long cardId, User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.prgrms.nabimarketbe.domain.card.entity.CardStatus;
import org.prgrms.nabimarketbe.domain.category.entity.CategoryEnum;
import org.prgrms.nabimarketbe.domain.item.entity.PriceRange;
import org.prgrms.nabimarketbe.domain.user.entity.User;

import java.util.List;

Expand All @@ -18,6 +19,13 @@ CardListReadPagingResponseDTO getCardsByCondition(
Integer size
);

CardListReadPagingResponseDTO getMyCardsByStatus(
User user,
CardStatus status,
String cursorId,
Integer size
);

List<SuggestionAvailableCardResponseDTO> getSuggestionAvailableCards(
Long userId,
PriceRange priceRange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.prgrms.nabimarketbe.domain.category.entity.CategoryEnum;
import org.prgrms.nabimarketbe.domain.item.entity.PriceRange;
import org.prgrms.nabimarketbe.domain.suggestion.entity.SuggestionType;
import org.prgrms.nabimarketbe.domain.user.entity.User;

import java.util.List;

Expand Down Expand Up @@ -65,6 +66,41 @@ public CardListReadPagingResponseDTO getCardsByCondition(
return new CardListReadPagingResponseDTO(cardList, nextCursor);
}

@Override
public CardListReadPagingResponseDTO getMyCardsByStatus(
User user,
CardStatus status,
String cursorId,
Integer size
) {
List<CardListReadResponseDTO> cardList = jpaQueryFactory.select(
Projections.fields(
CardListReadResponseDTO.class,
card.cardId,
card.cardTitle,
item.itemName,
item.priceRange,
card.thumbNailImage.as("thumbNail"),
card.status,
card.createdDate.as("createdAt"),
card.modifiedDate.as("modifiedAt")
)
)
.from(card)
.leftJoin(item).on(card.item.itemId.eq(item.itemId))
.where(
cursorId(cursorId),
card.status.eq(status)
)
.orderBy(card.createdDate.desc()) // 디폴트는 생성일자 최신순 정렬
.limit(size)
.fetch();

String nextCursor = cardList.size() < size ? null : generateCursor(cardList.get(cardList.size() - 1));

return new CardListReadPagingResponseDTO(cardList, nextCursor);
}

@Override
public List<SuggestionAvailableCardResponseDTO> getSuggestionAvailableCards(
Long userId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;

import org.prgrms.nabimarketbe.domain.card.dto.request.CardCreateRequestDTO;
import org.prgrms.nabimarketbe.domain.card.dto.request.CardStatusUpdateRequestDTO;
import org.prgrms.nabimarketbe.domain.card.dto.response.CardCreateResponseDTO;
import org.prgrms.nabimarketbe.domain.card.dto.response.CardListReadPagingResponseDTO;
import org.prgrms.nabimarketbe.domain.card.dto.response.CardListResponseDTO;
Expand Down Expand Up @@ -187,4 +188,57 @@ public CardListResponseDTO<SuggestionAvailableCardResponseDTO> getSuggestionAvai

return new CardListResponseDTO<>(cardListResponse);
}

@Transactional(readOnly = true)
public CardListReadPagingResponseDTO getMyCardsByStatus(
String token,
CardStatus status,
String cursorId,
Integer size
) {
User user = userRepository.findById(checkService.parseToken(token))
.orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_FOUND));

return cardRepository.getMyCardsByStatus(
user,
status,
cursorId,
size
);
}

@Transactional
public void updateCardStatusById(
String token,
Long cardId,
CardStatusUpdateRequestDTO cardStatusUpdateRequestDTO
) {
Card card = cardRepository.findById(cardId)
.orElseThrow(() -> new BaseException(ErrorCode.CARD_NOT_FOUND));

if (!checkService.isEqual(token, card.getUser().getUserId())) {
throw new BaseException(ErrorCode.USER_NOT_MATCHED);
}

switch (cardStatusUpdateRequestDTO.cardStatus()) {
case TRADE_AVAILABLE -> card.updateCardStatusToTradeAvailable();
case RESERVED -> card.updateCardStatusToReserved();
case TRADE_COMPLETE -> card.updateCardStatusToTradeComplete();
}
}

@Transactional
public void deleteCardById(
String token,
Long cardId
) {
Card card = cardRepository.findById(cardId)
.orElseThrow(() -> new BaseException(ErrorCode.CARD_NOT_FOUND));

if (!checkService.isEqual(token, card.getUser().getUserId())) {
throw new BaseException(ErrorCode.USER_NOT_MATCHED);
}

cardRepository.delete(card);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.prgrms.nabimarketbe.domain.completeRequest.api;

import lombok.RequiredArgsConstructor;

import org.prgrms.nabimarketbe.domain.completeRequest.dto.response.CompleteRequestDTO;
import org.prgrms.nabimarketbe.domain.completeRequest.dto.response.HistoryListReadLimitResponseDTO;
import org.prgrms.nabimarketbe.domain.completeRequest.dto.response.HistoryListReadPagingResponseDTO;
import org.prgrms.nabimarketbe.domain.completeRequest.service.CompleteRequestService;
import org.prgrms.nabimarketbe.global.util.ResponseFactory;
import org.prgrms.nabimarketbe.global.util.model.SingleResult;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/complete-requests")
public class CompleteRequestController {
private final CompleteRequestService completeRequestService;

@PostMapping
public ResponseEntity<SingleResult<CompleteRequestDTO>> createCompleteRequest(
@RequestHeader(name = "Authorization") String token,
@RequestBody org.prgrms.nabimarketbe.domain.completeRequest.dto.request.CompleteRequestDTO completeRequestDTO
) {
CompleteRequestDTO completeRequestResponseDTO = completeRequestService.createCompleteRequest(
token,
completeRequestDTO
);

return ResponseEntity.ok(ResponseFactory.getSingleResult(completeRequestResponseDTO));
}

@GetMapping
public ResponseEntity<SingleResult<HistoryListReadLimitResponseDTO>> getHistoryBySize(@RequestParam Integer size) {
HistoryListReadLimitResponseDTO historyListReadLimitResponseDTO = completeRequestService.getHistoryBySize(size);

return ResponseEntity.ok(ResponseFactory.getSingleResult(historyListReadLimitResponseDTO));
}

@GetMapping("/user")
public ResponseEntity<SingleResult<HistoryListReadPagingResponseDTO>> getHistoryByUser(
@RequestHeader("Authorization") String token,
@RequestParam(required = false) String cursorId,
@RequestParam Integer size
){
HistoryListReadPagingResponseDTO historyByUser = completeRequestService.getHistoryByUser(
token,
cursorId,
size
);

return ResponseEntity.ok(ResponseFactory.getSingleResult(historyByUser));
}

@PutMapping("/confirm")
public ResponseEntity<SingleResult<CompleteRequestDTO>> updateCompleteRequestStatus(
@RequestHeader(name = "Authorization") String token,
@RequestParam Long fromCardId,
@RequestParam Long toCardId,
@RequestParam Boolean isAccepted
) {
CompleteRequestDTO completeRequestDTO = completeRequestService.updateCompleteRequestStatus(
token,
fromCardId,
toCardId,
isAccepted
);

return ResponseEntity.ok(ResponseFactory.getSingleResult(completeRequestDTO));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.prgrms.nabimarketbe.domain.completeRequest.dto.request;

public record CompleteRequestDTO(
Long fromCardId,
Long toCardId
) {
}
Loading

0 comments on commit 7d4b834

Please sign in to comment.