Skip to content

Commit

Permalink
Merge pull request #52 from Kusitms-29th-Meetup-TeamE/feat/44/experie…
Browse files Browse the repository at this point in the history
…nce-detail

Feat: 배움나누기 상세 api 구현
  • Loading branch information
Jeongho427 authored May 18, 2024
2 parents ec3f44d + f5a6373 commit 0c9cc8e
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.meetup.teame.backend.domain.experience.controller;

import com.meetup.teame.backend.domain.experience.dto.request.ReadExperiencesReq;
import com.meetup.teame.backend.domain.experience.dto.response.ReadExperienceDetailRes;
import com.meetup.teame.backend.domain.experience.dto.response.ReadExperiencesRes;
import com.meetup.teame.backend.domain.experience.dto.response.MyExperienceProfileRes;
import com.meetup.teame.backend.domain.experience.service.ExperienceService;
Expand Down Expand Up @@ -47,4 +48,18 @@ public ResponseEntity<ReadExperiencesRes> readExperiences(@ModelAttribute @Valid
public ResponseEntity<MyExperienceProfileRes> readMyExperienceProfile() {
return ResponseEntity.ok(experienceService.readMyExperienceProfile());
}

@Operation(summary = "배움나누기 페이지 경험 상세 조회", description = """
배움 나누기 페이지의 경험 상세를 조회합니다.
jwt토큰도 같이 전달해서 요청해주셔야 합니다.
url 경로 파라미터로 다음과 같은 값을 전달해주셔야 합니다.
experienceId : 조회할 경험의 id
""")
@GetMapping("/{experienceId}")
public ResponseEntity<ReadExperienceDetailRes> readExperienceDetail(@PathVariable Long experienceId) {
return ResponseEntity.ok(experienceService.readExperienceDetail(experienceId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.meetup.teame.backend.domain.experience.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.meetup.teame.backend.domain.experience.entity.ExperienceType;
import com.meetup.teame.backend.domain.review.entity.Review;
import com.meetup.teame.backend.domain.user.entity.User;
import lombok.*;

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

@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Builder
public class ExperienceReviewsRes {
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Builder
public static class ExperienceReview {
private String title;
private String content;
private String name;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy.MM.dd")
private LocalDate date;

public static ExperienceReview of(Review review) {
return ExperienceReview.builder()
.title(review.getAppointmentTitle())
.content(review.getContent())
.name(review.getMentee().getName())
.date(review.getReviewDate())
.build();
}
}

private String type;
private List<ExperienceReview> reviews;

public static ExperienceReviewsRes of(ExperienceType type, User mentor) {
List<ExperienceReview> reviews = mentor.getReviewsAboutMe().stream()
.filter(review -> review.getAppointmentType().equals(type))
.map(ExperienceReview::of)
.toList();
return ExperienceReviewsRes.builder()
.type(type.getDescription())
.reviews(reviews)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.meetup.teame.backend.domain.experience.dto.response;

import com.meetup.teame.backend.domain.experience.entity.Experience;
import lombok.*;

@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Builder
public class OtherExperience {
private String type;
private String title;

public static OtherExperience of(Experience experience) {
return OtherExperience.builder()
.type(experience.getType().getDescription())
.title(experience.getDescription())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.meetup.teame.backend.domain.experience.dto.response;

import com.meetup.teame.backend.domain.experience.entity.Experience;
import com.meetup.teame.backend.domain.user.entity.User;
import lombok.*;

import java.util.List;

@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Builder
public class ReadExperienceDetailRes {
private String imageUrl;
private String name;
private Long age;
private String gender;
private String location;
private String oneWord;
private String title;
private String content;
private List<ExperienceReviewsRes> reviews;
private List<OtherExperience> otherExperiences;

public static ReadExperienceDetailRes of(Experience experience) {
User user = experience.getUser();

List<ExperienceReviewsRes> reviews = user.getExperiences().stream()
.map(Experience::getType)
.distinct()
.map(type -> ExperienceReviewsRes.of(type, user))
.toList();

List<OtherExperience> otherExperiences = user.getExperiences().stream()
.filter(exp -> !exp.getId().equals(experience.getId()))
.map(OtherExperience::of)
.toList();

return ReadExperienceDetailRes.builder()
.imageUrl(user.getImageUrl())
.name(user.getName())
.age(user.getAge())
.gender(user.getGender().getDescription())
.location(user.getLocation())
.oneWord(user.getOneWord())
.title(experience.getDescription())
.content(experience.getDetail())
.reviews(reviews)
.otherExperiences(otherExperiences)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.meetup.teame.backend.domain.auth.jwt.SecurityContextProvider;
import com.meetup.teame.backend.domain.experience.dto.request.ReadExperiencesReq;
import com.meetup.teame.backend.domain.experience.dto.response.ReadExperienceDetailRes;
import com.meetup.teame.backend.domain.experience.dto.response.ReadExperiencesRes;
import com.meetup.teame.backend.domain.experience.dto.response.MyExperienceProfileRes;
import com.meetup.teame.backend.domain.experience.entity.Experience;
import com.meetup.teame.backend.domain.experience.repository.ExperienceRepository;
import com.meetup.teame.backend.domain.user.entity.User;
import com.meetup.teame.backend.domain.user.repository.UserRepository;
Expand Down Expand Up @@ -45,4 +47,11 @@ public MyExperienceProfileRes readMyExperienceProfile() {
.orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_USER));
return MyExperienceProfileRes.of(user);
}


public ReadExperienceDetailRes readExperienceDetail(Long experienceId) {
Experience experience = experienceRepository.findById(experienceId)
.orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_EXPERIENCE));
return ReadExperienceDetailRes.of(experience);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class User {
@Comment("사용자 포인트")
private Long point;

@Comment("한마디")
@Comment("사용자 한마디")
private String oneWord;

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
Expand Down

0 comments on commit 0c9cc8e

Please sign in to comment.