-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from mash-up-kr/junhyoung/AddQuerydslSetting
feat: Add QueryDSL configuration, split BaseEntity and BaseTimeEntity & enable JPA Auditing
- Loading branch information
Showing
8 changed files
with
120 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package com.mashup.dojo | ||
|
||
import com.mashup.dojo.base.BaseEntity | ||
import jakarta.persistence.Entity | ||
|
||
@Entity | ||
|
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 com.mashup.dojo.base | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.EntityListeners | ||
import jakarta.persistence.MappedSuperclass | ||
import org.springframework.data.annotation.CreatedBy | ||
import org.springframework.data.annotation.LastModifiedBy | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener | ||
|
||
@MappedSuperclass | ||
@EntityListeners(AuditingEntityListener::class) | ||
abstract class BaseEntity : BaseTimeEntity() { | ||
@CreatedBy | ||
@Column(updatable = false) | ||
var createdBy: String? = null | ||
private set | ||
|
||
@LastModifiedBy | ||
var lastModifiedBy: String? = null | ||
private set | ||
|
||
@Column(nullable = false) | ||
var isDeleted: Boolean = false | ||
private set | ||
|
||
// 재활성화 - soft delete | ||
fun activate() { | ||
this.isDeleted = false | ||
} | ||
|
||
// 비활성화 - soft delete | ||
fun deactivate() { | ||
this.isDeleted = true | ||
} | ||
} |
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
entity/src/main/kotlin/com/mashup/dojo/config/BaseEntityConfig.kt
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 com.mashup.dojo.config | ||
|
||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.data.domain.AuditorAware | ||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing | ||
import java.util.Optional | ||
import java.util.UUID | ||
|
||
@EnableJpaAuditing | ||
@Configuration | ||
class BaseEntityConfig { | ||
@Bean | ||
fun auditorProvider(): AuditorAware<String> { | ||
return AuditorAware { | ||
/* | ||
val authentication: Authentication? = SecurityContextHolder.getContext().authentication | ||
if (authentication == null) { | ||
return@AuditorAware Optional.of("AnonymousNULL") | ||
} | ||
val principal: Any = authentication.principal | ||
if (principal is Member) { | ||
val email: String? = principal.email | ||
return@AuditorAware Optional.ofNullable(email) | ||
} | ||
// principal이 Member 타입이 아닌 경우의 처리 | ||
Optional.of("AnonymousNOT_TYPE") | ||
*/ | ||
|
||
// 임시로 UUID 생성하여 반환 | ||
Optional.of(UUID.randomUUID().toString()) | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
entity/src/main/kotlin/com/mashup/dojo/config/QuerydslConfig.kt
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,18 @@ | ||
package com.mashup.dojo.config | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory | ||
import jakarta.persistence.EntityManager | ||
import jakarta.persistence.PersistenceContext | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
class QuerydslConfig { | ||
@PersistenceContext | ||
private lateinit var entityManager: EntityManager | ||
|
||
@Bean | ||
fun jpaQueryFactory(): JPAQueryFactory { | ||
return JPAQueryFactory(entityManager) | ||
} | ||
} |
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 @@ | ||
javaVersion=21 | ||
kotlinLoggingJvmVersion=5.1.0 | ||
queryDslVersion=6.0 | ||
jasyptSpringBootStarterVersion=3.0.5 | ||
mysqlConnectorVersion=8.4.0 | ||
h2DatabaseVersion=2.1.210 | ||
p6spyVersion=1.9.0 |