Skip to content

Commit

Permalink
Merge pull request #22 from K-Hackathon-Fledge/21-PagingTotalPage
Browse files Browse the repository at this point in the history
21 paging total page
  • Loading branch information
gaguriee authored Aug 5, 2024
2 parents 42bc89c + afa3014 commit 153b0f5
Show file tree
Hide file tree
Showing 20 changed files with 359 additions and 216 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ public ResponseEntity<ApiResponse<CanaryProfileResponse>> updateCanaryProfile(

@Operation(summary = "자립준비청년 배송지 정보 조회", description = "자립준비청년 후원글 작성 시 배송지 정보를 불러올 수 있습니다.")
@GetMapping("/delivery")
public ResponseEntity<ApiResponse<CanaryGetDeliveryInfoResponse>> getCanaryDeliveryInfo(
)
{
public ResponseEntity<ApiResponse<CanaryGetDeliveryInfoResponse>> getCanaryDeliveryInfo() {
CanaryGetDeliveryInfoResponse canaryGetDeliveryInfoResponse = canaryProfileService.getCanaryDeliveryInfo();
return ApiResponse.success(SuccessStatus.DELIVERY_INFO_GET_SUCCESS, canaryGetDeliveryInfoResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
new AntPathRequestMatcher("/oauth2/authorization/**"),
new AntPathRequestMatcher("/login/oauth2/code/**"),
new AntPathRequestMatcher("/oauth2/**"),
new AntPathRequestMatcher("/api/v1/supports/**"),
new AntPathRequestMatcher("/api/v1/public/**")
).permitAll()
.anyRequest().authenticated()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public enum ErrorCode {
UNAUTHORIZED_REQUEST(UNAUTHORIZED, "권한이 없습니다."),
SUPPORT_NOT_FOUND(NOT_FOUND, "후원 요청 게시글을 찾을 수 없습니다."),
OVER_SUPPORT_PRICE(BAD_REQUEST, "후원 물품 금액을 초과하였습니다."),
POST_IMAGE_NOT_FOUND(NOT_FOUND, "후원 게시글의 이미지를 찾을 수 없습니다."),

// challenge
CHALLENGE_NOT_FOUND(NOT_FOUND, "챌린지를 찾을 수 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public enum SuccessStatus {
UPDATE_SUPPORT_SUCCESS(HttpStatus.OK, "후원하기 게시글 업데이트 성공"),
CREATE_DONATE_SUCCESS(HttpStatus.CREATED, "후원하기 성공"),
GET_SUPPORT_POST_PAGING_SUCCESS(HttpStatus.OK, "후원하기 게시글 페이징 조회 성공"),
GET_DEADLINE_APPROACHING_POST_SUCCESS(HttpStatus.OK, "마감 임박 후원하기 게시글 조회 성공"),
GET_SUPPORT_PROGRESS_SUCCESS(HttpStatus.OK, "후원하기 진행률 조회 성공"),

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
import com.fledge.fledgeserver.common.utils.SecurityUtils;
import com.fledge.fledgeserver.response.ApiResponse;
import com.fledge.fledgeserver.response.SuccessStatus;
import com.fledge.fledgeserver.support.dto.request.SupportPostUpdateRequest;
import com.fledge.fledgeserver.support.dto.request.SupportRecordCreateRequest;
import com.fledge.fledgeserver.support.dto.request.SupportPostCreateRequest;
import com.fledge.fledgeserver.support.dto.response.SupportGetForUpdateResponse;
import com.fledge.fledgeserver.support.dto.response.SupportPostGetResponse;
import com.fledge.fledgeserver.support.dto.response.SupportPostPagingResponse;
import com.fledge.fledgeserver.support.dto.response.SupportRecordProgressGetResponse;
import com.fledge.fledgeserver.support.dto.request.PostUpdateRequest;
import com.fledge.fledgeserver.support.dto.request.RecordCreateRequest;
import com.fledge.fledgeserver.support.dto.request.PostCreateRequest;
import com.fledge.fledgeserver.support.dto.response.*;
import com.fledge.fledgeserver.support.service.SupportService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -30,55 +27,72 @@ public class SupportController {
private final SupportService supportService;

@Operation(summary = "후원하기 게시글 등록",
description = "후원하기 게시글을 등록합니다.(자립 준비 청소년만)")
description = "후원하기 게시글을 등록합니다.(자립 준비 청소년만)\n" +
"\n" + // 추가적인 줄바꿈
"### promise\n" +
"[ONCE, WEEKLY, MONTHLY]" +
"\n" +
"### supportCategory\n" +
"[DAILY_NECESSITY, FOOD, HOME_APPLIANCES, EDUCATION, MEDICAL, LEGAL_AID, ETC]" +
"\n" +
"### 필수 정보\n" +
"- **MEDICAL** 또는 **LEGAL_AID** 카테고리를 선택할 경우, (은행 정보와 계좌 정보)가 필수입니다.\n" +
"- 기타 카테고리 선택 시 (이름, 전화번호, 주소, 상세 주소, 우편번호)가 필요합니다.")
@PostMapping
public ResponseEntity<ApiResponse<Object>> createSupport(
Principal principal,
@RequestBody SupportPostCreateRequest supportPostCreateRequest
@RequestBody PostCreateRequest postCreateRequest
) {
Long memberId = SecurityUtils.getCurrentUserId(principal);
supportService.createSupport(memberId, supportPostCreateRequest);
supportService.createSupport(memberId, postCreateRequest);
return ApiResponse.success(CREATE_SUPPORT_SUCCESS);
}

@Operation(summary = "후원하기 게시글 조회",
description = "후원하기 게시글을 조회합니다.(모든 회원 가능)")
@GetMapping("/{supportId}")
public ResponseEntity<ApiResponse<SupportPostGetResponse>> getSupport(
public ResponseEntity<ApiResponse<PostGetResponse>> getSupport(
@PathVariable(value = "supportId") Long supportId
) {
// TODO :: 후원 인증 관련 로직 추가
// TODO :: 후원 게시글 둘러보기를 후원하기 상세 페이지에서도 봐야함
return ApiResponse.success(GET_SUPPORT_SUCCESS, supportService.getSupport(supportId));
}

@Operation(summary = "후원 물품 금액 후원하기",
description = "후원하기 게시글에서 후원 물품 금액 조회합니다.(모든 회원 가능)")
description = "후원하기 게시글에서 후원 물품 금액 조회합니다.(모든 회원 가능)\n" +
"\n" +
"후원 시 후원 물품 금액을 초과하면 후원 물품 금액 초과 예외처리(400)")
@PostMapping("/{supportId}/record")
public ResponseEntity<ApiResponse<Object>> createSupportRecord(
@PathVariable(value = "supportId") Long supportId,
@RequestBody SupportRecordCreateRequest donationRequestDto,
@RequestBody RecordCreateRequest donationRequestDto,
Principal principal
) {
Long memberId = SecurityUtils.getCurrentUserId(principal);
// 후원 로직 처리
supportService.createSupportRecord(supportId, donationRequestDto, memberId);
return ApiResponse.success(CREATE_DONATE_SUCCESS);
}

@Operation(summary = "후원 진행률",
description = "후원하기 게시글 및 후원하기 시에 후원 진행률 반환")
@GetMapping("/{supportId}/progress")
public ResponseEntity<ApiResponse<SupportRecordProgressGetResponse>> getSupportProgress(
public ResponseEntity<ApiResponse<RecordProgressGetResponse>> getSupportProgress(
@PathVariable(value = "supportId") Long supportId
) {
return ApiResponse.success(GET_SUPPORT_PROGRESS_SUCCESS, supportService.getSupportProgress(supportId));
}

@Operation(summary = "후원하기 게시글 수정 시 기존 데이터 조회",
description = "후원하기 게시글의 기존 데이터를 반환합니다.\nStatus가 PENDING이면 공통 필드 수정 가능, 그 외 수정 불가")
description = "후원하기 게시글의 기존 데이터를 반환합니다.\n" +
"\n" +
"### 요청 정보\n" +
"- **supportId**: 수정할 게시글의 ID\n" +
"\n" +
"### 상태 정보\n" +
"- **Status가 PENDING**인 경우: 공통 필드 수정 가능\n" +
"- **그 외 상태**인 경우: 수정 불가")
@GetMapping("/{supportId}/update")
public ResponseEntity<ApiResponse<SupportGetForUpdateResponse>> getSupportForUpdate(
public ResponseEntity<ApiResponse<PostGetForUpdateResponse>> getSupportForUpdate(
@PathVariable(value = "supportId") Long supportId,
Principal principal
) {
Expand All @@ -88,30 +102,52 @@ public ResponseEntity<ApiResponse<SupportGetForUpdateResponse>> getSupportForUpd
);
}

@Operation(summary = "후원하기 게시글 수정", description = "(이미지 업데이트 안됨)후원하기 게시글을 수정합니다.")
@PutMapping("/{supportId}")
public ResponseEntity<ApiResponse<SupportPostGetResponse>> updateSupportPost(
@Operation(summary = "후원하기 게시글 수정",
description = "후원하기 게시글을 수정합니다.")
@PatchMapping("/{supportId}")
public ResponseEntity<ApiResponse<PostGetResponse>> updateSupportPost(
Principal principal,
@PathVariable(value = "supportId") Long supportId,
@RequestBody SupportPostUpdateRequest supportPostUpdateRequest
@RequestBody PostUpdateRequest postUpdateRequest
) {
Long memberId = SecurityUtils.getCurrentUserId(principal);
supportService.updateSupportPost(memberId, supportId, supportPostUpdateRequest);
supportService.updateSupportPost(memberId, supportId, postUpdateRequest);
return ApiResponse.success(SuccessStatus.UPDATE_SUPPORT_SUCCESS);
}

// TODO :: 후원하기 게시글 삭제 API


@Operation(summary = "후원하기 게시글 리스트 페이징",
description = "검색어(제목,내용) 및 카테고리 그리고 상태 기준으로 조회.")
description = "후원하기 게시글을 페이징하여 조회합니다.\n" +
"\n" +
"### 요청 파라미터\n" +
"- **page**: 현재 페이지 번호 (기본값: 1)\n" +
"- **q**: 검색어 (제목, 내용 기준으로 검색)\n" +
"- **category**: 카테고리 (여러 개 선택 가능)\n" +
" - 사용 예: category=\"Food\"&category=\"MEDICAL\"\n" +
"- **status**: 게시글 상태 ('ing'/'end', 기본값: 'ing')\n" +
"\n" +
"### 가능한 카테고리\n" +
"[DAILY_NECESSITY, FOOD, HOME_APPLIANCES, EDUCATION, MEDICAL, LEGAL_AID, ETC]")
@GetMapping("/paging")
public ResponseEntity<ApiResponse<List<SupportPostPagingResponse>>> pagingSupportPost(
@RequestParam(defaultValue = "0") int page, // 현재 페이지
// @RequestParam(defaultValue = "10") int limit //무조건 9개
public ResponseEntity<ApiResponse<PostTotalPagingResponse>> pagingSupportPost(
@RequestParam(defaultValue = "1") int page, // 현재 페이지
// @RequestParam(defaultValue = "9") int limit //무조건 9개
@RequestParam(defaultValue = "") String q,
@RequestParam(defaultValue = "") List<String> category, // 카테고리
@RequestParam(defaultValue = "") String q
@RequestParam(defaultValue = "ing") String status
) {
// 응답에 이미지 포함 시키기
return ApiResponse.success(GET_SUPPORT_POST_PAGING_SUCCESS, supportService.pagingSupportPost(page-1, q, category, status));
}

@Operation(summary = "마감 임박한 후원하기 게시글",
description = "4개씩 D-7까지 (limit=4, leftDays=7)")
@GetMapping("/deadline")
public ResponseEntity<ApiResponse<PostTotalPagingResponse>> deadlineApproachingPosts(
@RequestParam(defaultValue = "1") int page
// @RequestParam(defaultValue = "10") int limit // 무조건 4개
) {
return ApiResponse.success(GET_SUPPORT_POST_PAGING_SUCCESS, supportService.pagingSupportPost(page, category, q));
return ApiResponse.success(GET_DEADLINE_APPROACHING_POST_SUCCESS, supportService.deadlineApproachingPosts(page-1));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Getter
@Setter
@Schema(description = "후원하기 게시글 생성 DTO")
public class SupportPostCreateRequest {
public class PostCreateRequest {

@Schema(description = "후원 게시글 제목", required = true, example = "후원 요청")
@NotBlank(message = "제목은 필수입니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@Getter
@Setter
@Schema(description = "후원하기 게시글 수정 DTO")
public class SupportPostUpdateRequest {
public class PostUpdateRequest {

@Schema(description = "게시글 카테고리", required = true, example = "MEDICAL")
@NotBlank(message = "게시글 카테고리는 필수입니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Getter
@Setter
@Schema(description = "후원 기록 생성 DTO")
public class SupportRecordCreateRequest {
public class RecordCreateRequest {

@Schema(description = "후원 계좌 은행 이름", required = true, example = "국민은행")
@NotBlank(message = "은행 이름은 필수입니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@Getter
@Schema(description = "후원하기 게시글 수정 시 기존 데이터 조회 DTO")
public class SupportGetForUpdateResponse {
public class PostGetForUpdateResponse {

@Schema(description = "게시글 ID", example = "2")
private Long supportPostId;
Expand Down Expand Up @@ -73,7 +73,7 @@ public class SupportGetForUpdateResponse {
@Schema(description = "우편번호", example = "06123")
private String zip;

public SupportGetForUpdateResponse(Long supportPostId, String supportCategory, String supportPostStatus,Long memberId, String nickname, String title, String reason, String item, String purchaseUrl, int price, List<String> images, String promise, LocalDate expirationDate, String bank, String account, String recipientName, String phone, String address, String detailAddress, String zip) {
public PostGetForUpdateResponse(Long supportPostId, String supportCategory, String supportPostStatus, Long memberId, String nickname, String title, String reason, String item, String purchaseUrl, int price, List<String> images, String promise, LocalDate expirationDate, String bank, String account, String recipientName, String phone, String address, String detailAddress, String zip) {
this.supportPostId = supportPostId;
this.supportCategory = supportCategory;
this.supportPostStatus = supportPostStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@Getter
@Schema(description = "후원하기 게시글 조회 DTO")
public class SupportPostGetResponse {
public class PostGetResponse {
@Schema(description = "게시글 ID", example = "2")
private Long supportPostId;

Expand Down Expand Up @@ -48,7 +48,7 @@ public class SupportPostGetResponse {
@Schema(description = "후원자 리스트(후원자 + 금액)", example = "[{\"라이언고슬밥\": 10000}, {\"명륜진샤오미\": 20000}]")
private List<Map<String, Integer>> supporterList;

public SupportPostGetResponse(Long supportPostId, Long memberId, String nickname, String title, String reason, String item, String purchaseUrl, int price, List<String> images, LocalDate expirationDate, List<Map<String, Integer>> supporterList) {
public PostGetResponse(Long supportPostId, Long memberId, String nickname, String title, String reason, String item, String purchaseUrl, int price, List<String> images, LocalDate expirationDate, List<Map<String, Integer>> supporterList) {
this.supportPostId = supportPostId;
this.memberId = memberId;
this.nickname = nickname;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.fledge.fledgeserver.support.dto.response;

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

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;

@Getter
@Schema(description = "후원하기 게시글 Paging")
public class PostPagingResponse {
@Schema(description = "후원하기 게시글 ID", example = "2")
private Long supportId;

@Schema(description = "후원하기 게시글 제목", example = "")
private String title;

@Schema(description = "남은 기간", example = "99")
private String leftDays;

@Schema(description = "후원하기 게시글 사진 URL", example = "https://fledge-bucket.s3.ap-northeast-2.amazonaws.com/asdfndsvaksmdf")
private String supportPostImageUrl;

@Schema(description = "후원 받은 내역", example = "")
private RecordProgressGetResponse supportRecord;



public PostPagingResponse(Long supportId, String title, LocalDate expirationDate, String supportPostImageUrl, RecordProgressGetResponse supportRecord) {
this.supportId = supportId;
this.title = title;
this.leftDays = String.valueOf(ChronoUnit.DAYS.between(LocalDate.now(), expirationDate));
this.supportPostImageUrl = supportPostImageUrl;
this.supportRecord = supportRecord;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.fledge.fledgeserver.support.dto.response;

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

import java.util.List;

@Getter
@Schema(description = "후원하기 게시글 Paging - Total 페이지 수 포함")
public class PostTotalPagingResponse {
@Schema(description = "총 게시글 수", example = "100")
private int totalPosts;

@Schema(description = "총 페이지 수", example = "10")
private int totalPages;

@Schema(description = "후원하기 게시글 목록")
private List<PostPagingResponse> supportPosts;

public PostTotalPagingResponse(int totalPosts, int totalPages, List<PostPagingResponse> supportPosts) {
this.totalPosts = totalPosts;
this.totalPages = totalPages;
this.supportPosts = supportPosts;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@

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

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

@Schema(description = "현재 받은 후원금", example = "400000")
private int supportedPrice;

@Schema(description = "후원 진행률", example = "40")
@Schema(description = "후원 진행률(%)", example = "40")
private double progress;


public SupportRecordProgressGetResponse(int totalPrice, int supportedPrice) {
public RecordProgressGetResponse(int totalPrice, int supportedPrice) {
this.totalPrice = totalPrice;
this.supportedPrice = supportedPrice;
// 진행률 계산
double progressValue = (double) supportedPrice / totalPrice * 100;
this.progress = progressValue;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class SupportImage {
@ManyToOne
@JoinColumn(name = "support_post_id", nullable = false)
private SupportPost supportPost;


@Builder
public SupportImage(SupportPost supportPost, String imageUrl) {
Expand Down
Loading

0 comments on commit 153b0f5

Please sign in to comment.