diff --git a/src/main/java/com/numberone/backend/domain/sponsor/controller/SponsorController.java b/src/main/java/com/numberone/backend/domain/sponsor/controller/SponsorController.java index 1d57d104..2116bd96 100644 --- a/src/main/java/com/numberone/backend/domain/sponsor/controller/SponsorController.java +++ b/src/main/java/com/numberone/backend/domain/sponsor/controller/SponsorController.java @@ -3,6 +3,7 @@ import com.numberone.backend.domain.sponsor.dto.response.SponsorHomeResponse; import com.numberone.backend.domain.sponsor.dto.response.SponsorResponse; import com.numberone.backend.domain.sponsor.service.SponsorService; +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -16,16 +17,40 @@ public class SponsorController { private final SponsorService sponsorService; + @Operation(summary = "후원 단일 데이터 가져오기", description = + """ + 후원 한개의 데이터를 가져오는 API입니다. + + 후원 세부 페이지에서 사용하는 API입니다. + + 후원 목록 가져오기 API에서 반환된 응답에서 얻은 후원 id중 가져오고 싶은 후원의 id를 같이 전달해주세요. + """) @GetMapping("/{sponsorId}") public ResponseEntity getSponsorDetail(@PathVariable Long sponsorId){ return ResponseEntity.ok(sponsorService.getSponsorDetail(sponsorId)); } + @Operation(summary = "후원 목록 최신순 가져오기", description = + """ + 후원 목록을 최신순으로 가져오는 API입니다. + + 또한 후원 목록 페이지에서 필요한 총 후원한 사람들의 수(supporterCnt)와 사람들이 입력한 응원메시지(messages)가 같이 전달됩니다. + + 후원 목록 가져오기 API에서 반환된 응답에서 얻은 후원 id중 가져오고 싶은 후원의 id를 같이 전달해주세요. + """) @GetMapping("/latest") public ResponseEntity getSponsorHomeLatest(Authentication authentication){ return ResponseEntity.ok(sponsorService.getSponsorHomeLatest(authentication.getName())); } + @Operation(summary = "후원 목록 인기순 가져오기", description = + """ + 후원 목록을 인기순으로 가져오는 API입니다. + + 또한 후원 목록 페이지에서 필요한 총 후원한 사람들의 수(supporterCnt)와 사람들이 입력한 응원메시지(messages)가 같이 전달됩니다. + + 후원 목록 가져오기 API에서 반환된 응답에서 얻은 후원 id중 가져오고 싶은 후원의 id를 같이 전달해주세요. + """) @GetMapping("/popular") public ResponseEntity getSponsorHomePopular(Authentication authentication){ return ResponseEntity.ok(sponsorService.getSponsorHomePopular(authentication.getName())); diff --git a/src/main/java/com/numberone/backend/domain/sponsor/dto/response/SponsorResponse.java b/src/main/java/com/numberone/backend/domain/sponsor/dto/response/SponsorResponse.java index af099416..b9d76076 100644 --- a/src/main/java/com/numberone/backend/domain/sponsor/dto/response/SponsorResponse.java +++ b/src/main/java/com/numberone/backend/domain/sponsor/dto/response/SponsorResponse.java @@ -1,7 +1,9 @@ package com.numberone.backend.domain.sponsor.dto.response; import com.numberone.backend.domain.sponsor.entity.Sponsor; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; +import org.hibernate.annotations.Comment; import java.time.LocalDate; import java.time.Period; @@ -13,18 +15,48 @@ @AllArgsConstructor @Builder public class SponsorResponse { + @Schema(defaultValue = "1") private Long id; + + @Schema(defaultValue = "true") private Boolean isSupported; + + @Schema(defaultValue = "화재") private String disasterType; + + @Schema(defaultValue = "D-3") private String dday; + + @Schema(defaultValue = "제목") private String title; + + @Schema(defaultValue = "부제목") private String subtitle; + + @Schema(defaultValue = "세부 후원 페이지 내용") private String content; + + @Schema(defaultValue = "100") private Integer targetHeart; + + @Schema(defaultValue = "30") private Integer currentHeart; + + @Schema(defaultValue = "사회복지재단 월드비전") private String sponsorName; + + @Schema(defaultValue = "2018.11.12 ~ 2018.11.15") private String period; + @Schema(defaultValue = "https://numberone-dev-s3.s3.ap-northeast-2.amazonaws.com/static/sponsor_image.png") + private String thumbnailUrl; + + @Schema(defaultValue = "https://www.naver.com") + private String imageUrl; + + @Schema(defaultValue = "https://numberone-dev-s3.s3.ap-northeast-2.amazonaws.com/static/sponsor_thumbnail.png") + private String sponsorUrl; + public static SponsorResponse of(Boolean isSupported, Sponsor sponsor) { int dday = Period.between(LocalDate.now(), sponsor.getDueDate()).getDays(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy. MM. dd"); @@ -43,6 +75,9 @@ public static SponsorResponse of(Boolean isSupported, Sponsor sponsor) { .currentHeart(sponsor.getCurrentHeart()) .sponsorName(sponsor.getSponsorName()) .period(startDate + " ~ " + dueDate) + .thumbnailUrl(sponsor.getThumbnailUrl()) + .imageUrl(sponsor.getImageUrl()) + .sponsorUrl(sponsor.getSponsorUrl()) .build(); } } diff --git a/src/main/java/com/numberone/backend/domain/sponsor/entity/Sponsor.java b/src/main/java/com/numberone/backend/domain/sponsor/entity/Sponsor.java index a24d9061..3623cd98 100644 --- a/src/main/java/com/numberone/backend/domain/sponsor/entity/Sponsor.java +++ b/src/main/java/com/numberone/backend/domain/sponsor/entity/Sponsor.java @@ -30,7 +30,9 @@ public class Sponsor { @Comment("부제목") private String subtitle; - @Comment("세부 내용") + @Lob + @Column(columnDefinition = "TEXT") + @Comment("내용") private String content; @Comment("시작 날짜") @@ -48,6 +50,19 @@ public class Sponsor { @Comment("후원사 이름") private String sponsorName; + @Comment("썸네일 이미지") + private String thumbnailUrl; + + @Comment("상세페이지 이미지") + private String imageUrl; + + @Comment("후원사 링크") + private String sponsorUrl; + @OneToMany(mappedBy = "sponsor", cascade = CascadeType.ALL) private List supports = new ArrayList<>(); + + public void increaseHeart(int heart) { + currentHeart += heart; + } } diff --git a/src/main/java/com/numberone/backend/domain/support/entity/Support.java b/src/main/java/com/numberone/backend/domain/support/entity/Support.java index e73048c2..33ef7b4b 100644 --- a/src/main/java/com/numberone/backend/domain/support/entity/Support.java +++ b/src/main/java/com/numberone/backend/domain/support/entity/Support.java @@ -37,9 +37,8 @@ public Support(String message, Sponsor sponsor, Member member) { this.member = member; } - public static Support of(String message, Sponsor sponsor, Member member) { + public static Support of(Sponsor sponsor, Member member) { return Support.builder() - .message(message) .sponsor(sponsor) .member(member) .build(); diff --git a/src/main/java/com/numberone/backend/domain/support/service/SupportService.java b/src/main/java/com/numberone/backend/domain/support/service/SupportService.java index db74d1f3..50a285a6 100644 --- a/src/main/java/com/numberone/backend/domain/support/service/SupportService.java +++ b/src/main/java/com/numberone/backend/domain/support/service/SupportService.java @@ -33,16 +33,16 @@ public void editMessage(EditMessageRequest editMessageRequest, Long supportId) { } @Transactional - public CreateSupportResponse create(CreateSupportRequest createSupportRequest, String email){ + public CreateSupportResponse create(CreateSupportRequest createSupportRequest, String email) { Sponsor sponsor = sponsorRepository.findById(createSupportRequest.getSponsorId()) .orElseThrow(NotFoundSupportException::new); - Member member=memberRepository.findByEmail(email) + Member member = memberRepository.findByEmail(email) .orElseThrow(NotFoundMemberException::new); Support support = Support.of( - null, sponsor, member ); + sponsor.increaseHeart(createSupportRequest.getHeartCnt()); support = supportRepository.save(support); return CreateSupportResponse.of(support.getId()); }