Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

나의 모임 간단 및 상세 조회 기능 #67

Merged
merged 4 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/main/java/likelion/MZConnent/api/club/ClubController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@
import likelion.MZConnent.service.club.RegionCategoryService;
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.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

Expand Down
35 changes: 35 additions & 0 deletions src/main/java/likelion/MZConnent/api/club/MyClubController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package likelion.MZConnent.api.club;

import likelion.MZConnent.dto.club.response.MyClubDetailResponse;
import likelion.MZConnent.dto.club.response.MyClubSimpleResponse;
import likelion.MZConnent.jwt.principle.UserPrinciple;
import likelion.MZConnent.service.club.MyClubService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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;

@Slf4j
@RequiredArgsConstructor
@RestController
public class MyClubController {
private final MyClubService myClubService;

@GetMapping("/api/users/clubs")
public ResponseEntity<MyClubSimpleResponse> getMyClubs(@AuthenticationPrincipal UserPrinciple userPrinciple) {
MyClubSimpleResponse response = myClubService.getMyClubs(userPrinciple.getEmail());
return ResponseEntity.ok(response);
}

@GetMapping("/api/users/clubs/{clubId}")
public ResponseEntity<MyClubDetailResponse> getMyClubDetail(@AuthenticationPrincipal UserPrinciple userPrinciple, @PathVariable Long clubId) {
MyClubDetailResponse response = myClubService.getMyClubDetail(userPrinciple.getEmail(), clubId);
return ResponseEntity.ok(response);
}


}
45 changes: 40 additions & 5 deletions src/main/java/likelion/MZConnent/api/review/ReviewController.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package likelion.MZConnent.api.review;

