-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
88 additions
and
5 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/java/spring/data/jdbc/example/auditable/Issue.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,39 @@ | ||
package spring.data.jdbc.example.auditable; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
|
||
import org.springframework.data.annotation.CreatedBy; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jdbc.core.mapping.AggregateReference; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.With; | ||
import spring.data.jdbc.example.id.Member; | ||
|
||
@Builder | ||
@Getter | ||
public class Issue { | ||
@Id | ||
@With(AccessLevel.PACKAGE) | ||
private final Long id; | ||
|
||
@CreatedBy | ||
private final AggregateReference<Member, Long> memberId; | ||
|
||
@NotBlank | ||
private final String title; | ||
|
||
@CreatedDate | ||
@With(AccessLevel.PACKAGE) | ||
private final LocalDateTime createdAt; | ||
|
||
@LastModifiedDate | ||
@With(AccessLevel.PACKAGE) | ||
private final LocalDateTime updatedAt; | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/spring/data/jdbc/example/auditable/IssueRepository.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,6 @@ | ||
package spring.data.jdbc.example.auditable; | ||
|
||
import org.springframework.data.repository.CrudRepository; | ||
|
||
public interface IssueRepository extends CrudRepository<Issue, Long> { | ||
} |
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
23 changes: 23 additions & 0 deletions
23
src/test/java/spring/data/jdbc/example/auditable/IssueRepositoryTest.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 spring.data.jdbc.example.auditable; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.data.jdbc.core.mapping.AggregateReference; | ||
|
||
@SpringBootTest | ||
class IssueRepositoryTest { | ||
@Autowired | ||
private IssueRepository issueRepository; | ||
|
||
@Test | ||
void name() { | ||
final Issue issue = issueRepository.save( | ||
Issue.builder().title("이슈").memberId(AggregateReference.to(1L)).build()); | ||
|
||
assertThat(issue.getCreatedAt()).isNotNull(); | ||
assertThat(issue.getUpdatedAt()).isNotNull(); | ||
} | ||
} |