From 4c10855a083a4214c6c3b2a99dc03c1567675ce4 Mon Sep 17 00:00:00 2001 From: chaeyoungeee Date: Sat, 27 Jul 2024 11:43:13 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=EB=AC=B8=ED=99=94=20region=20colum?= =?UTF-8?q?n=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문화 domain에 region column을 추가하고 양방향 연관 관계를 설정함 +) region table의 id 0 데이터는 무관으로 설정할게요 --- .../java/likelion/MZConnent/domain/club/RegionCategory.java | 3 +++ .../java/likelion/MZConnent/domain/culture/Culture.java | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/main/java/likelion/MZConnent/domain/club/RegionCategory.java b/src/main/java/likelion/MZConnent/domain/club/RegionCategory.java index 37e20d7..30a0112 100644 --- a/src/main/java/likelion/MZConnent/domain/club/RegionCategory.java +++ b/src/main/java/likelion/MZConnent/domain/club/RegionCategory.java @@ -1,6 +1,7 @@ package likelion.MZConnent.domain.club; import jakarta.persistence.*; +import likelion.MZConnent.domain.culture.Culture; import lombok.Getter; import lombok.NoArgsConstructor; @@ -20,5 +21,7 @@ public class RegionCategory { @OneToMany(mappedBy = "region") private List clubs; + @OneToMany(mappedBy = "region") + private List cultures; } diff --git a/src/main/java/likelion/MZConnent/domain/culture/Culture.java b/src/main/java/likelion/MZConnent/domain/culture/Culture.java index 34e08e5..bba5cf7 100644 --- a/src/main/java/likelion/MZConnent/domain/culture/Culture.java +++ b/src/main/java/likelion/MZConnent/domain/culture/Culture.java @@ -2,6 +2,7 @@ import jakarta.persistence.*; import likelion.MZConnent.domain.club.Club; +import likelion.MZConnent.domain.club.RegionCategory; import likelion.MZConnent.domain.review.Review; import lombok.Builder; import lombok.Getter; @@ -42,6 +43,10 @@ public class Culture { @JoinColumn(name = "cultureCategoryId", nullable = false) private CultureCategory cultureCategory; + @ManyToOne + @JoinColumn(name = "region_id") + private RegionCategory region; + @OneToMany(mappedBy = "culture") private List clubs; @@ -51,6 +56,7 @@ public class Culture { @OneToMany(mappedBy = "culture") private List reviews; + @Builder public Culture(int interestCount, String content, String cultureImageUrl, String name, String summary, int clubCount, String recommendedMember, CultureCategory cultureCategory) { this.interestCount = interestCount; From 09873f57e555216acbc918f87211beac38015db4 Mon Sep 17 00:00:00 2001 From: chaeyoungeee Date: Sat, 27 Jul 2024 13:06:30 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=EC=A0=84=EC=B2=B4=20=EB=AC=B8?= =?UTF-8?q?=ED=99=94=20=EA=B0=84=EB=8B=A8=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 페이징 + 카테고리 선택을 포함한 문화 간단 조회 기능 추가함 --- .../api/culture/CultureController.java | 15 +++++++ .../MZConnent/domain/culture/Culture.java | 5 ++- .../culture/request/CreateCultureRequest.java | 2 + .../response/CulturesSimpleResponse.java | 32 +++++++++++++ .../repository/culture/CultureRepository.java | 6 +++ .../service/culture/CultureService.java | 45 +++++++++++++++++++ 6 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 src/main/java/likelion/MZConnent/dto/culture/response/CulturesSimpleResponse.java create mode 100644 src/main/java/likelion/MZConnent/service/culture/CultureService.java diff --git a/src/main/java/likelion/MZConnent/api/culture/CultureController.java b/src/main/java/likelion/MZConnent/api/culture/CultureController.java index b792e2f..ce5a3c7 100644 --- a/src/main/java/likelion/MZConnent/api/culture/CultureController.java +++ b/src/main/java/likelion/MZConnent/api/culture/CultureController.java @@ -1,11 +1,16 @@ package likelion.MZConnent.api.culture; import likelion.MZConnent.dto.culture.response.CultureCategoryResponse; +import likelion.MZConnent.dto.culture.response.CulturesSimpleResponse; +import likelion.MZConnent.dto.paging.response.PageContentResponse; +import likelion.MZConnent.dto.review.response.ReviewsSimpleResponse; import likelion.MZConnent.service.culture.CultureCategoryService; +import likelion.MZConnent.service.culture.CultureService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @@ -14,6 +19,8 @@ public class CultureController { private final CultureCategoryService cultureCategoryService; + private final CultureService cultureService; + // 전체 문화 카테고리 조회 @GetMapping("/api/categories/culture") public ResponseEntity getAllCultureCategories() { @@ -21,4 +28,12 @@ public ResponseEntity getAllCultureCategories() { log.info("전체 문화 카테고리: {}", all.getCultureCategories()); return ResponseEntity.ok(all); } + + // 전체 문화 간단 조회 + @GetMapping("/api/cultures") + ResponseEntity getReviewSimpleList(@RequestParam(required = false, defaultValue = "0", value = "category") Long category, @RequestParam(required = false, defaultValue = "0", value = "page") int page ) { + + PageContentResponse response = cultureService.getCulturesSimpleList(category, page); + return ResponseEntity.ok(response); + } } diff --git a/src/main/java/likelion/MZConnent/domain/culture/Culture.java b/src/main/java/likelion/MZConnent/domain/culture/Culture.java index bba5cf7..464cce3 100644 --- a/src/main/java/likelion/MZConnent/domain/culture/Culture.java +++ b/src/main/java/likelion/MZConnent/domain/culture/Culture.java @@ -1,5 +1,6 @@ package likelion.MZConnent.domain.culture; +import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.persistence.*; import likelion.MZConnent.domain.club.Club; import likelion.MZConnent.domain.club.RegionCategory; @@ -45,6 +46,7 @@ public class Culture { @ManyToOne @JoinColumn(name = "region_id") + @JsonIgnore private RegionCategory region; @OneToMany(mappedBy = "culture") @@ -58,7 +60,7 @@ public class Culture { @Builder - public Culture(int interestCount, String content, String cultureImageUrl, String name, String summary, int clubCount, String recommendedMember, CultureCategory cultureCategory) { + public Culture(int interestCount, String content, String cultureImageUrl, String name, String summary, int clubCount, String recommendedMember, CultureCategory cultureCategory, RegionCategory region) { this.interestCount = interestCount; this.content = content; this.cultureImageUrl = cultureImageUrl; @@ -67,5 +69,6 @@ public Culture(int interestCount, String content, String cultureImageUrl, String this.clubCount = clubCount; this.recommendedMember = recommendedMember; this.cultureCategory = cultureCategory; + this.region = region; } } diff --git a/src/main/java/likelion/MZConnent/dto/culture/request/CreateCultureRequest.java b/src/main/java/likelion/MZConnent/dto/culture/request/CreateCultureRequest.java index 30bfab2..3fbf71e 100644 --- a/src/main/java/likelion/MZConnent/dto/culture/request/CreateCultureRequest.java +++ b/src/main/java/likelion/MZConnent/dto/culture/request/CreateCultureRequest.java @@ -22,4 +22,6 @@ public class CreateCultureRequest { private String recommendedMember; private Long cultureCategoryId; + + private Long regionId; } diff --git a/src/main/java/likelion/MZConnent/dto/culture/response/CulturesSimpleResponse.java b/src/main/java/likelion/MZConnent/dto/culture/response/CulturesSimpleResponse.java new file mode 100644 index 0000000..9a4b9b0 --- /dev/null +++ b/src/main/java/likelion/MZConnent/dto/culture/response/CulturesSimpleResponse.java @@ -0,0 +1,32 @@ +package likelion.MZConnent.dto.culture.response; + +import likelion.MZConnent.domain.culture.Culture; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class CulturesSimpleResponse { + private Long cultureId; + private String name; + private String summary; + private String cultureImageUrl; + private String cultureCategoryName; + private String regionName; + private int interestCount; + private int clubCount; + + @Builder + public CulturesSimpleResponse(Culture culture) { + this.cultureId = culture.getCultureId(); + this.name = culture.getName(); + this.summary = culture.getSummary(); + this.cultureImageUrl = culture.getCultureImageUrl(); + this.cultureCategoryName = culture.getCultureCategory().getName(); + this.regionName = culture.getRegion().getName(); + this.interestCount = culture.getInterestCount(); + this.clubCount = culture.getClubCount(); + } +} diff --git a/src/main/java/likelion/MZConnent/repository/culture/CultureRepository.java b/src/main/java/likelion/MZConnent/repository/culture/CultureRepository.java index d1ac4b9..f5e044b 100644 --- a/src/main/java/likelion/MZConnent/repository/culture/CultureRepository.java +++ b/src/main/java/likelion/MZConnent/repository/culture/CultureRepository.java @@ -1,9 +1,15 @@ package likelion.MZConnent.repository.culture; +import io.lettuce.core.dynamic.annotation.Param; import likelion.MZConnent.domain.culture.Culture; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @Repository public interface CultureRepository extends JpaRepository { + @Query("SELECT c FROM Culture c WHERE :category = 0 OR c.cultureCategory.id = :category") + Page findAllByCultureCategory(@Param("category") Long category, Pageable pageable); } diff --git a/src/main/java/likelion/MZConnent/service/culture/CultureService.java b/src/main/java/likelion/MZConnent/service/culture/CultureService.java new file mode 100644 index 0000000..d390555 --- /dev/null +++ b/src/main/java/likelion/MZConnent/service/culture/CultureService.java @@ -0,0 +1,45 @@ +package likelion.MZConnent.service.culture; + +import likelion.MZConnent.domain.culture.Culture; +import likelion.MZConnent.domain.review.Review; +import likelion.MZConnent.dto.culture.response.CulturesSimpleResponse; +import likelion.MZConnent.dto.paging.response.PageContentResponse; +import likelion.MZConnent.dto.review.response.ReviewsSimpleResponse; +import likelion.MZConnent.repository.culture.CultureRepository; +import likelion.MZConnent.repository.review.ReviewRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +@Slf4j +@RequiredArgsConstructor +public class CultureService { + private final CultureRepository cultureRepository; + private final int PAGE_SIZE = 6; + + public PageContentResponse getCulturesSimpleList(Long cultureCategoryId, int page) { + Pageable pageable = PageRequest.of(page, PAGE_SIZE); + + Page cultures = cultureRepository.findAllByCultureCategory(cultureCategoryId, pageable); + + List cultureResponse = cultures.stream().map(culture -> CulturesSimpleResponse.builder() + .culture(culture).build() + ).collect(Collectors.toList()); + + return PageContentResponse.builder() + .content(cultureResponse) + .totalPages(cultures.getTotalPages()) + .totalElements(cultures.getTotalElements()) + .size(pageable.getPageSize()) + .build(); + + } +} From 2e2ca3de45362a78be250c4f84c2d94e5a224924 Mon Sep 17 00:00:00 2001 From: chaeyoungeee Date: Sat, 27 Jul 2024 13:07:07 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=EB=AC=B8=ED=99=94=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=20=EC=8B=9C=20region=EB=8F=84=20=EC=A0=80=EC=9E=A5?= =?UTF-8?q?=ED=95=98=EA=B2=8C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문화 저장 시 region도 저장하게 변경함 --- .../MZConnent/api/culture/CreateCultureController.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/likelion/MZConnent/api/culture/CreateCultureController.java b/src/main/java/likelion/MZConnent/api/culture/CreateCultureController.java index 3f59b94..a328d79 100644 --- a/src/main/java/likelion/MZConnent/api/culture/CreateCultureController.java +++ b/src/main/java/likelion/MZConnent/api/culture/CreateCultureController.java @@ -1,8 +1,10 @@ package likelion.MZConnent.api.culture; +import likelion.MZConnent.domain.club.RegionCategory; import likelion.MZConnent.domain.culture.Culture; import likelion.MZConnent.domain.culture.CultureCategory; import likelion.MZConnent.dto.culture.request.CreateCultureRequest; +import likelion.MZConnent.repository.club.RegionCategoryRepository; import likelion.MZConnent.repository.culture.CultureCategoryRepository; import likelion.MZConnent.repository.culture.CultureRepository; import lombok.RequiredArgsConstructor; @@ -22,6 +24,7 @@ public class CreateCultureController { private final CultureRepository cultureRepository; private final CultureCategoryRepository cultureCategoryRepository; + private final RegionCategoryRepository regionCategoryRepository; @PostMapping("/api/cultures") public ResponseEntity createCulture(@RequestBody CreateCultureRequest request) { @@ -30,6 +33,8 @@ public ResponseEntity createCulture(@RequestBody CreateCultureRequest r CultureCategory cultureCategory = cultureCategoryRepository.findById(request.getCultureCategoryId()).orElseThrow(()-> new IllegalArgumentException("해당하는 카테고리가 존재하지 않습니다.")); + RegionCategory regionCategory = regionCategoryRepository.findById(request.getRegionId()).orElseThrow(()-> new IllegalArgumentException("해당하는 지역이 존재하지 않습니다.")); + Culture newCulture = Culture.builder() .name(request.getName()) .summary(request.getSummary()) @@ -38,6 +43,7 @@ public ResponseEntity createCulture(@RequestBody CreateCultureRequest r .getCultureImageUrl()) .recommendedMember(request.getRecommendedMember()) .cultureCategory(cultureCategory) + .region(regionCategory) .build(); Culture savedCulture = cultureRepository.save(newCulture);