Skip to content

Commit

Permalink
fix: resolve merge conlficts from dev branch
Browse files Browse the repository at this point in the history
  • Loading branch information
chock-cho committed Jan 17, 2025
2 parents 419b985 + b539ffa commit 7d01e56
Show file tree
Hide file tree
Showing 37 changed files with 549 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.dobby.backend.application.mapper

import com.dobby.backend.application.usecase.member.GetMyExperimentPostsUseCase
import com.dobby.backend.domain.model.experiment.Pagination

object MemberMapper {
fun toDomainPagination(pagination: GetMyExperimentPostsUseCase.PaginationInput): Pagination {
return Pagination(
page = pagination.page,
count = pagination.count
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.dobby.backend.application.usecase.member.email.EmailCodeSendUseCase
import com.dobby.backend.application.usecase.member.email.EmailVerificationUseCase
import com.dobby.backend.infrastructure.database.entity.VerificationEntity
import com.dobby.backend.infrastructure.database.entity.enums.VerificationStatus
import com.dobby.backend.presentation.api.dto.request.signup.EmailSendRequest
import com.dobby.backend.presentation.api.dto.request.member.EmailSendRequest

object VerificationMapper {
fun toEntity(req: EmailSendRequest, code : String): VerificationEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ExperimentPostService(
}

@Transactional
fun getExperimentPosts(input : GetExperimentPostsUseCase.Input): List<GetExperimentPostsUseCase.Output> {
fun getExperimentPosts(input: GetExperimentPostsUseCase.Input): List<GetExperimentPostsUseCase.Output> {
validateFilter(input)
return getExperimentPostsUseCase.execute(input)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.dobby.backend.application.service

import com.dobby.backend.application.usecase.member.GetMyExperimentPostTotalCountUseCase
import com.dobby.backend.application.usecase.member.*
import com.dobby.backend.domain.exception.SignupOauthEmailDuplicateException
import com.dobby.backend.domain.gateway.member.MemberGateway
import com.dobby.backend.infrastructure.database.entity.enums.MemberStatus
import jakarta.transaction.Transactional
import org.springframework.stereotype.Service
import java.security.InvalidParameterException

@Service
class MemberService(
Expand All @@ -14,7 +16,9 @@ class MemberService(
private val createResearcherUseCase: CreateResearcherUseCase,
private val verifyResearcherEmailUseCase: VerifyResearcherEmailUseCase,
private val getResearcherInfoUseCase: GetResearcherInfoUseCase,
private val getParticipantInfoUseCase: GetParticipantInfoUseCase
private val getParticipantInfoUseCase: GetParticipantInfoUseCase,
private val getMyExperimentPostsUseCase: GetMyExperimentPostsUseCase,
private val getMyExperimentPostTotalCountUseCase: GetMyExperimentPostTotalCountUseCase
) {
@Transactional
fun participantSignup(input: CreateParticipantUseCase.Input): CreateParticipantUseCase.Output {
Expand All @@ -38,4 +42,21 @@ class MemberService(
fun getParticipantInfo(input: GetParticipantInfoUseCase.Input): GetParticipantInfoUseCase.Output {
return getParticipantInfoUseCase.execute(input)
}

@Transactional
fun getMyExperimentPosts(input: GetMyExperimentPostsUseCase.Input): List<GetMyExperimentPostsUseCase.Output> {
validateSortOrder(input.pagination.order)
return getMyExperimentPostsUseCase.execute(input)
}

private fun validateSortOrder(sortOrder: String): String {
return when (sortOrder) {
"ASC", "DESC" -> sortOrder
else -> throw InvalidParameterException("Invalid sort order. Please use 'ASC' or 'DESC'")
}
}

fun getMyExperimentPostsCount(input: GetMyExperimentPostTotalCountUseCase.Input): GetMyExperimentPostTotalCountUseCase.Output {
return getMyExperimentPostTotalCountUseCase.execute(GetMyExperimentPostTotalCountUseCase.Input(input.memberId))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.dobby.backend.application.service

import org.springframework.stereotype.Service

@Service
class PaginationService {

fun isLastPage(totalElements: Int, pageSize: Int, currentPage: Int): Boolean {
return totalElements <= pageSize * currentPage
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class GetExperimentPostCountsByRegionUseCase(
override fun execute(input: Input): Output {
val total = experimentPostGateway.countExperimentPosts()

val allRegions = Region.values()
val allRegions = Region.values().filter { it != Region.NONE }
val regionData = experimentPostGateway.countExperimentPostGroupedByRegion()
val regionDataMap = regionData.associateBy { it.get(0, Region::class.java) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class GetExperimentPostsUseCase (
)

data class PostInfoOutput(
val postId: Long,
val experimentPostId: Long,
val title: String,
val views: Int,
val univName: String,
Expand All @@ -66,7 +66,7 @@ class GetExperimentPostsUseCase (
return posts?.map { post ->
Output(
postInfo = PostInfoOutput(
postId = post.id,
experimentPostId = post.id,
title = post.title,
views = post.views,
univName = post.univName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CreateParticipantUseCase (
val gender: GenderType,
val birthDate: LocalDate,
var basicAddressInfo: AddressInfo,
var additionalAddressInfo: AddressInfo?,
var additionalAddressInfo: AddressInfo,
var matchType: MatchType,
)
data class AddressInfo(
Expand Down Expand Up @@ -86,9 +86,10 @@ class CreateParticipantUseCase (
region = input.basicAddressInfo.region,
area = input.basicAddressInfo.area
),
additionalAddressInfo = input.additionalAddressInfo?.let {
Participant.AddressInfo(region = it.region, area = it.area)
},
additionalAddressInfo = Participant.AddressInfo(
region = input.additionalAddressInfo.region,
area = input.additionalAddressInfo.area
),
matchType = input.matchType
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class CreateResearcherUseCase(
val provider: ProviderType,
val contactEmail: String,
val univEmail : String,
val emailVerified: Boolean,
val univName: String,
val name : String,
val major: String,
Expand Down Expand Up @@ -74,7 +73,7 @@ class CreateResearcherUseCase(
member = member,
univEmail = input.univEmail,
univName = input.univName,
emailVerified = input.emailVerified,
emailVerified = true,
major = input.major,
labInfo = input.labInfo
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.dobby.backend.application.usecase.member

import com.dobby.backend.application.usecase.UseCase
import com.dobby.backend.domain.gateway.experiment.ExperimentPostGateway

class GetMyExperimentPostTotalCountUseCase(
private val experimentPostGateway: ExperimentPostGateway
): UseCase<GetMyExperimentPostTotalCountUseCase.Input, GetMyExperimentPostTotalCountUseCase.Output> {

data class Input(
val memberId: Long
)

data class Output(
val totalPostCount: Int
)

override fun execute(input: Input): Output {
val totalPostCount = experimentPostGateway.countExperimentPostsByMemberId(input.memberId)
return Output(totalPostCount = totalPostCount)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.dobby.backend.application.usecase.member

import com.dobby.backend.application.mapper.MemberMapper
import com.dobby.backend.application.usecase.UseCase
import com.dobby.backend.domain.gateway.experiment.ExperimentPostGateway
import java.time.LocalDate

class GetMyExperimentPostsUseCase(
private val experimentPostGateway: ExperimentPostGateway
): UseCase<GetMyExperimentPostsUseCase.Input, List<GetMyExperimentPostsUseCase.Output>> {

data class Input(
val memberId: Long,
val pagination: PaginationInput
)

data class PaginationInput(
val page: Int = 1,
val count: Int = 6,
val order: String = "DESC"
)

data class Output(
val experimentPostId: Long,
val title: String,
val content: String,
val views: Int,
val recruitDone: Boolean,
val uploadDate: LocalDate
)

override fun execute(input: Input): List<Output> {
val posts = experimentPostGateway.findExperimentPostsByMemberIdWithPagination(
memberId = input.memberId,
pagination = MemberMapper.toDomainPagination(input.pagination),
order = input.pagination.order
)

return posts?.map { post ->
Output(
experimentPostId = post.id,
title = post.title,
content = post.content,
views = post.views,
recruitDone = post.recruitDone,
uploadDate = post.createdAt.toLocalDate()
)
} ?: emptyList()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import java.time.LocalDate

interface ExperimentPostGateway {
fun save(experimentPost: ExperimentPost): ExperimentPost
fun findExperimentPostsByCustomFilter(
customFilter: CustomFilter, pagination:Pagination): List<ExperimentPost>?
fun findExperimentPostsByCustomFilter(customFilter: CustomFilter, pagination: Pagination): List<ExperimentPost>?
fun findById(experimentPostId: Long): ExperimentPost?
fun countExperimentPostsByRegion(region: Region): Int
fun countExperimentPosts(): Int
fun countExperimentPostByRegionGroupedByArea(region: Region): List<Tuple>
fun countExperimentPostGroupedByRegion(): List<Tuple>
fun updateExperimentPostStatus(todayDate : LocalDate) : Long
fun findExperimentPostsByMemberIdWithPagination(memberId: Long, pagination: Pagination, order: String): List<ExperimentPost>?
fun countExperimentPostsByMemberId(memberId: Long): Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data class Participant(
val gender: GenderType,
val birthDate: LocalDate,
val basicAddressInfo: AddressInfo,
val additionalAddressInfo: AddressInfo?,
val additionalAddressInfo: AddressInfo,
val matchType: MatchType?
) {

Expand All @@ -27,7 +27,7 @@ data class Participant(
gender: GenderType,
birthDate: LocalDate,
basicAddressInfo: AddressInfo,
additionalAddressInfo: AddressInfo?,
additionalAddressInfo: AddressInfo,
matchType: MatchType?
) = Participant(
id = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object ParticipantConverter {
gender = entity.gender,
birthDate = entity.birthDate,
basicAddressInfo = entity.basicAddressInfo.toModel(),
additionalAddressInfo = entity.additionalAddressInfo?.toModel(),
additionalAddressInfo = entity.additionalAddressInfo.toModel(),
matchType = entity.matchType
)
}
Expand All @@ -47,7 +47,7 @@ object ParticipantConverter {
birthDate = participant.birthDate,
matchType = participant.matchType,
basicAddressInfo = participant.basicAddressInfo.toEntity(),
additionalAddressInfo = participant.additionalAddressInfo?.toEntity()
additionalAddressInfo = participant.additionalAddressInfo.toEntity()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,10 @@ enum class Area (val region: Region, val displayName: String){

// 제주특별자치도
JEJU_SEOGWIPOSI(Region.JEJU, "JEJU_SEOGWIPOSI"),
JEJU_JEJUSI(Region.JEJU, "JEJU_JEJUSI");
JEJU_JEJUSI(Region.JEJU, "JEJU_JEJUSI"),

// 기본값
NONE(Region.NONE, "NONE"),;

companion object {
fun findByRegion(region : Region) : List<Area> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ enum class Region(val displayName: String) {
GWANGJU("GWANGJU"),
JEONNAM("JEONNAM"),
JEONBUK("JEONBUK"),
JEJU("JEJU");
JEJU("JEJU"),
NONE("NONE"),;

fun getAreas(): List<Area> {
return Area.findByRegion(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class ParticipantEntity (

@Embedded
@AttributeOverrides(
AttributeOverride(name = "region", column = Column(name = "optional_region", nullable = true)),
AttributeOverride(name = "area", column = Column(name = "optional_area", nullable = true))
AttributeOverride(name = "region", column = Column(name = "optional_region", nullable = false)),
AttributeOverride(name = "area", column = Column(name = "optional_area", nullable = false))
)
val additionalAddressInfo: AddressInfo?,
val additionalAddressInfo: AddressInfo,

@Column(name = "match_type", nullable = true)
@Enumerated(EnumType.STRING)
Expand All @@ -52,7 +52,7 @@ class ParticipantEntity (
gender = gender,
birthDate = birthDate,
basicAddressInfo = basicAddressInfo.toDomain(),
additionalAddressInfo = additionalAddressInfo?.toDomain(),
additionalAddressInfo = additionalAddressInfo.toDomain(),
matchType = matchType
)

Expand All @@ -63,8 +63,8 @@ class ParticipantEntity (
member = MemberEntity.fromDomain(member),
gender = gender,
birthDate = birthDate,
basicAddressInfo = AddressInfo.fromDomain(basicAddressInfo), // 수정: AddressInfo.fromDomain() 사용
additionalAddressInfo = additionalAddressInfo?.let { AddressInfo.fromDomain(it) }, // 수정
basicAddressInfo = AddressInfo.fromDomain(basicAddressInfo),
additionalAddressInfo = AddressInfo.fromDomain(additionalAddressInfo),
matchType = matchType
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ interface ExperimentPostCustomRepository {
): List<ExperimentPostEntity>?

fun updateExperimentPostStatus(currentDate : LocalDate): Long
fun findExperimentPostsByMemberIdWithPagination(
memberId: Long,
pagination: Pagination,
order: String
): List<ExperimentPostEntity>?
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Area.Comp
import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Region
import com.dobby.backend.infrastructure.database.entity.experiment.ExperimentPostEntity
import com.dobby.backend.infrastructure.database.entity.experiment.QExperimentPostEntity
import com.querydsl.core.types.OrderSpecifier
import com.querydsl.core.types.dsl.BooleanExpression
import com.querydsl.jpa.impl.JPAQueryFactory
import org.springframework.stereotype.Repository
Expand Down Expand Up @@ -41,6 +42,22 @@ class ExperimentPostCustomRepositoryImpl (
.fetch()
}

override fun findExperimentPostsByMemberIdWithPagination(
memberId: Long,
pagination: Pagination,
order: String
): List<ExperimentPostEntity>? {
val post = QExperimentPostEntity.experimentPostEntity

return jpaQueryFactory.selectFrom(post)
.join(post.member).fetchJoin()
.where(post.member.id.eq(memberId))
.offset((pagination.page - 1L) * pagination.count)
.limit(pagination.count.toLong())
.orderBy(getOrderClause(order))
.fetch()
}

private fun matchTypeEq(post: QExperimentPostEntity, matchType: MatchType?): BooleanExpression? {
return matchType?.let {
if(it == MatchType.ALL) null else post.matchType.eq(it)
Expand Down Expand Up @@ -83,4 +100,13 @@ class ExperimentPostCustomRepositoryImpl (
)
.execute()
}

private fun getOrderClause(order: String): OrderSpecifier<*> {
val post = QExperimentPostEntity.experimentPostEntity
return if (order == "ASC") {
post.createdAt.asc()
} else {
post.createdAt.desc()
}
}
}
Loading

0 comments on commit 7d01e56

Please sign in to comment.