import com.fasterxml.jackson.core.JsonProcessingException;
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.ReviewsSimpleResponse;
import likelion.MZConnent.dto.review.response.SaveReviewResponse;
import likelion.MZConnent.jwt.principle.UserPrinciple;
import likelion.MZConnent.service.review.ReviewService;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.PageRequest;
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;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequiredArgsConstructor
Expand All @@ -23,4 +30,32 @@ ResponseEntity<PageContentResponse> getReviewSimpleList(@RequestParam(required =
PageContentResponse<ReviewsSimpleResponse> response = reviewService.getReviewsSimpleList(keyword, page);
return ResponseEntity.ok(response);
}

@PostMapping(value="/api/reviews/culture/{cultureId}", consumes = {"multipart/form-data"})
public ResponseEntity<SaveReviewResponse> saveReview(
@AuthenticationPrincipal UserPrinciple userPrinciple,
@RequestPart("info") String info,
@RequestPart(value = "reviewImage1", required = true) MultipartFile reviewImage1,
@RequestPart(value = "reviewImage2", required = false) MultipartFile reviewImage2,
@RequestPart(value = "reviewImage3", required = false) MultipartFile reviewImage3,
@RequestPart(value = "reviewImage4", required = false) MultipartFile reviewImage4,
@PathVariable Long cultureId) throws JsonProcessingException {

try {
ObjectMapper objectMapper = new ObjectMapper();
SaveReviewRequest request = objectMapper.readValue(info, SaveReviewRequest.class);

List<MultipartFile> images = new ArrayList<>();
if (reviewImage1 != null) images.add(reviewImage1);
if (reviewImage2 != null) images.add(reviewImage2);
if (reviewImage3 != null) images.add(reviewImage3);
if (reviewImage4 != null) images.add(reviewImage4);

SaveReviewResponse response = reviewService.createReview(userPrinciple.getEmail(), request, images, cultureId);
return ResponseEntity.ok(response);
} catch (IOException e) {
log.error("리뷰 저장 실패", e);
return ResponseEntity.status(500).body(null);
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/likelion/MZConnent/domain/culture/Culture.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;

@Entity
@Getter
@Setter
@NoArgsConstructor
public class Culture {
@Id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package likelion.MZConnent.dto.club.response;

import likelion.MZConnent.domain.club.ClubRole;
import likelion.MZConnent.domain.member.Age;
import likelion.MZConnent.domain.member.Gender;
import likelion.MZConnent.dto.club.SelfIntroductionDto;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.util.List;

@Getter
@NoArgsConstructor
public class MyClubDetailResponse {
private Long clubId;
private String title;
private LocalDate meetingDate;
private String content;
private int currentParticipant;
private MyClubCultureDto culture;
private List<MyClubMemberDto> members;

@Builder
public MyClubDetailResponse(Long clubId, String title, LocalDate meetingDate, String content, int currentParticipant, MyClubCultureDto culture, List<MyClubMemberDto> members) {
this.clubId = clubId;
this.title = title;
this.meetingDate = meetingDate;
this.content = content;
this.currentParticipant = currentParticipant;
this.culture = culture;
this.members = members;
}

@Getter
@NoArgsConstructor
public static class MyClubCultureDto {
private Long cultureId;
private String name;

@Builder
public MyClubCultureDto(Long cultureId, String name) {
this.cultureId = cultureId;
this.name = name;
}
}

@Getter
@NoArgsConstructor
public static class MyClubMemberDto {
private Long userId;
private String username;
private String profileImageUrl;
private Age age;
private Gender gender;
private ClubRole role;
private List<SelfIntroductionDto> selfIntroductions;

@Builder
public MyClubMemberDto(Long userId, String username, String profileImageUrl, Age age, Gender gender, ClubRole role, List<SelfIntroductionDto> selfIntroductions) {
this.userId = userId;
this.username = username;
this.profileImageUrl = profileImageUrl;
this.age = age;
this.gender = gender;
this.role = role;
this.selfIntroductions = selfIntroductions;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package likelion.MZConnent.dto.club.response;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDate;
import java.util.List;

@Slf4j
@Getter
@NoArgsConstructor
public class MyClubSimpleResponse {
private List<MyClubSimpleDto> myClubs;

@Builder
public MyClubSimpleResponse(List<MyClubSimpleDto> myClubs) {
this.myClubs = myClubs;
}

@Getter
@NoArgsConstructor
public static class MyClubSimpleDto {
private Long clubId;
private String title;
private String cultureName;
private LocalDate meetingDate;
private int currentParticipant;
private int maxParticipant;

@Builder
public MyClubSimpleDto(Long clubId, String title, String cultureName, LocalDate meetingDate, int currentParticipant, int maxParticipant) {
this.clubId = clubId;
this.title = title;
this.cultureName = cultureName;
this.meetingDate = meetingDate;
this.currentParticipant = currentParticipant;
this.maxParticipant = maxParticipant;
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package likelion.MZConnent.dto.review.request;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Slf4j
@Getter
@NoArgsConstructor
public class SaveReviewRequest {
private String title;
private String content;

@Builder
public SaveReviewRequest(String title, String content, List<String> reviewImageUrls) {
this.title = title;
this.content = content;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package likelion.MZConnent.dto.review.response;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Getter
@NoArgsConstructor
public class SaveReviewResponse {
private Long reviewId;
private ReviewerDto reviewer;
private ReviewCultureDto culture;
private String title;
private String reviewImageUrl1;
private String reviewImageUrl2;
private String reviewImageUrl3;
private String reviewImageUrl4;
private LocalDateTime createdDate;
private int likeCount;

@Builder
public SaveReviewResponse(Long reviewId, ReviewerDto reviewer, ReviewCultureDto culture, String title, String reviewImageUrl1, String reviewImageUrl2, String reviewImageUrl3, String reviewImageUrl4, LocalDateTime createdDate, int likeCount) {
this.reviewId = reviewId;
this.reviewer = reviewer;
this.culture = culture;
this.title = title;
this.reviewImageUrl1 = reviewImageUrl1;
this.reviewImageUrl2 = reviewImageUrl2;
this.reviewImageUrl3 = reviewImageUrl3;
this.reviewImageUrl4 = reviewImageUrl4;
this.createdDate = createdDate;
this.likeCount = likeCount;
}

@Getter
@NoArgsConstructor
public static class ReviewerDto {
private Long userId;
private String username;
private String profileImage;

@Builder
public ReviewerDto(Long userId, String username, String profileImage) {
this.userId = userId;
this.username = username;
this.profileImage = profileImage;
}
}

@Getter
@NoArgsConstructor
public static class ReviewCultureDto {
private Long cultureId;
private String cultureName;

@Builder
public ReviewCultureDto(Long cultureId, String cultureName) {
this.cultureId = cultureId;
this.cultureName = cultureName;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class ClubService {
public CreateClubResponse createClub(CreateClubRequest request, Member member) {

Culture culture = cultureRepository.findById(request.getCultureId()).orElseThrow(() -> new IllegalArgumentException("존재하지 않는 문화입니다."));
culture.setClubCount(culture.getClubCount() + 1);
RegionCategory region = regionCategoryRepository.findById(request.getRegionId()).orElseThrow(() -> new IllegalArgumentException("존재하지 않는 지역입니다."));

Club club = Club.builder()
Expand Down
Loading
Loading