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..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 @@ -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,25 @@ public ResponseEntity> getMyActivities() { return ResponseEntity.ok().body(myActivities); } - /* @PostMapping("/experience-profile") - public ResponseEntity createExperienceProfile() { - ReadExperienceProfileRes profile = userService.createExperienceProfile(); - return ResponseEntity.ok().body(profile); - }*/ + @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(); + 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 e205d40..2562a8c 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 @@ -81,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 3ba3e7a..d2da83a 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; @@ -150,10 +151,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); + } }