-
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.
GETP-198 refactor: service term 도메인에서 persistence adapter 분리 (#130)
- Loading branch information
Showing
19 changed files
with
161 additions
and
81 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
23 changes: 2 additions & 21 deletions
23
src/main/java/es/princip/getp/domain/serviceTerm/domain/ServiceTerm.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 |
---|---|---|
@@ -1,33 +1,14 @@ | ||
package es.princip.getp.domain.serviceTerm.domain; | ||
|
||
import es.princip.getp.common.domain.BaseTimeEntity; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.EmbeddedId; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(name = "service_term") | ||
@AllArgsConstructor | ||
public class ServiceTerm extends BaseTimeEntity { | ||
|
||
@EmbeddedId | ||
private ServiceTermTag tag; | ||
|
||
@Getter | ||
@Column(name = "required") | ||
private boolean required; | ||
|
||
@Column(name = "revocable") | ||
private boolean revocable; | ||
|
||
public ServiceTerm(ServiceTermTag tag, boolean required, boolean revocable) { | ||
this.tag = tag; | ||
this.required = required; | ||
this.revocable = revocable; | ||
} | ||
} |
11 changes: 0 additions & 11 deletions
11
src/main/java/es/princip/getp/domain/serviceTerm/domain/ServiceTermRepository.java
This file was deleted.
Oops, something went wrong.
21 changes: 7 additions & 14 deletions
21
src/main/java/es/princip/getp/domain/serviceTerm/domain/ServiceTermTag.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 |
---|---|---|
@@ -1,31 +1,24 @@ | ||
package es.princip.getp.domain.serviceTerm.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.*; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
import java.io.Serializable; | ||
import java.util.Objects; | ||
|
||
@Getter | ||
@ToString | ||
@Embeddable | ||
@EqualsAndHashCode | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class ServiceTermTag implements Serializable { | ||
public class ServiceTermTag { | ||
|
||
@Column(name = "service_term_tag") | ||
@NotNull | ||
private String value; | ||
private final String value; | ||
|
||
public ServiceTermTag(final String value) { | ||
this.value = value; | ||
} | ||
|
||
public static ServiceTermTag of(final String value) { | ||
if (value == null || value.isEmpty()) { | ||
throw new IllegalArgumentException("ServiceTermTag value must not be null or empty"); | ||
} | ||
Objects.requireNonNull(value); | ||
return new ServiceTermTag(value); | ||
} | ||
} |
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
5 changes: 4 additions & 1 deletion
5
src/main/java/es/princip/getp/domain/serviceTerm/port/out/CheckServiceTermPort.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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
package es.princip.getp.domain.serviceTerm.port.out; | ||
|
||
import es.princip.getp.domain.serviceTerm.domain.ServiceTermTag; | ||
|
||
public interface CheckServiceTermPort { | ||
|
||
|
||
boolean existsBy(ServiceTermTag tag); | ||
} |
6 changes: 5 additions & 1 deletion
6
src/main/java/es/princip/getp/domain/serviceTerm/port/out/LoadServiceTermPort.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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
package es.princip.getp.domain.serviceTerm.port.out; | ||
|
||
import es.princip.getp.domain.serviceTerm.domain.ServiceTerm; | ||
import es.princip.getp.domain.serviceTerm.domain.ServiceTermTag; | ||
|
||
public interface LoadServiceTermPort { | ||
|
||
|
||
ServiceTerm loadBy(ServiceTermTag tag); | ||
} |
5 changes: 4 additions & 1 deletion
5
src/main/java/es/princip/getp/domain/serviceTerm/port/out/SaveServiceTermPort.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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
package es.princip.getp.domain.serviceTerm.port.out; | ||
|
||
import es.princip.getp.domain.serviceTerm.domain.ServiceTerm; | ||
|
||
public interface SaveServiceTermPort { | ||
|
||
|
||
void save(ServiceTerm serviceTerm); | ||
} |
5 changes: 0 additions & 5 deletions
5
src/main/java/es/princip/getp/domain/serviceTerm/port/out/UpdateServiceTermPort.java
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
src/main/java/es/princip/getp/persistence/adapter/BaseTimeJpaEntity.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,25 @@ | ||
package es.princip.getp.persistence.adapter; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.MappedSuperclass; | ||
import lombok.Getter; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@MappedSuperclass | ||
@EntityListeners(AuditingEntityListener.class) | ||
public abstract class BaseTimeJpaEntity { | ||
|
||
@CreatedDate | ||
@Column(columnDefinition = "TIMESTAMP") | ||
protected LocalDateTime createdAt; | ||
|
||
@LastModifiedDate | ||
@Column(columnDefinition = "TIMESTAMP") | ||
protected LocalDateTime updatedAt; | ||
} |
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
3 changes: 2 additions & 1 deletion
3
...ception/NotFoundServiceTermException.java → ...iceTerm/NotFoundServiceTermException.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
29 changes: 29 additions & 0 deletions
29
src/main/java/es/princip/getp/persistence/adapter/serviceTerm/ServiceTermJpaEntity.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,29 @@ | ||
package es.princip.getp.persistence.adapter.serviceTerm; | ||
|
||
import es.princip.getp.persistence.adapter.BaseTimeJpaEntity; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@AllArgsConstructor | ||
@Table(name = "service_term") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
class ServiceTermJpaEntity extends BaseTimeJpaEntity { | ||
|
||
@Id | ||
@Column(name = "service_term_tag") | ||
private String tag; | ||
|
||
@Column(name = "required") | ||
private boolean required; | ||
|
||
@Column(name = "revocable") | ||
private boolean revocable; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/es/princip/getp/persistence/adapter/serviceTerm/ServiceTermJpaRepository.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,12 @@ | ||
package es.princip.getp.persistence.adapter.serviceTerm; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
interface ServiceTermJpaRepository extends JpaRepository<ServiceTermJpaEntity, String> { | ||
|
||
Optional<ServiceTermJpaEntity> findByTag(String tag); | ||
|
||
boolean existsByTag(String tag); | ||
} |
34 changes: 34 additions & 0 deletions
34
...n/java/es/princip/getp/persistence/adapter/serviceTerm/ServiceTermPersistenceAdapter.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,34 @@ | ||
package es.princip.getp.persistence.adapter.serviceTerm; | ||
|
||
import es.princip.getp.domain.serviceTerm.domain.ServiceTerm; | ||
import es.princip.getp.domain.serviceTerm.domain.ServiceTermTag; | ||
import es.princip.getp.domain.serviceTerm.port.out.CheckServiceTermPort; | ||
import es.princip.getp.domain.serviceTerm.port.out.LoadServiceTermPort; | ||
import es.princip.getp.domain.serviceTerm.port.out.SaveServiceTermPort; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
class ServiceTermPersistenceAdapter implements LoadServiceTermPort, CheckServiceTermPort, SaveServiceTermPort { | ||
|
||
private final ServiceTermJpaRepository serviceTermJpaRepository; | ||
private final ServiceTermPersistenceMapper mapper; | ||
|
||
@Override | ||
public boolean existsBy(final ServiceTermTag tag) { | ||
return serviceTermJpaRepository.existsByTag(tag.getValue()); | ||
} | ||
|
||
@Override | ||
public ServiceTerm loadBy(final ServiceTermTag tag) { | ||
return serviceTermJpaRepository.findByTag(tag.getValue()) | ||
.map(mapper::mapToDomain) | ||
.orElseThrow(NotFoundServiceTermException::new); | ||
} | ||
|
||
@Override | ||
public void save(final ServiceTerm serviceTerm) { | ||
serviceTermJpaRepository.save(mapper.mapToJpa(serviceTerm)); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...in/java/es/princip/getp/persistence/adapter/serviceTerm/ServiceTermPersistenceMapper.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,15 @@ | ||
package es.princip.getp.persistence.adapter.serviceTerm; | ||
|
||
import es.princip.getp.domain.serviceTerm.domain.ServiceTerm; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
|
||
@Mapper(componentModel = "spring") | ||
interface ServiceTermPersistenceMapper { | ||
|
||
@Mapping(source = "tag", target = "tag.value") | ||
ServiceTerm mapToDomain(ServiceTermJpaEntity serviceTermJpaEntity); | ||
|
||
@Mapping(target = "tag", source = "tag.value") | ||
ServiceTermJpaEntity mapToJpa(ServiceTerm serviceTerm); | ||
} |