Skip to content

Commit

Permalink
#8 feat: 유저 프로필 조회 API - 유저 필수 및 추가 정보 통합 조회 & 추후 City, administrativ…
Browse files Browse the repository at this point in the history
…eArea 추가 필요
  • Loading branch information
shinhn committed Oct 28, 2022
1 parent f35d2f5 commit e2a409e
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.yogit.server.user.controller;

import com.yogit.server.global.dto.ApplicationResponse;
import com.yogit.server.user.dto.request.*;
import com.yogit.server.user.dto.request.AddUserAdditionalProfileReq;
import com.yogit.server.user.dto.request.CreateUserEssentialProfileReq;
import com.yogit.server.user.dto.request.CreateUserImageReq;
import com.yogit.server.user.dto.request.CreateUserReq;
import com.yogit.server.user.dto.response.UserAdditionalProfileRes;
import com.yogit.server.user.dto.response.UserEssentialProfileRes;
import com.yogit.server.user.dto.response.UserImagesRes;
import com.yogit.server.user.dto.response.UserProfileRes;
import com.yogit.server.user.entity.Gender;
import com.yogit.server.user.entity.Nationality;
import com.yogit.server.user.service.UserService;
Expand Down Expand Up @@ -44,12 +48,12 @@ public ApplicationResponse<UserEssentialProfileRes> enterEssentialProfile(@Model
* 유저 Profile 조회
* @author 강신현
*/
// @ApiOperation(value = "유저 Profile 조회")
// @ApiImplicitParam(name = "userId", required = true, dataTypeClass = Long.class, example = "0")
// @GetMapping("/prifile/{userId}")
// public ApplicationResponse<UserProfileRes> getProfile(@PathVariable Long userId){
// return userService.getProfile(userId);
// }
@ApiOperation(value = "유저 Profile 조회")
@ApiImplicitParam(name = "userId", required = true, dataTypeClass = Long.class, example = "0")
@GetMapping("/prifile/{userId}")
public ApplicationResponse<UserProfileRes> getProfile(@PathVariable Long userId){
return userService.getProfile(userId);
}

/**
* 유저 Profile 삭제
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,78 @@
package com.yogit.server.user.dto.response;

import com.yogit.server.user.entity.Gender;
import com.yogit.server.user.entity.Nationality;
import com.yogit.server.user.entity.User;
import com.yogit.server.user.entity.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@NoArgsConstructor
@AllArgsConstructor
@Data
public class UserProfileRes {
String about_me;
String about_me_interest;
String about_me_job;

int age;
Long userId;

// 유저 필수 정보
Integer age;
String name;
Gender gender; // Prefer not to say, male, female 중 하나
float member_temp;
Gender gender;
float memberTemp;
Nationality nationality;
String profile_img; // 대표 프로필 이미지
String profileImg; // 대표 프로필 이미지
String aboutMe;
String login_id;
UserStatus userStatus;
String phone;

List<String> languageNames = new ArrayList<>();
List<String> languageLevels = new ArrayList<>();

// String login_id; //TODO
// String pass_word; //TODO
// 유저 추가 정보
String administrativeArea;
float longtitude;
float latitude;

CityName city;

List<String> interests = new ArrayList<>();

public static UserProfileRes create(User user){
UserProfileRes userProfileRes = new UserProfileRes();

userProfileRes.about_me = user.getAboutMe();
userProfileRes.userId = user.getId();

// 유저 필수 정보
userProfileRes.age = user.getAge();
userProfileRes.name = user.getName();
userProfileRes.gender = user.getGender();
userProfileRes.member_temp = user.getMemberTemp();
userProfileRes.nationality = user.getNationality();
userProfileRes.profile_img = user.getProfileImg();
userProfileRes.profileImg = user.getProfileImg();
userProfileRes.aboutMe = user.getAboutMe();
userProfileRes.login_id = user.getLoginId();
userProfileRes.userStatus = user.getUserStatus();
userProfileRes.phone = user.getPhone();

// 유저 추가 정보
userProfileRes.administrativeArea = user.getAdministrativeArea();
userProfileRes.longtitude = user.getLongtitude();
userProfileRes.latitude = user.getLatitude();

return userProfileRes;
}

public void addCity(CityName city){
this.city = city;
}

public void addLanguage(String languageName, String languageLevel){
this.languageNames.add(languageName);
this.languageLevels.add(languageLevel);
}

public void addInterest(String interest){
this.interests.add(interest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
import com.yogit.server.user.entity.UserInterest;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface UserInterestRepository extends JpaRepository<UserInterest, Long> {
Optional<UserInterest> findByUserId(Long userId);
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.yogit.server.user.service;

import com.yogit.server.global.dto.ApplicationResponse;
import com.yogit.server.user.dto.request.*;
import com.yogit.server.user.dto.request.AddUserAdditionalProfileReq;
import com.yogit.server.user.dto.request.CreateUserEssentialProfileReq;
import com.yogit.server.user.dto.request.CreateUserImageReq;
import com.yogit.server.user.dto.request.CreateUserReq;
import com.yogit.server.user.dto.response.UserAdditionalProfileRes;
import com.yogit.server.user.dto.response.UserEssentialProfileRes;
import com.yogit.server.user.dto.response.UserImagesRes;
import com.yogit.server.user.dto.response.UserProfileRes;

public interface UserService {
ApplicationResponse<UserEssentialProfileRes> enterEssentialProfile(CreateUserEssentialProfileReq createUserEssentialProfileReq);

//ApplicationResponse<UserProfileRes> getProfile(Long userId);
ApplicationResponse<UserProfileRes> getProfile(Long userId);

ApplicationResponse<Void> delProfile(Long userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import com.yogit.server.global.dto.ApplicationResponse;
import com.yogit.server.s3.AwsS3Service;
import com.yogit.server.user.dto.request.*;
import com.yogit.server.user.dto.request.AddUserAdditionalProfileReq;
import com.yogit.server.user.dto.request.CreateUserEssentialProfileReq;
import com.yogit.server.user.dto.request.CreateUserImageReq;
import com.yogit.server.user.dto.request.CreateUserReq;
import com.yogit.server.user.dto.response.UserAdditionalProfileRes;
import com.yogit.server.user.dto.response.UserEssentialProfileRes;
import com.yogit.server.user.dto.response.UserImagesRes;
import com.yogit.server.user.dto.response.UserProfileRes;
import com.yogit.server.user.entity.*;
import com.yogit.server.user.exception.NotFoundUserException;
import com.yogit.server.user.exception.UserDuplicationLoginId;
Expand All @@ -15,6 +19,7 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -58,21 +63,28 @@ public ApplicationResponse<UserEssentialProfileRes> enterEssentialProfile(Create
}


// @Override
// public ApplicationResponse<UserProfileRes> getProfile(Long userId){
// User user = userRepository.findById(userId).orElseThrow(NotFoundUserException::new);
//
// UserProfileRes userProfileRes = UserProfileRes.create(user);
//
// List<Language> languages = languageRepository.findAllByUserId(userId);
// if(!languages.isEmpty()){
// for(Language l : languages){
// userProfileRes.addLanguage(l);
// }
// }
//
// return ApplicationResponse.ok(userProfileRes);
// }
@Override
public ApplicationResponse<UserProfileRes> getProfile(Long userId){
User user = userRepository.findById(userId).orElseThrow(NotFoundUserException::new);

UserProfileRes userProfileRes = UserProfileRes.create(user);

// if(user.getCity()) userProfileRes.addCity(user.getCity().getName()); // TODO administrativeArea 와의 차이 문의중 (활동 지역 필요하면, 지금 city 연관관계로 진행)

List<Language> languages = languageRepository.findAllByUserId(userId);
if(!languages.isEmpty()){
for(Language l : languages){
userProfileRes.addLanguage(l.getName(), l.getLevel());
}
}

Optional<UserInterest> userInterest = userInterestRepository.findByUserId(userId);
if(userInterest.isPresent()){
userProfileRes.addInterest(userInterest.get().getInterest().getName());
}

return ApplicationResponse.ok(userProfileRes);
}

@Override
@Transactional
Expand Down

0 comments on commit e2a409e

Please sign in to comment.