Skip to content

Commit

Permalink
�Merge: (#39) 진행 상황 저장 및 제거 API
Browse files Browse the repository at this point in the history
  • Loading branch information
alsdl0629 authored Nov 17, 2023
2 parents cf164a7 + 6f52571 commit 8e48322
Show file tree
Hide file tree
Showing 30 changed files with 492 additions and 118 deletions.
23 changes: 0 additions & 23 deletions src/main/kotlin/team/sfe/server/domain/disease/domain/Disease.kt

This file was deleted.

This file was deleted.

This file was deleted.

27 changes: 0 additions & 27 deletions src/main/kotlin/team/sfe/server/domain/person/domain/Person.kt

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,42 @@
package team.sfe.server.domain.progress.domain

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.JoinColumn
import jakarta.persistence.MapsId
import jakarta.persistence.OneToOne
import jakarta.validation.constraints.NotNull
import team.sfe.server.domain.progress.presentation.dto.Disease
import team.sfe.server.domain.user.domain.UserEntity
import team.sfe.server.global.entity.BaseIdEntity

@Entity
class DiseaseEntity(
override val id: Long = 0L,

@field:NotNull
@MapsId
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
val userEntity: UserEntity,

@field:NotNull
@Column(columnDefinition = "FLOAT")
val infectWeight: Float,

@field:NotNull
@Column(columnDefinition = "INT")
val infectivity: Int,

@field:NotNull
@Column(columnDefinition = "FLOAT")
val infectPower: Float
) : BaseIdEntity(id) {

fun toDiseaseDto() = Disease(
infectWeight = this.infectWeight,
infectivity = this.infectivity,
infectPower = this.infectPower
)
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
package team.sfe.server.domain.gameInfo.domain
package team.sfe.server.domain.progress.domain

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.JoinColumn
import jakarta.persistence.MapsId
import jakarta.persistence.OneToOne
import jakarta.validation.constraints.NotNull
import team.sfe.server.domain.user.domain.UserEntity
import team.sfe.server.global.entity.BaseIdEntity

@Entity
class GameInfo(
class GameInfoEntity(
override val id: Long = 0L,

@field:NotNull
@MapsId
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
val userEntity: UserEntity,

@field:NotNull
@Column(columnDefinition = "TINYINT(1)")
val diseaseEnable: Boolean,
val diseaseEnabled: Boolean,

@field:NotNull
@Column(columnDefinition = "TINYINT(1)")
val pcrEnable: Boolean,
val pcrEnabled: Boolean,

@field:NotNull
@Column(columnDefinition = "TINYINT(1)")
val kitEnable: Boolean,
val kitEnabled: Boolean,

@field:NotNull
@Column(columnDefinition = "INT")
val kitChance: Int,

@field:NotNull
@Column(columnDefinition = "TINYINT(1)")
val vaccineReserch: Boolean,
val vaccineResearch: Boolean,

@field:NotNull
@Column(columnDefinition = "TINYINT(1)")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package team.sfe.server.domain.personData.domain
package team.sfe.server.domain.progress.domain

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import jakarta.persistence.FetchType
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.validation.constraints.NotNull
import team.sfe.server.domain.personData.domain.type.SymptomType
import team.sfe.server.domain.user.domain.User
import team.sfe.server.domain.progress.domain.type.SymptomType
import team.sfe.server.domain.progress.presentation.dto.PersonData
import team.sfe.server.domain.user.domain.UserEntity
import team.sfe.server.global.entity.BaseIdEntity

@Entity
class PersonData(

class PersonDataEntity(
override val id: Long = 0L,

@field:NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
val user: User,
val userEntity: UserEntity,

@field:NotNull
@Column(columnDefinition = "INT")
Expand All @@ -29,6 +31,7 @@ class PersonData(
val isInfected: Boolean,

@field:NotNull
@Enumerated(EnumType.STRING)
@Column(columnDefinition = "VARCHAR(10)")
val symptomType: SymptomType,

Expand All @@ -39,4 +42,13 @@ class PersonData(
@field:NotNull
@Column(columnDefinition = "FLOAT")
val recoverWeight: Float
) : BaseIdEntity(id)
) : BaseIdEntity(id) {

fun toPersonDataDto() = PersonData(
catchDate = this.catchData,
isInfected = this.isInfected,
symptomType = this.symptomType,
deathWeight = this.deathWeight,
recoverWeight = this.recoverWeight
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package team.sfe.server.domain.progress.domain

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.JoinColumn
import jakarta.persistence.MapsId
import jakarta.persistence.OneToOne
import jakarta.validation.constraints.NotNull
import team.sfe.server.domain.progress.presentation.dto.Person
import team.sfe.server.domain.user.domain.UserEntity
import team.sfe.server.global.entity.BaseIdEntity

@Entity
class PersonEntity(
override val id: Long = 0L,

@field:NotNull
@MapsId
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
val userEntity: UserEntity,

@field:NotNull
@Column(columnDefinition = "INT")
val totalPerson: Int,

@field:NotNull
@Column(columnDefinition = "INT")
val healthyPerson: Int,

@field:NotNull
@Column(columnDefinition = "INT")
val deathPerson: Int,

@field:NotNull
@Column(columnDefinition = "INT")
val infectedPerson: Int
) : BaseIdEntity(id) {

fun toPersonDto() = Person(
totalPerson = this.totalPerson,
healthyPerson = this.healthyPerson,
deathPerson = this.deathPerson,
infectedPerson = this.infectedPerson
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package team.sfe.server.domain.progress.domain

import com.querydsl.core.group.GroupBy.groupBy
import com.querydsl.core.group.GroupBy.list
import com.querydsl.jpa.impl.JPAQueryFactory
import org.springframework.stereotype.Repository
import team.sfe.server.domain.progress.domain.QDiseaseEntity.diseaseEntity
import team.sfe.server.domain.progress.domain.QGameInfoEntity.gameInfoEntity
import team.sfe.server.domain.progress.domain.QPersonDataEntity.personDataEntity
import team.sfe.server.domain.progress.domain.QPersonEntity.personEntity
import team.sfe.server.domain.progress.domain.vo.QQueryProgressVO
import team.sfe.server.domain.progress.domain.vo.QueryProgressVO
import team.sfe.server.domain.user.domain.QUserEntity.userEntity

@Repository
class ProgressRepository(
private val jpaQueryFactory: JPAQueryFactory
) {

fun queryProgress(userId: Long): QueryProgressVO? {
return jpaQueryFactory
.selectFrom(userEntity)
.join(diseaseEntity.userEntity, userEntity)
.join(gameInfoEntity.userEntity, userEntity)
.join(personDataEntity.userEntity, userEntity)
.join(personEntity.userEntity, userEntity)
.where(userEntity.id.eq(userId))
.transform(
groupBy(userEntity.id).list(
QQueryProgressVO(
diseaseEntity,
gameInfoEntity,
list(personDataEntity),
personEntity
)
)
)[0]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package team.sfe.server.domain.progress.domain.repository

import org.springframework.data.repository.CrudRepository
import team.sfe.server.domain.progress.domain.DiseaseEntity
import team.sfe.server.domain.user.domain.UserEntity

interface DiseaseRepository : CrudRepository<DiseaseEntity, Long> {

fun findByUserEntity(userEntity: UserEntity): DiseaseEntity?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package team.sfe.server.domain.progress.domain.repository

import org.springframework.data.repository.CrudRepository
import team.sfe.server.domain.progress.domain.GameInfoEntity
import team.sfe.server.domain.user.domain.UserEntity

interface GameInfoRepository : CrudRepository<GameInfoEntity, Long> {

fun findByUserEntity(userEntity: UserEntity): GameInfoEntity?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package team.sfe.server.domain.progress.domain.repository

import org.springframework.data.repository.CrudRepository
import team.sfe.server.domain.progress.domain.PersonDataEntity
import team.sfe.server.domain.user.domain.UserEntity

interface PersonDataRepository : CrudRepository<PersonDataEntity, Long> {

fun findAllByUserEntity(userEntity: UserEntity): List<PersonDataEntity>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package team.sfe.server.domain.progress.domain.repository

import org.springframework.data.repository.CrudRepository
import team.sfe.server.domain.progress.domain.PersonEntity
import team.sfe.server.domain.user.domain.UserEntity

interface PersonRepository : CrudRepository<PersonEntity, Long> {

fun findByUserEntity(userEntity: UserEntity): PersonEntity?
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package team.sfe.server.domain.personData.domain.type
package team.sfe.server.domain.progress.domain.type

enum class SymptomType {
Nothing,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package team.sfe.server.domain.progress.domain.vo

import com.querydsl.core.annotations.QueryProjection
import team.sfe.server.domain.progress.domain.DiseaseEntity
import team.sfe.server.domain.progress.domain.GameInfoEntity
import team.sfe.server.domain.progress.domain.PersonDataEntity
import team.sfe.server.domain.progress.domain.PersonEntity

data class QueryProgressVO @QueryProjection constructor(
val diseaseEntity: DiseaseEntity,
val gameInfoEntity: GameInfoEntity,
val personDataEntity: List<PersonDataEntity>,
val personEntity: PersonEntity
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package team.sfe.server.domain.progress.exception

import team.sfe.server.global.error.CustomException

object ProgressNotFoundException : CustomException(404, "게임 진행 상황을 찾지 못했습니다.")
Loading

0 comments on commit 8e48322

Please sign in to comment.