Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
gaguriee committed Aug 10, 2024
2 parents 32779e7 + 76aa85d commit 40810e5
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 26 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ jobs:
sudo docker pull "${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:backend"
sudo docker run -d \
--name "$CONTAINER_NAME" \
-p 80:8080 \
--log-driver=awslogs \
--log-opt awslogs-group=/fledge/backend \
--log-opt awslogs-region=ap-northeast-2 \
--log-opt awslogs-stream="$CONTAINER_NAME" \
"${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:backend"
--name "$CONTAINER_NAME" \
-p 80:8080 \
--log-driver=awslogs \
--log-opt awslogs-group=/fledge/backend \
--log-opt awslogs-region=ap-northeast-2 \
--log-opt awslogs-stream="$CONTAINER_NAME" \
-e TZ=Asia/Seoul \
-e SPRING_PROFILES_ACTIVE=prod \
"${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:backend"
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public class PostCreateRequest {
private String item;

@Schema(description = "구매 URL", example = "https://example.com/product/1")
@NotBlank(message = "구매 URL은 필수입니다.")
@URL(message = "유효한 URL 형식이어야 합니다.")
private String purchaseUrl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class PostUpdateRequest {
private String item;

@Schema(description = "구매 URL", example = "https://example.com/product/1")
@NotBlank(message = "구매 URL은 필수입니다.")
@URL(message = "유효한 URL 형식이어야 합니다.")
private String purchaseUrl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ public class RecordCreateRequest {
@NotNull(message = "후원 금액은 필수입니다.")
@Positive(message = "후원 금액은 0보다 큰 숫자여야 합니다.")
private int amount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import java.text.DecimalFormat;

@Getter
@Schema(description = "후원 게시글 조회 시 후원 기록 반환")
public class RecordProgressGetResponse {

private static final DecimalFormat df = new DecimalFormat("#.#");

@Schema(description = "후원 물품 총 금액", example = "1000000")
private int totalPrice;

Expand All @@ -16,11 +19,14 @@ public class RecordProgressGetResponse {
@Schema(description = "후원 진행률(%)", example = "40")
private double progress;


public RecordProgressGetResponse(int totalPrice, int supportedPrice) {
this.totalPrice = totalPrice;
this.supportedPrice = supportedPrice;
double progressValue = (double) supportedPrice / totalPrice * 100;
this.progress = progressValue;
if (totalPrice == 0) {
this.progress = 0.0;
} else {
double progressValue = (double) supportedPrice / totalPrice * 100;
this.progress = Double.parseDouble(df.format(progressValue));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,24 @@ default SupportPost findSupportByIdOrThrow(Long supportId) {
}

@Query("SELECT sp FROM SupportPost sp " +
"LEFT JOIN FETCH sp.images " + // Fetch images
"LEFT JOIN FETCH sp.images " +
"WHERE (:category IS NULL OR sp.supportCategory IN :category) " +
"AND (sp.title LIKE %:q% OR sp.reason LIKE %:q%) " +
"AND (:status IS NULL OR " +
" (sp.supportPostStatus IN (com.fledge.fledgeserver.support.entity.SupportPostStatus.PENDING, " +
" com.fledge.fledgeserver.support.entity.SupportPostStatus.IN_PROGRESS) AND :status = 'ing') OR " +
" (sp.supportPostStatus IN (com.fledge.fledgeserver.support.entity.SupportPostStatus.COMPLETED, " +
" com.fledge.fledgeserver.support.entity.SupportPostStatus.TERMINATED) AND :status = 'end')) " +
"AND (:status IS NULL OR (" +
" (:status = 'ing' AND sp.supportPostStatus IN " +
" (com.fledge.fledgeserver.support.entity.SupportPostStatus.PENDING, " +
" com.fledge.fledgeserver.support.entity.SupportPostStatus.IN_PROGRESS)) " +
" OR " +
" (:status = 'end' AND sp.supportPostStatus IN " +
" (com.fledge.fledgeserver.support.entity.SupportPostStatus.COMPLETED, " +
" com.fledge.fledgeserver.support.entity.SupportPostStatus.TERMINATED))" +
")) " +
"ORDER BY sp.createdDate DESC")
Page<SupportPost> findByCategoryAndSearchAndSupportPostStatusWithImages(@Param("category") List<SupportCategory> category,
@Param("q") String q,
@Param("status") String status,
Pageable pageable);

@Query("SELECT sp FROM SupportPost sp " +
"WHERE FUNCTION('DATEDIFF', sp.expirationDate, CURRENT_DATE) <= 7 " +
"AND (sp.supportPostStatus = :pending OR sp.supportPostStatus = :inProgress) " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;

import static com.fledge.fledgeserver.support.entity.SupportPostStatus.IN_PROGRESS;
Expand Down Expand Up @@ -253,13 +250,19 @@ private void clearAndUpdateImages(SupportPost supportPost, PostUpdateRequest pos

@Transactional(readOnly = true)
public PostTotalPagingResponse pagingSupportPost(int page, String q, List<String> category, String status) {
PageRequest pageable = PageRequest.of(page, 9);
PageRequest pageable = PageRequest.of(page, 9); // 페이지 번호가 0부터 시작

List<SupportCategory> selectedCategories = category.isEmpty() ? null : category.stream()
.map(SupportCategory::valueOf)
.collect(Collectors.toList());

// 쿼리를 통해 페이징된 결과를 가져옵니다.
Page<SupportPost> supportPostPage = supportPostRepository.findByCategoryAndSearchAndSupportPostStatusWithImages(selectedCategories, q, status, pageable);
// 결과가 없을 경우 빈 리스트 반환
if (supportPostPage.isEmpty()) {
return new PostTotalPagingResponse(0, 0, Collections.emptyList());
}

long totalElements = supportPostPage.getTotalElements();

List<PostPagingResponse> postPagingResponse = supportPostPage.getContent().stream()
Expand All @@ -268,8 +271,10 @@ public PostTotalPagingResponse pagingSupportPost(int page, String q, List<String
int supportedPrice = supportPost.getSupportRecords().stream()
.mapToInt(SupportRecord::getAmount)
.sum();

RecordProgressGetResponse supportRecordProgress = new RecordProgressGetResponse(totalPrice, supportedPrice);
String imageUrl = supportPost.getImages().isEmpty() ? null : fileService.getDownloadPresignedUrl(supportPost.getImages().get(0).getImageUrl());
System.out.println("imageUrl = " + imageUrl);
return new PostPagingResponse(
supportPost.getId(),
supportPost.getTitle(),
Expand All @@ -280,7 +285,7 @@ public PostTotalPagingResponse pagingSupportPost(int page, String q, List<String
})
.collect(Collectors.toList());

int totalPages = supportPostPage.getTotalPages();
int totalPages = supportPostPage.getTotalPages(); // 총 페이지 수 계산

return new PostTotalPagingResponse((int) totalElements, totalPages, postPagingResponse);
}
Expand All @@ -294,7 +299,7 @@ public List<PostPagingResponse> deadlineApproachingPosts() {
.map(supportPost -> {
int totalPrice = supportPost.getPrice();
Long supportPostId = supportPost.getId();
System.out.println("supportPostId = " + supportPostId);

int supportedPrice = supportRecordRepository.sumSupportedPriceBySupportPostId(supportPostId);

RecordProgressGetResponse supportRecordProgress = new RecordProgressGetResponse(totalPrice, supportedPrice);
Expand Down

0 comments on commit 40810e5

Please sign in to comment.