-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: UserEntity와 UserRepository 개발 (#5)
* feat: UserEntity와 UserRepository를 개발한다 * feat: User도메인 을 수정하고, UserConnector를 구현한다 * refactor: ddl에 oauth정보를 추가한다 * ci: type-labeler 의 오타를 수정한다 * refactor: 유저도메인의 Character를 통합시킨다 * feat: User도메인에 약관 도메인을 추가한다 * feat: 유저 생성 및 수정시간을 추가한다 * refactor: List에 기본값을 바인딩한다 * refactor: street에 기본생성자를 추가한다
- Loading branch information
Showing
22 changed files
with
555 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/net/teumteum/core/entity/TimeBaseEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package net.teumteum.core.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.MappedSuperclass; | ||
import jakarta.persistence.PrePersist; | ||
import jakarta.persistence.PreUpdate; | ||
import java.time.Instant; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@MappedSuperclass | ||
public abstract class TimeBaseEntity { | ||
|
||
@Column(name = "created_at", columnDefinition = "TIMESTAMP(6)", nullable = false, updatable = false) | ||
protected Instant createdAt; | ||
|
||
@Column(name = "updated_at", columnDefinition = "TIMESTAMP(6)", nullable = false) | ||
protected Instant updatedAt; | ||
|
||
@PrePersist | ||
void prePersist() { | ||
var now = Instant.now(); | ||
|
||
createdAt = createdAt != null ? createdAt : now; | ||
updatedAt = updatedAt != null ? updatedAt : now; | ||
} | ||
|
||
@PreUpdate | ||
void preUpdate() { | ||
updatedAt = updatedAt != null ? updatedAt : Instant.now(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package net.teumteum.user.domain; | ||
|
||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.ElementCollection; | ||
import jakarta.persistence.Embeddable; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Embeddable | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ActivityArea { | ||
|
||
@Column(name = "city") | ||
private String city; | ||
|
||
@ElementCollection | ||
private List<String> street = new ArrayList<>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package net.teumteum.user.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Embeddable | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Job { | ||
|
||
@Column(name = "job_name") | ||
private String name; | ||
|
||
@Column(name = "certificated") | ||
private boolean certificated; | ||
|
||
@Column(name = "job_class") | ||
private String jobClass; | ||
|
||
@Column(name = "detail_job_class") | ||
private String detailJobClass; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.teumteum.user.domain; | ||
|
||
public enum JobStatus { | ||
|
||
직장인, | ||
학생, | ||
취업준비생, | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.teumteum.user.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Embeddable | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Oauth { | ||
|
||
@Column(name = "oauth_authenticate_info", unique = true) | ||
private String oAuthAuthenticateInfo; | ||
|
||
@Column(name = "authenticated") | ||
private String authenticated; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package net.teumteum.user.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import jakarta.persistence.PrePersist; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.util.Assert; | ||
|
||
@Getter | ||
@Embeddable | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Terms { | ||
|
||
@Column(name = "terms_of_service", nullable = false) | ||
private Boolean service; | ||
|
||
@Column(name = "privacy_policy", nullable = false) | ||
private Boolean privacyPolicy; | ||
|
||
@PrePersist | ||
private void assertTerms() { | ||
Assert.isTrue(service, () -> "서비스 이용 약관은 항상 동의 되어야 합니다."); | ||
Assert.isTrue(privacyPolicy, () -> "개인정보 처리 방침은 항상 동의 되어야 합니다."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package net.teumteum.user.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.ElementCollection; | ||
import jakarta.persistence.Embedded; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.PrePersist; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import net.teumteum.core.entity.TimeBaseEntity; | ||
import org.springframework.format.annotation.DateTimeFormat; | ||
import org.springframework.util.Assert; | ||
|
||
@Getter | ||
@Entity(name = "users") | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class User extends TimeBaseEntity { | ||
|
||
@Id | ||
@Column(name = "id") | ||
private Long id; | ||
|
||
@Column(name = "name", length = 10) | ||
private String name; | ||
|
||
@Column(name = "birth", length = 10) | ||
@DateTimeFormat(pattern = "yyyy.MM.dd") | ||
private String birth; | ||
|
||
@Column(name = "character_id") | ||
private Long characterId; | ||
|
||
@Column(name = "manner_temperature") | ||
private int mannerTemperature; | ||
|
||
@Embedded | ||
private Oauth oauth; | ||
|
||
@Embedded | ||
private ActivityArea activityArea; | ||
|
||
@Column(name = "mbti", length = 4) | ||
private String mbti; | ||
|
||
@Column(name = "status") | ||
@Enumerated(EnumType.STRING) | ||
private JobStatus status; | ||
|
||
@Column(name = "goal", length = 50) | ||
private String goal; | ||
|
||
@Embedded | ||
private Job job; | ||
|
||
@ElementCollection | ||
private List<String> interests = new ArrayList<>(); | ||
|
||
@Embedded | ||
private Terms terms; | ||
|
||
@PrePersist | ||
private void assertField() { | ||
assertName(); | ||
} | ||
|
||
private void assertName() { | ||
Assert.doesNotContain(name, " ", () -> "이름에 공백이 포함되어 있습니다. \"" + name + "\""); | ||
Assert.isTrue(name.length() >= 2 && name.length() <= 10, () -> "이름은 2자 ~ 10자 사이가 되어야 합니다. \"" + name + "\""); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package net.teumteum.user.domain; | ||
|
||
import java.util.Optional; | ||
|
||
public interface UserConnector { | ||
|
||
Optional<User> findUserById(Long id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package net.teumteum.user.domain; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface UserRepository extends JpaRepository<User, Long> { | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/net/teumteum/user/service/UserConnectorImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package net.teumteum.user.service; | ||
|
||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import net.teumteum.user.domain.User; | ||
import net.teumteum.user.domain.UserConnector; | ||
import net.teumteum.user.domain.UserRepository; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class UserConnectorImpl implements UserConnector { | ||
|
||
private final UserRepository userRepository; | ||
|
||
@Override | ||
public Optional<User> findUserById(Long id) { | ||
return userRepository.findById(id); | ||
} | ||
|
||
} |
Empty file.
Oops, something went wrong.