Skip to content

Commit

Permalink
feat: 문화 상세 정보 조회 기능 추가
Browse files Browse the repository at this point in the history
문화 상세 정보 조회 기능 추가함
  • Loading branch information
chaeyoungeee committed Jul 28, 2024
1 parent 2cdcc7d commit f98e1b7
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package likelion.MZConnent.api.culture;

import likelion.MZConnent.dto.culture.response.CultureCategoryResponse;
import likelion.MZConnent.dto.culture.response.CultureDetailResponse;
import likelion.MZConnent.dto.culture.response.CulturesSimpleResponse;
import likelion.MZConnent.dto.paging.response.PageContentResponse;
import likelion.MZConnent.dto.review.response.ReviewsSimpleResponse;
Expand All @@ -12,6 +13,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -33,7 +35,7 @@ public ResponseEntity<CultureCategoryResponse> getAllCultureCategories() {

// 전체 문화 간단 조회
@GetMapping("/api/cultures")
ResponseEntity<PageContentResponse> getCulturesSimpleList(@RequestParam(required = false, defaultValue = "0", value = "category") Long category, @RequestParam(required = false, defaultValue = "0", value = "page") int page ) {
public ResponseEntity<PageContentResponse> getCulturesSimpleList(@RequestParam(required = false, defaultValue = "0", value = "category") Long category, @RequestParam(required = false, defaultValue = "0", value = "page") int page) {

PageContentResponse<CulturesSimpleResponse> response = cultureService.getCulturesSimpleList(category, page);
return ResponseEntity.ok(response);
Expand All @@ -42,9 +44,18 @@ ResponseEntity<PageContentResponse> getCulturesSimpleList(@RequestParam(required

// 나의 관심 문화 간단 조회
@GetMapping("/api/cultures/interest")
ResponseEntity<PageContentResponse> getMyInterestCulturesSimpleList(@RequestParam(required = false, defaultValue = "0", value = "category") Long category, @RequestParam(required = false, defaultValue = "0", value = "page") int page, @AuthenticationPrincipal UserPrinciple userPrinciple) {
public ResponseEntity<PageContentResponse> getMyInterestCulturesSimpleList(@RequestParam(required = false, defaultValue = "0", value = "category") Long category, @RequestParam(required = false, defaultValue = "0", value = "page") int page, @AuthenticationPrincipal UserPrinciple userPrinciple) {

PageContentResponse<CulturesSimpleResponse> response = cultureService.getMyIntersetCulturesSimpleList(userPrinciple.getEmail(), category, page);
return ResponseEntity.ok(response);
}

@GetMapping("/api/cultures/{cultureId}")
public ResponseEntity<CultureDetailResponse> getCultureDetailInfo(@PathVariable("cultureId") Long cultureId) {
CultureDetailResponse response = cultureService.getCultureDetailInfo(cultureId);

log.info("문화 정보 조회 성공: {}", response.getCultureId());

return ResponseEntity.ok(response);
}
}
4 changes: 4 additions & 0 deletions src/main/java/likelion/MZConnent/domain/club/ClubRole.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package likelion.MZConnent.domain.club;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -11,10 +13,12 @@ public enum ClubRole {

private final String clubRole;

@JsonValue
public String getClubRole() {
return clubRole;
}

@JsonProperty
public static ClubRole fromRole(String role) {
for (ClubRole cR : ClubRole.values()) {
if (cR.getClubRole().equals(role)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package likelion.MZConnent.dto.culture.response;

import likelion.MZConnent.domain.club.AgeRestriction;
import likelion.MZConnent.domain.club.Club;
import likelion.MZConnent.domain.club.ClubRole;
import likelion.MZConnent.domain.club.GenderRestriction;
import likelion.MZConnent.domain.culture.Culture;
import likelion.MZConnent.dto.review.response.ReviewsSimpleResponse;
import lombok.*;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Getter
@Slf4j
@ToString
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class CultureDetailResponse {
private Long cultureId;
private String name;
private String cultureImageUrl;
private String regionName;
private int interestCount;
private String recommendedMember;
private String content;
private List<ClubsSimpleResponse> clubs;
private List<ReviewsSimpleResponse> reviews;

@Builder
public CultureDetailResponse(Culture culture) {
this.cultureId = culture.getCultureId();
this.name = culture.getName();
this.cultureImageUrl = culture.getCultureImageUrl();
this.regionName = culture.getRegion().getName();
this.interestCount = culture.getInterestCount();
this.recommendedMember = culture.getRecommendedMember();
this.content = culture.getContent();
this.clubs = culture.getClubs().stream().filter(club ->
(club.getStatus().equals("OPEN")
)).map(club ->
ClubsSimpleResponse.builder()
.club(club).build()).collect(Collectors.toList());
this.reviews = culture.getReviews().stream().map(
review -> ReviewsSimpleResponse.builder()
.review(review).build()
).collect(Collectors.toList());
}


@Getter
@ToString
@NoArgsConstructor(access = AccessLevel.PROTECTED)
static private class ClubsSimpleResponse {
private Long clubId;
private String title;
private String regionName;
private String cultureName;
private String leaderProfileImage;
private LocalDate meetingDate;
private LocalDateTime createdDate;
private GenderRestriction genderRestriction;
private AgeRestriction ageRestriction;
private int currentParticipant;
private int maxParticipant;

@Builder
public ClubsSimpleResponse(Club club) {
this.clubId = club.getClubId();
this.title = club.getTitle();
this.regionName = club.getRegion().getName();
this.cultureName = club.getCulture().getName();
this.leaderProfileImage = club.getClubMembers().stream().filter((member) ->
member.getClubRole() == ClubRole.LEADER
).findFirst().orElseThrow(() -> {
log.info("모임장이 존재하지 않음.");
return new IllegalArgumentException("모임장이 존재하지 않습니다.");
}).getMember().getProfileImageUrl();
this.meetingDate = club.getMeetingDate();
this.createdDate = club.getCreatedDate();
this.genderRestriction = club.getGenderRestriction();
this.ageRestriction = club.getAgeRestriction();
this.currentParticipant = club.getCurrentParticipant();
this.maxParticipant = club.getMaxParticipant();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

@Getter
@NoArgsConstructor
@ToString
public class ReviewsSimpleResponse {
private Long reviewId;
private MemberProfileDto reviewer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import likelion.MZConnent.domain.culture.Culture;
import likelion.MZConnent.domain.review.Review;
import likelion.MZConnent.dto.culture.response.CultureDetailResponse;
import likelion.MZConnent.dto.culture.response.CulturesSimpleResponse;
import likelion.MZConnent.dto.paging.response.PageContentResponse;
import likelion.MZConnent.dto.review.response.ReviewsSimpleResponse;
Expand All @@ -14,12 +15,14 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
@Transactional
@RequiredArgsConstructor
public class CultureService {
private final CultureRepository cultureRepository;
Expand Down Expand Up @@ -60,4 +63,13 @@ public PageContentResponse<CulturesSimpleResponse> getMyIntersetCulturesSimpleLi
.build();

}

public CultureDetailResponse getCultureDetailInfo(Long cultureId) {
Culture culture = cultureRepository.findById(cultureId).orElseThrow(() -> {
log.info("해당 문화가 존재하지 않습니다.");
return new IllegalArgumentException("해당 문화가 존재하지 않습니다.");
});
return CultureDetailResponse.builder()
.culture(culture).build();
}
}

0 comments on commit f98e1b7

Please sign in to comment.