Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ck-end into fix-config-bug
  • Loading branch information
oosedus committed Aug 6, 2024
2 parents 800fe82 + f02a782 commit 3affe38
Show file tree
Hide file tree
Showing 17 changed files with 283 additions and 51 deletions.
25 changes: 25 additions & 0 deletions src/main/java/likelion/MZConnent/api/main/MainInfoController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package likelion.MZConnent.api.main;

import likelion.MZConnent.dto.main.response.MainInfoResponse;
import likelion.MZConnent.service.main.MainInfoService;
import lombok.Getter;
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.RestController;

@RestController
@Slf4j
@RequiredArgsConstructor
public class MainInfoController {
private final MainInfoService mainInfoService;

@GetMapping("/api/main")
public ResponseEntity<MainInfoResponse> getMainInfo() {
MainInfoResponse mainInfo = mainInfoService.getMainInfo();
log.info("메인 정보 조회: {}", mainInfo);

return ResponseEntity.ok(mainInfo);
}
}
16 changes: 16 additions & 0 deletions src/main/java/likelion/MZConnent/api/review/ReviewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import likelion.MZConnent.dto.paging.response.PageContentResponse;
import likelion.MZConnent.dto.review.request.SaveReviewRequest;
import likelion.MZConnent.dto.review.response.ReviewDetailResponse;
import likelion.MZConnent.dto.review.response.ReviewsSimpleResponse;
import likelion.MZConnent.dto.review.response.SaveReviewResponse;
import likelion.MZConnent.jwt.principle.UserPrinciple;
Expand Down Expand Up @@ -71,4 +72,19 @@ public ResponseEntity<Map<String, String>> toggleReviewLike(@PathVariable("revie
return ResponseEntity.ok(Map.of("message", "후기 좋아요 삭제 성공"));
}
}


// 후기 상세 정보 조회
@GetMapping("/api/reviews/{reviewId}")
public ResponseEntity<ReviewDetailResponse> getReviewDetailInfo(@PathVariable("reviewId") Long reviewId) {
ReviewDetailResponse response = reviewService.getReviewDetailInfo(reviewId);
log.info("후기 상세 정보: {}", response);
return ResponseEntity.ok(response);
}

