Skip to content

Commit

Permalink
#31 feat : 일정 후기 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
sycuuui committed Jun 4, 2024
1 parent bb1ea52 commit b6cbbcf
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package Journey.Together.domain.dairy.controller;

import Journey.Together.domain.dairy.dto.PlanReq;
import Journey.Together.domain.dairy.dto.PlanReviewReq;
import Journey.Together.domain.dairy.service.PlanService;
import Journey.Together.global.common.ApiResponse;
import Journey.Together.global.exception.Success;
Expand Down Expand Up @@ -35,7 +36,8 @@ public ApiResponse deletePlan(@AuthenticationPrincipal PrincipalDetails principa
}

@PostMapping("/review/{plan_id}")
public ApiResponse savePlanReview(@AuthenticationPrincipal PrincipalDetails principalDetails,@PathVariable("plan_id")Long planId){
public ApiResponse savePlanReview(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("plan_id")Long planId, @RequestBody PlanReviewReq planReviewReq){
planService.savePlanReview(principalDetails.getMember(),planId,planReviewReq);
return ApiResponse.success(Success.CREATE_REVIEW_SUCCESS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import org.springframework.web.multipart.MultipartFile;

import javax.swing.text.StyledEditorKit;
import java.util.List;

public record PlanReviewReq(
float grade,
String content,
List<MultipartFile> images
List<MultipartFile> images,
Boolean isPublic
) {
}
18 changes: 13 additions & 5 deletions src/main/java/Journey/Together/domain/dairy/entity/PlanReview.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,24 @@ public class PlanReview extends BaseTimeEntity {
@Column(name = "planReview_id",columnDefinition = "bigint")
private Long planReviewId;

@Column(name = "grade")
private float grade;

@Column(name = "content",columnDefinition = "varchar(300)")
private String content;

@OneToOne(mappedBy = "plan", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
@JoinColumn(name = "plan_id")
private Plan plan;

@OneToMany(mappedBy = "planReviewImage", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
private List<PlanReviewImage> planReviewImages = new ArrayList<>();

@Column(name = "grade")
private float grade;

@Column(name = "content",columnDefinition = "varchar(300)")
private String content;
@Builder
public PlanReview(float grade, String content,Plan plan,List<PlanReviewImage> planReviewImages){
this.grade = grade;
this.content=content;
this.plan=plan;
this.planReviewImages=planReviewImages;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public class PlanReviewImage {

@Column(name = "imageUrl")
private String imageUrl;

@Builder
public PlanReviewImage(String imageUrl){
this.imageUrl=imageUrl;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package Journey.Together.domain.dairy.repository;

import Journey.Together.domain.dairy.entity.PlanReviewImage;
import org.springframework.data.jpa.repository.JpaRepository;

public interface PlanReviewImageRepository extends JpaRepository<PlanReviewImage,Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package Journey.Together.domain.dairy.repository;

import Journey.Together.domain.dairy.entity.PlanReview;
import org.springframework.data.jpa.repository.JpaRepository;


public interface PlanReviewRepository extends JpaRepository<PlanReview,Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,31 @@

import Journey.Together.domain.dairy.dto.DailyPlace;
import Journey.Together.domain.dairy.dto.PlanReq;
import Journey.Together.domain.dairy.dto.PlanReviewReq;
import Journey.Together.domain.dairy.entity.Day;
import Journey.Together.domain.dairy.entity.Plan;
import Journey.Together.domain.dairy.entity.PlanReview;
import Journey.Together.domain.dairy.entity.PlanReviewImage;
import Journey.Together.domain.dairy.repository.DayRepository;
import Journey.Together.domain.dairy.repository.PlanRepository;
import Journey.Together.domain.dairy.repository.PlanReviewImageRepository;
import Journey.Together.domain.dairy.repository.PlanReviewRepository;
import Journey.Together.domain.member.entity.Member;
import Journey.Together.domain.member.repository.MemberRepository;
import Journey.Together.domain.place.entity.Place;
import Journey.Together.domain.place.repository.PlaceRepository;
import Journey.Together.global.exception.ApplicationException;
import Journey.Together.global.exception.ErrorCode;
import Journey.Together.global.util.S3Client;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDate;
import java.util.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Service
@Transactional(readOnly = true)
Expand All @@ -27,6 +36,9 @@ public class PlanService {
private final PlanRepository planRepository;
private final DayRepository dayRepository;
private final PlaceRepository placeRepository;
private final PlanReviewRepository planReviewRepository;
private final PlanReviewImageRepository planReviewImageRepository;
private final S3Client s3Client;

@Transactional
public void savePlan(Member member, PlanReq planReq){
Expand Down Expand Up @@ -79,13 +91,30 @@ public void deletePlan(Member member,Long planId){
}

@Transactional
public void savePlanReview(Member member,Long planId){
public void savePlanReview(Member member, Long planId, PlanReviewReq planReviewReq){
// Validation
Plan plan = planRepository.findPlanByMemberAndPlanIdAndEndDateIsAfterAndDeletedAtIsNull(member,planId,LocalDate.now());
if(plan == null){
throw new ApplicationException(ErrorCode.NOT_FOUND_EXCEPTION);
}

//Business
List<PlanReviewImage> list = new ArrayList<>();
for(MultipartFile file : planReviewReq.images()){
String uuid = UUID.randomUUID().toString();
String url = s3Client.upload(file,member.getProfileUuid(),uuid);
PlanReviewImage planReviewImage = PlanReviewImage.builder()
.imageUrl(url)
.build();
planReviewImageRepository.save(planReviewImage);
list.add(planReviewImage);
}
PlanReview planReview = PlanReview.builder()
.grade(planReviewReq.grade())
.content(planReviewReq.content())
.plan(plan)
.planReviewImages(list)
.build();
planReviewRepository.save(planReview);

}
}
2 changes: 1 addition & 1 deletion src/main/java/Journey/Together/global/util/S3Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public String upload(MultipartFile multipartFile, String folderName, String imag
}

// Response
return uuid;
return baseUrl+url;
}

public String update(String fileName, MultipartFile newFile) {
Expand Down

0 comments on commit b6cbbcf

Please sign in to comment.