Skip to content

Commit

Permalink
Merge pull request #319 from catenax-ng/feat/api-model_rename_dtos_step3
Browse files Browse the repository at this point in the history
Feat/api model rename dtos step3
  • Loading branch information
nicoprow authored Jul 7, 2023
2 parents dd37b1e + adea00b commit 7c45439
Show file tree
Hide file tree
Showing 72 changed files with 362 additions and 344 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package org.eclipse.tractusx.bpdm.common.dto.response
import io.swagger.v3.oas.annotations.media.Schema

@Schema(description = "Paginated collection of results")
data class PageResponse<T>(
data class PageDto<T>(

@get:Schema(description = "Total number of all results in all pages")
val totalElements: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.responses.ApiResponses
import jakarta.validation.Valid
import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
import org.eclipse.tractusx.bpdm.common.dto.response.PageResponse
import org.eclipse.tractusx.bpdm.common.dto.response.PageDto
import org.eclipse.tractusx.bpdm.gate.api.model.request.AddressGateInputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.request.AddressGateOutputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.response.AddressGateInputResponse
Expand Down Expand Up @@ -93,7 +93,7 @@ interface GateAddressApi {
fun getAddressesByExternalIds(
@ParameterObject @Valid paginationRequest: PaginationRequest,
@RequestBody externalIds: Collection<String>
): PageResponse<AddressGateInputResponse>
): PageDto<AddressGateInputResponse>


@Operation(
Expand All @@ -108,7 +108,7 @@ interface GateAddressApi {
)
@GetMapping("/input/addresses")
@GetExchange("/input/addresses")
fun getAddresses(@ParameterObject @Valid paginationRequest: PaginationRequest): PageResponse<AddressGateInputResponse>
fun getAddresses(@ParameterObject @Valid paginationRequest: PaginationRequest): PageDto<AddressGateInputResponse>

@Operation(
summary = "Get page of addresses (Output)",
Expand All @@ -125,7 +125,7 @@ interface GateAddressApi {
fun getAddressesOutput(
@ParameterObject @Valid paginationRequest: PaginationRequest,
@RequestBody(required = false) externalIds: Collection<String>?
): PageResponse<AddressGateOutputDto>
): PageDto<AddressGateOutputDto>

@Operation(
summary = "Create or update output addresses.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.responses.ApiResponses
import jakarta.validation.Valid
import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
import org.eclipse.tractusx.bpdm.common.dto.response.PageResponse
import org.eclipse.tractusx.bpdm.common.dto.response.PageDto
import org.eclipse.tractusx.bpdm.gate.api.model.request.LegalEntityGateInputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.request.LegalEntityGateOutputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.response.LegalEntityGateInputDto
Expand Down Expand Up @@ -90,7 +90,7 @@ interface GateLegalEntityApi {
fun getLegalEntitiesByExternalIds(
@ParameterObject @Valid paginationRequest: PaginationRequest,
@RequestBody externalIds: Collection<String>
): PageResponse<LegalEntityGateInputDto>
): PageDto<LegalEntityGateInputDto>

@Operation(
summary = "Get page of legal entities",
Expand All @@ -104,7 +104,7 @@ interface GateLegalEntityApi {
)
@GetMapping("/input/legal-entities")
@GetExchange("/input/legal-entities")
fun getLegalEntities(@ParameterObject @Valid paginationRequest: PaginationRequest): PageResponse<LegalEntityGateInputDto>
fun getLegalEntities(@ParameterObject @Valid paginationRequest: PaginationRequest): PageDto<LegalEntityGateInputDto>

@Operation(
summary = "Get page of legal entities",
Expand All @@ -121,7 +121,7 @@ interface GateLegalEntityApi {
fun getLegalEntitiesOutput(
@ParameterObject @Valid paginationRequest: PaginationRequest,
@RequestBody(required = false) externalIds: Collection<String>?
): PageResponse<LegalEntityGateOutputResponse>
): PageDto<LegalEntityGateOutputResponse>

@Operation(
summary = "Create or update output legal entities.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.responses.ApiResponses
import jakarta.validation.Valid
import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
import org.eclipse.tractusx.bpdm.common.dto.response.PageResponse
import org.eclipse.tractusx.bpdm.common.dto.response.PageDto
import org.eclipse.tractusx.bpdm.gate.api.model.LsaType
import org.eclipse.tractusx.bpdm.gate.api.model.response.SharingStateDto
import org.springdoc.core.annotations.ParameterObject
Expand Down Expand Up @@ -54,7 +54,7 @@ interface GateSharingStateApi {
@ParameterObject @Valid paginationRequest: PaginationRequest,
@Parameter(description = "LSA Type") @RequestParam(required = false) lsaType: LsaType?,
@Parameter(description = "External identifiers") @RequestParam(required = false) externalIds: Collection<String>?
): PageResponse<SharingStateDto>
): PageDto<SharingStateDto>

@Operation(
summary = "Insert/update sharing state (including error info and BPN) for business partner with LSA type and external ID"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.responses.ApiResponses
import jakarta.validation.Valid
import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
import org.eclipse.tractusx.bpdm.common.dto.response.PageResponse
import org.eclipse.tractusx.bpdm.common.dto.response.PageDto
import org.eclipse.tractusx.bpdm.gate.api.model.request.SiteGateInputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.request.SiteGateOutputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.response.SiteGateInputDto
Expand Down Expand Up @@ -90,7 +90,7 @@ interface GateSiteApi {
fun getSitesByExternalIds(
@ParameterObject @Valid paginationRequest: PaginationRequest,
@RequestBody externalIds: Collection<String>
): PageResponse<SiteGateInputDto>
): PageDto<SiteGateInputDto>

@Operation(
summary = "Get page of sites",
Expand All @@ -104,7 +104,7 @@ interface GateSiteApi {
)
@GetMapping("/input/sites")
@GetExchange("/input/sites")
fun getSites(@ParameterObject @Valid paginationRequest: PaginationRequest): PageResponse<SiteGateInputDto>
fun getSites(@ParameterObject @Valid paginationRequest: PaginationRequest): PageDto<SiteGateInputDto>

@Operation(
summary = "Get page of sites",
Expand All @@ -121,7 +121,7 @@ interface GateSiteApi {
fun getSitesOutput(
@ParameterObject @Valid paginationRequest: PaginationRequest,
@RequestBody(required = false) externalIds: Collection<String>?
): PageResponse<SiteGateOutputResponse>
): PageDto<SiteGateOutputResponse>

@Operation(
summary = "Create or update output sites.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.eclipse.tractusx.bpdm.gate.controller

import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
import org.eclipse.tractusx.bpdm.common.dto.response.PageResponse
import org.eclipse.tractusx.bpdm.common.dto.response.PageDto
import org.eclipse.tractusx.bpdm.gate.api.GateAddressApi
import org.eclipse.tractusx.bpdm.gate.api.model.request.AddressGateInputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.request.AddressGateOutputRequest
Expand Down Expand Up @@ -67,20 +67,20 @@ class AddressController(
override fun getAddressesByExternalIds(
paginationRequest: PaginationRequest,
externalIds: Collection<String>
): PageResponse<AddressGateInputResponse> {
): PageDto<AddressGateInputResponse> {
return addressService.getAddresses(page = paginationRequest.page, size = paginationRequest.size, externalIds = externalIds)
}

@PreAuthorize("hasAuthority(@gateSecurityConfigProperties.getReadCompanyInputDataAsRole())")
override fun getAddresses(paginationRequest: PaginationRequest): PageResponse<AddressGateInputResponse> {
override fun getAddresses(paginationRequest: PaginationRequest): PageDto<AddressGateInputResponse> {
return addressService.getAddresses(page = paginationRequest.page, size = paginationRequest.size)
}

@PreAuthorize("hasAuthority(@gateSecurityConfigProperties.getReadCompanyOutputDataAsRole())")
override fun getAddressesOutput(
paginationRequest: PaginationRequest,
externalIds: Collection<String>?
): PageResponse<AddressGateOutputDto> {
): PageDto<AddressGateOutputDto> {
return addressService.getAddressesOutput(externalIds = externalIds, page = paginationRequest.page, size = paginationRequest.size)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.eclipse.tractusx.bpdm.gate.controller

import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
import org.eclipse.tractusx.bpdm.common.dto.response.PageResponse
import org.eclipse.tractusx.bpdm.common.dto.response.PageDto
import org.eclipse.tractusx.bpdm.gate.api.GateLegalEntityApi
import org.eclipse.tractusx.bpdm.gate.api.model.request.LegalEntityGateInputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.request.LegalEntityGateOutputRequest
Expand Down Expand Up @@ -57,20 +57,20 @@ class LegalEntityController(
override fun getLegalEntitiesByExternalIds(
paginationRequest: PaginationRequest,
externalIds: Collection<String>
): PageResponse<LegalEntityGateInputDto> {
): PageDto<LegalEntityGateInputDto> {
return legalEntityService.getLegalEntities(page = paginationRequest.page, size = paginationRequest.size, externalIds = externalIds)
}

@PreAuthorize("hasAuthority(@gateSecurityConfigProperties.getReadCompanyInputDataAsRole())")
override fun getLegalEntities(paginationRequest: PaginationRequest): PageResponse<LegalEntityGateInputDto> {
override fun getLegalEntities(paginationRequest: PaginationRequest): PageDto<LegalEntityGateInputDto> {
return legalEntityService.getLegalEntities(page = paginationRequest.page, size = paginationRequest.size)
}

@PreAuthorize("hasAuthority(@gateSecurityConfigProperties.getReadCompanyOutputDataAsRole())")
override fun getLegalEntitiesOutput(
paginationRequest: PaginationRequest,
externalIds: Collection<String>?
): PageResponse<LegalEntityGateOutputResponse> {
): PageDto<LegalEntityGateOutputResponse> {
return legalEntityService.getLegalEntitiesOutput(externalIds = externalIds, page = paginationRequest.page, size = paginationRequest.size)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package org.eclipse.tractusx.bpdm.gate.controller

import mu.KotlinLogging
import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
import org.eclipse.tractusx.bpdm.common.dto.response.PageResponse
import org.eclipse.tractusx.bpdm.common.dto.response.PageDto
import org.eclipse.tractusx.bpdm.gate.api.GateSharingStateApi
import org.eclipse.tractusx.bpdm.gate.api.model.LsaType
import org.eclipse.tractusx.bpdm.gate.api.model.response.SharingStateDto
Expand All @@ -36,7 +36,7 @@ class SharingStateController(
private val logger = KotlinLogging.logger { }

@PreAuthorize("hasAuthority(@gateSecurityConfigProperties.getReadCompanyOutputDataAsRole())")
override fun getSharingStates(paginationRequest: PaginationRequest, lsaType: LsaType?, externalIds: Collection<String>?): PageResponse<SharingStateDto> {
override fun getSharingStates(paginationRequest: PaginationRequest, lsaType: LsaType?, externalIds: Collection<String>?): PageDto<SharingStateDto> {
return sharingStateService.findSharingStates(paginationRequest, lsaType, externalIds)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.eclipse.tractusx.bpdm.gate.controller

import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
import org.eclipse.tractusx.bpdm.common.dto.response.PageResponse
import org.eclipse.tractusx.bpdm.common.dto.response.PageDto
import org.eclipse.tractusx.bpdm.gate.api.GateSiteApi
import org.eclipse.tractusx.bpdm.gate.api.model.request.SiteGateInputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.request.SiteGateOutputRequest
Expand Down Expand Up @@ -59,17 +59,17 @@ class SiteController(
override fun getSitesByExternalIds(
paginationRequest: PaginationRequest,
externalIds: Collection<String>
): PageResponse<SiteGateInputDto> {
): PageDto<SiteGateInputDto> {
return siteService.getSites(page = paginationRequest.page, size = paginationRequest.size, externalIds = externalIds)
}

@PreAuthorize("hasAuthority(@gateSecurityConfigProperties.getReadCompanyInputDataAsRole())")
override fun getSites(paginationRequest: PaginationRequest): PageResponse<SiteGateInputDto> {
override fun getSites(paginationRequest: PaginationRequest): PageDto<SiteGateInputDto> {
return siteService.getSites(page = paginationRequest.page, size = paginationRequest.size)
}

@PreAuthorize("hasAuthority(@gateSecurityConfigProperties.getReadCompanyOutputDataAsRole())")
override fun getSitesOutput(paginationRequest: PaginationRequest, externalIds: Collection<String>?): PageResponse<SiteGateOutputResponse> {
override fun getSitesOutput(paginationRequest: PaginationRequest, externalIds: Collection<String>?): PageDto<SiteGateOutputResponse> {
return siteService.getSitesOutput(externalIds = externalIds, page = paginationRequest.page, size = paginationRequest.size)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.eclipse.tractusx.bpdm.gate.service

import mu.KotlinLogging
import org.eclipse.tractusx.bpdm.common.dto.response.PageResponse
import org.eclipse.tractusx.bpdm.common.dto.response.PageDto
import org.eclipse.tractusx.bpdm.common.exception.BpdmNotFoundException
import org.eclipse.tractusx.bpdm.common.model.OutputInputEnum
import org.eclipse.tractusx.bpdm.gate.api.model.LsaType
Expand All @@ -46,15 +46,15 @@ class AddressService(
) {
private val logger = KotlinLogging.logger { }

fun getAddresses(page: Int, size: Int, externalIds: Collection<String>? = null): PageResponse<AddressGateInputResponse> {
fun getAddresses(page: Int, size: Int, externalIds: Collection<String>? = null): PageDto<AddressGateInputResponse> {

val logisticAddressPage = if (externalIds != null) {
addressRepository.findByExternalIdInAndDataType(externalIds, OutputInputEnum.Input, PageRequest.of(page, size))
} else {
addressRepository.findByDataType(OutputInputEnum.Input, PageRequest.of(page, size))
}

return PageResponse(
return PageDto(
page = page,
totalElements = logisticAddressPage.totalElements,
totalPages = logisticAddressPage.totalPages,
Expand All @@ -81,15 +81,15 @@ class AddressService(
/**
* Get output addresses by fetching addresses from the database.
*/
fun getAddressesOutput(externalIds: Collection<String>? = null, page: Int, size: Int): PageResponse<AddressGateOutputDto> {
fun getAddressesOutput(externalIds: Collection<String>? = null, page: Int, size: Int): PageDto<AddressGateOutputDto> {

val logisticAddressPage = if (externalIds != null && externalIds.isNotEmpty()) {
addressRepository.findByExternalIdInAndDataType(externalIds, OutputInputEnum.Output, PageRequest.of(page, size))
} else {
addressRepository.findByDataType(OutputInputEnum.Output, PageRequest.of(page, size))
}

return PageResponse(
return PageDto(
page = page,
totalElements = logisticAddressPage.totalElements,
totalPages = logisticAddressPage.totalPages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.eclipse.tractusx.bpdm.gate.service

import mu.KotlinLogging
import org.eclipse.tractusx.bpdm.common.dto.response.PageResponse
import org.eclipse.tractusx.bpdm.common.dto.response.PageDto
import org.eclipse.tractusx.bpdm.common.exception.BpdmNotFoundException
import org.eclipse.tractusx.bpdm.common.model.OutputInputEnum
import org.eclipse.tractusx.bpdm.gate.api.model.request.LegalEntityGateInputRequest
Expand Down Expand Up @@ -64,15 +64,15 @@ class LegalEntityService(
return toValidSingleLegalEntity(legalEntity)
}

fun getLegalEntities(page: Int, size: Int, externalIds: Collection<String>? = null): PageResponse<LegalEntityGateInputDto> {
fun getLegalEntities(page: Int, size: Int, externalIds: Collection<String>? = null): PageDto<LegalEntityGateInputDto> {

val legalEntitiesPage = if (externalIds != null) {
legalEntityRepository.findByExternalIdInAndDataType(externalIds, OutputInputEnum.Input, PageRequest.of(page, size))
} else {
legalEntityRepository.findByDataType(OutputInputEnum.Input, PageRequest.of(page, size))
}

return PageResponse(
return PageDto(
page = page,
totalElements = legalEntitiesPage.totalElements,
totalPages = legalEntitiesPage.totalPages,
Expand All @@ -84,15 +84,15 @@ class LegalEntityService(
/**
* Get output legal entities by first fetching legal entities from the database
*/
fun getLegalEntitiesOutput(externalIds: Collection<String>?, page: Int, size: Int): PageResponse<LegalEntityGateOutputResponse> {
fun getLegalEntitiesOutput(externalIds: Collection<String>?, page: Int, size: Int): PageDto<LegalEntityGateOutputResponse> {

val legalEntityPage = if (!externalIds.isNullOrEmpty()) {
legalEntityRepository.findByExternalIdInAndDataType(externalIds, OutputInputEnum.Output, PageRequest.of(page, size))
} else {
legalEntityRepository.findByDataType(OutputInputEnum.Output, PageRequest.of(page, size))
}

return PageResponse(
return PageDto(
page = page,
totalElements = legalEntityPage.totalElements,
totalPages = legalEntityPage.totalPages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.eclipse.tractusx.bpdm.gate.service

import org.eclipse.tractusx.bpdm.common.dto.*
import org.eclipse.tractusx.bpdm.common.dto.response.PageResponse
import org.eclipse.tractusx.bpdm.common.dto.response.PageDto
import org.eclipse.tractusx.bpdm.common.model.OutputInputEnum
import org.eclipse.tractusx.bpdm.gate.api.model.*
import org.eclipse.tractusx.bpdm.gate.api.model.request.*
Expand Down Expand Up @@ -127,8 +127,8 @@ private fun StreetGateDto.toStreetEntity(): Street {
)
}

fun <S, T> Page<S>.toDto(dtoContent: Collection<T>): PageResponse<T> {
return PageResponse(this.totalElements, this.totalPages, this.number, this.numberOfElements, dtoContent)
fun <S, T> Page<S>.toDto(dtoContent: Collection<T>): PageDto<T> {
return PageDto(this.totalElements, this.totalPages, this.number, this.numberOfElements, dtoContent)
}

// Site Mappers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.eclipse.tractusx.bpdm.gate.service

import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
import org.eclipse.tractusx.bpdm.common.dto.response.PageResponse
import org.eclipse.tractusx.bpdm.common.dto.response.PageDto
import org.eclipse.tractusx.bpdm.gate.api.model.LsaType
import org.eclipse.tractusx.bpdm.gate.api.model.response.SharingStateDto
import org.eclipse.tractusx.bpdm.gate.entity.SharingState
Expand Down Expand Up @@ -72,7 +72,7 @@ class SharingStateService(private val stateRepository: SharingStateRepository) {
this.stateRepository.save(entity)
}

fun findSharingStates(paginationRequest: PaginationRequest, lsaType: LsaType?, externalIds: Collection<String>?): PageResponse<SharingStateDto> {
fun findSharingStates(paginationRequest: PaginationRequest, lsaType: LsaType?, externalIds: Collection<String>?): PageDto<SharingStateDto> {

val spec = Specification.allOf(byLsaType(lsaType), byExternalIdsIn(externalIds))
val pageRequest = PageRequest.of(paginationRequest.page, paginationRequest.size)
Expand Down
Loading

0 comments on commit 7c45439

Please sign in to comment.