Skip to content

Commit

Permalink
feat: init Vaccination Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
h-beeen committed Oct 27, 2024
1 parent 60f2ed2 commit 1c19176
Show file tree
Hide file tree
Showing 22 changed files with 183 additions and 94 deletions.
2 changes: 2 additions & 0 deletions vacgom-api/src/main/kotlin/kr/co/vacgom/api/VagomApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package kr.co.vacgom.api
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.domain.EntityScan
import org.springframework.boot.runApplication
import org.springframework.context.annotation.ComponentScan

@SpringBootApplication
@ComponentScan(basePackages = ["kr.co.vacgom"])
@EntityScan(basePackages = ["kr.co.vacgom.persistence"])
class VacgomApi

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package kr.co.vacgom.api.global.presentation

object GlobalPath {
const val BASE_URL = "/api/v3"
const val BASE_V3 = "/api/v3"
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package kr.co.vacgom.api.vaccination.application

import kr.co.vacgom.api.vaccination.application.dto.CreateVaccinations
import kr.co.vacgom.persistence.vaccination.infrastructure.VaccinationRepository
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional
class VaccinationCreateService(
private val vaccinationRepository: VaccinationRepository
) {
fun createVaccinations(request: CreateVaccinations.ClientRequest) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package kr.co.vacgom.api.vaccination.application

import org.springframework.stereotype.Service

@Service
class VaccinationReadService
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package kr.co.vacgom.api.vaccination.application.dto

import java.time.LocalDate
import java.util.*

class CreateVaccinations {
sealed class ClientRequest {

data class Request(val vaccinations: List<VaccinationRequest>)

data class VaccinationRequest(
val doseRound: Long,
val doseDescription: String?,
val vaccinatedDate: LocalDate,
val vaccinationFacility: String?,
val vaccineManufacturer: String?,
val vaccineProductName: String?,
val vaccineLotNumber: String?
)
}

sealed class ClientResponse(val id: UUID)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package kr.co.vacgom.api.vaccination.domain

import java.time.LocalDate

data class Vaccination(
val doseRound: Long,
val doseDescription: String,
val vaccinatedDate: LocalDate,
val vaccinationFacility: String?,
val vaccinationManufacturer: String?,
val vaccineProductName: String?,
val vaccineLotNumber: String?
) {
companion object {
fun create(
doseRound: Long,
doseDescription: String,
vaccinatedDate: LocalDate,
vaccinationFacility: String? = null,
vaccinationManufacturer: String? = null,
vaccineProductName: String? = null,
vaccineLotNumber: String? = null
): Vaccination {
return Vaccination(
doseRound,
doseDescription,
vaccinatedDate,
vaccinationFacility,
vaccinationManufacturer,
vaccineProductName,
vaccineLotNumber
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package kr.co.vacgom.api.vaccination.presentation

import kr.co.vacgom.api.global.presentation.GlobalPath.BASE_V3
import kr.co.vacgom.api.vaccination.application.VaccinationCreateService
import kr.co.vacgom.api.vaccination.application.VaccinationReadService
import kr.co.vacgom.api.vaccination.application.dto.CreateVaccinations
import kr.co.vacgom.api.vaccination.presentation.VaccinationPath.VACCINATIONS
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping(BASE_V3 + VACCINATIONS)
class VaccinationController(
private val vaccinationCreateService: VaccinationCreateService,
private val vaccinationReadService: VaccinationReadService
) {

@PostMapping
fun createVaccinations(
@RequestBody request: CreateVaccinations.ClientRequest
) {
vaccinationCreateService.createVaccinations(request)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package kr.co.vacgom.api.vaccination.presentation

object VaccinationPath {
const val VACCINATIONS = "/vaccinations"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kr.co.vacgom.persistence.disease.domain;

import jakarta.persistence.*;
import kr.co.vacgom.persistence.global.entity.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -15,7 +16,7 @@
@NoArgsConstructor
@Builder(access = PRIVATE)
@AllArgsConstructor(access = PRIVATE)
public class DiseaseEntity {
public class DiseaseEntity extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package kr.co.vacgom.persistence.disease.domain;

import jakarta.persistence.*;
import kr.co.vacgom.persistence.inoculation.domain.VaccineEntity;
import kr.co.vacgom.persistence.global.entity.BaseEntity;
import kr.co.vacgom.persistence.vaccination.entity.VaccineEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -12,12 +13,12 @@
import static lombok.AccessLevel.PRIVATE;

@Entity
@Table(name = "TB_PREVENTABLE_DISEASE")
@Table(name = "TB_PREVENTABLE_DISEASE_MAPPING")
@Getter
@NoArgsConstructor
@Builder(access = PRIVATE)
@AllArgsConstructor(access = PRIVATE)
public class PreventableDiseaseEntity {
public class PreventableDiseaseEntity extends BaseEntity {

@Id
@Column(name = "MAPPING_ID", nullable = false, updatable = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package kr.co.vacgom.persistence.inoculation.domain;
package kr.co.vacgom.persistence.vaccination.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.persistence.*;
import kr.co.vacgom.persistence.disease.domain.DiseaseEntity;
import kr.co.vacgom.persistence.global.entity.BaseEntity;
import kr.co.vacgom.persistence.global.util.UuidBinaryConverter;
import kr.co.vacgom.persistence.global.util.UuidUtility;
Expand Down Expand Up @@ -44,9 +43,8 @@ public class VaccinationEntity extends BaseEntity {
@JsonFormat(shape = STRING, pattern = "yyyy-MM-dd")
@Column(nullable = false)
@Comment("[Not Null] 백신 접종 일자")
private LocalDate vaccinationDate;
private LocalDate vaccinatedDate;

@Column(nullable = false)
@Comment("[Nullable] 백신 접종 기관")
private String vaccinationFacility;

Expand All @@ -59,11 +57,6 @@ public class VaccinationEntity extends BaseEntity {
@Comment("[Nullable] 백신 고유 로트번호")
private String vaccineLotNumber;

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "DISEASE_ID")
@Comment("[NotNull] 질병(Disease) Id")
private DiseaseEntity disease;

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "VACCINE_ID")
@Comment("[NotNull] 백신(Vaccine) Id")
Expand All @@ -72,24 +65,22 @@ public class VaccinationEntity extends BaseEntity {
public static VaccinationEntity create(
Long doseRound,
String doseDescription,
LocalDate vaccinationDate,
LocalDate vaccinatedDate,
String vaccinationFacility,
String vaccinationManufacturer,
String vaccineProductName,
String vaccineLotNumber,
DiseaseEntity disease,
VaccineEntity vaccine
) {
return VaccinationEntity.builder()
.id(UuidUtility.generateRandomUUID())
.doseRound(doseRound)
.doseDescription(doseDescription)
.vaccinationDate(vaccinationDate)
.vaccinatedDate(vaccinatedDate)
.vaccinationFacility(vaccinationFacility)
.vaccinationManufacturer(vaccinationManufacturer)
.vaccineProductName(vaccineProductName)
.vaccineLotNumber(vaccineLotNumber)
.disease(disease)
.vaccine(vaccine)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package kr.co.vacgom.persistence.inoculation.domain;
package kr.co.vacgom.persistence.vaccination.entity;

import jakarta.persistence.*;
import kr.co.vacgom.persistence.global.entity.BaseEntity;
import kr.co.vacgom.persistence.inoculation.domain.constants.VaccineType;
import kr.co.vacgom.persistence.vaccination.entity.constants.VaccineType;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -18,6 +18,7 @@
public class VaccineEntity extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "VACCINE_ID", nullable = false, updatable = false)
@Comment("[Not Null] 백신 엔티티 Id")
private Long id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kr.co.vacgom.persistence.inoculation.domain.constants;
package kr.co.vacgom.persistence.vaccination.entity.constants;

public enum VaccineType {
NATION,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package kr.co.vacgom.persistence.vaccination.infrastructure;

import kr.co.vacgom.persistence.vaccination.entity.VaccinationEntity;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.UUID;

interface VaccinationJpaRepository extends JpaRepository<VaccinationEntity, UUID> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package kr.co.vacgom.persistence.vaccination.infrastructure;

import org.springframework.stereotype.Repository;

@Repository
class VaccinationQueryDslRepository {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package kr.co.vacgom.persistence.vaccination.infrastructure;

import kr.co.vacgom.persistence.vaccination.entity.VaccinationEntity;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface VaccinationRepository {

VaccinationEntity save(VaccinationEntity vaccination);

List<VaccinationEntity> saveAll(List<VaccinationEntity> vaccinations);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package kr.co.vacgom.persistence.vaccination.infrastructure;

import kr.co.vacgom.persistence.vaccination.entity.VaccinationEntity;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@RequiredArgsConstructor
class VaccinationRepositoryAdapter implements VaccinationRepository {

private final VaccinationQueryDslRepository vaccinationQueryDslRepository;
private final VaccinationJpaRepository vaccinationJpaRepository;

@Override
public VaccinationEntity save(VaccinationEntity vaccination) {
return null;
}

@Override
public List<VaccinationEntity> saveAll(List<VaccinationEntity> vaccinations) {
return List.of();
}
}

0 comments on commit 1c19176

Please sign in to comment.