-
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.
Merge pull request #9 from Good-Moneying/feature/8-home-api
[Feature] #8 뉴스레터 조회 및 홈에 필요한 엔티티 설계
- Loading branch information
Showing
102 changed files
with
1,383 additions
and
250 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
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
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
39 changes: 39 additions & 0 deletions
39
...ication/src/main/java/kusitms/duduk/application/archive/persistence/ArchiveJpaMapper.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 kusitms.duduk.application.archive.persistence; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import kusitms.duduk.application.archive.persistence.entity.ArchiveJpaEntity; | ||
import kusitms.duduk.common.annotation.Mapper; | ||
import kusitms.duduk.domain.archive.Archive; | ||
|
||
@Mapper | ||
public class ArchiveJpaMapper { | ||
|
||
public ArchiveJpaEntity toJpaEntity(Archive archive) { | ||
return ArchiveJpaEntity.builder() | ||
.id(archive.getId()) | ||
.category(archive.getCategory()) | ||
.newsLetterIds(getNewsLetterIds(archive)) | ||
.termIds(getTermIds(archive)) | ||
.build(); | ||
} | ||
|
||
private static List<Long> getNewsLetterIds(Archive archive) { | ||
return archive.getTermIds() == null ? new ArrayList<>() | ||
: archive.getNewsLetterIds(); | ||
} | ||
|
||
private static List<Long> getTermIds(Archive archive) { | ||
return archive.getTermIds() == null ? new ArrayList<>() | ||
: archive.getTermIds(); | ||
} | ||
|
||
public Archive toDomainEntity(ArchiveJpaEntity archiveJpaEntity) { | ||
return Archive.builder() | ||
.id(archiveJpaEntity.getId()) | ||
.category(archiveJpaEntity.getCategory()) | ||
.newsLetterIds(new ArrayList<>(archiveJpaEntity.getNewsLetterIds())) | ||
.termIds(new ArrayList<>(archiveJpaEntity.getTermIds())) | ||
.build(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...rc/main/java/kusitms/duduk/application/archive/persistence/ArchivePersistenceAdapter.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,8 @@ | ||
package kusitms.duduk.application.archive.persistence; | ||
|
||
import kusitms.duduk.common.annotation.Adapter; | ||
|
||
@Adapter | ||
public class ArchivePersistenceAdapter { | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
.../src/main/java/kusitms/duduk/application/archive/persistence/entity/ArchiveJpaEntity.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,54 @@ | ||
package kusitms.duduk.application.archive.persistence.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Convert; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import kusitms.duduk.application.global.converter.ListLongToStringConverter; | ||
import kusitms.duduk.application.global.entity.BaseEntity; | ||
import kusitms.duduk.domain.global.Category; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
@Getter | ||
@Entity | ||
@Table(name = "archives") | ||
@Builder(toBuilder = true) | ||
public class ArchiveJpaEntity extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "archive_id") | ||
private Long id; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private Category category; | ||
|
||
@Convert(converter = ListLongToStringConverter.class) | ||
@Builder.Default | ||
private List<Long> newsLetterIds = new ArrayList<>(); | ||
|
||
@Convert(converter = ListLongToStringConverter.class) | ||
@Builder.Default | ||
private List<Long> termIds = new ArrayList<>(); | ||
|
||
public static ArchiveJpaEntity create(Category category) { | ||
return ArchiveJpaEntity.builder() | ||
.category(category) | ||
.newsLetterIds(new ArrayList<>()) | ||
.termIds(new ArrayList<>()) | ||
.build(); | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...sistence/AttendantPersistenceAdapter.java → ...sistence/AttendantPersistenceAdapter.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
4 changes: 2 additions & 2 deletions
4
...ence/persistence/AttendantRepository.java → ...dant/persistence/AttendantRepository.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
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
2 changes: 1 addition & 1 deletion
2
...attendence/service/AttendUserCommand.java → .../attendant/service/AttendUserCommand.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
37 changes: 37 additions & 0 deletions
37
...n/src/main/java/kusitms/duduk/application/global/converter/ListLongToStringConverter.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,37 @@ | ||
package kusitms.duduk.application.global.converter; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import jakarta.persistence.AttributeConverter; | ||
import java.util.List; | ||
import kusitms.duduk.common.exception.custom.ConvertException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
public class ListLongToStringConverter implements AttributeConverter<List<Long>, String> { | ||
|
||
private static final ObjectMapper objectMapper = new ObjectMapper() | ||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) | ||
.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false); | ||
|
||
@Override | ||
public String convertToDatabaseColumn(List<Long> attribute) { | ||
try { | ||
return objectMapper.writeValueAsString(attribute); | ||
} catch (Exception e) { | ||
throw new ConvertException("attribute를 String으로 변환하는 과정에서 오류가 발생하였습니다."); | ||
} | ||
} | ||
|
||
@Override | ||
public List<Long> convertToEntityAttribute(String dbData) { | ||
TypeReference<List<Long>> typeReference = new TypeReference<>() { | ||
}; | ||
try { | ||
return objectMapper.readValue(dbData, typeReference); | ||
} catch (Exception e) { | ||
throw new ConvertException("dbData를 List<Long>으로 변환하는 과정에서 오류가 발생하였습니다."); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
application/src/main/java/kusitms/duduk/application/global/entity/BaseEntity.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 kusitms.duduk.application.global.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.MappedSuperclass; | ||
import java.time.LocalDateTime; | ||
import lombok.Getter; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
@EntityListeners(AuditingEntityListener.class) | ||
@Getter | ||
@MappedSuperclass | ||
public class BaseEntity { | ||
@CreatedDate | ||
@Column(name = "created_at", updatable = false) | ||
private LocalDateTime createdAt; | ||
|
||
@LastModifiedDate | ||
@Column(name = "updated_at") | ||
private 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
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
Oops, something went wrong.