Skip to content

Commit

Permalink
Merge branch 'dev' into NABI-255--junhyuk--fix--card-list-read-with-c…
Browse files Browse the repository at this point in the history
…ursor-paging
  • Loading branch information
hi-june committed Nov 18, 2023
2 parents 61ecbd0 + c6f6857 commit 91c9f19
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 106 deletions.
54 changes: 28 additions & 26 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ on:
branches: [ "main", "dev" ] # master branch로 pull request될 때 실행

env:
# 아무거나 해도 됨
PROJECT_NAME: nabi
# aws 이름 똑같아야됨
BUCKET_NAME: team-01-bucket
CODE_DEPLOY_APP_NAME: team01-codedeploy
DEPLOYMENT_GROUP_NAME: team01-instance-group
Expand Down Expand Up @@ -64,29 +66,29 @@ jobs:
run: ./gradlew build
shell: bash

- name: Make zip file
run: zip -r ./$GITHUB_SHA.zip .
shell: bash

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.SECRET_KEY }}
aws-region: ap-northeast-2

# script files 복사
- name: Copy script
run: cp ./scripts/*.sh ./deploy
# S3에 빌드 결과 업로드
- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$BUCKET_NAME/$PROJECT_NAME/$GITHUB_SHA.zip

# Deploy 실행
- name: Code Deploy To EC2 instance
run: aws deploy create-deployment
--application-name $CODE_DEPLOY_APP_NAME
--deployment-config-name CodeDeployDefault.AllAtOnce
--deployment-group-name $DEPLOYMENT_GROUP_NAME
--s3-location bucket=$BUCKET_NAME,bundleType=zip,key=$PROJECT_NAME/$GITHUB_SHA.zip
# - name: Make zip file
# run: zip -r ./$GITHUB_SHA.zip .
# shell: bash
#
# - name: Configure AWS credentials
# uses: aws-actions/configure-aws-credentials@v1
# with:
# aws-access-key-id: ${{ secrets.ACCESS_KEY }}
# aws-secret-access-key: ${{ secrets.SECRET_KEY }}
# aws-region: ap-northeast-2
#
# # script files 복사
# - name: Copy script
# run: cp ./scripts/*.sh ./deploy
#
# # S3에 빌드 결과 업로드
# - name: Upload to S3
# run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$BUCKET_NAME/$PROJECT_NAME/$GITHUB_SHA.zip
#
# # Deploy 실행
# - name: Code Deploy To EC2 instance
# run: aws deploy create-deployment
# --application-name $CODE_DEPLOY_APP_NAME
# --deployment-config-name CodeDeployDefault.AllAtOnce
# --deployment-group-name $DEPLOYMENT_GROUP_NAME
# --s3-location bucket=$BUCKET_NAME,bundleType=zip,key=$PROJECT_NAME/$GITHUB_SHA.zip
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ plugins {
id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
}

// SNAPSHOT-plain 생성 막기위함
jar {
enabled = false
}

group = 'org.prgrms'
version = '0.0.1-SNAPSHOT'

Expand Down Expand Up @@ -74,7 +79,7 @@ querydsl {
sourceSets {
main.java.srcDir querydslDir
}
compileQuerydsl{
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
configurations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.prgrms.nabimarketbe.global.annotation.ValidEnum;

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

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

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;
Expand All @@ -11,7 +9,8 @@
import org.prgrms.nabimarketbe.domain.category.entity.CategoryEnum;
import org.prgrms.nabimarketbe.domain.item.entity.PriceRange;

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

@Builder
public record CardDetailResponseDTO(
Expand All @@ -26,7 +25,7 @@ public record CardDetailResponseDTO(
Integer viewCount,
PriceRange priceRange,
String content,
CardStatus cardStatus,
CardStatus status,
TradeType tradeType,
String tradeArea,
Integer dibCount,
Expand All @@ -50,7 +49,7 @@ public static CardDetailResponseDTO of(
.viewCount(card.getViewCount())
.priceRange(card.getItem().getPriceRange())
.content(card.getContent())
.cardStatus(card.getStatus())
.status(card.getStatus())
.tradeType(card.getTradeType())
.tradeArea(card.getTradeArea())
.dibCount(card.getDibCount())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.prgrms.nabimarketbe.domain.card.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

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;
Expand Down Expand Up @@ -38,7 +35,9 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

@Service
@RequiredArgsConstructor
Expand All @@ -61,14 +60,14 @@ public class CardService {

@Transactional
public CardResponseDTO<CardCreateResponseDTO> createCard(
String token,
CardCreateRequestDTO cardCreateRequestDTO
String token,
CardCreateRequestDTO cardCreateRequestDTO
) {
User user = userRepository.findById(checkService.parseToken(token))
.orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_FOUND));
.orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_FOUND));

Category category = categoryRepository.findCategoryByCategoryName(cardCreateRequestDTO.category())
.orElseThrow(() -> new BaseException(ErrorCode.CATEGORY_NOT_FOUND));
.orElseThrow(() -> new BaseException(ErrorCode.CATEGORY_NOT_FOUND));

Item item = cardCreateRequestDTO.toItemEntity(category);

Expand Down Expand Up @@ -108,7 +107,7 @@ public CardResponseDTO<CardUpdateResponseDTO> updateCardById(
CardUpdateRequestDTO cardUpdateRequestDTO
) {
Long userId = checkService.parseToken(token);
if (userRepository.existsById(userId)) {
if (!userRepository.existsById(userId)) {
throw new BaseException(ErrorCode.USER_NOT_FOUND);
}

Expand Down Expand Up @@ -162,44 +161,44 @@ public CardResponseDTO<CardUpdateResponseDTO> updateCardById(
return new CardResponseDTO<>(cardUpdateResponseDTO);
}

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

Boolean isMyDib = false;
Boolean isMyDib = false;

if(token != null) {
Long userId = checkService.parseToken(token);
User loginUser = userRepository.findById(userId)
.orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_FOUND));
if (token != null) {
Long userId = checkService.parseToken(token);
User loginUser = userRepository.findById(userId)
.orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_FOUND));

if (!checkService.isEqual(userId, card.getUser().getUserId())) {
card.updateViewCount();
isMyDib = dibRepository.existsDibByCardAndUser(card, loginUser);
}
}
if (!checkService.isEqual(userId, card.getUser().getUserId())) {
card.updateViewCount();
isMyDib = dibRepository.existsDibByCardAndUser(card, loginUser);
}
}

User cardOwner = card.getUser();
User cardOwner = card.getUser();

List<CardImage> cardImages = cardImageRepository.findAllByCard(card);
List<CardImage> cardImages = cardImageRepository.findAllByCard(card);

CardDetailResponseDTO cardInfo = CardDetailResponseDTO.of(
card,
cardImages,
isMyDib
);
CardDetailResponseDTO cardInfo = CardDetailResponseDTO.of(
card,
cardImages,
isMyDib
);

UserSummaryResponseDTO userInfo = UserSummaryResponseDTO.from(cardOwner);
UserSummaryResponseDTO userInfo = UserSummaryResponseDTO.from(cardOwner);

return CardUserResponseDTO.of(
cardInfo,
userInfo
);
}
return CardUserResponseDTO.of(
cardInfo,
userInfo
);
}

@Transactional(readOnly = true)
public CardPagingResponseDTO getCardsByCondition(
Expand Down Expand Up @@ -227,7 +226,7 @@ public CardListResponseDTO<CardSuggestionResponseDTO> getSuggestionAvailableCard
) {
Long userId = checkService.parseToken(token);
User requestUser = userRepository.findById(userId)
.orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_FOUND));
.orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_FOUND));
Card suggestionTargetCard = cardRepository.findById(targetCardId)
.orElseThrow(() -> new BaseException(ErrorCode.CARD_NOT_FOUND));

Expand Down Expand Up @@ -282,7 +281,7 @@ public void updateCardStatusById(
throw new BaseException(ErrorCode.USER_NOT_MATCHED);
}

switch (cardStatusUpdateRequestDTO.cardStatus()) {
switch (cardStatusUpdateRequestDTO.status()) {
case TRADE_AVAILABLE -> card.updateCardStatusToTradeAvailable();
case RESERVED -> card.updateCardStatusToReserved();
case TRADE_COMPLETE -> card.updateCardStatusToTradeComplete();
Expand All @@ -308,7 +307,7 @@ public void deleteCardById(

cardRepository.delete(card);
}

@Transactional
public List<CardSuggestionResponseDTO> getSuggestionResultCardList(
Long targetId,
Expand All @@ -334,8 +333,7 @@ private List<CardSuggestionResponseDTO> parseCardListWithPokeAndOffer(
.peek(cardSuggestionResponseDTO -> {
if (targetPriceRange.isHigherThan(cardSuggestionResponseDTO.getCardInfo().getPriceRange())) {
cardSuggestionResponseDTO.getSuggestionInfo().updateSuggestionType(SuggestionType.POKE);
}
else {
} else {
cardSuggestionResponseDTO.getSuggestionInfo().updateSuggestionType(SuggestionType.OFFER);
}
}).toList();
Expand All @@ -357,7 +355,7 @@ private List<CardSuggestionResponseDTO> parseCardListWithOnlyOffer(

return offerOnlyCardList;
}

private List<CardImage> addThumbnail(
List<CardImage> cardImages,
CardImage thumbnail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ public class CardImageBatchRepository {

private static final String sql = "INSERT INTO card_images (created_date, modified_date, image_url, card_id) VALUES (?, ?, ?, ?)";

private static final Integer SUCCESS_SIGNAL = -2;
private static final Integer SUCCESS_SIGNAL = 1;

@Transactional
public boolean saveAll(List<CardImage> cardImages) {
int[][] result = jdbcTemplate.batchUpdate(sql,
cardImages,
cardImages.size(),
(PreparedStatement preparedStatement, CardImage cardImage) -> {
preparedStatement.setTimestamp(1,Timestamp.valueOf(LocalDateTime.now()));
preparedStatement.setTimestamp(2,Timestamp.valueOf(LocalDateTime.now()));
preparedStatement.setTimestamp(1, Timestamp.valueOf(LocalDateTime.now()));
preparedStatement.setTimestamp(2, Timestamp.valueOf(LocalDateTime.now()));
preparedStatement.setString(3, cardImage.getImageUrl());
preparedStatement.setLong(4,cardImage.getCard().getCardId());
preparedStatement.setLong(4, cardImage.getCard().getCardId());
});

for (int[] value : result) {
if ( value[0] != SUCCESS_SIGNAL) {
if (value[0] != SUCCESS_SIGNAL) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

@Builder
public record UserSummaryResponseDTO(
Long userId,
String nickname,
String profileUrl
Long userId,
String nickname,
String imageUrl
) {
public static UserSummaryResponseDTO from(User user) {
return UserSummaryResponseDTO.builder()
.userId(user.getUserId())
.nickname(user.getNickname())
.profileUrl(user.getImageUrl())
.build();
}
public static UserSummaryResponseDTO from(User user) {
return UserSummaryResponseDTO.builder()
.userId(user.getUserId())
.nickname(user.getNickname())
.imageUrl(user.getImageUrl())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

@Builder
public record UserUpdateResponseDTO(
Long userId,
String nickname,
String profileUrl
Long userId,
String nickname,
String imageUrl
) {
public static UserUpdateResponseDTO from(User user) {
return UserUpdateResponseDTO.builder()
.userId(user.getUserId())
.nickname(user.getNickname())
.profileUrl(user.getImageUrl())
.build();
}
public static UserUpdateResponseDTO from(User user) {
return UserUpdateResponseDTO.builder()
.userId(user.getUserId())
.nickname(user.getNickname())
.imageUrl(user.getImageUrl())
.build();
}
}

0 comments on commit 91c9f19

Please sign in to comment.