@DeleteMapping("/api/reviews/{reviewId}")
public ResponseEntity<Map<String, String>> deleteReview(@PathVariable("reviewId") Long reviewId) {
reviewService.deleteReview(reviewId);
return ResponseEntity.ok(Map.of("message", "후기 삭제 성공"));
}
}
4 changes: 2 additions & 2 deletions src/main/java/likelion/MZConnent/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class SecurityConfig {
private final String[] permitAllUrl = {"/error",
"/api/auth/login", "/api/auth/email", "/api/auth/username", // 회원
"/api/categories/culture", "/api/cultures", "/api/cultures/**", // 문화
"/api/reviews", // 후기
"/api/reviews/**", // 후기
"/api/categories/region", "/api/clubs/list",
"/api/main", "/api/clubs/**",
"/swagger", "/swagger-ui.html", "/swagger-ui/**", "/api-docs", "/api-docs/**", "/v3/api-docs/**", //swagger
Expand Down Expand Up @@ -86,7 +86,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration config = new CorsConfiguration();
config.setAllowedOrigins(Arrays.asList("http://localhost:3000")); // frontend url
config.setAllowedOrigins(Arrays.asList("http://mzconnect.site", "http://localhost:3000")); // frontend url
config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS"));
config.setAllowedHeaders(Collections.singletonList("*"));
config.setAllowCredentials(true);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/likelion/MZConnent/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@ToString
@NoArgsConstructor
public class Member {
public static final String DEFAULT_PROFILE_IMAGE_URL = "https://mzconnect-bucket.s3.ap-northeast-2.amazonaws.com/default_image.jpeg";
public static final String DEFAULT_PROFILE_IMAGE_URL = "https://mzconnect-bucket.s3.ap-northeast-2.amazonaws.com/default_image.png";

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package likelion.MZConnent.dto.club.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 lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Getter
@Slf4j
@ToString
@NoArgsConstructor
public class ClubSimpleResponse {
private Long clubId;
Expand All @@ -19,15 +27,15 @@ public class ClubSimpleResponse {
private String leaderProfileImage;
private LocalDate meetingDate;
private LocalDateTime createdDate;
private String genderRestriction;
private String ageRestriction;
private GenderRestriction genderRestriction;
private AgeRestriction ageRestriction;
private int currentParticipant;
private int maxParticipant;

@Builder
public ClubSimpleResponse(Long clubId, String title, Long regionId, String regionName, Long cultureCategoryId,
String cultureName, String leaderProfileImage, LocalDate meetingDate,
LocalDateTime createdDate, String genderRestriction, String ageRestriction,
LocalDateTime createdDate, GenderRestriction genderRestriction, AgeRestriction ageRestriction,
int currentParticipant, int maxParticipant) {
this.clubId = clubId;
this.title = title;
Expand All @@ -43,4 +51,23 @@ public ClubSimpleResponse(Long clubId, String title, Long regionId, String regio
this.currentParticipant = currentParticipant;
this.maxParticipant = maxParticipant;
}

public ClubSimpleResponse(Club club) {
this.clubId = club.getClubId();
this.title = club.getTitle();
this.regionId = club.getRegion().getRegionId();
this.regionName = club.getRegion().getName();
this.cultureCategoryId = club.getCulture().getCultureId();
this.cultureName = club.getCulture().getName();
this.leaderProfileImage = club.getClubMembers().stream().filter(clubMember -> clubMember.getClubRole().equals(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 @@ -5,6 +5,7 @@
import likelion.MZConnent.domain.club.ClubRole;
import likelion.MZConnent.domain.club.GenderRestriction;
import likelion.MZConnent.domain.culture.Culture;
import likelion.MZConnent.dto.club.response.ClubSimpleResponse;
import likelion.MZConnent.dto.review.response.ReviewsSimpleResponse;
import lombok.*;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -27,7 +28,7 @@ public class CultureDetailResponse {
private int interestCount;
private String recommendedMember;
private String content;
private List<ClubsSimpleResponse> clubs;
private List<ClubSimpleResponse> clubs;
private List<ReviewsSimpleResponse> reviews;

@Builder
Expand All @@ -40,51 +41,11 @@ public CultureDetailResponse(Culture culture) {
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());
(club.getStatus().equals("OPEN")
)).map(ClubSimpleResponse::new).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
@@ -0,0 +1,30 @@
package likelion.MZConnent.dto.main.response;

import likelion.MZConnent.domain.club.Club;
import likelion.MZConnent.domain.culture.Culture;
import likelion.MZConnent.domain.review.Review;
import likelion.MZConnent.dto.club.response.ClubSimpleResponse;
import likelion.MZConnent.dto.culture.response.CulturesSimpleResponse;
import likelion.MZConnent.dto.review.response.ReviewsSimpleResponse;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

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

@Data
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class MainInfoResponse {
private List<CulturesSimpleResponse> popularCultures;
private List<ReviewsSimpleResponse> popularReviews;
private List<ClubSimpleResponse> recentClubs;

@Builder
public MainInfoResponse(List<Culture> popularCultures, List<Review> popularReviews, List<Club> recentClubs) {
this.popularCultures = popularCultures.stream().map(culture -> CulturesSimpleResponse.builder().culture(culture).build()).collect(Collectors.toList());
this.popularReviews = popularReviews.stream().map(review -> ReviewsSimpleResponse.builder().review(review).build()).collect(Collectors.toList());
this.recentClubs = recentClubs.stream().map(ClubSimpleResponse::new).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package likelion.MZConnent.dto.review.response;

import likelion.MZConnent.domain.culture.Culture;
import likelion.MZConnent.domain.review.Review;
import likelion.MZConnent.domain.review.ReviewComment;
import likelion.MZConnent.dto.member.MemberProfileDto;
import lombok.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Getter
@ToString
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ReviewDetailResponse {
private Long reviewId;
private MemberProfileDto reviewer;
private CultureSimpleDto culture;
private String title;
private String reviewImageUrl1;
private String reviewImageUrl2;
private String reviewImageUrl3;
private String reviewImageUrl4;
private String content;
private LocalDateTime createdDate;
private int likeCount;
private List<CommentSimpleDto> comments = new ArrayList<CommentSimpleDto>();

@Builder
public ReviewDetailResponse(Review review) {
this.reviewId = review.getReviewId();
this.reviewer = MemberProfileDto.builder().member(review.getMember()).build();
this.culture = CultureSimpleDto.builder().culture(review.getCulture()).build();
this.title = review.getTitle();
this.reviewImageUrl1 = review.getReviewImageUrl1();
this.reviewImageUrl2 = review.getReviewImageUrl2();
this.reviewImageUrl3 = review.getReviewImageUrl3();
this.reviewImageUrl4 = review.getReviewImageUrl4();
this.content = review.getContent();
this.createdDate = review.getCreatedDate();
this.likeCount = review.getLikeCount();
this.comments = review.getReviewComments().stream()
.map(CommentSimpleDto::new).collect(Collectors.toList());
}

@Getter
@ToString
@NoArgsConstructor(access = AccessLevel.PROTECTED)
private static class CultureSimpleDto {
private Long cultureId;
private String name;

@Builder
public CultureSimpleDto(Culture culture) {
this.cultureId = culture.getCultureId();
this.name = culture.getName();
}
}

@Getter
@ToString
@NoArgsConstructor(access = AccessLevel.PROTECTED)
private static class CommentSimpleDto {
private Long commentId;
private MemberProfileDto commenter;
private String content;

@Builder
public CommentSimpleDto(ReviewComment comment) {
this.commentId = comment.getCommentId();
this.commenter = MemberProfileDto.builder().member(comment.getMember()).build();
this.content = comment.getContent();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;

@Repository
public interface ClubRepository extends JpaRepository<Club, Long> {
Expand All @@ -27,5 +28,8 @@ Page<Club> findAllByFilters(@Param("cultureCategoryId") Long cultureCategoryId,
Pageable pageable);

Collection<Club> findAllByStatus(String status);

@Query("SELECT c FROM Club c WHERE c.status = 'OPEN' ORDER BY c.createdDate DESC")
List<Club> findTop6OrderByCreatedDateDesc(Pageable pageable);
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CultureRepository extends JpaRepository<Culture, Long> {
@Query("SELECT c FROM Culture c WHERE :category = 0 OR c.cultureCategory.id = :category")
Page<Culture> findAllByCultureCategory(@Param("category") Long category, Pageable pageable);

@Query("SELECT c FROM Culture c JOIN c.cultureInterests ci JOIN ci.member m WHERE (:category = 0 OR c.cultureCategory.id = :category) AND m.email = :email")
Page<Culture> findByMemberAndCategory(@Param("email") String email, @Param("category") Long category, Pageable pageable);

@Query("SELECT c FROM Culture c ORDER BY c.interestCount DESC")
List<Culture> findTop4ByInterestCount(Pageable pageable);

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package likelion.MZConnent.repository.review;

import likelion.MZConnent.domain.review.Review;
import likelion.MZConnent.domain.review.ReviewComment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface ReviewCommentRepository extends JpaRepository<ReviewComment, Long> {
List<ReviewComment> findAllByReview(Review review);
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
Expand All @@ -16,4 +17,6 @@ public interface ReviewLikeRepository extends JpaRepository<ReviewLike, Long> {
boolean existsByMemberAndReview(Member member, Review review);

Optional<ReviewLike> findByMemberAndReview(Member member, Review review);

List<ReviewLike> findAllByReview(Review review);
}
Loading

0 comments on commit 3affe38

Please sign in to comment.