Skip to content

Commit

Permalink
Fixes #120 - Changed inheritance from service trat to implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
TebaleloS committed Mar 26, 2024
1 parent 3b05824 commit c063480
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ import zio.macros.accessible

@accessible
trait PartitioningController {
def createPartitioningIfNotExists(partitioning: PartitioningSubmitDTO): IO[ServiceError, AtumContextDTO]
def createPartitioningIfNotExists(partitioning: PartitioningSubmitDTO): IO[ErrorResponse, AtumContextDTO]
def createOrUpdateAdditionalData(additionalData: AdditionalDataSubmitDTO): IO[ErrorResponse, AdditionalDataSubmitDTO]
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,37 @@

package za.co.absa.atum.server.api.controller


import za.co.absa.atum.model.dto._
import za.co.absa.atum.server.api.exception.ServiceError
import za.co.absa.atum.server.api.service.PartitioningService
import za.co.absa.atum.server.api.service.PartitioningServiceImpl
import za.co.absa.atum.server.model.ErrorResponse
import zio._

class PartitioningControllerImpl(partitioningService: PartitioningService)
class PartitioningControllerImpl(partitioningServiceImpl: PartitioningServiceImpl)
extends PartitioningController with BaseController {

override def createPartitioningIfNotExists(partitioning: PartitioningSubmitDTO): IO[ServiceError, AtumContextDTO] = {
partitioningService.returnAtumContext(partitioning)
override def createPartitioningIfNotExists(partitioning: PartitioningSubmitDTO): IO[ErrorResponse, AtumContextDTO] = {
serviceCallWithStatus[Unit, AtumContextDTO](
partitioningServiceImpl.returnAtumContext(partitioning),
_ => AtumContextDTO(partitioning = partitioning.partitioning, measures = Set.empty, additionalData = Map.empty)
)
}

override def createOrUpdateAdditionalData(
additionalData: AdditionalDataSubmitDTO
): IO[ErrorResponse, AdditionalDataSubmitDTO] = {
serviceCallWithStatus[Unit, AdditionalDataSubmitDTO](
partitioningService.createOrUpdateAdditionalData(additionalData),
partitioningServiceImpl.createOrUpdateAdditionalData(additionalData),
_ => additionalData
)
}

}

object PartitioningControllerImpl {
val layer: URLayer[PartitioningService, PartitioningController] = ZLayer {
val layer: URLayer[PartitioningServiceImpl, PartitioningController] = ZLayer {
for {
partitioningService <- ZIO.service[PartitioningService]
} yield new PartitioningControllerImpl(partitioningService)
partitioningServiceImpl <- ZIO.service[PartitioningServiceImpl]
} yield new PartitioningControllerImpl(partitioningServiceImpl)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ class GetPartitioningAdditionalData (implicit schema: DBSchema, dbEngine: Doobie
}

object GetPartitioningAdditionalData {
val layer: URLayer[PostgresDatabaseProvider, GetPartitioningMeasures] = ZLayer {
val layer: URLayer[PostgresDatabaseProvider, GetPartitioningAdditionalData] = ZLayer {
for {
dbProvider <- ZIO.service[PostgresDatabaseProvider]
} yield new GetPartitioningMeasures()(Runs, dbProvider.dbEngine)
} yield new GetPartitioningAdditionalData()(Runs, dbProvider.dbEngine)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package za.co.absa.atum.server.api.service

import za.co.absa.atum.model.dto.{AdditionalDataDTO, AdditionalDataSubmitDTO, AtumContextDTO, MeasureDTO, PartitioningSubmitDTO}
import za.co.absa.atum.model.dto.{AdditionalDataDTO, AdditionalDataSubmitDTO, MeasureDTO, PartitioningSubmitDTO}
import za.co.absa.atum.server.api.exception.ServiceError
import za.co.absa.fadb.exceptions.StatusException
import zio.IO
Expand All @@ -36,6 +36,4 @@ trait PartitioningService {
def createOrUpdateAdditionalData(additionalData: AdditionalDataSubmitDTO):
IO[ServiceError, Either[StatusException, Unit]]

def returnAtumContext(partitioning: PartitioningSubmitDTO):
IO[ServiceError, AtumContextDTO]
}

0 comments on commit c063480

Please sign in to comment.