Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
id 'org.jetbrains.kotlin.plugin.spring' version '1.7.22'
id 'org.jetbrains.kotlin.plugin.jpa' version '1.7.22'
id "org.jlleitschuh.gradle.ktlint" version "11.0.0"
id 'kotlin-extension'
}

group = 'com.record'
Expand All @@ -17,7 +18,7 @@ repositories {
mavenCentral()
}

subprojects {
subprojects { //ktlint 적용 린트
repositories {
mavenCentral()
}
Expand All @@ -41,14 +42,17 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

compileKotlin {
compileKotlin {
kotlinOptions {
freeCompilerArgs = ['-Xjsr305=strict']
jvmTarget = '17'
}
}

allOpen {
//JPA 엔티티 만들 때 규칙이 있음 (final 클래스 안돼)
//코틀린은 클래스 기본이 final이야. @Entity 등 annotation이 붙이면 자동으로 final 아니게 설정
//이렇게 안 하면 모든 클래스에 open을 붙여야됨
annotation("jakarta.persistence.Entity")
annotation("jakarta.persistence.MappedSuperclass")
annotation("jakarta.persistence.Embeddable")
Expand All @@ -58,6 +62,6 @@ noArg {
annotation("jakarta.persistence.Entity")
}

test{
test {
useJUnitPlatform()
}
13 changes: 13 additions & 0 deletions src/main/kotlin/com/record/zooc/domain/entity/Alarm.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import com.record.zooc.domain.entity.BaseTimeEntityCreated
import jakarta.persistence.Entity
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id

@Entity
class Alarm() : BaseTimeEntityCreated() {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long? = null
protected set
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.record.zooc.domain.entity

import jakarta.persistence.Column
import jakarta.persistence.EntityListeners
import jakarta.persistence.MappedSuperclass
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import java.time.LocalDateTime

@MappedSuperclass
@EntityListeners(AuditingEntityListener::class)
abstract class BaseTimeEntityCreated {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금도 객체의 이름이 나쁘지는 않다고 생각은 들지만 조금 더 이해하기 쉬운 역할의 이름을 부여해 주는 것이 어떨까요?

이 추상 클래스가 해주고 싶은 역할은 결국 어떤 것일까요?
그 역할 이름을 부자연스러운 단어의 조합보다 그 역할 자체를 쉽게 풀어 쓰는 단어를 붙여주는 것이 좋지 않을까요?
마치 지금은 이름 자체만 보면 BaseTime 엔티티 생성된 과 같은 순서로 읽혀 정확히 어떤 일을 처리하고 싶은지 알기 힘든 것 같은 느낌이 듭니다.

@CreatedDate
@Column(nullable = false, updatable = false)
var createdAt: LocalDateTime = LocalDateTime.now()
protected set
// var로 해야지 시간 저장될 때 오류 안남
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.record.zooc.domain.entity

import com.fasterxml.jackson.annotation.JsonFormat
import jakarta.persistence.Column
import jakarta.persistence.EntityListeners
import jakarta.persistence.MappedSuperclass
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.LastModifiedDate
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import java.time.LocalDateTime

@MappedSuperclass
@EntityListeners(AuditingEntityListener::class)
abstract class BaseTimeEntityModified {
@CreatedDate
@Column(nullable = false, updatable = false)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
var createdAt: LocalDateTime = LocalDateTime.now()
protected set
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modifiedAt 을 다루는 곳에서는 JsonFormat 을 사용하고 있는데 이로 인해 BaseTimeEntityCreated에서 createAt에 대한 포맷 문제가 있진 않을까요?
혹은 포맷 뿐 아니라 만약 컬럼명이 변하는 경우 두 파일을 모두 수정해야 하는 상황이 발생할 수 있는데
이 처럼 수정으로 인한 불일치가 생기지 않도록 처리가 필요하지 않을까요?


@LastModifiedDate
@Column(nullable = false)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
var modifiedAt: LocalDateTime = LocalDateTime.now()
protected set
}
19 changes: 19 additions & 0 deletions src/main/kotlin/com/record/zooc/domain/entity/Comment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import com.record.zooc.domain.entity.BaseTimeEntityModified
import jakarta.persistence.DiscriminatorColumn
import jakarta.persistence.Entity
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.Inheritance
import jakarta.persistence.InheritanceType

@DiscriminatorColumn(name = "comment_type")
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
class Comment(
) : BaseTimeEntityModified() {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long? = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id에 대해 디폴트 초기화 값을 통일해주는 것이 좋을 것 같습니다!

본인만의 정확한 기준을 만들어 null 혹은 Default value 중 선택을 해보는 것이 어떨까요?

protected set
}
6 changes: 6 additions & 0 deletions src/main/kotlin/com/record/zooc/domain/entity/Emojicomment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import jakarta.persistence.DiscriminatorValue

@DiscriminatorValue("Emoji")
class Emojicomment(
emoji: Int
) : Comment()
Empty file.
1 change: 1 addition & 0 deletions src/main/kotlin/com/record/zooc/domain/entity/FcmToken.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class FcmToken() {}
25 changes: 25 additions & 0 deletions src/main/kotlin/com/record/zooc/domain/entity/Memory.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import com.record.zooc.domain.entity.BaseTimeEntityModified
import jakarta.persistence.Column
import jakarta.persistence.DiscriminatorColumn
import jakarta.persistence.Entity
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.Inheritance
import jakarta.persistence.InheritanceType

@DiscriminatorColumn(name = "mission_type")
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
class Memory(

@Column
var image: String,

@Column
var content: String,
) : BaseTimeEntityModified() {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = 0; // ㅜㅜ 이거 어카지...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

val 의 경우 자바의 final 변수와 동일하게 한번 선언 후 값을 변경할 수 없습니다.
만약 id 가 final 일 경우 어떤 문제가 발생할 수 있을까요? 혹은 예상되는 문제가 없을까요?

}
Empty file.
10 changes: 10 additions & 0 deletions src/main/kotlin/com/record/zooc/domain/entity/Missionmemory.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import jakarta.persistence.DiscriminatorValue

@DiscriminatorValue("Mission")
class Missionmemory(
image: String,
content: String
) : Memory(
image,
content
)
23 changes: 23 additions & 0 deletions src/main/kotlin/com/record/zooc/domain/entity/Pet.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id

@Entity
class Pet(
name: String,
) {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long? = null
protected set

@Column(name = "profile_image")
var profileImage: String? = null
protected set

@Column
var name: String = name
protected set
}
10 changes: 10 additions & 0 deletions src/main/kotlin/com/record/zooc/domain/entity/Recordmemory.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import jakarta.persistence.DiscriminatorValue

@DiscriminatorValue("Record")
class Recordmemory(
image: String,
content: String
) : Memory(
image,
content
)
6 changes: 6 additions & 0 deletions src/main/kotlin/com/record/zooc/domain/entity/Textcomment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import jakarta.persistence.DiscriminatorValue

@DiscriminatorValue("Text")
class Textcomment(
content: String
) : Comment()
72 changes: 72 additions & 0 deletions src/main/kotlin/com/record/zooc/domain/entity/User.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.Table

// @Builder가 필요한 상황 찾아보기
// reflection 개념 찾아보기

@Entity
@Table(name = "user")
class User(
role: String,
userEmail: String? = null,
profileImage: String? = null,
everRecorded: Boolean = false,
refreshToken: String,
snsToken: String,
snsType: String,
) {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long? = 0
protected set
// 객체의 id를 null로 두고 데이터베이스에 insert일어날 때 생성되기 때문에 nullable이어야됨

@Column
var role: String = role
protected set

@Column(name = "user_email")
var userEmail: String? = userEmail
protected set

@Column(name = "profile_image")
var profileImage: String? = profileImage
protected set

@Column(name = "ever_recorded")
var everRecorded: Boolean = everRecorded
protected set

@Column(name = "refresh_token")
var refreshToken: String = refreshToken
protected set

@Column(name = "sns_token")
var snsToken: String = snsToken
protected set

@Column(name = "sns_type")
var snsType: String = snsType
protected set

fun updateUserRoleAndProfile(
role: String? = null,
profileImage: String? = null,
) {

if(role != null) this.role = role

//role이 null이 아니면 this에 role 저장
role?.let { this.role = it }
profileImage?.let { this.profileImage = it }
}

fun userRecordedForTheFirstTime() {
this.everRecorded = true
}

}
Empty file.
36 changes: 18 additions & 18 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
server:
port: 8082
port: 8082

spring:
datasource:
driver-class-name: org.postgresql.Driver
url: ${url}
username: ${username}
password: ${password}
jpa:
hibernate:
ddl-auto: update
show-sql: true
database: postgresql
database-platform: org.hibernate.dialect.PostgreSQLDialect
open-in-view: false
generate-ddl: true
properties:
hibernate:
default_schema: dev
format_sql: true
datasource:
driver-class-name: org.postgresql.Driver
url: ${url}
username: ${username}
password: ${password}
jpa:
hibernate:
ddl-auto: update
show-sql: true
database: postgresql
database-platform: org.hibernate.dialect.PostgreSQLDialect
open-in-view: false
generate-ddl: true
properties:
hibernate:
default_schema: dev
format_sql: true
24 changes: 12 additions & 12 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
server:
port: 8080
port: 8080

spring:
datasource:
driver-class-name: org.postgresql.Driver
url: ${url}
username: ${username}
password: ${password}
jpa:
database: postgresql
database-platform: org.hibernate.dialect.PostgreSQLDialect
properties:
hibernate:
default_schema: prod
datasource:
driver-class-name: org.postgresql.Driver
url: ${url}
username: ${username}
password: ${password}
jpa:
database: postgresql
database-platform: org.hibernate.dialect.PostgreSQLDialect
properties:
hibernate:
default_schema: prod