Skip to content

Commit

Permalink
Merge pull request #9 from Good-Moneying/feature/8-home-api
Browse files Browse the repository at this point in the history
[Feature] #8 뉴스레터 조회 및 홈에 필요한 엔티티 설계
  • Loading branch information
packdev937 authored May 12, 2024
2 parents adb0927 + 3b950d5 commit 6811f61
Show file tree
Hide file tree
Showing 102 changed files with 1,383 additions and 250 deletions.
1 change: 1 addition & 0 deletions api-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies {
implementation project(':domain')
implementation project(':application')
implementation project(':core')
implementation project(':common')

// Spring Boot Starter
implementation 'org.springframework.boot:spring-boot-starter-web'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"kusitms.duduk.apiserver",
"kusitms.duduk.application",
"kusitms.duduk.domain",
"kusitms.duduk.core"})
"kusitms.duduk.core",
"kusitms.duduk.common"})
public class DudukApiServerApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import kusitms.duduk.core.exception.ErrorResponse;
import kusitms.duduk.common.exception.ErrorResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import kusitms.duduk.core.security.dto.response.OAuthLoginResponse;
import kusitms.duduk.core.exception.ErrorResponse;
import kusitms.duduk.common.exception.ErrorResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kusitms.duduk.apiserver.user.presentation;

import kusitms.duduk.apiserver.security.infrastructure.CustomUserDetails;
import kusitms.duduk.core.user.dto.request.CreateUserRequest;
import kusitms.duduk.core.user.dto.request.ValidateUserEmailRequest;
import kusitms.duduk.core.user.dto.request.ValidateUserNicknameRequest;
Expand All @@ -9,6 +10,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -39,4 +42,13 @@ public ResponseEntity<Void> validateNickname(@RequestBody ValidateUserNicknameRe
validateDuplicatedUserQuery.validateDuplicatedNickname(request);
return new ResponseEntity<>(HttpStatus.OK);
}

@GetMapping("/test")
public ResponseEntity<String> test(@AuthenticationPrincipal
CustomUserDetails customUserDetails) {
return new ResponseEntity<>(customUserDetails.getEmail()
, HttpStatus.OK);
}


}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package kusitms.duduk.apiserver.user.presentation;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import kusitms.duduk.core.exception.ErrorResponse;
import kusitms.duduk.common.exception.ErrorResponse;
import kusitms.duduk.core.user.dto.request.CreateUserRequest;
import kusitms.duduk.core.user.dto.request.ValidateUserEmailRequest;
import kusitms.duduk.core.user.dto.request.ValidateUserNicknameRequest;
Expand All @@ -17,6 +16,7 @@

@Tag(name = "User", description = "유저 API")
public interface UserControllerDocs {

@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "400", description = "BAD REQUEST",
Expand All @@ -29,7 +29,7 @@ public interface UserControllerDocs {
description = "회원 가입을 위한 필수 정보를 담고 있는 DTO 클래스",
required = true,
content = @Content(
schema = @Schema(implementation = CreateUserRequest.class)
schema = @Schema(implementation = CreateUserRequest.class)
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import static org.codehaus.groovy.runtime.DefaultGroovyMethods.any;

import kusitms.duduk.application.attendence.persistence.AttendantRepository;
import kusitms.duduk.application.attendence.persistence.entity.AttendantJpaEntity;
import kusitms.duduk.application.user.event.LoginUserEvent;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
2 changes: 2 additions & 0 deletions application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jar.enabled = true
dependencies {
implementation(project(":domain"))
implementation(project(":core"))
implementation project(':common')


// Spring Data JPA
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
@SpringBootApplication(scanBasePackages = {
"kusitms.duduk.application",
"kusitms.duduk.domain",
"kusitms.duduk.core"
"kusitms.duduk.core",
"kusitms.duduk.common"
})
public class DudukApplication {

Expand Down
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();
}
}
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 {

}
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();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package kusitms.duduk.application.attendence.persistence;
package kusitms.duduk.application.attendant.persistence;

import java.time.LocalDate;
import kusitms.duduk.application.attendence.persistence.entity.AttendantJpaEntity;
import kusitms.duduk.core.annotation.Adapter;
import kusitms.duduk.application.attendant.persistence.entity.AttendantJpaEntity;
import kusitms.duduk.common.annotation.Adapter;
import kusitms.duduk.core.attendant.port.output.LoadAttendantPort;
import kusitms.duduk.core.attendant.port.output.SaveAttendantPort;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package kusitms.duduk.application.attendence.persistence;
package kusitms.duduk.application.attendant.persistence;

import java.time.LocalDate;
import kusitms.duduk.application.attendence.persistence.entity.AttendantJpaEntity;
import kusitms.duduk.application.attendant.persistence.entity.AttendantJpaEntity;
import org.springframework.data.jpa.repository.JpaRepository;

public interface AttendantRepository extends JpaRepository<AttendantJpaEntity, Long> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kusitms.duduk.application.attendence.persistence.entity;
package kusitms.duduk.application.attendant.persistence.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand All @@ -16,15 +16,15 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Entity
@Table(name = "attendences", uniqueConstraints = {
@Table(name = "attendants", uniqueConstraints = {
@UniqueConstraint(columnNames = {"date", "email"})
})
@Builder(toBuilder = true)
public class AttendantJpaEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "attendence_id")
@Column(name = "attendant_id")
private Long id;
private LocalDate date;
private String email;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kusitms.duduk.application.attendence.service;
package kusitms.duduk.application.attendant.service;

import java.time.LocalDate;
import kusitms.duduk.core.attendant.port.output.LoadAttendantPort;
Expand Down
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>으로 변환하는 과정에서 오류가 발생하였습니다.");
}
}
}
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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;
import kusitms.duduk.application.newsletter.persistence.entity.NewsLetterJpaEntity;
import kusitms.duduk.core.annotation.Mapper;
import kusitms.duduk.common.annotation.Mapper;
import kusitms.duduk.domain.global.Count;
import kusitms.duduk.domain.global.Id;
import kusitms.duduk.domain.newsletter.NewsLetter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import java.util.List;
import java.util.Optional;
import kusitms.duduk.application.newsletter.persistence.entity.NewsLetterJpaEntity;
import kusitms.duduk.core.annotation.Adapter;
import kusitms.duduk.common.annotation.Adapter;
import kusitms.duduk.core.newsletter.port.output.DeleteNewsLetterPort;
import kusitms.duduk.core.newsletter.port.output.LoadNewsLetterPort;
import kusitms.duduk.core.newsletter.port.output.SaveNewsLetterPort;
import kusitms.duduk.core.newsletter.port.output.UpdateNewsLetterPort;
import kusitms.duduk.domain.global.Id;
import kusitms.duduk.domain.newsletter.NewsLetter;
import lombok.RequiredArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import kusitms.duduk.application.global.entity.BaseEntity;
import kusitms.duduk.domain.global.Category;
import kusitms.duduk.domain.newsletter.vo.Type;
import lombok.AccessLevel;
Expand All @@ -22,7 +23,7 @@
@Entity
@Table(name = "news_letter")
@Builder(toBuilder = true)
public class NewsLetterJpaEntity {
public class NewsLetterJpaEntity extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Loading

0 comments on commit 6811f61

Please sign in to comment.