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

채팅방 목록 조회 시 쿼리 변경 #760

Closed
wants to merge 10 commits into from
Closed
72 changes: 72 additions & 0 deletions .github/workflows/backend_flyway.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: flyway 스크립트 검증

on:
pull_request:
paths:
- 'backend/ddang/src/main/resources/db/migration/**.sql'
types: [opened, reopened, synchronize]
branches: [develop-be]

permissions: write-all
jobs:
build:
if: contains(github.event.pull_request.labels.*.name, 'backend')
runs-on: ubuntu-latest
services:
mysql:
image: mysql:latest
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: testdb
MYSQL_USER: test
MYSQL_PASSWORD: password
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- uses: actions/checkout@v3

- name: settings java
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: cache gradle
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: chmod gradle
run: chmod +x backend/ddang/gradlew

- name: Wait for MySQL to be ready
run: |
while [ -z "$DATABASE_URL" ]; do
echo "Waiting for MySQL to be ready..."
export DATABASE_URL=$(echo "SELECT 'ready';" | mysql -h127.0.0.1 -P3306 -utest -ppassword testdb --skip-column-names 2>/dev/null)
sleep 1
done

- name: Create flyway.conf
run: |
touch flyway.conf
echo "flyway.driver=com.mysql.cj.jdbc.Driver" >> flyway.conf
echo "flyway.url=jdbc:mysql://127.0.0.1:3306/testdb" >> flyway.conf
echo "flyway.user=test" >> flyway.conf
echo "flyway.password=password" >> flyway.conf
echo "flyway.encoding=UTF-8" >> flyway.conf
echo "flyway.locations=filesystem:src/main/resources/db/migration" >> flyway.conf
echo "flyway.validateOnMigrate=true" >> flyway.conf
working-directory: ./backend/ddang

- name: flywayValidate
run: |
./gradlew -Dflyway.configFiles=flyway.conf flywayMigrate --stacktrace
working-directory: ./backend/ddang
30 changes: 3 additions & 27 deletions .github/workflows/backend_pr_decorator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,6 @@ jobs:
echo "AUTHOR_NAME=${AUTHOR_NAME}" >> $GITHUB_OUTPUT
echo "AUTHOR_ID=${AUTHOR_ID}" >> $GITHUB_OUTPUT

- name: set variables
id: variables
run: |
REVIEWERS_GIT_ID='${{ toJson(github.event.pull_request.requested_reviewers[*].login) }}'
reviewers=$(echo "$REVIEWERS_GIT_ID" | jq -r '.[]')

REVIEWERS_SLACK_ID=""

for reviewer in $reviewers; do
echo "Reviewer: $reviewer"
if [ "$reviewer" == "apptie" ]; then
REVIEWERS_SLACK_ID+="<@${{ secrets.apptie_slack_id }}> "
elif [ "$reviewer" == "swonny" ]; then
REVIEWERS_SLACK_ID+="<@${{ secrets.swonny_slack_id }}> "
elif [ "$reviewer" == "JJ503" ]; then
REVIEWERS_SLACK_ID+="<@${{ secrets.JJ503_slack_id }}> "
elif [ "$reviewer" == "kwonyj1022" ]; then
REVIEWERS_SLACK_ID+="<@${{ secrets.kwonyj1022_slack_id }}> "
fi
done

echo "AUTHOR=${AUTHOR}" >> $GITHUB_OUTPUT
echo "REVIEWERS=${REVIEWERS}" >> $GITHUB_OUTPUT
echo "REVIEWERS_SLACK_ID=${REVIEWERS_SLACK_ID}" >> $GITHUB_OUTPUT

- name: slack notification
if: github.event_name == 'pull_request' && github.event.action != 'synchronize'
run: |
Expand All @@ -97,8 +72,7 @@ jobs:
SLACK_MESSAGE+="${{ github.event.pull_request.title }}"
SLACK_MESSAGE+="\n>\n>분석 결과\n>"
SLACK_MESSAGE+=":white_check_mark:"
SLACK_MESSAGE+="\n>\n>*리뷰어*\n>"
SLACK_MESSAGE+="${{ steps.variables.outputs.REVIEWERS_SLACK_ID }}"
SLACK_MESSAGE+="\n\n리뷰 요청은 스레드로 직접 멘션해주세요."
SLACK_MESSAGE+='"}}]}'

