Skip to content

Commit

Permalink
Merge pull request #13 from PLADI-ALM/feat/PDS-169-feign-user
Browse files Browse the repository at this point in the history
[PDS-170/feat] 유저 정보 변경, 삭제 API 기능구현
  • Loading branch information
chaerlo127 authored Nov 6, 2023
2 parents 010885d + 072a248 commit 2485d72
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public ResponseCustom<?> addUser(@RequestBody UserReq userReq){
return ResponseCustom.OK();
}

@PatchMapping("")
@PostMapping("change")
public ResponseCustom<?> changeUserProfile(@RequestBody UserReq userReq){
this.userService.changeUserProfile(userReq);
return ResponseCustom.OK();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.PLADIALMArchiving.user.dto.request;

import com.example.PLADIALMArchiving.user.entity.Role;
import lombok.Data;
import lombok.NoArgsConstructor;

Expand All @@ -8,5 +9,5 @@
public class UserReq {
private Long userId;
private String name;
private String role;
private Role role;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

@NoArgsConstructor(access= AccessLevel.PROTECTED)
@Getter
@Entity
@SQLDelete(sql = "UPDATE user SET is_enable = false, update_at = current_timestamp WHERE user_id = ?")
public class User extends BaseEntity {
@Id
@Column(nullable = false)
Expand All @@ -30,15 +32,16 @@ public User(Long userId, String name, Role role){
this.role = role;
}

public void modifyProfile(String name) {
public void changeProfile(String name, Role role) {
this.name = name;
this.role = role;
}

public static User toEntity(UserReq userReq) {
return User.builder()
.userId(userReq.getUserId())
.name(userReq.getName())
.role(Role.getRoleByName(userReq.getRole()))
.role(userReq.getRole())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import com.example.PLADIALMArchiving.user.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

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


@Repository
public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByUserIdAndIsEnable(Long userId, Boolean isEnable);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.example.PLADIALMArchiving.user.service;

import com.example.PLADIALMArchiving.global.exception.BaseException;
import com.example.PLADIALMArchiving.global.exception.BaseResponseCode;
import com.example.PLADIALMArchiving.user.dto.request.UserReq;
import com.example.PLADIALMArchiving.user.entity.Role;
import com.example.PLADIALMArchiving.user.entity.User;
import com.example.PLADIALMArchiving.user.repository.UserRepository;
import lombok.RequiredArgsConstructor;
Expand All @@ -18,34 +21,13 @@ public void addUser(UserReq userReq) {

@Override
public void changeUserProfile(UserReq userReq) {

User user = this.userRepository.findByUserIdAndIsEnable(userReq.getUserId(), true).orElseThrow(() -> new BaseException(BaseResponseCode.USER_NOT_FOUND));
user.changeProfile(user.getName(), userReq.getRole());
}

@Override
public void deleteUser(UserReq userReq) {

User user = this.userRepository.findByUserIdAndIsEnable(userReq.getUserId(), true).orElseThrow(() -> new BaseException(BaseResponseCode.USER_NOT_FOUND));
userRepository.delete(user);
}

// private final UserAssembler userAssembler;

// @Transactional
// @Override
// public void addUser(UserReq userReq) {
// this.userRepository.save(this.userAssembler.toEntity(userReq));
// }
//
// @Transactional
// @Override
// public void changeUserProfile(UserReq userReq) {
// User user = this.userRepository.findByUserIdxAndIsEnable(userReq.getUserIdx(), true).orElseThrow(UserNotFoundException::new);
// user.modifyProfile(userReq.getNickname(), userReq.getProfileImgKey());
// }
//
//
// @Transactional
// @Override
// public void deleteUser(UserReq userReq) {
// User user = this.userRepository.findByUserIdxAndIsEnable(userReq.getUserIdx(), true).orElseThrow(UserNotFoundException::new);
// this.userRepository.deleteById(userReq.getUserIdx());
// }
}

0 comments on commit 2485d72

Please sign in to comment.