Skip to content

Commit

Permalink
Refactor. TokenUserInfo -> UserEntity 변환 정
Browse files Browse the repository at this point in the history
  • Loading branch information
Miensoap committed Jun 24, 2024
1 parent 88dff33 commit f5dfa04
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer m
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null && authentication.isAuthenticated()) {

return UserEntity.ofToken((TokenUserInfo) authentication.getPrincipal());
return ((TokenUserInfo) authentication.getPrincipal()).toUserEntity();
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@ public static TokenUserInfo of(UserEntity userEntity) {
public String stringRole() {
return this.role.getKey();
}

public UserEntity toUserEntity() {
return new UserEntity(
this.id,
this.name,
this.profileImg,
this.role
);
}
}
23 changes: 6 additions & 17 deletions BE/src/main/java/team07/airbnb/entity/UserEntity.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
package team07.airbnb.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import team07.airbnb.data.user.dto.response.TokenUserInfo;
import team07.airbnb.data.user.enums.Role;

import java.util.ArrayList;
Expand Down Expand Up @@ -79,13 +70,11 @@ public void setRoleToUser() {
this.role = Role.USER;
}

public static UserEntity ofToken(TokenUserInfo tokenUserInfo) {
return UserEntity.builder()
.id(tokenUserInfo.id())
.name(tokenUserInfo.name())
.picture(tokenUserInfo.profileImg())
.role(tokenUserInfo.role())
.build();
public UserEntity(Long id, String name, String picture, Role role) {
this.id = id;
this.name = name;
this.picture = picture;
this.role = role;
}

@Override
Expand Down

0 comments on commit f5dfa04

Please sign in to comment.