From e4291310e740ee25774430e927eb9e041631a1cd Mon Sep 17 00:00:00 2001 From: Jeongho Date: Sat, 18 May 2024 20:28:11 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Feat:=20=EA=B2=BD=ED=97=98=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=20=EC=83=9D=EC=84=B1=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/experience/entity/Experience.java | 8 +++-- .../repository/ExperienceRepository.java | 4 +++ .../domain/like/service/LikeService.java | 2 ++ .../user/controller/UserController.java | 22 ++++++++------ .../user/dto/request/MyExperienceReq.java | 17 +++++++++++ .../user/dto/response/MyExperienceRes.java | 28 +++++++++++++++++ .../response/ReadExperienceProfileRes.java | 19 +++++++++++- .../backend/domain/user/entity/User.java | 7 +++++ .../domain/user/service/UserService.java | 30 +++++++++++++++---- 9 files changed, 118 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/meetup/teame/backend/domain/user/dto/request/MyExperienceReq.java create mode 100644 src/main/java/com/meetup/teame/backend/domain/user/dto/response/MyExperienceRes.java diff --git a/src/main/java/com/meetup/teame/backend/domain/experience/entity/Experience.java b/src/main/java/com/meetup/teame/backend/domain/experience/entity/Experience.java index 7719ec1..c7ccdc0 100644 --- a/src/main/java/com/meetup/teame/backend/domain/experience/entity/Experience.java +++ b/src/main/java/com/meetup/teame/backend/domain/experience/entity/Experience.java @@ -1,6 +1,7 @@ package com.meetup.teame.backend.domain.experience.entity; import com.meetup.teame.backend.domain.chatroom.entity.DirectChatRoom; +import com.meetup.teame.backend.domain.user.dto.request.MyExperienceReq; import com.meetup.teame.backend.domain.user.entity.User; import jakarta.persistence.*; import lombok.*; @@ -45,10 +46,11 @@ public class Experience { @OneToMany(mappedBy = "experience", cascade = CascadeType.ALL) private List directChatRooms; - public static Experience of(ExperienceType type, String description, User user) { + public static Experience of(MyExperienceReq req, User user) { return Experience.builder() - .type(type) - .description(description) + .description(req.getTitle()) + .type(ExperienceType.of(req.getExperienceType())) + .detail(req.getDetail()) .user(user) .reviewCount(0L) .build(); diff --git a/src/main/java/com/meetup/teame/backend/domain/experience/repository/ExperienceRepository.java b/src/main/java/com/meetup/teame/backend/domain/experience/repository/ExperienceRepository.java index 5e8d763..5e5508b 100644 --- a/src/main/java/com/meetup/teame/backend/domain/experience/repository/ExperienceRepository.java +++ b/src/main/java/com/meetup/teame/backend/domain/experience/repository/ExperienceRepository.java @@ -2,7 +2,11 @@ import com.meetup.teame.backend.domain.experience.entity.Experience; import com.meetup.teame.backend.domain.experience.repository.custom.ExperienceRepositoryCustom; +import com.meetup.teame.backend.domain.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface ExperienceRepository extends JpaRepository, ExperienceRepositoryCustom { + List findAllByUser(User user); } diff --git a/src/main/java/com/meetup/teame/backend/domain/like/service/LikeService.java b/src/main/java/com/meetup/teame/backend/domain/like/service/LikeService.java index 6b440a4..ad6bd5f 100644 --- a/src/main/java/com/meetup/teame/backend/domain/like/service/LikeService.java +++ b/src/main/java/com/meetup/teame/backend/domain/like/service/LikeService.java @@ -11,8 +11,10 @@ import com.meetup.teame.backend.global.exception.ExceptionContent; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @RequiredArgsConstructor +@Transactional @Service public class LikeService { diff --git a/src/main/java/com/meetup/teame/backend/domain/user/controller/UserController.java b/src/main/java/com/meetup/teame/backend/domain/user/controller/UserController.java index 901de04..6569eb5 100644 --- a/src/main/java/com/meetup/teame/backend/domain/user/controller/UserController.java +++ b/src/main/java/com/meetup/teame/backend/domain/user/controller/UserController.java @@ -2,13 +2,11 @@ import com.meetup.teame.backend.domain.activity.dto.response.ActivitySummaryRes; import com.meetup.teame.backend.domain.review.dto.response.MyReviewRes; +import com.meetup.teame.backend.domain.user.dto.request.MyExperienceReq; import com.meetup.teame.backend.domain.user.dto.request.OnboardingReq; import com.meetup.teame.backend.domain.user.dto.request.ReadCalenderReq; import com.meetup.teame.backend.domain.user.dto.request.UpdateUserReq; -import com.meetup.teame.backend.domain.user.dto.response.ReadCalenderRes; -import com.meetup.teame.backend.domain.user.dto.response.ReadExperienceProfileRes; -import com.meetup.teame.backend.domain.user.dto.response.ReadMainRes; -import com.meetup.teame.backend.domain.user.dto.response.UserInfoRes; +import com.meetup.teame.backend.domain.user.dto.response.*; import com.meetup.teame.backend.domain.user.service.UserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -127,9 +125,15 @@ public ResponseEntity> getMyActivities() { return ResponseEntity.ok().body(myActivities); } - /* @PostMapping("/experience-profile") - public ResponseEntity createExperienceProfile() { - ReadExperienceProfileRes profile = userService.createExperienceProfile(); - return ResponseEntity.ok().body(profile); - }*/ + @PostMapping("/experience-profile") + public ResponseEntity createExperienceProfile(@RequestBody MyExperienceReq request) { + String response = userService.createExperienceProfile(request); + return ResponseEntity.ok().body(response); + } + + @GetMapping("/experience-profile") + public ResponseEntity getExperienceProfile() { + ReadExperienceProfileRes response = userService.getExperienceProfile(); + return ResponseEntity.ok().body(response); + } } diff --git a/src/main/java/com/meetup/teame/backend/domain/user/dto/request/MyExperienceReq.java b/src/main/java/com/meetup/teame/backend/domain/user/dto/request/MyExperienceReq.java new file mode 100644 index 0000000..40d518c --- /dev/null +++ b/src/main/java/com/meetup/teame/backend/domain/user/dto/request/MyExperienceReq.java @@ -0,0 +1,17 @@ +package com.meetup.teame.backend.domain.user.dto.request; + +import lombok.*; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +public class MyExperienceReq { + + private String title; + + private String experienceType; + + private String detail; + + private String introduce; +} diff --git a/src/main/java/com/meetup/teame/backend/domain/user/dto/response/MyExperienceRes.java b/src/main/java/com/meetup/teame/backend/domain/user/dto/response/MyExperienceRes.java new file mode 100644 index 0000000..ec826ec --- /dev/null +++ b/src/main/java/com/meetup/teame/backend/domain/user/dto/response/MyExperienceRes.java @@ -0,0 +1,28 @@ +package com.meetup.teame.backend.domain.user.dto.response; + +import com.meetup.teame.backend.domain.experience.entity.Experience; +import lombok.*; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder +@Getter +public class MyExperienceRes { + + private Long id; + + private String title; + + private String ExperienceType; + + private String description; + + public static MyExperienceRes of(Experience experience) { + return MyExperienceRes.builder() + .id(experience.getId()) + .title(experience.getDescription()) + .ExperienceType(experience.getType().getDescription()) + .description(experience.getDetail()) + .build(); + } +} diff --git a/src/main/java/com/meetup/teame/backend/domain/user/dto/response/ReadExperienceProfileRes.java b/src/main/java/com/meetup/teame/backend/domain/user/dto/response/ReadExperienceProfileRes.java index de61eed..ef58692 100644 --- a/src/main/java/com/meetup/teame/backend/domain/user/dto/response/ReadExperienceProfileRes.java +++ b/src/main/java/com/meetup/teame/backend/domain/user/dto/response/ReadExperienceProfileRes.java @@ -1,7 +1,11 @@ package com.meetup.teame.backend.domain.user.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; + @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PRIVATE) @Builder @@ -22,5 +26,18 @@ public class ReadExperienceProfileRes { private String introduce; - + private List experiences; + + public static ReadExperienceProfileRes of(User user, List experienceRes) { + return ReadExperienceProfileRes.builder() + .id(user.getId()) + .name(user.getName()) + .age(user.getAge()) + .gender(user.getGender().getDescription()) + .location(user.getLocation()) + .area(user.getLocation()) + .introduce(user.getOneWord()) + .experiences(experienceRes) + .build(); + } } diff --git a/src/main/java/com/meetup/teame/backend/domain/user/entity/User.java b/src/main/java/com/meetup/teame/backend/domain/user/entity/User.java index a316109..cce603d 100644 --- a/src/main/java/com/meetup/teame/backend/domain/user/entity/User.java +++ b/src/main/java/com/meetup/teame/backend/domain/user/entity/User.java @@ -51,6 +51,9 @@ public class User { @Comment("사용자 포인트") private Long point; + @Comment("한마디") + private String oneWord; + @OneToMany(mappedBy = "user", cascade = CascadeType.ALL) private List experiences; @@ -78,6 +81,10 @@ public void setPersonalities(List personalities) { this.personalities = personalities; } + public void setOneWord(String oneWord) { + this.oneWord = oneWord; + } + public void update(UpdateUserReq request) { this.name = request.getName(); this.email = request.getEmail(); diff --git a/src/main/java/com/meetup/teame/backend/domain/user/service/UserService.java b/src/main/java/com/meetup/teame/backend/domain/user/service/UserService.java index 24504c8..76cc4f0 100644 --- a/src/main/java/com/meetup/teame/backend/domain/user/service/UserService.java +++ b/src/main/java/com/meetup/teame/backend/domain/user/service/UserService.java @@ -1,25 +1,26 @@ package com.meetup.teame.backend.domain.user.service; import com.meetup.teame.backend.domain.activity.dto.response.ActivitySummaryRes; +import com.meetup.teame.backend.domain.activity.entity.Activity; import com.meetup.teame.backend.domain.activity.repository.ActivityRepository; import com.meetup.teame.backend.domain.auth.jwt.SecurityContextProvider; import com.meetup.teame.backend.domain.auth.oauth.dto.CreateUserRequest; import com.meetup.teame.backend.domain.chatroom.repository.DirectChatRoomRepository; import com.meetup.teame.backend.domain.chatroom.repository.GroupChatRoomRepository; import com.meetup.teame.backend.domain.chatroom.entity.GroupChatRoom; +import com.meetup.teame.backend.domain.experience.entity.Experience; +import com.meetup.teame.backend.domain.experience.entity.ExperienceType; import com.meetup.teame.backend.domain.experience.repository.ExperienceRepository; import com.meetup.teame.backend.domain.like.repository.ActivityLikeRepository; import com.meetup.teame.backend.domain.personality.Personality; import com.meetup.teame.backend.domain.review.dto.response.MyReviewRes; import com.meetup.teame.backend.domain.review.entity.Review; import com.meetup.teame.backend.domain.review.repository.ReviewRepository; +import com.meetup.teame.backend.domain.user.dto.request.MyExperienceReq; import com.meetup.teame.backend.domain.user.dto.request.OnboardingReq; import com.meetup.teame.backend.domain.user.dto.request.ReadCalenderReq; import com.meetup.teame.backend.domain.user.dto.request.UpdateUserReq; -import com.meetup.teame.backend.domain.user.dto.response.ReadCalenderRes; -import com.meetup.teame.backend.domain.user.dto.response.ReadExperienceProfileRes; -import com.meetup.teame.backend.domain.user.dto.response.ReadMainRes; -import com.meetup.teame.backend.domain.user.dto.response.UserInfoRes; +import com.meetup.teame.backend.domain.user.dto.response.*; import com.meetup.teame.backend.domain.user.entity.Gender; import com.meetup.teame.backend.domain.user.entity.User; import com.meetup.teame.backend.domain.user.repository.UserRepository; @@ -148,10 +149,27 @@ public ReadCalenderRes readCalender(ReadCalenderReq readCalenderReq) { ); } - /*public ReadExperienceProfileRes createExperienceProfile() { + @Transactional + public String createExperienceProfile(MyExperienceReq req) { Long userId = SecurityContextProvider.getAuthenticatedUserId(); User user = userRepository.findById(userId) .orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_USER)); - }*/ + user.setOneWord(req.getIntroduce()); + Experience experience = Experience.of(req, user); + experienceRepository.save(experience); + return "배움 프로필 생성 성공"; + } + + public ReadExperienceProfileRes getExperienceProfile() { + Long userId = SecurityContextProvider.getAuthenticatedUserId(); + User user = userRepository.findById(userId) + .orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_USER)); + + List experiences = experienceRepository.findAllByUser(user); + List myExperienceRes = experiences.stream() + .map(MyExperienceRes::of) + .toList(); + return ReadExperienceProfileRes.of(user, myExperienceRes); + } } From 6b1661b94a9d553061041edfdaad73a3f65092a5 Mon Sep 17 00:00:00 2001 From: Jeongho Date: Sat, 18 May 2024 20:45:26 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Docs:=20=EB=B0=B0=EC=9B=80=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=20swagger=20=EC=84=A4=EB=AA=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/user/controller/UserController.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/meetup/teame/backend/domain/user/controller/UserController.java b/src/main/java/com/meetup/teame/backend/domain/user/controller/UserController.java index 6569eb5..067394f 100644 --- a/src/main/java/com/meetup/teame/backend/domain/user/controller/UserController.java +++ b/src/main/java/com/meetup/teame/backend/domain/user/controller/UserController.java @@ -125,12 +125,22 @@ public ResponseEntity> getMyActivities() { return ResponseEntity.ok().body(myActivities); } + @Operation(summary = "배움 프로필 생성", description = """ + 배움 프로필 생성 api입니다. + + 배움 제목(title), 배움 유형(experienceType), detail, 나의 한마디(introduce)를 입력헤주세요. + """) @PostMapping("/experience-profile") public ResponseEntity createExperienceProfile(@RequestBody MyExperienceReq request) { String response = userService.createExperienceProfile(request); return ResponseEntity.ok().body(response); } + + @Operation(summary = "배움 프로필 조회", description = """ + 배움 프로필 조회 api입니다. + + """) @GetMapping("/experience-profile") public ResponseEntity getExperienceProfile() { ReadExperienceProfileRes response = userService.getExperienceProfile();