curl -X POST ${{ secrets.SLACK_WEBHOOK }} -d "${SLACK_MESSAGE}"
Expand All @@ -116,6 +90,7 @@ jobs:
SLACK_MESSAGE+="${{ github.event.pull_request.title }}"
SLACK_MESSAGE+="\n>\n>분석 결과\n>"
SLACK_MESSAGE+=":x:"
SLACK_MESSAGE+="\n\n리뷰 요청은 문제 해결 후 스레드로 직접 멘션해주세요."
SLACK_MESSAGE+='"}}]}'

curl -X POST ${{ secrets.SLACK_WEBHOOK }} -d "${SLACK_MESSAGE}"
Expand All @@ -133,6 +108,7 @@ jobs:
SLACK_MESSAGE+="${{ github.event.pull_request.title }}"
SLACK_MESSAGE+="\n>\n>분석 결과\n>"
SLACK_MESSAGE+=":black_square_for_stop:"
SLACK_MESSAGE+="\n\n리뷰 요청은 문제 해결 후 스레드로 직접 멘션해주세요."
SLACK_MESSAGE+='"}}]}'

curl -X POST ${{ secrets.SLACK_WEBHOOK }} -d "${SLACK_MESSAGE}"
15 changes: 15 additions & 0 deletions backend/ddang/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.flywaydb:flyway-mysql:9.16.0'
}
}

plugins {
id 'java'
id 'org.springframework.boot' version '3.0.8'
id 'io.spring.dependency-management' version '1.1.0'
id 'jacoco'
id 'org.asciidoctor.jvm.convert' version '3.3.2'
id 'org.flywaydb.flyway' version '9.16.0'
}

