Skip to content

Commit

Permalink
pr cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat Losoponkul committed May 2, 2023
1 parent dfbd816 commit 3c111fb
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 18 deletions.
1 change: 0 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import org.scoverage.coveralls.Imports.CoverallsKeys._

inThisBuild(
Seq(
maxErrors := 5, // TODO: remove before PR
organization := "io.iohk.atala",
scalaVersion := "3.2.2",
fork := true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object EndpointOutputs {
def basicFailuresWith(extraFailures: OneOfVariant[ErrorResponse]*) = {
oneOf(
FailureVariant.badRequest,
(Seq(FailureVariant.internalServerError) ++ extraFailures): _*
(FailureVariant.internalServerError +: extraFailures): _*
)
}

Expand Down Expand Up @@ -42,6 +42,11 @@ object EndpointOutputs {
StatusCode.UnprocessableEntity,
jsonBody[ErrorResponse].description("Unable to process the request")
)(statusCodeMatcher(StatusCode.UnprocessableEntity))

val conflict = oneOfVariantValueMatcher(
StatusCode.Conflict,
jsonBody[ErrorResponse].description("Cannot process due to conflict with current state of the resource")
)(statusCodeMatcher(StatusCode.Conflict))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,13 @@ object ErrorResponse {
detail = detail,
instance = instance
)

def conflict(title: String = "Conflict", detail: Option[String] = None, instance: String = "") =
ErrorResponse(
StatusCode.Conflict.code,
`type` = title,
title = title,
detail = detail,
instance = instance
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ object DIDRegistrarController {
case UpdateManagedDIDError.DIDNotFound(did) =>
ErrorResponse.notFound(detail = Some(s"DID not found: $did"))
case UpdateManagedDIDError.DIDNotPublished(did) =>
ErrorResponse.unprocessableEntity(detail = Some(s"DID not published: $did"))
ErrorResponse.conflict(detail = Some(s"DID not published: $did"))
case UpdateManagedDIDError.DIDAlreadyDeactivated(did) =>
ErrorResponse.unprocessableEntity(detail = Some(s"DID already deactivated: $did"))
ErrorResponse.conflict(detail = Some(s"DID already deactivated: $did"))
case UpdateManagedDIDError.InvalidArgument(msg) =>
ErrorResponse.badRequest(detail = Some(msg))
case e => ErrorResponse.internalServerError(detail = Some(e.toString))
Expand Down Expand Up @@ -118,9 +118,7 @@ class DIDRegistrarControllerImpl(service: ManagedDIDService) extends DIDRegistra
longFormDID <- service
.createAndStoreDID(didTemplate)
.mapError[ErrorResponse](e => e)
} yield CreateManagedDIDResponse(
longFormDid = longFormDID.toString
)
} yield CreateManagedDIDResponse(longFormDid = longFormDID.toString)
}

override def getManagedDid(did: String)(rc: RequestContext): IO[ErrorResponse, ManagedDID] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ object DIDRegistrarEndpoints {
] = baseEndpoint.post
.in(DIDInput.didRefPathSegment / "updates")
.in(jsonBody[UpdateManagedDIDRequest])
.errorOut(EndpointOutputs.basicFailuresWith(FailureVariant.unprocessableEntity, FailureVariant.notFound))
.errorOut(
EndpointOutputs
.basicFailuresWith(FailureVariant.unprocessableEntity, FailureVariant.notFound, FailureVariant.conflict)
)
.out(statusCode(StatusCode.Accepted).description("DID update operation accepted"))
.out(jsonBody[DIDOperationResponse])
.summary("Update DID in Prism Agent's wallet and post update operation to the VDR")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.iohk.atala.castor.controller.http

import io.iohk.atala.agent.walletapi.model as walletDomain
import io.iohk.atala.agent.walletapi.model.DIDPublicKeyTemplate
import io.iohk.atala.agent.walletapi.model.ManagedDIDDetail
import io.iohk.atala.agent.walletapi.model.ManagedDIDState
import io.iohk.atala.api.http.Annotation
Expand Down Expand Up @@ -108,7 +109,7 @@ object CreateManagedDidRequestDocumentTemplate {
def toDomain: Either[String, walletDomain.ManagedDIDTemplate] = {
for {
services <- template.services.traverse(_.toDomain)
publicKeys = template.publicKeys.map(_.toDomain)
publicKeys = template.publicKeys.map[DIDPublicKeyTemplate](k => k)
} yield walletDomain.ManagedDIDTemplate(
publicKeys = publicKeys,
services = services
Expand Down Expand Up @@ -177,14 +178,11 @@ object ManagedDIDKeyTemplate {
given decoder: JsonDecoder[ManagedDIDKeyTemplate] = DeriveJsonDecoder.gen[ManagedDIDKeyTemplate]
given schema: Schema[ManagedDIDKeyTemplate] = Schema.derived

extension (publicKeyTemplate: ManagedDIDKeyTemplate) {
def toDomain: walletDomain.DIDPublicKeyTemplate = {
walletDomain.DIDPublicKeyTemplate(
id = publicKeyTemplate.id,
purpose = publicKeyTemplate.purpose
)
}
}
given Conversion[ManagedDIDKeyTemplate, walletDomain.DIDPublicKeyTemplate] = publicKeyTemplate =>
walletDomain.DIDPublicKeyTemplate(
id = publicKeyTemplate.id,
purpose = publicKeyTemplate.purpose
)
}

final case class CreateManagedDIDResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ object UpdateManagedDIDRequestAction {
case ActionType.ADD_KEY =>
action.addKey
.toRight("addKey property is missing from action type ADD_KEY")
.map(template => AddKey(template.toDomain))
.map(template => AddKey(template))
case ActionType.REMOVE_KEY =>
action.removeKey
.toRight("removeKey property is missing from action type REMOVE_KEY")
Expand Down

0 comments on commit 3c111fb

Please sign in to comment.