Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .coderabbit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: ko
reviews:
auto_review:
enabled: true
base_branches:
- main
- dev
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ out/

### VS Code ###
.vscode/

### Custom ###
db_dev.mv.db
db_dev.trace.db
30 changes: 12 additions & 18 deletions src/main/java/com/back/domain/user/entity/User.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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";
}
28 changes: 28 additions & 0 deletions src/main/java/com/back/domain/user/enums/AbvLevel.java
Original file line number Diff line number Diff line change
@@ -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; // 기본값
}
}
20 changes: 20 additions & 0 deletions src/main/java/com/back/domain/user/service/UserService.java
Original file line number Diff line number Diff line change
@@ -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));
}
}