Skip to content

Commit

Permalink
FEAT : 후원 등록하기 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
JuseungL committed Aug 2, 2024
1 parent 1f3d228 commit 23fa59e
Show file tree
Hide file tree
Showing 13 changed files with 376 additions and 161 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.fledge.fledgeserver.canary.controller;

import com.fledge.fledgeserver.auth.dto.OAuthUserImpl;
import com.fledge.fledgeserver.canary.dto.CanaryGetDeliveryInfoResponse;
import com.fledge.fledgeserver.canary.dto.CanaryProfileRequest;
import com.fledge.fledgeserver.canary.dto.CanaryProfileResponse;
import com.fledge.fledgeserver.canary.dto.CanaryProfileUpdateRequest;
import com.fledge.fledgeserver.canary.dto.*;
import com.fledge.fledgeserver.canary.service.CanaryProfileService;
import com.fledge.fledgeserver.common.utils.SecurityUtils;
import com.fledge.fledgeserver.member.entity.Member;
import com.fledge.fledgeserver.response.ApiResponse;
import com.fledge.fledgeserver.response.SuccessStatus;
import com.fledge.fledgeserver.support.dto.response.SupportGetResponseDto;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand All @@ -23,6 +21,8 @@

import java.security.Principal;

import static com.fledge.fledgeserver.response.SuccessStatus.GET_SUPPORT_SUCCESS;

@Tag(name = "자립준비청년 API", description = "자립준비청년 관리 관련 API")
@RestController
@RequiredArgsConstructor
Expand Down Expand Up @@ -71,6 +71,10 @@ public ResponseEntity<ApiResponse<CanaryProfileResponse>> updateCanaryProfile(
return ApiResponse.success(SuccessStatus.PROFILE_UPDATE_SUCCESS, response);
}

/**
* 이하 API 후원하기 시에 필요
*/

@Operation(summary = "자립준비청년 배송지 정보 조회", description = "자립준비청년 후원글 작성 시 배송지 정보를 불러올 수 있습니다.")
@GetMapping("/delivery")
public ResponseEntity<ApiResponse<CanaryGetDeliveryInfoResponse>> getCanaryDeliveryInfo(
Expand All @@ -81,4 +85,13 @@ public ResponseEntity<ApiResponse<CanaryGetDeliveryInfoResponse>> getCanaryDeliv
System.out.println("memberId = " + memberId);
return ApiResponse.success(SuccessStatus.DELIVERY_INFO_GET_SUCCESS, canaryProfileService.getCanaryDeliveryInfo(memberId));
}

