Skip to content

Commit 9bda000

Browse files
authored
Merge pull request #14 from prgrms-web-devcourse-final-project/feat#7
[feat] User 엔티티 필드 수정 및 User 서비스 추가 #7
2 parents 8c43a92 + 198db37 commit 9bda000

File tree

4 files changed

+67
-18
lines changed

4 files changed

+67
-18
lines changed

.coderabbit.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: ko
2+
reviews:
3+
auto_review:
4+
enabled: true
5+
base_branches:
6+
- main
7+
- dev
Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
package com.back.domain.user.entity;
22

33
import jakarta.persistence.*;
4-
import jakarta.validation.constraints.Email;
5-
import jakarta.validation.constraints.NotBlank;
64
import lombok.*;
75

86
import java.time.LocalDateTime;
97

108
@Entity
11-
@Table(
12-
name = "users", // DB 테이블 이름: User 대신 users 권장 (예약어 충돌 방지)
13-
indexes = {
14-
@Index(name = "ux_users_email", columnList = "email", unique = true)
15-
}
16-
)
9+
@Table(name = "users") // 예약어 충돌 방지를 위해 "users" 권장
1710
@Getter
1811
@Setter
1912
@NoArgsConstructor
@@ -25,20 +18,21 @@ public class User {
2518
@GeneratedValue(strategy = GenerationType.IDENTITY)
2619
private Long id;
2720

28-
@NotBlank
29-
@Email
30-
@Column(nullable = false, unique = true)
31-
private String email; // 유저 소셜 이메일 (OAuth2 로그인 시 저장)
21+
// OAuth 동의 범위에 따라 이메일이 없을 수 있어 nullable
22+
// 여러 provider에서 동일 이메일이 올 수 있으므로 unique 하지 않아도 됨
23+
@Column(length = 100)
24+
private String email;
3225

33-
@NotBlank
34-
@Column(nullable = false, unique = true)
35-
private String nickname; // 유저 닉네임
26+
@Column(nullable = false, unique = true, length = 50)
27+
private String nickname; // 고유 닉네임
3628

37-
private String profileImgUrl; // 프로필 이미지 URL
38-
39-
private Double abvDegree; // 온도(회원 등급)
29+
private Double abvDegree; // 알콜도수(회원 등급)
4030

4131
private LocalDateTime createdAt; // 생성 날짜
4232

4333
private LocalDateTime updatedAt; // 수정 날짜
34+
35+
@Builder.Default
36+
@Column(nullable = false, length = 20)
37+
private String role = "USER";
4438
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.back.domain.user.enums;
2+
3+
public enum AbvLevel {
4+
L1(1, 0, 10, "/img/grade/1.png"),
5+
L2(2, 11, 25, "/img/grade/2.png"),
6+
L3(3, 26, 45, "/img/grade/3.png"),
7+
L4(4, 46, 65, "/img/grade/4.png"),
8+
L5(5, 66, 85, "/img/grade/5.png"),
9+
L6(6, 86, 100, "/img/grade/6.png");
10+
11+
public final int code;
12+
public final int min, max;
13+
public final String imagePath;
14+
15+
AbvLevel(int code, int min, int max, String imagePath) {
16+
this.code = code;
17+
this.min = min;
18+
this.max = max;
19+
this.imagePath = imagePath;
20+
}
21+
22+
public static AbvLevel of(int percent) {
23+
for (var lv : values()) {
24+
if (percent >= lv.min && percent <= lv.max) return lv;
25+
}
26+
return L1; // 기본값
27+
}
28+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.back.domain.user.service;
2+
3+
import com.back.domain.user.entity.User;
4+
import com.back.domain.user.repository.UserRepository;
5+
import lombok.RequiredArgsConstructor;
6+
import org.springframework.stereotype.Service;
7+
import org.springframework.transaction.annotation.Transactional;
8+
9+
@Service
10+
@RequiredArgsConstructor
11+
public class UserService {
12+
13+
private final UserRepository userRepository;
14+
15+
@Transactional(readOnly = true)
16+
public User findById(Long id) {
17+
return userRepository.findById(id)
18+
.orElseThrow(() -> new IllegalArgumentException("User not found. id=" + id));
19+
}
20+
}

0 commit comments

Comments
 (0)