This repository has been archived by the owner on Oct 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#164] feat: WishBookHistory 와 Auditing 을 추가한다.
- Loading branch information
1 parent
38f0569
commit cd0e543
Showing
5 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...domain/src/main/java/com/woowacourse/tecobrary/config/audit/JpaAuditingConfiguration.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,21 @@ | ||
package com.woowacourse.tecobrary.config.audit; | ||
|
||
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 org.springframework.security.core.context.SecurityContextHolder; | ||
|
||
import java.util.Optional; | ||
|
||
@Configuration | ||
@EnableJpaAuditing(auditorAwareRef = "auditorProvider") | ||
public class JpaAuditingConfiguration { | ||
|
||
@Bean | ||
public AuditorAware<String> auditorProvider() { | ||
return () -> Optional.ofNullable(SecurityContextHolder.getContext() | ||
.getAuthentication() | ||
.getName()); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...in/src/main/java/com/woowacourse/tecobrary/domain/common/entity/ModifiableBaseEntity.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,24 @@ | ||
package com.woowacourse.tecobrary.domain.common.entity; | ||
|
||
import lombok.Getter; | ||
import org.springframework.data.annotation.CreatedBy; | ||
import org.springframework.data.annotation.LastModifiedBy; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.EntityListeners; | ||
import javax.persistence.MappedSuperclass; | ||
|
||
@Getter | ||
@EntityListeners(AuditingEntityListener.class) | ||
@MappedSuperclass | ||
public class ModifiableBaseEntity extends ModifiableEntity { | ||
|
||
@CreatedBy | ||
@Column(length = 50) | ||
private String createdBy; | ||
|
||
@LastModifiedBy | ||
@Column(length = 50) | ||
private String modifiedBy; | ||
} |
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
...omain/src/main/java/com/woowacourse/tecobrary/domain/wishbook/entity/WishBookHistory.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 com.woowacourse.tecobrary.domain.wishbook.entity; | ||
|
||
import com.woowacourse.tecobrary.domain.common.entity.ModifiableBaseEntity; | ||
import lombok.*; | ||
|
||
import javax.persistence.*; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
@Entity | ||
@EqualsAndHashCode(of = "id", callSuper = false) | ||
public class WishBookHistory extends ModifiableBaseEntity { | ||
|
||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Id | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private String reason; | ||
|
||
@Column(nullable = false, length = 30) | ||
@Enumerated(EnumType.STRING) | ||
private WishBookStatus status; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) | ||
@JoinColumn(name = "wish_book_id") | ||
private WishBook wishBook; | ||
|
||
@Builder | ||
public WishBookHistory(String reason, WishBookStatus status, WishBook wishBook) { | ||
this.reason = reason; | ||
this.status = status; | ||
this.wishBook = wishBook; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
.../java/com/woowacourse/tecobrary/domain/wishbook/repository/WishBookHistoryRepository.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,9 @@ | ||
package com.woowacourse.tecobrary.domain.wishbook.repository; | ||
|
||
import com.woowacourse.tecobrary.domain.wishbook.entity.WishBookHistory; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface WishBookHistoryRepository extends JpaRepository<WishBookHistory, Long> { | ||
} |