diff --git a/.coderabbit.yml b/.coderabbit.yml new file mode 100644 index 00000000..5c0466b7 --- /dev/null +++ b/.coderabbit.yml @@ -0,0 +1,7 @@ +language: ko +reviews: + auto_review: + enabled: true + base_branches: + - main + - dev \ No newline at end of file diff --git a/.gitignore b/.gitignore index c2065bc2..992bd44c 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,7 @@ out/ ### VS Code ### .vscode/ + +### Custom ### +db_dev.mv.db +db_dev.trace.db \ No newline at end of file diff --git a/src/main/java/com/back/domain/user/entity/User.java b/src/main/java/com/back/domain/user/entity/User.java index f8a1d18c..5edbc08a 100644 --- a/src/main/java/com/back/domain/user/entity/User.java +++ b/src/main/java/com/back/domain/user/entity/User.java @@ -1,19 +1,12 @@ package com.back.domain.user.entity; import jakarta.persistence.*; -import jakarta.validation.constraints.Email; -import jakarta.validation.constraints.NotBlank; import lombok.*; import java.time.LocalDateTime; @Entity -@Table( - name = "users", // DB 테이블 이름: User 대신 users 권장 (예약어 충돌 방지) - indexes = { - @Index(name = "ux_users_email", columnList = "email", unique = true) - } -) +@Table(name = "users") // 예약어 충돌 방지를 위해 "users" 권장 @Getter @Setter @NoArgsConstructor @@ -25,20 +18,21 @@ public class User { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @NotBlank - @Email - @Column(nullable = false, unique = true) - private String email; // 유저 소셜 이메일 (OAuth2 로그인 시 저장) + // OAuth 동의 범위에 따라 이메일이 없을 수 있어 nullable + // 여러 provider에서 동일 이메일이 올 수 있으므로 unique 하지 않아도 됨 + @Column(length = 100) + private String email; - @NotBlank - @Column(nullable = false, unique = true) - private String nickname; // 유저 닉네임 + @Column(nullable = false, unique = true, length = 50) + private String nickname; // 고유 닉네임 - private String profileImgUrl; // 프로필 이미지 URL - - private Double abvDegree; // 온도(회원 등급) + private Double abvDegree; // 알콜도수(회원 등급) private LocalDateTime createdAt; // 생성 날짜 private LocalDateTime updatedAt; // 수정 날짜 + + @Builder.Default + @Column(nullable = false, length = 20) + private String role = "USER"; } \ No newline at end of file diff --git a/src/main/java/com/back/domain/user/enums/AbvLevel.java b/src/main/java/com/back/domain/user/enums/AbvLevel.java new file mode 100644 index 00000000..41e20a4a --- /dev/null +++ b/src/main/java/com/back/domain/user/enums/AbvLevel.java @@ -0,0 +1,28 @@ +package com.back.domain.user.enums; + +public enum AbvLevel { + L1(1, 0, 10, "/img/grade/1.png"), + L2(2, 11, 25, "/img/grade/2.png"), + L3(3, 26, 45, "/img/grade/3.png"), + L4(4, 46, 65, "/img/grade/4.png"), + L5(5, 66, 85, "/img/grade/5.png"), + L6(6, 86, 100, "/img/grade/6.png"); + + public final int code; + public final int min, max; + public final String imagePath; + + AbvLevel(int code, int min, int max, String imagePath) { + this.code = code; + this.min = min; + this.max = max; + this.imagePath = imagePath; + } + + public static AbvLevel of(int percent) { + for (var lv : values()) { + if (percent >= lv.min && percent <= lv.max) return lv; + } + return L1; // 기본값 + } +} \ No newline at end of file diff --git a/src/main/java/com/back/domain/user/service/UserService.java b/src/main/java/com/back/domain/user/service/UserService.java new file mode 100644 index 00000000..103c5a97 --- /dev/null +++ b/src/main/java/com/back/domain/user/service/UserService.java @@ -0,0 +1,20 @@ +package com.back.domain.user.service; + +import com.back.domain.user.entity.User; +import com.back.domain.user.repository.UserRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class UserService { + + private final UserRepository userRepository; + + @Transactional(readOnly = true) + public User findById(Long id) { + return userRepository.findById(id) + .orElseThrow(() -> new IllegalArgumentException("User not found. id=" + id)); + } +} \ No newline at end of file