Skip to content

Commit

Permalink
Merge pull request #51 from Kusitms-29th-Meetup-TeamE/feat/42/review
Browse files Browse the repository at this point in the history
Feat: 나의 배움 프로필 api
  • Loading branch information
nohy6630 authored May 18, 2024
2 parents 4803518 + 6b1661b commit ec3f44d
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down Expand Up @@ -45,10 +46,11 @@ public class Experience {
@OneToMany(mappedBy = "experience", cascade = CascadeType.ALL)
private List<DirectChatRoom> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Experience, Long>, ExperienceRepositoryCustom {
List<Experience> findAllByUser(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -127,9 +125,25 @@ public ResponseEntity<List<ActivitySummaryRes>> getMyActivities() {
return ResponseEntity.ok().body(myActivities);
}

/* @PostMapping("/experience-profile")
public ResponseEntity<ReadExperienceProfileRes> createExperienceProfile() {
ReadExperienceProfileRes profile = userService.createExperienceProfile();
return ResponseEntity.ok().body(profile);
}*/
@Operation(summary = "배움 프로필 생성", description = """
배움 프로필 생성 api입니다.
배움 제목(title), 배움 유형(experienceType), detail, 나의 한마디(introduce)를 입력헤주세요.
""")
@PostMapping("/experience-profile")
public ResponseEntity<String> createExperienceProfile(@RequestBody MyExperienceReq request) {
String response = userService.createExperienceProfile(request);
return ResponseEntity.ok().body(response);
}


@Operation(summary = "배움 프로필 조회", description = """
배움 프로필 조회 api입니다.
""")
@GetMapping("/experience-profile")
public ResponseEntity<ReadExperienceProfileRes> getExperienceProfile() {
ReadExperienceProfileRes response = userService.getExperienceProfile();
return ResponseEntity.ok().body(response);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,5 +26,18 @@ public class ReadExperienceProfileRes {

private String introduce;


private List<MyExperienceRes> experiences;

public static ReadExperienceProfileRes of(User user, List<MyExperienceRes> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public class User {
@Comment("사용자 포인트")
private Long point;

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

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
private List<Experience> experiences;

Expand Down Expand Up @@ -78,6 +81,10 @@ public void setPersonalities(List<Personality> 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Experience> experiences = experienceRepository.findAllByUser(user);
List<MyExperienceRes> myExperienceRes = experiences.stream()
.map(MyExperienceRes::of)
.toList();
return ReadExperienceProfileRes.of(user, myExperienceRes);
}
}

0 comments on commit ec3f44d

Please sign in to comment.