Skip to content

Commit

Permalink
MediatorCoordinationExecuter is not using mongodb
Browse files Browse the repository at this point in the history
  • Loading branch information
FabioPinheiro committed Jun 5, 2023
1 parent 1598691 commit 338781b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 37 deletions.
Expand Up @@ -113,47 +113,57 @@ object MediatorCoordinationExecuter
case _ => m.makeRespondMediateDeny.toPlaintextMessage
} yield SyncReplyOnly(reply)
case m: KeylistUpdate =>
case class Tmp(id: FROMTO, a: KeylistAction, r: KeylistResult)
for {
_ <- ZIO.logInfo("KeylistUpdate")
repo <- ZIO.service[DidAccountRepo]
updateResponse <- ZIO.foreach(m.updates) {
case (fromto, KeylistAction.add) =>
repo.addAlias(m.from.toDID, fromto.toDID).map {
case Left(value) => (fromto, KeylistAction.add, KeylistResult.server_error)
case Right(newState) => (fromto, KeylistAction.add, KeylistResult.success)
}
case (fromto, KeylistAction.remove) =>
repo.removeAlias(m.from.toDID, fromto.toDID).map {
case Left(value) => (fromto, KeylistAction.remove, KeylistResult.server_error)
case Right(newState) => (fromto, KeylistAction.remove, KeylistResult.success)
}
}
// TODO!!!!!!!!!!!!!!!!!!!!
db <- ZIO.service[Ref[MediatorDB]]
updatesAndNewMediatorDB <- db.modify { mediatorDB =>
val did2Add = m.updates.collect { case (fromto, KeylistAction.add) => fromto }
val did2Remove = m.updates.collect { case (fromto, KeylistAction.remove) => fromto }
m.updates.foldLeft((Seq.empty[Tmp], mediatorDB)) {
case ((resultList, tmpDB), (fromto, KeylistAction.add)) =>
tmpDB.addAlias(ower = m.from.toDIDSubject, newAlias = fromto.toDIDSubject) match
case Left(value) =>
(
resultList :+ Tmp(fromto, KeylistAction.add, KeylistResult.server_error),
tmpDB
)
case Right(newState) =>
(
resultList :+ Tmp(fromto, KeylistAction.add, KeylistResult.success),
newState
)
// case class Tmp(id: FROMTO, a: KeylistAction, r: KeylistResult)
// db <- ZIO.service[Ref[MediatorDB]]
// updatesAndNewMediatorDB <- db.modify { mediatorDB =>
// m.updates.foldLeft((Seq.empty[Tmp], mediatorDB)) {
// case ((resultList, tmpDB), (fromto, KeylistAction.add)) =>
// tmpDB.addAlias(ower = m.from.toDIDSubject, newAlias = fromto.toDIDSubject) match
// case Left(value) =>
// (
// resultList :+ Tmp(fromto, KeylistAction.add, KeylistResult.server_error),
// tmpDB
// )
// case Right(newState) =>
// (
// resultList :+ Tmp(fromto, KeylistAction.add, KeylistResult.success),
// newState
// )

case ((resultList, tmpDB), (fromto, KeylistAction.remove)) =>
tmpDB.removeAlias(ower = m.from.toDIDSubject, newAlias = fromto.toDIDSubject) match
case Left(value) =>
(
resultList :+ Tmp(fromto, KeylistAction.remove, KeylistResult.server_error),
tmpDB
)
case Right(newState) =>
(
resultList :+ Tmp(fromto, KeylistAction.remove, KeylistResult.success),
newState
)
}
}
keylistResponse = m.makeKeylistResponse(
updatesAndNewMediatorDB.map(e => (e._1, e._2, e._3))
)
} yield SyncReplyOnly(keylistResponse.toPlaintextMessage)
// case ((resultList, tmpDB), (fromto, KeylistAction.remove)) =>
// tmpDB.removeAlias(ower = m.from.toDIDSubject, newAlias = fromto.toDIDSubject) match
// case Left(value) =>
// (
// resultList :+ Tmp(fromto, KeylistAction.remove, KeylistResult.server_error),
// tmpDB
// )
// case Right(newState) =>
// (
// resultList :+ Tmp(fromto, KeylistAction.remove, KeylistResult.success),
// newState
// )
// }
// }
// keylistResponse = m.makeKeylistResponse(
// updatesAndNewMediatorDB.map(e => (e._1, e._2, e._3))
// )
} yield SyncReplyOnly(m.makeKeylistResponse(updateResponse).toPlaintextMessage)
case m: KeylistResponse => ZIO.logWarning("KeylistResponse") *> ZIO.succeed(NoReply)
case m: KeylistQuery => ZIO.logError("Not implemented KeylistQuery") *> ZIO.succeed(NoReply) // TODO
case m: Keylist => ZIO.logWarning("Keylist") *> ZIO.succeed(NoReply)
Expand Down
2 changes: 1 addition & 1 deletion did-mediator/src/main/scala/fmgp/did/db/DataModels.scala
Expand Up @@ -19,7 +19,7 @@ object MessageMetaData {
given BSONDocumentReader[MessageMetaData] = Macros.reader[MessageMetaData]
}

// clients_store did
// did_account did
case class DidAccount(
_id: BSONObjectID = BSONObjectID.generate(),
did: DIDSubject,
Expand Down

0 comments on commit 338781b

Please sign in to comment.