Skip to content
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

Nabi-189--feat : api 명세 변경으로 인한 card create, update, s3 upload #31

Merged
merged 7 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package org.prgrms.nabimarketbe.domain.card.api;

import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.RequiredArgsConstructor;

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.request.CardUpdateRequestDTO;
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.CardResponseDTO;
import org.prgrms.nabimarketbe.domain.card.dto.response.CardUpdateResponseDTO;
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;
Expand All @@ -17,10 +22,8 @@
import org.prgrms.nabimarketbe.global.util.model.CommonResult;
import org.prgrms.nabimarketbe.global.util.model.SingleResult;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

Expand All @@ -30,33 +33,28 @@
public class CardController {
private final CardService cardService;

@PostMapping(
consumes = {
MediaType.MULTIPART_FORM_DATA_VALUE,
MediaType.APPLICATION_JSON_VALUE
}, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SingleResult<CardCreateResponseDTO>> createCard(
@RequestHeader(name = "Authorization") String token,
@RequestPart("thumbnail") MultipartFile thumbnail,
@RequestPart("dto") CardCreateRequestDTO cardCreateRequestDTO,
@RequestPart("files") List<MultipartFile> files
@Parameter(
name = "Authorization",
description = "로그인 성공 후 AccessToken",
required = true,
schema = @Schema(type = "string"),
in = ParameterIn.HEADER)
@PostMapping
public ResponseEntity<SingleResult<CardResponseDTO<CardCreateResponseDTO>>> createCard(
@RequestHeader("Authorization") String token,
@RequestBody CardCreateRequestDTO cardCreateRequestDTO
) {
CardCreateResponseDTO cardCreateResponseDTO = cardService.createCard(
token,
cardCreateRequestDTO,
thumbnail,
files
);
CardResponseDTO<CardCreateResponseDTO> card = cardService.createCard(token, cardCreateRequestDTO);

return ResponseEntity.ok(ResponseFactory.getSingleResult(cardCreateResponseDTO));
return ResponseEntity.ok(ResponseFactory.getSingleResult(card));
}

@GetMapping("/{cardId}")
public ResponseEntity<SingleResult<CardSingleReadResponseDTO>> getCardById(@PathVariable Long cardId) {
CardSingleReadResponseDTO cardSingleReadResponseDTO = cardService.getCardById(cardId);

return ResponseEntity.ok(ResponseFactory.getSingleResult(cardSingleReadResponseDTO));
}
// @GetMapping("/{cardId}")
// public ResponseEntity<SingleResult<CardSingleReadResponseDTO>> getCardById(@PathVariable Long cardId) {
// CardSingleReadResponseDTO cardSingleReadResponseDTO = cardService.getCardById(cardId);
//
// return ResponseEntity.ok(ResponseFactory.getSingleResult(cardSingleReadResponseDTO));
// }

@GetMapping
public ResponseEntity<SingleResult<CardListReadPagingResponseDTO>> getCardsByCondition(
Expand Down Expand Up @@ -90,6 +88,21 @@ public ResponseEntity<SingleResult<CardListResponseDTO<SuggestionAvailableCardRe
return ResponseEntity.ok(ResponseFactory.getSingleResult(cardListResponseDTO));
}

@PutMapping("/{cardId}")
public ResponseEntity<SingleResult<CardResponseDTO<CardUpdateResponseDTO>>> updateCardById(
@RequestHeader("Authorization") String token,
@PathVariable Long cardId,
@RequestBody CardUpdateRequestDTO cardUpdateRequestDTO
) {
CardResponseDTO<CardUpdateResponseDTO> cardResponseDTO = cardService.updateCardById(
token,
cardId,
cardUpdateRequestDTO
);

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

@PutMapping("/status/{cardId}")
public ResponseEntity<CommonResult> updateCardStatusById(
@RequestHeader(name = "authorization") String token,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.prgrms.nabimarketbe.domain.card.entity.Card;
import org.prgrms.nabimarketbe.domain.card.entity.TradeType;
import org.prgrms.nabimarketbe.domain.cardimage.dto.request.CardImageCreateRequestDTO;
import org.prgrms.nabimarketbe.domain.category.entity.Category;
import org.prgrms.nabimarketbe.domain.category.entity.CategoryEnum;
import org.prgrms.nabimarketbe.domain.item.entity.Item;
Expand All @@ -11,11 +12,15 @@

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

public record CardCreateRequestDTO( // TODO: images form-data로 받기
public record CardCreateRequestDTO(
@NotBlank(message = "공백을 허용하지 않습니다.")
String cardTitle,

@NotBlank(message = "공백을 허용하지 않습니다.")
String thumbNailImage,

@NotBlank(message = "공백을 허용하지 않습니다.")
String itemName,

Expand All @@ -25,17 +30,19 @@ public record CardCreateRequestDTO( // TODO: images form-data로 받기
@ValidEnum(enumClass = TradeType.class, message = "유효하지 않은 거래 방식입니다.")
TradeType tradeType,

@ValidEnum(enumClass = CategoryEnum.class, message = "유효하지 않은 카테고리입니다.")
CategoryEnum category,

@NotBlank(message = "공백을 허용하지 않습니다.")
String tradeArea,

@ValidEnum(enumClass = CategoryEnum.class, message = "유효하지 않은 카테고리입니다.")
CategoryEnum category,

@NotNull(message = "비울 수 없는 값입니다.")
Boolean pokeAvailable,

@NotBlank(message = "공백을 허용하지 않습니다.")
String content
String content,

List<CardImageCreateRequestDTO> images
) {
public Item toItemEntity(Category category) {
return Item.builder()
Expand All @@ -48,6 +55,7 @@ public Item toItemEntity(Category category) {
public Card toCardEntity(Item item, User user) {
return Card.builder()
.cardTitle(cardTitle)
.thumbNailImage(thumbNailImage)
.content(content)
.tradeArea(tradeArea)
.poke(pokeAvailable)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.prgrms.nabimarketbe.domain.card.dto.request;

import org.prgrms.nabimarketbe.global.annotation.ValidEnum;

import org.prgrms.nabimarketbe.domain.card.entity.Card;
import org.prgrms.nabimarketbe.domain.card.entity.TradeType;
import org.prgrms.nabimarketbe.domain.cardimage.dto.request.CardImageCreateRequestDTO;
import org.prgrms.nabimarketbe.domain.category.entity.Category;
import org.prgrms.nabimarketbe.domain.category.entity.CategoryEnum;
import org.prgrms.nabimarketbe.domain.item.entity.Item;
import org.prgrms.nabimarketbe.domain.item.entity.PriceRange;
import org.prgrms.nabimarketbe.domain.user.entity.User;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

public record CardUpdateRequestDTO(
@NotBlank(message = "공백을 허용하지 않습니다.")
String cardTitle,

@NotBlank(message = "공백을 허용하지 않습니다.")
String thumbNailImage,

@NotBlank(message = "공백을 허용하지 않습니다.")
String itemName,

@ValidEnum(enumClass = PriceRange.class, message = "유효하지 않은 가격대입니다.")
PriceRange priceRange,

@ValidEnum(enumClass = TradeType.class, message = "유효하지 않은 거래 방식입니다.")
TradeType tradeType,

@ValidEnum(enumClass = CategoryEnum.class, message = "유효하지 않은 카테고리입니다.")
CategoryEnum category,

@NotBlank(message = "공백을 허용하지 않습니다.")
String tradeArea,

@NotNull(message = "비울 수 없는 값입니다.")
Boolean poke,

@NotBlank(message = "공백을 허용하지 않습니다.")
String content,

List<CardImageCreateRequestDTO> images
) {
public Item toItemEntity(Category category) {
return Item.builder()
.itemName(itemName)
.priceRange(priceRange)
.category(category)
.build();
}

public Card toCardEntity(Item item, User user) {
return Card.builder()
.cardTitle(cardTitle)
.thumbNailImage(thumbNailImage)
.content(content)
.tradeArea(tradeArea)
.poke(poke)
.tradeType(tradeType)
.item(item)
.user(user)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.prgrms.nabimarketbe.domain.card.dto.response;

import lombok.Builder;
import org.prgrms.nabimarketbe.domain.card.entity.Card;
import org.prgrms.nabimarketbe.domain.card.entity.TradeType;
import org.prgrms.nabimarketbe.domain.cardimage.dto.response.CardImageCreateResponseDTO;
import org.prgrms.nabimarketbe.domain.cardimage.entity.CardImage;
import org.prgrms.nabimarketbe.domain.category.entity.CategoryEnum;
import org.prgrms.nabimarketbe.domain.item.entity.Item;
import org.prgrms.nabimarketbe.domain.item.entity.PriceRange;

import java.time.LocalDateTime;
Expand All @@ -28,38 +31,30 @@ public record CardCreateResponseDTO(
List<CardImageCreateResponseDTO> images
) {
public static CardCreateResponseDTO of(
Long cardId,
String cardTitle,
String itemName,
String thumbNailImage,
PriceRange priceRange,
TradeType tradeType,
CategoryEnum category,
String tradeArea,
Boolean pokeAvailable,
String content,
Integer viewCount,
Integer dibCount,
LocalDateTime createdAt,
LocalDateTime modifiedAt,
List<CardImageCreateResponseDTO> images
Card card,
Item item,
List<CardImage> cardImages
) {
List<CardImageCreateResponseDTO> cardImagesResponses = cardImages.stream()
.map(cardImage -> CardImageCreateResponseDTO.from(cardImage.getImageUrl()))
.toList();

return CardCreateResponseDTO.builder()
.cardId(cardId)
.cardTitle(cardTitle)
.itemName(itemName)
.thumbNailImage(thumbNailImage)
.priceRange(priceRange)
.tradeType(tradeType)
.category(category)
.tradeArea(tradeArea)
.pokeAvailable(pokeAvailable)
.content(content)
.viewCount(viewCount)
.dibCount(dibCount)
.createdAt(createdAt)
.modifiedAt(modifiedAt)
.images(images)
.cardId(card.getCardId())
.cardTitle(card.getCardTitle())
.itemName(item.getItemName())
.thumbNailImage(card.getThumbNailImage())
.priceRange(item.getPriceRange())
.tradeType(card.getTradeType())
.category(item.getCategory().getCategoryName())
.tradeArea(card.getTradeArea())
.pokeAvailable(card.getPoke())
.content(card.getContent())
.viewCount(card.getViewCount())
.dibCount(card.getDibCount())
.createdAt(card.getCreatedDate())
.modifiedAt(card.getModifiedDate())
.images(cardImagesResponses)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.prgrms.nabimarketbe.domain.card.dto.response;

import lombok.Builder;
import org.prgrms.nabimarketbe.domain.card.entity.Card;
import org.prgrms.nabimarketbe.domain.card.entity.CardStatus;
import org.prgrms.nabimarketbe.domain.card.entity.TradeType;
import org.prgrms.nabimarketbe.domain.cardimage.dto.response.CardImageSingleReadResponseDTO;
import org.prgrms.nabimarketbe.domain.cardimage.entity.CardImage;
import org.prgrms.nabimarketbe.domain.category.entity.CategoryEnum;
import org.prgrms.nabimarketbe.domain.item.entity.Item;
import org.prgrms.nabimarketbe.domain.item.entity.PriceRange;

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

@Builder
public record CardDetail(
Long cardId,
String cardTitle,
CategoryEnum category,
String itemName,
Boolean pokeAvailable,
LocalDateTime createdAt,
LocalDateTime modifiedAt,
Integer viewCount,
PriceRange priceRange,
String content,
CardStatus cardStatus,
TradeType tradeType,
String tradeArea,
Integer dibsCount,
Boolean isMyDib,
List<CardImageSingleReadResponseDTO> images
) {
public static CardDetail of(
Card card,
Item item,
List<CardImage> cardImages
) {
return CardDetail.builder().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.prgrms.nabimarketbe.domain.card.dto.response;

public record CardResponseDTO<T> (T cardInfo) {
}
Loading