Skip to content

Commit

Permalink
[YS-197] refact: 실험자 마이페이지 실험 공고 관련 API URI 변경 (#53)
Browse files Browse the repository at this point in the history
* refact: move updateExperimentPostRecruitStatus API from member to experiment-posts

* refact: move getMyExperimentPosts API from member to experiment-posts

* refact: delete unused import code

* refact: rename usecase name

* refact: rename pagination mapper name

* refact: refact toExperimentPostResponse mapper code
  • Loading branch information
Ji-soo708 authored Jan 23, 2025
1 parent 64df291 commit 1610779
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 156 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.dobby.backend.application.mapper

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

object MemberMapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import com.dobby.backend.application.usecase.experiment.*
import com.dobby.backend.application.usecase.experiment.CreateExperimentPostUseCase
import com.dobby.backend.application.usecase.experiment.GetExperimentPostApplyMethodUseCase
import com.dobby.backend.application.usecase.experiment.GetExperimentPostDetailUseCase
import com.dobby.backend.application.usecase.experiment.GetMyExperimentPostTotalCountUseCase
import com.dobby.backend.application.usecase.experiment.GetMyExperimentPostsUseCase
import com.dobby.backend.domain.exception.ExperimentAreaInCorrectException
import com.dobby.backend.domain.exception.ExperimentAreaOverflowException
import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Area
import jakarta.transaction.Transactional
import org.springframework.stereotype.Service
import java.security.InvalidParameterException

@Service
class ExperimentPostService(
Expand All @@ -22,8 +25,11 @@ class ExperimentPostService(
private val getExperimentPostApplyMethodUseCase: GetExperimentPostApplyMethodUseCase,
private val generateExperimentPostPreSignedUrlUseCase: GenerateExperimentPostPreSignedUrlUseCase,
private val updateExpiredExperimentPostUseCase: UpdateExpiredExperimentPostUseCase,
private val deleteExperimentPostUseCase: DeleteExperimentPostUseCase,
private val updateExperimentPostRecruitStatusUseCase: UpdateExperimentPostRecruitStatusUseCase,
private val getExperimentPostTotalCountByCustomFilterUseCase: GetExperimentPostTotalCountByCustomFilterUseCase,
private val deleteExperimentPostUseCase: DeleteExperimentPostUseCase
private val getMyExperimentPostsUseCase: GetMyExperimentPostsUseCase,
private val getMyExperimentPostTotalCountUseCase: GetMyExperimentPostTotalCountUseCase,
) {
@Transactional
fun createNewExperimentPost(input: CreateExperimentPostUseCase.Input): CreateExperimentPostUseCase.Output {
Expand Down Expand Up @@ -56,6 +62,11 @@ class ExperimentPostService(
return updateExpiredExperimentPostUseCase.execute(input)
}

@Transactional
fun updateExperimentPostRecruitStatus(input: UpdateExperimentPostRecruitStatusUseCase.Input): UpdateExperimentPostRecruitStatusUseCase.Output {
return updateExperimentPostRecruitStatusUseCase.execute(input)
}

fun getExperimentPostCounts(input: Any): Any {
return when (input) {
is GetExperimentPostCountsByRegionUseCase.Input -> getExperimentPostCountsByRegionUseCase.execute(input)
Expand Down Expand Up @@ -91,6 +102,23 @@ class ExperimentPostService(
return getExperimentPostTotalCountByCustomFilterUseCase.execute(input)
}

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

fun getMyExperimentPostsCount(input: GetMyExperimentPostTotalCountUseCase.Input): GetMyExperimentPostTotalCountUseCase.Output {
return getMyExperimentPostTotalCountUseCase.execute(GetMyExperimentPostTotalCountUseCase.Input(input.memberId))
}

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

@Transactional
fun deleteExperimentPost(input: DeleteExperimentPostUseCase.Input) {
deleteExperimentPostUseCase.execute(input)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
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 @@ -17,9 +15,6 @@ class MemberService(
private val verifyResearcherEmailUseCase: VerifyResearcherEmailUseCase,
private val getResearcherInfoUseCase: GetResearcherInfoUseCase,
private val getParticipantInfoUseCase: GetParticipantInfoUseCase,
private val getMyExperimentPostsUseCase: GetMyExperimentPostsUseCase,
private val getMyExperimentPostTotalCountUseCase: GetMyExperimentPostTotalCountUseCase,
private val updateMyExperimentPostRecruitStatusUseCase: UpdateMyExperimentPostRecruitStatusUseCase
) {
@Transactional
fun participantSignup(input: CreateParticipantUseCase.Input): CreateParticipantUseCase.Output {
Expand All @@ -43,26 +38,4 @@ 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))
}

@Transactional
fun updateMyExperimentPostRecruitStatus(input: UpdateMyExperimentPostRecruitStatusUseCase.Input): UpdateMyExperimentPostRecruitStatusUseCase.Output {
return updateMyExperimentPostRecruitStatusUseCase.execute(input)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dobby.backend.application.usecase.member
package com.dobby.backend.application.usecase.experiment

import com.dobby.backend.application.usecase.UseCase
import com.dobby.backend.domain.gateway.experiment.ExperimentPostGateway
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dobby.backend.application.usecase.member
package com.dobby.backend.application.usecase.experiment

import com.dobby.backend.application.mapper.MemberMapper
import com.dobby.backend.application.usecase.UseCase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dobby.backend.application.usecase.member
package com.dobby.backend.application.usecase.experiment

import com.dobby.backend.application.usecase.UseCase
import com.dobby.backend.domain.exception.ExperimentPostNotFoundException
Expand All @@ -7,9 +7,9 @@ import com.dobby.backend.domain.gateway.experiment.ExperimentPostGateway
import com.dobby.backend.domain.model.experiment.ExperimentPost
import java.time.LocalDateTime

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

data class Input(
val memberId: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.dobby.backend.presentation.api.dto.response.experiment.ExperimentPost
import com.dobby.backend.presentation.api.dto.response.experiment.ExperimentPostCountsResponse
import com.dobby.backend.presentation.api.dto.response.experiment.ExperimentPostDetailResponse
import com.dobby.backend.presentation.api.dto.response.member.DefaultResponse
import com.dobby.backend.presentation.api.dto.response.member.MyExperimentPostResponse
import com.dobby.backend.presentation.api.mapper.ExperimentPostMapper
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
Expand Down Expand Up @@ -46,6 +47,20 @@ class ExperimentPostController (
return ExperimentPostMapper.toCreateExperimentPostResponse(output)
}

@PreAuthorize("hasRole('RESEARCHER')")
@PatchMapping("/{postId}/recruit-status")
@Operation(
summary = "연구자가 작성한 특정 실험 공고 모집 상태 수정",
description = "로그인한 연구자가 작성한 특정 실험 공고의 모집 상태를 변경합니다"
)
fun updateExperimentPostRecruitStatus(
@PathVariable postId: Long
): MyExperimentPostResponse {
val input = ExperimentPostMapper.toUpdateExperimentPostRecruitStatusUseCaseInput(postId)
val output = experimentPostService.updateExperimentPostRecruitStatus(input)
return ExperimentPostMapper.toExperimentPostResponse(output)
}

@PreAuthorize("hasRole('RESEARCHER')")
@DeleteMapping("/{postId}")
@Operation(
Expand Down Expand Up @@ -145,7 +160,7 @@ class ExperimentPostController (
@RequestParam(defaultValue = "6") count: Int
): PaginatedResponse<ExperimentPostResponse> {
val customFilter = ExperimentPostMapper.toUseCaseCustomFilter(matchType, gender, age, region, areas, recruitStatus)
val pagination = ExperimentPostMapper.toUseCasePagination(page, count)
val pagination = ExperimentPostMapper.toGetExperimentPostsUseCasePagination(page, count)
val input = ExperimentPostMapper.toGetExperimentPostsUseCaseInput(customFilter, pagination)
val posts = experimentPostService.getExperimentPosts(input)

Expand All @@ -154,4 +169,25 @@ class ExperimentPostController (
val isLast = paginationService.isLastPage(totalCount, page, count)
return ExperimentPostMapper.toGetExperimentPostsResponse(posts, page, totalCount, isLast)
}

@PreAuthorize("hasRole('RESEARCHER')")
@GetMapping("/my-posts")
@Operation(
summary = "연구자가 작성한 실험 공고 리스트 조회",
description = "로그인한 연구자가 작성한 실험 공고 리스트를 반환합니다"
)
fun getMyExperimentPosts(
@RequestParam(defaultValue = "1") page: Int,
@RequestParam(defaultValue = "6") count: Int,
@RequestParam(defaultValue = "DESC") order: String
): PaginatedResponse<MyExperimentPostResponse> {
val pagination = ExperimentPostMapper.toGetMyExperimentPostsUseCasePagination(page, count, order)
val input = ExperimentPostMapper.toGetMyExperimentPosts(pagination)
val posts = experimentPostService.getMyExperimentPosts(input)

val totalCountInput = ExperimentPostMapper.toGetTotalMyExperimentPostCountUseCaseInput()
val totalCount = experimentPostService.getMyExperimentPostsCount(totalCountInput).totalPostCount
val isLast = paginationService.isLastPage(totalCount, count, page)
return ExperimentPostMapper.toGetMyExperimentPostsResponse(posts, page, totalCount, isLast)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.dobby.backend.presentation.api.controller

import com.dobby.backend.application.service.MemberService
import com.dobby.backend.application.service.PaginationService
import com.dobby.backend.presentation.api.dto.response.PaginatedResponse
import com.dobby.backend.presentation.api.dto.response.member.MyExperimentPostResponse
import com.dobby.backend.presentation.api.dto.request.member.ParticipantSignupRequest
import com.dobby.backend.presentation.api.dto.request.member.ResearcherSignupRequest
import com.dobby.backend.presentation.api.dto.response.member.ParticipantInfoResponse
Expand Down Expand Up @@ -75,39 +73,4 @@ class MemberController(
val output = memberService.getParticipantInfo(input)
return MemberMapper.toParticipantInfoResponse(output)
}

@PreAuthorize("hasRole('RESEARCHER')")
@GetMapping("/researchers/me/experiment-posts")
@Operation(
summary = "연구자가 작성한 실험 공고 리스트 조회",
description = "로그인한 연구자가 작성한 실험 공고 리스트를 반환합니다"
)
fun getMyExperimentPosts(
@RequestParam(defaultValue = "1") page: Int,
@RequestParam(defaultValue = "6") count: Int,
@RequestParam(defaultValue = "DESC") order: String
): PaginatedResponse<MyExperimentPostResponse> {
val pagination = MemberMapper.toUseCasePagination(page, count, order)
val input = MemberMapper.toGetMyExperimentPosts(pagination)
val posts = memberService.getMyExperimentPosts(input)

val totalCountInput = MemberMapper.toGetTotalMyExperimentPostCountUseCaseInput()
val totalCount = memberService.getMyExperimentPostsCount(totalCountInput).totalPostCount
val isLast = paginationService.isLastPage(totalCount, count, page)
return MemberMapper.toGetMyExperimentPostsResponse(posts, page, totalCount, isLast)
}

@PreAuthorize("hasRole('RESEARCHER')")
@PatchMapping("/researchers/me/experiment-posts/{postId}/recruit-status")
@Operation(
summary = "연구자가 작성한 특정 실험 공고 모집 상태 수정",
description = "로그인한 연구자가 작성한 특정 실험 공고의 모집 상태를 변경합니다"
)
fun updateMyExperimentPostRecruitStatus(
@PathVariable postId: Long
): MyExperimentPostResponse {
val input = MemberMapper.toUpdateMyExperimentPostRecruitStatusUseCaseInput(postId)
val output = memberService.updateMyExperimentPostRecruitStatus(input)
return MemberMapper.toMyExperimentPostResponse(output)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.dobby.backend.infrastructure.database.entity.enums.experiment.Recruit
import com.dobby.backend.presentation.api.dto.request.experiment.*
import com.dobby.backend.presentation.api.dto.response.PaginatedResponse
import com.dobby.backend.presentation.api.dto.response.experiment.*
import com.dobby.backend.presentation.api.dto.response.member.MyExperimentPostResponse
import com.dobby.backend.util.getCurrentMemberId
import com.dobby.backend.util.getCurrentMemberIdOrNull

Expand Down Expand Up @@ -252,7 +253,7 @@ object ExperimentPostMapper {
)
}

fun toUseCasePagination(
fun toGetExperimentPostsUseCasePagination(
page: Int, count: Int
) : GetExperimentPostsUseCase.PaginationInput {
return GetExperimentPostsUseCase.PaginationInput(
Expand Down Expand Up @@ -294,7 +295,7 @@ object ExperimentPostMapper {
),
recruitStatus = post.postInfo.recruitStatus
)
},
},
page = page,
size = output.size,
totalCount = totalCount,
Expand Down Expand Up @@ -339,4 +340,72 @@ object ExperimentPostMapper {
postId = postId
)
}

fun toUpdateExperimentPostRecruitStatusUseCaseInput(postId: Long): UpdateExperimentPostRecruitStatusUseCase.Input {
return UpdateExperimentPostRecruitStatusUseCase.Input(
memberId = getCurrentMemberId(),
postId = postId
)
}

fun toExperimentPostResponse(output: UpdateExperimentPostRecruitStatusUseCase.Output): MyExperimentPostResponse {
return MyExperimentPostResponse(
experimentPostId = output.experimentPost.id,
title = output.experimentPost.title,
content = output.experimentPost.content,
views = output.experimentPost.views,
recruitStatus = output.experimentPost.recruitStatus,
uploadDate = output.experimentPost.createdAt.toLocalDate()
)
}

fun toGetMyExperimentPostsResponse(
output: List<GetMyExperimentPostsUseCase.Output>,
page: Int,
totalCount: Int,
isLast: Boolean
): PaginatedResponse<MyExperimentPostResponse> {
return PaginatedResponse(
content = output.map { post ->
MyExperimentPostResponse(
experimentPostId = post.experimentPostId,
title = post.title,
content = post.content,
views = post.views,
recruitStatus = post.recruitStatus,
uploadDate = post.uploadDate
)
},
page = page,
size = output.size,
totalCount = totalCount,
isLast = isLast
)
}

fun toGetMyExperimentPosts(
pagination: GetMyExperimentPostsUseCase.PaginationInput
): GetMyExperimentPostsUseCase.Input {
return GetMyExperimentPostsUseCase.Input(
memberId = getCurrentMemberId(),
pagination = pagination
)
}


fun toGetTotalMyExperimentPostCountUseCaseInput(): GetMyExperimentPostTotalCountUseCase.Input {
return GetMyExperimentPostTotalCountUseCase.Input(
memberId = getCurrentMemberId()
)
}

fun toGetMyExperimentPostsUseCasePagination(
page: Int, count: Int, order: String
) : GetMyExperimentPostsUseCase.PaginationInput {
return GetMyExperimentPostsUseCase.PaginationInput(
page = page,
count = count,
order = order
)
}
}
Loading

0 comments on commit 1610779

Please sign in to comment.