@Operation(summary = "후원하기 게시글 조회 시 자립준비청년 프로필 조회", description = "후원하기 게시글에서 자립준비청년 프로필을 조회합니다.")
@GetMapping("/{memberId}/supports")
public ResponseEntity<ApiResponse<CanaryProfileGetResponseDto>> getSupport(
@PathVariable(value = "memberId") Long memberId
) {
// TODO :: 자립준비청년이 완료한 챌린지 및 후원 인증 스토리 그리고 인증률도 함께 보여줘야함!
return ApiResponse.success(GET_SUPPORT_SUCCESS, canaryProfileService.getCanaryForSupport(memberId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.fledge.fledgeserver.canary.dto;

import com.fledge.fledgeserver.canary.entity.CanaryProfile;
import com.fledge.fledgeserver.member.entity.Member;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

import java.util.Date;

@Getter
@Schema(description = "후원하기에서 자립준비청년 프로필 조회 응답 DTO")
public class CanaryProfileGetResponseDto {

@Schema(description = "닉네임", example = "카드값줘체리")
private String nickname;

@Schema(description = "자기 소개", example = "안녕하세요, 저는...")
private String introduction;


public CanaryProfileGetResponseDto(CanaryProfile canaryProfile) {
this.nickname = canaryProfile.getMember().getNickname();
this.introduction = canaryProfile.getIntroduction();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.fledge.fledgeserver.canary.service;

import com.fledge.fledgeserver.auth.dto.OAuthUserImpl;
import com.fledge.fledgeserver.canary.dto.CanaryGetDeliveryInfoResponse;
import com.fledge.fledgeserver.canary.dto.CanaryProfileRequest;
import com.fledge.fledgeserver.canary.dto.CanaryProfileResponse;
import com.fledge.fledgeserver.canary.dto.CanaryProfileUpdateRequest;
import com.fledge.fledgeserver.canary.dto.*;
import com.fledge.fledgeserver.canary.entity.CanaryProfile;
import com.fledge.fledgeserver.canary.repository.CanaryProfileRepository;
import com.fledge.fledgeserver.common.utils.SecurityUtils;
Expand Down Expand Up @@ -111,4 +108,12 @@ public CanaryGetDeliveryInfoResponse getCanaryDeliveryInfo(Long userId) {
canary.getPhone()
);
}

@Transactional(readOnly = true)
public CanaryProfileGetResponseDto getCanaryForSupport(Long memberId) {
CanaryProfile canaryProfile = canaryProfileRepository.findByMemberId(memberId)
.orElseThrow(() -> new CustomException(ErrorCode.CANARY_NOT_FOUND));

return new CanaryProfileGetResponseDto(canaryProfile);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
new AntPathRequestMatcher("/actuator/health"),
new AntPathRequestMatcher("/oauth2/authorization/**"),
new AntPathRequestMatcher("/login/oauth2/code/**"),
new AntPathRequestMatcher("/oauth2/**"),
new AntPathRequestMatcher("/api/v1/supports/**")
new AntPathRequestMatcher("/oauth2/**")
).permitAll()
.anyRequest().authenticated()
)
Expand All @@ -79,7 +78,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
return http.build();
}

@Bean
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return web -> web.ignoring()
.requestMatchers("/error", "/favicon.ico", "/swagger-ui/**", "/api-docs/**");
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/fledge/fledgeserver/promise/entity/Promise.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.fledge.fledgeserver.promise.entity;


import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public enum Promise {
ONCE("ONCE"), // 1회 인증
WEEKLY("WEEKLY"), // 4주간 매 주 인증
MONTHLY("MONTHLY"); // 3개월간 매 달 인증

private final String key;
public String getKey() { return key; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.fledge.fledgeserver.promise.entity;

import com.fledge.fledgeserver.common.entity.BaseTimeEntity;
import com.fledge.fledgeserver.member.entity.Member;
import com.fledge.fledgeserver.support.entity.Support;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PromiseLog extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id", nullable = false)
private Member member;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "support_id", nullable = false)
private Support support;

@Column(nullable = false)
private LocalDate startDate;

@Column(nullable = false)
private LocalDate endDate;

@Column(nullable = false)
private PromiseStatus promiseStatus;

@Builder
public PromiseLog(Member member, Support support, LocalDate startDate, LocalDate endDate, PromiseStatus promiseStatus) {
this.member = member;
this.support = support;
this.startDate = startDate;
this.endDate = endDate;
this.promiseStatus = promiseStatus;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.fledge.fledgeserver.promise.entity;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public enum PromiseStatus {
PENDING("PENDING"), // 인증 대기중
VERIFIED("VERIFIED"), // 인증 완료
UNVERIFIED("UNVERIFIED"); // 인증하지 않음


private final String key;

public String getStatus() {
return key;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@
@RequiredArgsConstructor
public class SupportController {
private final SupportService supportService;
/**
* ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ후원 게시글 관련ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
*/

/**
* CREATE
*/
@Operation(summary = "후원하기 게시글 등록", description = "후원하기 게시글을 등록합니다.(자립 준비 청소년만)")
@PostMapping
public ResponseEntity<ApiResponse<Object>> createSupport(
Expand All @@ -37,40 +43,64 @@ public ResponseEntity<ApiResponse<Object>> createSupport(
return ApiResponse.success(CREATE_SUPPORT_SUCCESS);
}

@Operation(summary = "후원하기 게시글 조회", description = "후원하기 게시글을 조회합니다.(모든 회원 가능)")
@GetMapping("/{supportId}")
public ResponseEntity<ApiResponse<SupportGetResponseDto>> getSupport(
@PathVariable(value = "supportId") Long supportId
) {
// TODO :: 후원하기(후원자) & 후원 인증 관련 로직 추가
return ApiResponse.success(GET_SUPPORT_SUCCESS, supportService.getSupport(supportId));
}
/**
* READ
*/
//
// @Operation(summary = "후원하기 게시글 조회", description = "후원하기 게시글을 조회합니다.(모든 회원 가능)")
// @GetMapping("/{supportId}")
// public ResponseEntity<ApiResponse<SupportGetResponseDto>> getSupport(
// @PathVariable(value = "supportId") Long supportId
// ) {
// // TODO :: 후원하기(후원자) & 후원 인증 관련 로직 추가
// return ApiResponse.success(GET_SUPPORT_SUCCESS, supportService.getSupport(supportId));
// }
//
// /**
// * UPDATE
// */
//
// @Operation(summary = "후원하기 게시글 수정 시 기존 데이터 조회", description = "후원하기 게시글의 기존 데이터를 반환합니다.")
// @GetMapping("/{supportId}/update")
// public ResponseEntity<ApiResponse<SupportGetForUpdateResponseDto>> getSupportForUpdate(
// @PathVariable(value = "supportId") Long supportId,
// Principal principal
// ) {
// Long memberId = SecurityUtils.getCurrentUserId(principal);
// return ApiResponse.success(
// SuccessStatus.GET_SUPPORT_FOR_UPDATE_SUCCESS,
// supportService.getSupportForUpdate(memberId, supportId)
// );
// }
//
// @Operation(summary = "후원하기 게시글 수정", description = "후원하기 게시글을 수정합니다.")
// @PutMapping("/{supportId}")
// public ResponseEntity<ApiResponse<SupportGetResponseDto>> updateSupport(
// Principal principal,
// @PathVariable(value = "supportId") Long supportId,
// @RequestBody SupportUpdateRequestDto supportUpdateRequestDto
// ) {
// Long memberId = SecurityUtils.getCurrentUserId(principal);
// supportService.updateSupport(memberId, supportId, supportUpdateRequestDto);
// return ApiResponse.success(SuccessStatus.UPDATE_SUPPORT_SUCCESS);
// }

@Operation(summary = "후원하기 게시글 수정 시 기존 데이터 조회", description = "후원하기 게시글의 기존 데이터를 반환합니다.")
@GetMapping("/{supportId}/update")
public ResponseEntity<ApiResponse<SupportGetForUpdateResponseDto>> getSupportForUpdate(
@PathVariable(value = "supportId") Long supportId,
Principal principal
) {
Long memberId = SecurityUtils.getCurrentUserId(principal);
return ApiResponse.success(
SuccessStatus.GET_SUPPORT_FOR_UPDATE_SUCCESS,
supportService.getSupportForUpdate(memberId, supportId)
);
}
/**
* DELETE
*/
// TODO :: 후원하기 게시글 삭제 API

@Operation(summary = "후원하기 게시글 수정", description = "후원하기 게시글을 수정합니다.")
@PutMapping("/{supportId}")
public ResponseEntity<ApiResponse<SupportGetResponseDto>> updateSupport(
Principal principal,
@PathVariable(value = "supportId") Long supportId,
@RequestBody SupportUpdateRequestDto supportUpdateRequestDto
) {
Long memberId = SecurityUtils.getCurrentUserId(principal);
supportService.updateSupport(memberId, supportId, supportUpdateRequestDto);
return ApiResponse.success(SuccessStatus.UPDATE_SUPPORT_SUCCESS);
}

/**
* ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ후원 하기ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
*/
/**
* 후원하기 팝업에서 정보 조회
*/


/**
* 후원하기 시 후원 처리
*/

// TODO :: 후원하기 게시글 삭제 API
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public class SupportCreateRequestDto {
@Size(max = 500, message = "후원 사유는 최대 500자까지 입력 가능합니다.")
private String reason;

@Schema(description = "후원자의 약속", required = true, example = "ONCE")
@NotBlank(message = "후원자의 약속은 필수입니다.")
@Pattern(regexp = "ONCE|WEEKLY|MONTHLY",
message = "후원자의 약속은 ONCE, WEEKLY, MONTHLY 중 하나여야 합니다.")
private String promise;

@Schema(description = "후원 물품 명", required = true, example = "노트북")
@NotBlank(message = "후원 물품 명은 필수입니다.")
@Size(max = 100, message = "후원 물품 명은 최대 100자까지 입력 가능합니다.")
Expand All @@ -42,38 +48,37 @@ public class SupportCreateRequestDto {
@Schema(description = "후원 물품 이미지 리스트", required = true)
private List<String> images;

@Schema(description = "후원 인증 기간", required = true, example = "30")
@NotBlank(message = "후원 인증 기간은 필수입니다.")
@Positive(message = "후원 인증 기간은 0보다 큰 값이어야 합니다.")
private int checkPeriod;

@Schema(description = "후원 인증 횟수", required = true, example = "1")
@NotBlank(message = "후원 인증 횟수는 필수입니다.")
@Positive(message = "후원 인증 횟수는 0보다 큰 값이어야 합니다.")
private int checkCount;

@Schema(description = "만료 시점", required = true, example = "2024-12-31")
@NotBlank(message = "만료 시점은 필수입니다.")
@Future(message = "만료 시점은 현재 시간 이후여야 합니다.")
private LocalDate expirationDate;

@Schema(description = "수령인 이름", required = true, example = "홍길동")
@NotBlank(message = "수령인 이름은 필수입니다.")
@Schema(description = "후원 카테고리", example = "FOOD")
@NotBlank(message = "후원 카테고리는 필수입니다.")
@Pattern(regexp = "DAILY_NECESSITY|FOOD|HOME_APPLIANCES|EDUCATION|MEDICAL|LEGAL_AID|ETC",
message = "후원 카테고리는 DAILY_NECESSITY, FOOD, HOME_APPLIANCES, EDUCATION, MEDICAL, LEGAL_AID, ETC 중 하나여야 합니다.")
private String supportCategory;

// MEDICAL, LEGAL_AID인 겨우
@Schema(description = "은행명", example = "카카오뱅크")
private String bank;

@Schema(description = "은행 계좌번호", example = "1234-12-1234-12")
private String account;

// DAILY_NECESSITY, FOOD, HOME_APPLIANCES, EDUCATION, ETC인 경우
@Schema(description = "수령인 이름", example = "홍길동")
private String recipientName;

@Schema(description = "전화번호", required = true, example = "010-1234-5678")
@NotBlank(message = "전화번호는 필수입니다.")
@Schema(description = "전화번호", example = "010-1234-5678")
private String phone;

@Schema(description = "주소", required = true, example = "서울특별시 노원구 공릉로232")
@NotBlank(message = "주소는 필수입니다.")
@Schema(description = "주소", example = "서울특별시 노원구 공릉로232")
private String address;

@Schema(description = "상세 주소", required = true, example = "OO빌라 101호")
@NotBlank(message = "상세 주소는 필수입니다.")
@Schema(description = "상세 주소", example = "OO빌라 101호")
private String detailAddress;

@Schema(description = "우편번호", required = true, example = "123456")
@NotBlank(message = "우편번호는 필수입니다.")
@Schema(description = "우편번호", example = "123456")
private String zip;
}
Loading

0 comments on commit 23fa59e

Please sign in to comment.