Skip to content

Commit

Permalink
Fixes #120 - Calling getPartioningAdditionalData of the repo in the s…
Browse files Browse the repository at this point in the history
…ervice
  • Loading branch information
TebaleloS committed Mar 19, 2024
1 parent 086525e commit 52449d3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion server/src/main/scala/za/co/absa/atum/server/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package za.co.absa.atum.server

import za.co.absa.atum.server.api.controller._
import za.co.absa.atum.server.api.database.{PostgresDatabaseProvider, TransactorProvider}
import za.co.absa.atum.server.api.database.runs.functions.{CreatePartitioningIfNotExists, GetPartitioningMeasures, WriteCheckpoint}
import za.co.absa.atum.server.api.database.runs.functions.{CreatePartitioningIfNotExists, WriteCheckpoint}
import za.co.absa.atum.server.api.http.Server
import za.co.absa.atum.server.api.repository.{CheckpointRepositoryImpl, PartitioningRepositoryImpl}
import za.co.absa.atum.server.api.service.{CheckpointServiceImpl, PartitioningServiceImpl}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ class PartitioningControllerImpl(partitioningService: PartitioningService) exten
case Right(_) =>
// partitioningService.getPartitioningMeasures(partitioning)
// .flatMap { measures => ZIO.succeed(AtumContextDTO) }

ZIO.succeed {
val measures: Set[MeasureDTO] = partitioningService.getPartitioningMeasures(partitioning)
.flatMap(measures => ZIO.succeed(measures)).getOrElse(Set.empty[MeasureDTO])
val additionalData = AdditionalDataDTO(additionalData = Map.empty)
.flatMap(measures => ZIO.succeed(measures))
val additionalData = AdditionalDataDTO(additionalData = Map.empty[String, Option[String]])
AtumContextDTO(partitioning.partitioning, measures, additionalData)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import zio.interop.catz.asyncInstance
import zio.{Task, URLayer, ZIO, ZLayer}

class GetPartitioningAdditionalData (implicit schema: DBSchema, dbEngine: DoobieEngine[Task])
extends DoobieSingleResultFunctionWithStatus[PartitioningSubmitDTO, AdditionalDataDTO, Task]
extends DoobieSingleResultFunctionWithStatus[PartitioningSubmitDTO, Seq[AdditionalDataDTO], Task]
with StandardStatusHandling {

override def sql(values: PartitioningSubmitDTO)(implicit read: Read[StatusWithData[AdditionalDataDTO]]): Fragment = {
override def sql(values: PartitioningSubmitDTO)(implicit read: Read[StatusWithData[Seq[AdditionalDataDTO]]]): Fragment = {
val partitioning = PartitioningForDB.fromSeqPartitionDTO(values.partitioning)
val partitioningJsonString = Json.toJson(partitioning).toString

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ trait PartitioningRepository {

def getPartitioningAdditionalData(
partitioning: PartitioningSubmitDTO
): IO[DatabaseError, Either[StatusException, AdditionalDataDTO]]
): IO[DatabaseError, Either[StatusException, Seq[AdditionalDataDTO]]]

}

Expand Down Expand Up @@ -73,7 +73,7 @@ class PartitioningRepositoryImpl(createPartitioningIfNotExistsFn: CreatePartitio
.tapError(error => ZIO.logError(s"Failed to retrieve partitioning measures from database: ${error.message}"))
}

override def getPartitioningAdditionalData(partitioning: PartitioningSubmitDTO): IO[DatabaseError, Either[StatusException, AdditionalDataDTO]] = {
override def getPartitioningAdditionalData(partitioning: PartitioningSubmitDTO): IO[DatabaseError, Either[StatusException, Seq[AdditionalDataDTO]]] = {
getPartitioningAdditionalDataFn(partitioning)
.tap {
case Left(statusException) =>
Expand All @@ -93,8 +93,8 @@ object PartitioningRepositoryImpl {
val layer: URLayer[CreatePartitioningIfNotExists, PartitioningRepository] = ZLayer {
for {
createPartitioningIfNotExists <- ZIO.service[CreatePartitioningIfNotExists]
// getPartitioningMeasures <- ZIO.service[GetPartitioningMeasures]
// getPartitioningAdditionalData <- ZIO.service[GetPartitioningAdditionalData]
} yield new PartitioningRepositoryImpl(createPartitioningIfNotExists)
getPartitioningMeasures <- ZIO.service[GetPartitioningMeasures]
getPartitioningAdditionalData <- ZIO.service[GetPartitioningAdditionalData]
} yield new PartitioningRepositoryImpl(createPartitioningIfNotExists, getPartitioningMeasures, getPartitioningAdditionalData)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ trait PartitioningService {

def getPartioningAdditionalData(
partitioning: PartitioningSubmitDTO
): IO[ServiceError, Either[StatusException, AdditionalDataDTO]]
): IO[ServiceError, Either[StatusException, Seq[AdditionalDataDTO]]]
}

class PartitioningServiceImpl(partitioningRepository: PartitioningRepository) extends PartitioningService {
Expand All @@ -57,7 +57,7 @@ class PartitioningServiceImpl(partitioningRepository: PartitioningRepository) ex
}
}

override def getPartioningAdditionalData(partitioning: PartitioningSubmitDTO): IO[ServiceError, Either[StatusException, AdditionalDataDTO]] = {
override def getPartioningAdditionalData(partitioning: PartitioningSubmitDTO): IO[ServiceError, Either[StatusException, Seq[AdditionalDataDTO]]] = {
partitioningRepository
.getPartitioningAdditionalData(partitioning)
.mapError { case DatabaseError(message) =>
Expand Down

0 comments on commit 52449d3

Please sign in to comment.