Skip to content

Commit

Permalink
refactor(company): Using function for create dto (#39)
Browse files Browse the repository at this point in the history
* Using function for create dto

* fix syntax
  • Loading branch information
dojinyou authored Dec 14, 2024
1 parent 584ffa9 commit 055008f
Showing 1 changed file with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,40 @@ import com.threedays.oas.model.SearchCompaniesResponse
import com.threedays.support.common.base.domain.UUIDTypeId
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.RestController
import java.util.*
import java.util.UUID

@RestController
class CompaniesController (
private val companyQueryRepository: CompanyQueryRepository
): CompaniesApi {
class CompaniesController(
private val companyQueryRepository: CompanyQueryRepository,
) : CompaniesApi {

override fun searchCompanies(
name: String,
next: UUID?,
limit: Int
limit: Int,
): ResponseEntity<SearchCompaniesResponse> {
val (resultCompanies, resultNext) = companyQueryRepository.searchCompanies(
name = name,
next = next?.let { UUIDTypeId.from(it) },
limit = limit
)

val companyResponse = resultCompanies.map {
return ResponseEntity.ok(createSearchCompaniesResponse(resultCompanies, resultNext))
}

private fun createSearchCompaniesResponse(
companies: List<com.threedays.domain.user.entity.Company>,
nextID: com.threedays.domain.user.entity.Company.Id?,
): SearchCompaniesResponse {
val companyResponse = companies.map {
Company(
id = it.id.value,
name = it.name
)
}

return ResponseEntity.ok(
SearchCompaniesResponse(
companies = companyResponse,
next = resultNext?.value
)
return SearchCompaniesResponse(
companies = companyResponse,
next = nextID?.value
)
}

}

0 comments on commit 055008f

Please sign in to comment.