Skip to content

Commit

Permalink
feat : JD 조회 application 계층 생성, SliceResponse 생성(#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
isprogrammingfun committed May 19, 2024
1 parent c6801a2 commit 15c3ef6
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.bamyanggang.apimodule.common.dto

import com.bamyanggang.domainmodule.common.pagination.SliceDomain

data class SliceResponse<T>(
val content: List<T>,
val page: Int,
val size: Int,
val hasNext: Boolean
) {
companion object {
fun <T> from(slice: SliceDomain<T>): SliceResponse<T> {
return SliceResponse(
content = slice.content,
page = slice.pageNumber,
size = slice.pageSize,
hasNext = slice.hasNext
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.bamyanggang.apimodule.domain.jobDescription.application.dto

import com.bamyanggang.domainmodule.domain.jobDescription.enums.WriteStatus
import java.time.LocalDateTime
import java.util.UUID

class GetJobDescriptionInfo {

data class Response(
val jobDescriptionId: UUID,
val remainingDate: Int,
val enterpriseName: String,
val title: String,
val writeStatus: WriteStatus,
val createdAt: LocalDateTime,
val startedAt: LocalDateTime,
val endedAt: LocalDateTime,
)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.bamyanggang.apimodule.domain.jobDescription.application.service

import com.bamyanggang.apimodule.common.dto.SliceResponse
import com.bamyanggang.apimodule.common.getAuthenticationPrincipal
import com.bamyanggang.apimodule.domain.jobDescription.application.dto.GetJobDescriptionInfo
import com.bamyanggang.domainmodule.common.pagination.SliceDomain
import com.bamyanggang.domainmodule.domain.jobDescription.enums.SortType
import com.bamyanggang.domainmodule.domain.jobDescription.enums.WriteStatus
import com.bamyanggang.domainmodule.domain.jobDescription.service.ApplyReader
import com.bamyanggang.domainmodule.domain.jobDescription.service.JobDescriptionReader
import org.springframework.data.domain.Pageable
import org.springframework.data.domain.SliceImpl
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional


@Service
class JobDescriptionInfoGetService(
private val jobDescriptionReader: JobDescriptionReader,
private val applyReader: ApplyReader
) {

@Transactional(readOnly = true)
fun getJobDescriptionInfo(pageable: Pageable, writeStatus: WriteStatus?, sortType: SortType?): SliceResponse<GetJobDescriptionInfo.Response> {
return getAuthenticationPrincipal().let{ userId ->
val jobDescriptions = jobDescriptionReader.readJobDescriptionByUserIdAndSortType(userId, pageable.pageNumber, pageable.pageSize, sortType)

val jobDescriptionInfoResponses = jobDescriptions.content.map{ jobDescription ->
val apply = applyReader.readApplyByJobDescriptionId(jobDescription.id)
GetJobDescriptionInfo.Response(
jobDescription.id,
jobDescription.getRemainingDate(),
jobDescription.enterpriseName,
jobDescription.title,
apply?.writeStatus?: WriteStatus.NOT_APPLIED,
jobDescription.createdAt,
jobDescription.startedAt,
jobDescription.endedAt
)
}

val jobDescriptionsSlice = SliceDomain(jobDescriptionInfoResponses, jobDescriptions.pageNumber, jobDescriptions.pageSize, jobDescriptions.hasNext)
SliceResponse.from(jobDescriptionsSlice)
}
}


}

0 comments on commit 15c3ef6

Please sign in to comment.