Skip to content

Commit

Permalink
Merge branch 'main' into feat/board
Browse files Browse the repository at this point in the history
  • Loading branch information
xhaktmchl committed Oct 19, 2022
2 parents c293306 + d8b4104 commit 1f42549
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.yogit.server.user.controller;

import com.yogit.server.global.dto.ApplicationResponse;
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.EditUserEssentialProfileReq;
import com.yogit.server.user.dto.response.UserAdditionalProfileRes;
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.LanguageLevel;
import com.yogit.server.user.entity.LanguageName;
import com.yogit.server.user.entity.Nationality;
import com.yogit.server.user.entity.*;
import com.yogit.server.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
Expand Down Expand Up @@ -87,4 +86,15 @@ public ApplicationResponse<Void> delProfile(@PathVariable Long userId){
public ApplicationResponse<UserImagesRes> enterUserImage(@ModelAttribute CreateUserImageReq createUserImageReq){
return userService.enterUserImage(createUserImageReq);
}

/**
* 유저 추가 정보 입력
* @author 강신현
*/
@ApiOperation(value = "유저 추가 정보 입력")
@ApiImplicitParam(name = "userId", required = true, dataTypeClass = Long.class, example = "0")
@PatchMapping("/additional-profile")
public ApplicationResponse<UserAdditionalProfileRes> enterAdditionalProfile(@ModelAttribute AddUserAdditionalProfileReq addUserAdditionalProfileReq){
return userService.enterAdditionalProfile(addUserAdditionalProfileReq);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
package com.yogit.server.user.dto.request;

//@NoArgsConstructor
//@AllArgsConstructor
//@Data
//public class AddUserAdditionalProfileReq {
//
//}
import com.yogit.server.user.entity.CityName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@NoArgsConstructor
@AllArgsConstructor
@Data
public class AddUserAdditionalProfileReq {

Long userId;

float latitude;
float longitude;
String aboutMe;

CityName city;
List<String> interests;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.yogit.server.user.dto.response;

import com.yogit.server.user.entity.CityName;
import com.yogit.server.user.entity.User;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

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

@NoArgsConstructor
@AllArgsConstructor
@Data
public class UserAdditionalProfileRes {
Long userId;

float latitude;
float longitude;
String aboutMe;

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

public static UserAdditionalProfileRes create(User user){
UserAdditionalProfileRes userAdditionalProfileRes = new UserAdditionalProfileRes();

userAdditionalProfileRes.userId = user.getId();
userAdditionalProfileRes.latitude = user.getLatitude();
userAdditionalProfileRes.longitude = user.getLongtitude();
userAdditionalProfileRes.aboutMe = user.getAboutMe();

return userAdditionalProfileRes;
}

}
11 changes: 10 additions & 1 deletion server/src/main/java/com/yogit/server/user/entity/City.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.yogit.server.board.entity.Board;
import com.yogit.server.config.domain.BaseEntity;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -26,5 +27,13 @@ public class City extends BaseEntity {
@OneToMany(mappedBy = "city")
private List<Board> boards = new ArrayList<>();

private String name;
@Enumerated(EnumType.STRING)
private CityName name;

@Builder
public City(User user, CityName name){
this.name = name;
this.users.add(user);
user.addCity(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.yogit.server.user.entity;

public enum CityName {
SEOUL,
BUSAN,
JEJU
}
12 changes: 10 additions & 2 deletions server/src/main/java/com/yogit/server/user/entity/Interest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.yogit.server.config.domain.BaseEntity;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -21,7 +22,14 @@ public class Interest extends BaseEntity {
@OneToMany(mappedBy = "interest")
private List<UserInterest> userInterests = new ArrayList<>();

// TODO : user interest 항목별로 (personality, lifestyle 등) 정해지면 엔티티에 항목 이름도 구분해서 넣기
// @Enumerated(EnumType.STRING)
private String name;

public void addUserInterest(UserInterest userInterest){
this.userInterests.add(userInterest);
}

@Builder
public Interest(String name){
this.name = name;
}
}
14 changes: 14 additions & 0 deletions server/src/main/java/com/yogit/server/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,18 @@ public void addImage(UserImage userImage) {
public void changeMainImgUUid(String mainImgUUid){
this.profileImg = mainImgUUid;
}

public void addUserInterest(UserInterest userInterest){
this.userInterests.add(userInterest);
}

public void addAdditionalProfile(float latitude, float longitude, String aboutMe){
this.latitude = latitude;
this.longtitude = longitude;
this.aboutMe = aboutMe;
}

public void addCity(City city){
this.city = city;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.yogit.server.config.domain.BaseEntity;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -23,4 +24,13 @@ public class UserInterest extends BaseEntity {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "interest_id")
private Interest interest;

@Builder
public UserInterest(User user, Interest interest){
this.user = user;
user.addUserInterest(this);

this.interest = interest;
interest.addUserInterest(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.yogit.server.user.repository;

import com.yogit.server.user.entity.Interest;
import org.springframework.data.jpa.repository.JpaRepository;

public interface InterestRepository extends JpaRepository<Interest, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.yogit.server.user.repository;

import com.yogit.server.user.entity.UserInterest;
import org.springframework.data.jpa.repository.JpaRepository;

public interface UserInterestRepository extends JpaRepository<UserInterest, Long> {
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.yogit.server.user.service;

import com.yogit.server.global.dto.ApplicationResponse;
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.EditUserEssentialProfileReq;
import com.yogit.server.user.dto.response.UserAdditionalProfileRes;
import com.yogit.server.user.dto.response.UserImagesRes;
import com.yogit.server.user.dto.response.UserProfileRes;

Expand All @@ -17,4 +19,6 @@ public interface UserService {
ApplicationResponse<Void> delProfile(Long userId);

ApplicationResponse<UserImagesRes> enterUserImage(CreateUserImageReq createUserImageReq);

ApplicationResponse<UserAdditionalProfileRes> enterAdditionalProfile(AddUserAdditionalProfileReq addUserAdditionalProfileReq);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

import com.yogit.server.global.dto.ApplicationResponse;
import com.yogit.server.s3.AwsS3Service;
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.EditUserEssentialProfileReq;
import com.yogit.server.user.dto.response.UserAdditionalProfileRes;
import com.yogit.server.user.dto.response.UserImagesRes;
import com.yogit.server.user.dto.response.UserProfileRes;
import com.yogit.server.user.entity.Language;
import com.yogit.server.user.entity.User;
import com.yogit.server.user.entity.UserImage;
import com.yogit.server.user.entity.*;
import com.yogit.server.user.exception.NotFoundUserException;
import com.yogit.server.user.repository.LanguageRepository;
import com.yogit.server.user.repository.UserImageRepository;
import com.yogit.server.user.repository.UserRepository;
import com.yogit.server.user.repository.*;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -28,6 +26,9 @@ public class UserServiceImpl implements UserService {
private final UserRepository userRepository;
private final LanguageRepository languageRepository;
private final UserImageRepository userImageRepository;
private final CityRepository cityRepository;
private final InterestRepository interestRepository;
private final UserInterestRepository userInterestRepository;
private final AwsS3Service awsS3Service;

@Transactional
Expand Down Expand Up @@ -212,4 +213,44 @@ public ApplicationResponse<UserImagesRes> enterUserImage(CreateUserImageReq crea

return ApplicationResponse.ok(userImagesRes);
}

@Override
@Transactional
public ApplicationResponse<UserAdditionalProfileRes> enterAdditionalProfile(AddUserAdditionalProfileReq addUserAdditionalProfileReq){
User user = userRepository.findById(addUserAdditionalProfileReq.getUserId()).orElseThrow(NotFoundUserException::new);

user.addAdditionalProfile(addUserAdditionalProfileReq.getLatitude(), addUserAdditionalProfileReq.getLongitude(), addUserAdditionalProfileReq.getAboutMe());

UserAdditionalProfileRes userAdditionalProfileRes = UserAdditionalProfileRes.create(user);

if(addUserAdditionalProfileReq.getCity() != null){
City city = City.builder()
.user(user)
.name(addUserAdditionalProfileReq.getCity())
.build();
cityRepository.save(city);

userAdditionalProfileRes.setCity(city.getName());
}

for(String interestName : addUserAdditionalProfileReq.getInterests()){
Interest interest = Interest.builder()
.name(interestName)
.build();
interestRepository.save(interest);

UserInterest userInterest = UserInterest.builder()
.user(user)
.interest(interest)
.build();
userInterestRepository.save(userInterest);

userAdditionalProfileRes.getInterests().add(interestName);
}




return ApplicationResponse.ok(userAdditionalProfileRes);
}
}

0 comments on commit 1f42549

Please sign in to comment.