Skip to content

Commit

Permalink
Merge pull request #31 from Ajou-Hertz/feature/#30-user-profile-image…
Browse files Browse the repository at this point in the history
…-entity

유저 프로필 이미지 추가
  • Loading branch information
tinon1004 authored Feb 18, 2024
2 parents 4504344 + 47081b9 commit c794a65
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.ajou.hertz.common.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties("hertz")
public record HertzProperties(String userDefaultProfileImageUrl) {
}
2 changes: 2 additions & 0 deletions src/main/java/com/ajou/hertz/domain/user/dto/UserDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class UserDto {
private String email;
private String password;
private String kakaoUid;
private String profileImageUrl;
private LocalDate birth;
private Gender gender;
private String phone;
Expand All @@ -32,6 +33,7 @@ public static UserDto from(User user) {
user.getEmail(),
user.getPassword(),
user.getKakaoUid(),
user.getProfileImageUrl(),
user.getBirth(),
user.getGender(),
user.getPhone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class UserResponse {

private Long id;
private String email;
private String profileImageUrl;
private LocalDate birth;
private Gender gender;
private String contactLink;
Expand All @@ -25,6 +26,7 @@ public static UserResponse from(UserDto userDto) {
return new UserResponse(
userDto.getId(),
userDto.getEmail(),
userDto.getProfileImageUrl(),
userDto.getBirth(),
userDto.getGender(),
userDto.getContactLink()
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/com/ajou/hertz/domain/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public class User extends TimeTrackedBaseEntity {
@Column(unique = true)
private String kakaoUid;

@Column(nullable = false)
private String profileImageUrl;

private LocalDate birth;

@Column(nullable = false)
Expand All @@ -72,10 +75,14 @@ public class User extends TimeTrackedBaseEntity {
public static User create(
@NonNull String email,
@NonNull String password,
@NonNull String profileImageUrl,
LocalDate birth,
@NonNull Gender gender,
String phone
) {
return new User(null, Set.of(RoleType.USER), email, password, null, birth, gender, phone, null);
return new User(
null, Set.of(RoleType.USER), email, password, null,
profileImageUrl, birth, gender, phone, null
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.ajou.hertz.domain.user.entity;

import com.ajou.hertz.common.entity.FileEntity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Entity
public class UserProfileImage extends FileEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "user_profile_image_id", nullable = false)
private Long id;

@JoinColumn(name = "user_id", nullable = false)
@OneToOne(fetch = FetchType.LAZY)
private User user;

private UserProfileImage(Long id, User user, String originalName, String storedName, String url) {
super(originalName, storedName, url);
this.id = id;
this.user = user;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ajou.hertz.common.properties.HertzProperties;
import com.ajou.hertz.domain.user.dto.UserDto;
import com.ajou.hertz.domain.user.dto.request.SignUpRequest;
import com.ajou.hertz.domain.user.entity.User;
Expand All @@ -20,6 +21,7 @@ public class UserCommandService {
private final UserQueryService userQueryService;
private final UserRepository userRepository;
private final PasswordEncoder passwordEncoder;
private final HertzProperties hertzProperties;

/**
* 새로운 회원을 등록한다.
Expand All @@ -38,6 +40,7 @@ public UserDto createNewUser(SignUpRequest signUpRequest) {
User.create(
email,
passwordEncoder.encode(signUpRequest.getPassword()),
hertzProperties.userDefaultProfileImageUrl(),
signUpRequest.getBirth(),
signUpRequest.getGender(),
signUpRequest.getPhone()
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
hertz.app-version=0.0.1
hertz.user-default-profile-image-url=${USER_DEFAULT_PROFILE_IMAGE}

jwt.secret-key=${JWT_SECRET_KEY}

Expand Down
3 changes: 2 additions & 1 deletion src/test/java/com/ajou/hertz/config/TestSecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void securitySetUp() throws Exception {
private UserDto createUserDto() throws Exception {
Constructor<UserDto> userResponseConstructor = UserDto.class.getDeclaredConstructor(
Long.class, Set.class, String.class, String.class, String.class,
LocalDate.class, Gender.class, String.class, String.class
String.class, LocalDate.class, Gender.class, String.class, String.class
);
userResponseConstructor.setAccessible(true);
return userResponseConstructor.newInstance(
Expand All @@ -55,6 +55,7 @@ private UserDto createUserDto() throws Exception {
"[email protected]",
"$2a$abc123",
"kakao-user-id",
"https://user-default-profile-image",
LocalDate.of(2024, 1, 1),
Gender.ETC,
"01012345678",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private JwtTokenInfoDto createJwtTokenInfoDto() {
private UserDto createUserDto(long id) throws Exception {
Constructor<UserDto> userResponseConstructor = UserDto.class.getDeclaredConstructor(
Long.class, Set.class, String.class, String.class, String.class,
LocalDate.class, Gender.class, String.class, String.class
String.class, LocalDate.class, Gender.class, String.class, String.class
);
userResponseConstructor.setAccessible(true);
return userResponseConstructor.newInstance(
Expand All @@ -118,6 +118,7 @@ private UserDto createUserDto(long id) throws Exception {
"[email protected]",
"$2a$abc123",
"kakao-user-id",
"https://user-default-profile-image",
LocalDate.of(2024, 1, 1),
Gender.ETC,
"01012345678",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private SignUpRequest createSignUpRequest() throws Exception {
private UserDto createUserDto(long id) throws Exception {
Constructor<UserDto> userResponseConstructor = UserDto.class.getDeclaredConstructor(
Long.class, Set.class, String.class, String.class, String.class,
LocalDate.class, Gender.class, String.class, String.class
String.class, LocalDate.class, Gender.class, String.class, String.class
);
userResponseConstructor.setAccessible(true);
return userResponseConstructor.newInstance(
Expand All @@ -194,6 +194,7 @@ private UserDto createUserDto(long id) throws Exception {
"[email protected]",
"$2a$abc123",
"kakao-user-id",
"https://user-default-profile-image",
LocalDate.of(2024, 1, 1),
Gender.ETC,
"01012345678",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.test.context.event.annotation.BeforeTestMethod;

import com.ajou.hertz.common.properties.HertzProperties;
import com.ajou.hertz.domain.user.constant.Gender;
import com.ajou.hertz.domain.user.constant.RoleType;
import com.ajou.hertz.domain.user.dto.UserDto;
Expand All @@ -41,6 +43,14 @@ class UserCommandServiceTest {
@Mock
private PasswordEncoder passwordEncoder;

@Mock
private HertzProperties hertzProperties;

@BeforeTestMethod
public void setUp() {
given(hertzProperties.userDefaultProfileImageUrl()).willReturn("https://user-default-profile-image");
}

@Test
void 주어진_회원_정보로_신규_회원을_등록한다() throws Exception {
// given
Expand Down Expand Up @@ -88,7 +98,7 @@ private void verifyEveryMocksShouldHaveNoMoreInteractions() {
private User createUser(Long id, String password) throws Exception {
Constructor<User> userConstructor = User.class.getDeclaredConstructor(
Long.class, Set.class, String.class, String.class, String.class,
LocalDate.class, Gender.class, String.class, String.class
String.class, LocalDate.class, Gender.class, String.class, String.class
);
userConstructor.setAccessible(true);
return userConstructor.newInstance(
Expand All @@ -97,6 +107,7 @@ private User createUser(Long id, String password) throws Exception {
"[email protected]",
password,
"kakao-user-id",
"https://user-default-profile-image-url",
LocalDate.of(2024, 1, 1),
Gender.ETC,
"010-1234-5678",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private void verifyEveryMocksShouldHaveNoMoreInteractions() {
private User createUser(Long id, String email) throws Exception {
Constructor<User> userConstructor = User.class.getDeclaredConstructor(
Long.class, Set.class, String.class, String.class, String.class,
LocalDate.class, Gender.class, String.class, String.class
String.class, LocalDate.class, Gender.class, String.class, String.class
);
userConstructor.setAccessible(true);
return userConstructor.newInstance(
Expand All @@ -131,6 +131,7 @@ private User createUser(Long id, String email) throws Exception {
email,
"password",
"kakao-user-id",
"https://user-default-profile-image-url",
LocalDate.of(2024, 1, 1),
Gender.ETC,
"010-1234-5678",
Expand Down

0 comments on commit c794a65

Please sign in to comment.