configurations {
Expand Down Expand Up @@ -67,6 +77,11 @@ dependencies {
implementation 'ch.qos.logback.contrib:logback-json-classic:0.1.5'
implementation 'net.logstash.logback:logstash-logback-encoder:6.1'

// aws
implementation platform('software.amazon.awssdk:bom:2.20.56')
implementation 'software.amazon.awssdk:s3'
implementation 'software.amazon.awssdk:cloudfront'

implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.ddang.ddang.auction.application.dto;

import com.ddang.ddang.auction.domain.Auction;
import com.ddang.ddang.image.application.util.ImageStoreNameProcessor;

public record CreateInfoAuctionDto(
Long id,
String title,
Long auctionImageId,
String auctionStoreName,
int startPrice
) {

public static CreateInfoAuctionDto from(final Auction auction) {
return new CreateInfoAuctionDto(
auction.getId(),
auction.getTitle(),
auction.getAuctionImages().get(0).getId(),
ImageStoreNameProcessor.process(auction.getAuctionImages().get(0)),
auction.getStartPrice().getValue()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import com.ddang.ddang.auction.domain.Auction;
import com.ddang.ddang.auction.domain.AuctionStatus;
import com.ddang.ddang.bid.domain.Bid;
import com.ddang.ddang.image.application.util.ImageIdProcessor;
import com.ddang.ddang.image.domain.AuctionImage;
import com.ddang.ddang.image.application.util.ImageStoreNameProcessor;

import java.time.LocalDateTime;
import java.util.List;
Expand All @@ -20,12 +19,12 @@ public record ReadAuctionDto(
LocalDateTime registerTime,
LocalDateTime closingTime,
List<ReadRegionsDto> auctionRegions,
List<Long> auctionImageIds,
List<String> auctionImageStoreNames,
int auctioneerCount,
String mainCategory,
String subCategory,
Long sellerId,
Long sellerProfileId,
String sellerProfileImageStoreName,
String sellerName,
double sellerReliability,
boolean isSellerDeleted,
Expand All @@ -45,12 +44,12 @@ public static ReadAuctionDto of(final Auction auction, final LocalDateTime targe
auction.getCreatedTime(),
auction.getClosingTime(),
convertReadRegionsDto(auction),
convertImageIds(auction),
convertImageStoreNames(auction),
auction.getAuctioneerCount(),
auction.getSubCategory().getMainCategory().getName(),
auction.getSubCategory().getName(),
auction.getSeller().getId(),
ImageIdProcessor.process(auction.getSeller().getProfileImage()),
ImageStoreNameProcessor.process(auction.getSeller().getProfileImage()),
auction.getSeller().getName(),
auction.getSeller().getReliability().getValue(),
auction.getSeller().isDeleted(),
Expand All @@ -59,10 +58,10 @@ public static ReadAuctionDto of(final Auction auction, final LocalDateTime targe
);
}

private static List<Long> convertImageIds(final Auction auction) {
private static List<String> convertImageStoreNames(final Auction auction) {
return auction.getAuctionImages()
.stream()
.map(AuctionImage::getId)
.map(ImageStoreNameProcessor::process)
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,8 @@ public Optional<User> findLastBidder() {

return Optional.of(lastBid.getBidder());
}

public Optional<Bid> findLastBid() {
return Optional.ofNullable(lastBid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public interface JpaAuctionRepository extends JpaRepository<Auction, Long> {
LEFT JOIN FETCH a.lastBid
JOIN FETCH a.subCategory sc
JOIN FETCH sc.mainCategory
JOIN FETCH a.seller
JOIN FETCH a.seller seller
LEFT JOIN FETCH seller.profileImage
WHERE a.deleted = false AND a.id = :id
""")
Optional<Auction> findTotalAuctionById(final Long id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ private List<Auction> findAuctionsByIdsAndOrderSpecifiers(
.join(auction.subCategory, category).fetchJoin()
.join(category.mainCategory).fetchJoin()
.join(auction.seller).fetchJoin()
.join(auction.seller.profileImage).fetchJoin()
.where(auction.id.in(targetIds.toArray(Long[]::new)))
.orderBy(orderSpecifiers.toArray(OrderSpecifier[]::new))
.fetch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public static AuctionDetailResponse from(final ReadAuctionDto dto) {
}

private static List<String> convertImageFullUrls(final ReadAuctionDto dto) {
return dto.auctionImageIds()
return dto.auctionImageStoreNames()
.stream()
.map(id -> ImageUrlCalculator.calculateBy(ImageRelativeUrl.AUCTION, id))
.map(imageStoreName -> ImageUrlCalculator.calculateBy(ImageRelativeUrl.AUCTION, imageStoreName))
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public static CreateAuctionResponse from(final CreateInfoAuctionDto dto) {
return new CreateAuctionResponse(
dto.id(),
dto.title(),
convertAuctionImageUrl(dto.auctionImageId()),
convertAuctionImageUrl(dto.auctionStoreName()),
dto.startPrice(),
AuctionStatus.UNBIDDEN.name(),
0
);
}

private static String convertAuctionImageUrl(final Long id) {
return ImageUrlCalculator.calculateBy(ImageRelativeUrl.AUCTION, id);
private static String convertAuctionImageUrl(final String storeName) {
return ImageUrlCalculator.calculateBy(ImageRelativeUrl.AUCTION, storeName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static ReadAuctionResponse from(final ReadAuctionDto dto) {
return new ReadAuctionResponse(
dto.id(),
dto.title(),
ImageUrlCalculator.calculateBy(ImageRelativeUrl.AUCTION, dto.auctionImageIds().get(0)),
ImageUrlCalculator.calculateBy(ImageRelativeUrl.AUCTION, dto.auctionImageStoreNames().get(0)),
processAuctionPrice(dto.startPrice(), dto.lastBidPrice()),
dto.auctionStatus().name(),
dto.auctioneerCount()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static ReadUserInAuctionQuestionResponse from(final ReadUserInQnaDto writ
return new ReadUserInAuctionQuestionResponse(
writerDto.id(),
NameProcessor.process(writerDto.isDeleted(), writerDto.name()),
ImageUrlCalculator.calculateBy(ImageRelativeUrl.USER, writerDto.profileImageId())
ImageUrlCalculator.calculateBy(ImageRelativeUrl.USER, writerDto.profileImageStoreName())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public record SellerResponse(
public static SellerResponse from(final ReadAuctionDto auctionDto) {
return new SellerResponse(
auctionDto.sellerId(),
ImageUrlCalculator.calculateBy(ImageRelativeUrl.USER, auctionDto.sellerProfileId()),
ImageUrlCalculator.calculateBy(ImageRelativeUrl.USER, auctionDto.sellerProfileImageStoreName()),
NameProcessor.process(auctionDto.isSellerDeleted(), auctionDto.sellerName()),
ReliabilityProcessor.process(auctionDto.sellerReliability())
);
Expand Down
Loading
Loading