Skip to content

Commit

Permalink
requestId, ResponseEnvelope
Browse files Browse the repository at this point in the history
  • Loading branch information
salamonpavel committed May 27, 2024
1 parent 859834f commit 7933f7e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,35 @@ package za.co.absa.atum.server.model

import play.api.libs.json.{Json, Reads, Writes}

import java.util.UUID

object ErrorResponse {

sealed trait ErrorResponse {
sealed trait ErrorResponse extends ResponseEnvelope {
def message: String
}

implicit val reads: Reads[ErrorResponse] = Json.reads[ErrorResponse]
implicit val writes: Writes[ErrorResponse] = Json.writes[ErrorResponse]

final case class BadRequestResponse(message: String) extends ErrorResponse
final case class BadRequestResponse(message: String, override val requestId: UUID = UUID.randomUUID())
extends ErrorResponse

implicit val readsBadRequestResponse: Reads[BadRequestResponse] = Json.reads[BadRequestResponse]
implicit val writesBadRequestResponse: Writes[BadRequestResponse] = Json.writes[BadRequestResponse]

final case class GeneralErrorResponse(message: String) extends ErrorResponse
final case class GeneralErrorResponse(message: String, override val requestId: UUID = UUID.randomUUID())
extends ErrorResponse

implicit val readsGeneralErrorResponse: Reads[GeneralErrorResponse] = Json.reads[GeneralErrorResponse]
implicit val writesGeneralErrorResponse: Writes[GeneralErrorResponse] = Json.writes[GeneralErrorResponse]

final case class InternalServerErrorResponse(message: String) extends ErrorResponse
final case class InternalServerErrorResponse(message: String, override val requestId: UUID = UUID.randomUUID())
extends ErrorResponse

implicit val readsInternalServerErrorResponse: Reads[InternalServerErrorResponse] = Json.reads[InternalServerErrorResponse]
implicit val writesInternalServerErrorResponse: Writes[InternalServerErrorResponse] = Json.writes[InternalServerErrorResponse]
implicit val readsInternalServerErrorResponse: Reads[InternalServerErrorResponse] =
Json.reads[InternalServerErrorResponse]
implicit val writesInternalServerErrorResponse: Writes[InternalServerErrorResponse] =
Json.writes[InternalServerErrorResponse]

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2021 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package za.co.absa.atum.server.model

import java.util.UUID

trait ResponseEnvelope {
def requestId: UUID
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@

package za.co.absa.atum.server.model

import java.util.UUID

object SuccessResponse {

sealed trait SuccessResponse
sealed trait SuccessResponse extends ResponseEnvelope

case class SingleSuccessResponse[T](data: T, override val requestId: UUID = UUID.randomUUID())
extends SuccessResponse

case class SingleSuccessResponse[T](data: T) extends SuccessResponse
case class MultiSuccessResponse[T](data: Seq[T]) extends SuccessResponse
case class MultiSuccessResponse[T](data: Seq[T], override val requestId: UUID = UUID.randomUUID())
extends SuccessResponse

}

0 comments on commit 7933f7e

Please sign in to comment.