diff --git a/src/main/java/com/fledge/fledgeserver/canary/controller/CanaryProfileController.java b/src/main/java/com/fledge/fledgeserver/canary/controller/CanaryProfileController.java index ddb5913..82383fa 100644 --- a/src/main/java/com/fledge/fledgeserver/canary/controller/CanaryProfileController.java +++ b/src/main/java/com/fledge/fledgeserver/canary/controller/CanaryProfileController.java @@ -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; @@ -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 @@ -71,6 +71,10 @@ public ResponseEntity> updateCanaryProfile( return ApiResponse.success(SuccessStatus.PROFILE_UPDATE_SUCCESS, response); } + /** + * 이하 API 후원하기 시에 필요 + */ + @Operation(summary = "자립준비청년 배송지 정보 조회", description = "자립준비청년 후원글 작성 시 배송지 정보를 불러올 수 있습니다.") @GetMapping("/delivery") public ResponseEntity> getCanaryDeliveryInfo( @@ -81,4 +85,13 @@ public ResponseEntity> 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> getSupport( + @PathVariable(value = "memberId") Long memberId + ) { + // TODO :: 자립준비청년이 완료한 챌린지 및 후원 인증 스토리 그리고 인증률도 함께 보여줘야함! + return ApiResponse.success(GET_SUPPORT_SUCCESS, canaryProfileService.getCanaryForSupport(memberId)); + } } \ No newline at end of file diff --git a/src/main/java/com/fledge/fledgeserver/canary/dto/CanaryProfileGetResponseDto.java b/src/main/java/com/fledge/fledgeserver/canary/dto/CanaryProfileGetResponseDto.java new file mode 100644 index 0000000..46b9586 --- /dev/null +++ b/src/main/java/com/fledge/fledgeserver/canary/dto/CanaryProfileGetResponseDto.java @@ -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(); + } +} diff --git a/src/main/java/com/fledge/fledgeserver/canary/service/CanaryProfileService.java b/src/main/java/com/fledge/fledgeserver/canary/service/CanaryProfileService.java index 69722c9..b52b0b1 100644 --- a/src/main/java/com/fledge/fledgeserver/canary/service/CanaryProfileService.java +++ b/src/main/java/com/fledge/fledgeserver/canary/service/CanaryProfileService.java @@ -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; @@ -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); + } } \ No newline at end of file diff --git a/src/main/java/com/fledge/fledgeserver/config/WebSecurityConfig.java b/src/main/java/com/fledge/fledgeserver/config/WebSecurityConfig.java index 9196bf6..5c01d0f 100644 --- a/src/main/java/com/fledge/fledgeserver/config/WebSecurityConfig.java +++ b/src/main/java/com/fledge/fledgeserver/config/WebSecurityConfig.java @@ -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() ) @@ -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/**"); diff --git a/src/main/java/com/fledge/fledgeserver/promise/entity/Promise.java b/src/main/java/com/fledge/fledgeserver/promise/entity/Promise.java new file mode 100644 index 0000000..12812f3 --- /dev/null +++ b/src/main/java/com/fledge/fledgeserver/promise/entity/Promise.java @@ -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; } +} \ No newline at end of file diff --git a/src/main/java/com/fledge/fledgeserver/promise/entity/PromiseLog.java b/src/main/java/com/fledge/fledgeserver/promise/entity/PromiseLog.java new file mode 100644 index 0000000..cde2607 --- /dev/null +++ b/src/main/java/com/fledge/fledgeserver/promise/entity/PromiseLog.java @@ -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; + } +} diff --git a/src/main/java/com/fledge/fledgeserver/promise/entity/PromiseStatus.java b/src/main/java/com/fledge/fledgeserver/promise/entity/PromiseStatus.java new file mode 100644 index 0000000..c795d1b --- /dev/null +++ b/src/main/java/com/fledge/fledgeserver/promise/entity/PromiseStatus.java @@ -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; + } +} diff --git a/src/main/java/com/fledge/fledgeserver/support/controller/SupportController.java b/src/main/java/com/fledge/fledgeserver/support/controller/SupportController.java index 6185a13..77ee4ef 100644 --- a/src/main/java/com/fledge/fledgeserver/support/controller/SupportController.java +++ b/src/main/java/com/fledge/fledgeserver/support/controller/SupportController.java @@ -25,7 +25,13 @@ @RequiredArgsConstructor public class SupportController { private final SupportService supportService; + /** + * ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ후원 게시글 관련ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ + */ + /** + * CREATE + */ @Operation(summary = "후원하기 게시글 등록", description = "후원하기 게시글을 등록합니다.(자립 준비 청소년만)") @PostMapping public ResponseEntity> createSupport( @@ -37,40 +43,64 @@ public ResponseEntity> createSupport( return ApiResponse.success(CREATE_SUPPORT_SUCCESS); } - @Operation(summary = "후원하기 게시글 조회", description = "후원하기 게시글을 조회합니다.(모든 회원 가능)") - @GetMapping("/{supportId}") - public ResponseEntity> getSupport( - @PathVariable(value = "supportId") Long supportId - ) { - // TODO :: 후원하기(후원자) & 후원 인증 관련 로직 추가 - return ApiResponse.success(GET_SUPPORT_SUCCESS, supportService.getSupport(supportId)); - } + /** + * READ + */ +// +// @Operation(summary = "후원하기 게시글 조회", description = "후원하기 게시글을 조회합니다.(모든 회원 가능)") +// @GetMapping("/{supportId}") +// public ResponseEntity> 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> 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> 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> 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> 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 } diff --git a/src/main/java/com/fledge/fledgeserver/support/dto/request/SupportCreateRequestDto.java b/src/main/java/com/fledge/fledgeserver/support/dto/request/SupportCreateRequestDto.java index 9dd037a..48905fe 100644 --- a/src/main/java/com/fledge/fledgeserver/support/dto/request/SupportCreateRequestDto.java +++ b/src/main/java/com/fledge/fledgeserver/support/dto/request/SupportCreateRequestDto.java @@ -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자까지 입력 가능합니다.") @@ -42,38 +48,37 @@ public class SupportCreateRequestDto { @Schema(description = "후원 물품 이미지 리스트", required = true) private List 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; } diff --git a/src/main/java/com/fledge/fledgeserver/support/entity/Support.java b/src/main/java/com/fledge/fledgeserver/support/entity/Support.java index b96509b..de2a7ba 100644 --- a/src/main/java/com/fledge/fledgeserver/support/entity/Support.java +++ b/src/main/java/com/fledge/fledgeserver/support/entity/Support.java @@ -2,6 +2,7 @@ import com.fledge.fledgeserver.common.entity.BaseTimeEntity; import com.fledge.fledgeserver.member.entity.Member; +import com.fledge.fledgeserver.promise.entity.Promise; import com.fledge.fledgeserver.support.dto.request.SupportCreateRequestDto; import com.fledge.fledgeserver.support.dto.request.SupportUpdateRequestDto; import jakarta.persistence.*; @@ -46,32 +47,42 @@ public class Support extends BaseTimeEntity { private List images = new ArrayList<>(); @Column(nullable = false) - private int checkPeriod; + private LocalDate expirationDate; @Column(nullable = false) - private int checkCount; + private Boolean expirationStatus = false; @Column(nullable = false) - private String recipientName; + @Enumerated(value = EnumType.STRING) + private Promise promise; // 인증 주기 및 횟수 @Column(nullable = false) + @Enumerated(value = EnumType.STRING) + private SupportCategory supportCategory; + + // ------의료비 또는 법률구조비------ + @Column(nullable = true) + private String bank; + + @Column(nullable = true) + private String account; + + // -----------기타----------- + @Column(nullable = true) + private String recipientName; + + @Column(nullable = true) private String phone; - @Column(nullable = false) + @Column(nullable = true) private String address; - @Column(nullable = false) + @Column(nullable = true) private String detailAddress; - @Column(nullable = false) + @Column(nullable = true) private String zip; - @Column(nullable = false) - private LocalDate expirationDate; - - @Column(nullable = false) - private Boolean expirationStatus = false; - // TODO :: 챌린지 구현 후 참여 중이거나 완료한 챌린지(뱃지)에 대한 로직 추가 @Builder @@ -82,24 +93,37 @@ public Support(Member member, SupportCreateRequestDto supportCreateRequestDto) { this.item = supportCreateRequestDto.getItem(); this.purchaseUrl = supportCreateRequestDto.getPurchaseUrl(); this.price = supportCreateRequestDto.getPrice(); - this.checkPeriod = supportCreateRequestDto.getCheckPeriod(); - this.checkCount = supportCreateRequestDto.getCheckCount(); - this.recipientName = supportCreateRequestDto.getRecipientName(); - this.phone = supportCreateRequestDto.getPhone(); - this.address = supportCreateRequestDto.getAddress(); - this.detailAddress = supportCreateRequestDto.getDetailAddress(); - this.zip = supportCreateRequestDto.getZip(); this.expirationDate = supportCreateRequestDto.getExpirationDate(); + this.promise = Promise.valueOf(supportCreateRequestDto.getPromise()); + this.supportCategory = SupportCategory.valueOf(supportCreateRequestDto.getSupportCategory()); + + if ("MEDICAL".equals(supportCategory.name()) || "LEGAL_AID".equals(supportCategory.name())) { + this.bank = supportCreateRequestDto.getBank(); + this.account = supportCreateRequestDto.getAccount(); + this.recipientName = null; + this.phone = null; + this.address = null; + this.detailAddress = null; + this.zip = null; + } else { + this.recipientName = supportCreateRequestDto.getRecipientName(); + this.phone = supportCreateRequestDto.getPhone(); + this.address = supportCreateRequestDto.getAddress(); + this.detailAddress = supportCreateRequestDto.getDetailAddress(); + this.zip = supportCreateRequestDto.getZip(); + this.bank = null; + this.account = null; + } } + + public void update(SupportUpdateRequestDto supportUpdateRequestDto) { this.title = supportUpdateRequestDto.getTitle(); this.reason = supportUpdateRequestDto.getReason(); this.item = supportUpdateRequestDto.getItem(); this.purchaseUrl = supportUpdateRequestDto.getPurchaseUrl(); this.price = supportUpdateRequestDto.getPrice(); - this.checkPeriod = supportUpdateRequestDto.getCheckPeriod(); - this.checkCount = supportUpdateRequestDto.getCheckCount(); this.recipientName = supportUpdateRequestDto.getRecipientName(); this.phone = supportUpdateRequestDto.getPhone(); this.address = supportUpdateRequestDto.getAddress(); diff --git a/src/main/java/com/fledge/fledgeserver/support/entity/SupportCategory.java b/src/main/java/com/fledge/fledgeserver/support/entity/SupportCategory.java new file mode 100644 index 0000000..70cc2bc --- /dev/null +++ b/src/main/java/com/fledge/fledgeserver/support/entity/SupportCategory.java @@ -0,0 +1,19 @@ +package com.fledge.fledgeserver.support.entity; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public enum SupportCategory { + DAILY_NECESSITY("DAILY_NECESSITY"), // 생필품 + FOOD("FOOD"), // 식품 + HOME_APPLIANCES("HOME_APPLIANCES"), // 가전제품 + EDUCATION("EDUCATION"), // 교육비/교재비 + MEDICAL("MEDICAL"), // 의료비 + LEGAL_AID("LEGAL_AID"), // 법률 구조비 + ETC("ETC"); // 기타 + + private final String key; + public String getKey() { + return key; + } +} \ No newline at end of file diff --git a/src/main/java/com/fledge/fledgeserver/support/entity/SupportRecord.java b/src/main/java/com/fledge/fledgeserver/support/entity/SupportRecord.java index caf9662..8c0a220 100644 --- a/src/main/java/com/fledge/fledgeserver/support/entity/SupportRecord.java +++ b/src/main/java/com/fledge/fledgeserver/support/entity/SupportRecord.java @@ -1,18 +1,36 @@ package com.fledge.fledgeserver.support.entity; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; +import com.fledge.fledgeserver.common.entity.BaseTimeEntity; +import com.fledge.fledgeserver.member.entity.Member; +import jakarta.persistence.*; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class SupportRecord { +public class SupportRecord extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + + @ManyToOne(fetch = FetchType.LAZY) // Member와의 다대일 관계 + @JoinColumn(name = "member_id", nullable = false) + private Member member; + + @ManyToOne(fetch = FetchType.LAZY) // Support와의 다대일 관계 + @JoinColumn(name = "support_id", nullable = false) + private Support support; + + @Column(nullable = false) + private String account; + + @Builder + public SupportRecord(Member member, Support support, String account) { + this.member = member; + this.support = support; + this.account = account; + } } diff --git a/src/main/java/com/fledge/fledgeserver/support/service/SupportService.java b/src/main/java/com/fledge/fledgeserver/support/service/SupportService.java index 2b9c3f6..fdc1c2d 100644 --- a/src/main/java/com/fledge/fledgeserver/support/service/SupportService.java +++ b/src/main/java/com/fledge/fledgeserver/support/service/SupportService.java @@ -54,76 +54,74 @@ public void createSupport(Long memberId, SupportCreateRequestDto supportCreateRe } } - public SupportGetResponseDto getSupport(Long supportId) { - Support support = supportRepository.findSupportByIdWithFetch(supportId) - .orElseThrow(() -> new CustomException(ErrorCode.SUPPORT_NOT_FOUND)); - - return new SupportGetResponseDto( - support.getMember().getId(), - support.getMember().getNickname(), - support.getTitle(), - support.getReason(), - support.getItem(), - support.getPurchaseUrl(), - support.getPrice(), - // Images Presigned-URL처리 - support.getImages().stream() - .map(supportImage -> fileService.getFileUrl(supportImage.getImageUrl())) - .toList(), - support.getCheckPeriod(), - support.getCheckCount(), - support.getExpirationDate() - ); - } - - public SupportGetForUpdateResponseDto getSupportForUpdate(Long memberId, Long supportId) { - Support support = supportRepository.findSupportByIdWithFetch(supportId) - .orElseThrow(() -> new CustomException(ErrorCode.SUPPORT_NOT_FOUND)); - - if (support.getMember().getId() != memberId) { - throw new CustomException(ErrorCode.NO_ACCESS); - } - - // 이미지를 Presigned URL로 처리 - List imageUrls = support.getImages().stream() - .map(supportImage -> fileService.getFileUrl(supportImage.getImageUrl())) - .toList(); - - return new SupportGetForUpdateResponseDto( - support.getMember().getId(), - support.getMember().getNickname(), - support.getTitle(), - support.getReason(), - support.getItem(), - support.getPurchaseUrl(), - support.getPrice(), - imageUrls, - support.getCheckPeriod(), - support.getCheckCount(), - support.getExpirationDate() - ); - } - - public void updateSupport(Long memberId, Long supportId, SupportUpdateRequestDto supportUpdateRequestDto) { - Support support = supportRepository.findSupportByIdWithFetch(supportId) - .orElseThrow(() -> new CustomException(ErrorCode.SUPPORT_NOT_FOUND)); - - if (support.getMember().getId() != memberId) { - throw new CustomException(ErrorCode.NO_ACCESS); - } - support.update(supportUpdateRequestDto); - support.getImages().clear(); - - List newImages = supportUpdateRequestDto.getImages().stream() - .map(imageUrl -> new SupportImage(support, imageUrl)) - .toList(); - - support.getImages().addAll(newImages); - - // 5. 기존 이미지 삭제 - support.getImages().clear(); // 기존 이미지 제거 - - // 6. 새로운 이미지 추가 - support.getImages().addAll(newImages); - } +// public SupportGetResponseDto getSupport(Long supportId) { +// Support support = supportRepository.findSupportByIdWithFetch(supportId) +// .orElseThrow(() -> new CustomException(ErrorCode.SUPPORT_NOT_FOUND)); +// +// return new SupportGetResponseDto( +// support.getMember().getId(), +// support.getMember().getNickname(), +// support.getTitle(), +// support.getReason(), +// support.getItem(), +// support.getPurchaseUrl(), +// support.getPrice(), +// // Images Presigned-URL처리 +// support.getImages().stream() +// .map(supportImage -> fileService.getFileUrl(supportImage.getImageUrl())) +// .toList(), +// support.getExpirationDate() +// ); +// } +// +// public SupportGetForUpdateResponseDto getSupportForUpdate(Long memberId, Long supportId) { +// Support support = supportRepository.findSupportByIdWithFetch(supportId) +// .orElseThrow(() -> new CustomException(ErrorCode.SUPPORT_NOT_FOUND)); +// +// if (support.getMember().getId() != memberId) { +// throw new CustomException(ErrorCode.NO_ACCESS); +// } +// +// // 이미지를 Presigned URL로 처리 +// List imageUrls = support.getImages().stream() +// .map(supportImage -> fileService.getFileUrl(supportImage.getImageUrl())) +// .toList(); +// +// return new SupportGetForUpdateResponseDto( +// support.getMember().getId(), +// support.getMember().getNickname(), +// support.getTitle(), +// support.getReason(), +// support.getItem(), +// support.getPurchaseUrl(), +// support.getPrice(), +// imageUrls, +// support.getCheckPeriod(), +// support.getCheckCount(), +// support.getExpirationDate() +// ); +// } +// +// public void updateSupport(Long memberId, Long supportId, SupportUpdateRequestDto supportUpdateRequestDto) { +// Support support = supportRepository.findSupportByIdWithFetch(supportId) +// .orElseThrow(() -> new CustomException(ErrorCode.SUPPORT_NOT_FOUND)); +// +// if (support.getMember().getId() != memberId) { +// throw new CustomException(ErrorCode.NO_ACCESS); +// } +// support.update(supportUpdateRequestDto); +// support.getImages().clear(); +// +// List newImages = supportUpdateRequestDto.getImages().stream() +// .map(imageUrl -> new SupportImage(support, imageUrl)) +// .toList(); +// +// support.getImages().addAll(newImages); +// +// // 5. 기존 이미지 삭제 +// support.getImages().clear(); // 기존 이미지 제거 +// +// // 6. 새로운 이미지 추가 +// support.getImages().addAll(newImages); +// } }