1 /* 2 * Make.org Core API 3 * Copyright (C) 2018 Make.org 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU Affero General Public License as 7 * published by the Free Software Foundation, either version 3 of the 8 * License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Affero General Public License for more details. 14 * 15 * You should have received a copy of the GNU Affero General Public License 16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package org.make.api.userhistory 21 22 import akka.actor.typed.ActorRef 23 import org.make.api.sessionhistory.Ack 24 import org.make.api.technical.{ActorCommand, ActorProtocol} 25 import org.make.api.userhistory.UserHistoryResponse.SessionEventsInjected 26 import org.make.core.MakeSerializable 27 import org.make.core.technical.Pagination 28 import org.make.core.history.HistoryActions.VoteAndQualifications 29 import org.make.core.proposal.{ProposalId, QualificationKey, VoteKey} 30 import org.make.core.user.UserId 31 import spray.json.DefaultJsonProtocol._ 32 import spray.json.{DefaultJsonProtocol, RootJsonFormat} 33 34 //State 35 36 final case class UserVotesAndQualifications(votesAndQualifications: Map[ProposalId, VoteAndQualifications]) 37 extends MakeSerializable 38 39 object UserVotesAndQualifications { 40 implicit val formatter: RootJsonFormat[UserVotesAndQualifications] = 41 DefaultJsonProtocol.jsonFormat1(UserVotesAndQualifications.apply) 42 } 43 44 // Protocol 45 46 sealed trait UserHistoryActorProtocol extends ActorProtocol 47 48 // Commands 49 50 sealed trait UserHistoryCommand extends ActorCommand[UserId] with UserHistoryActorProtocol { 51 def id: UserId = userId 52 def userId: UserId 53 } 54 55 final case class RequestVoteValues( 56 userId: UserId, 57 proposalIds: Seq[ProposalId], 58 replyTo: ActorRef[UserHistoryResponse[Map[ProposalId, VoteAndQualifications]]] 59 ) extends UserHistoryCommand 60 61 final case class RequestUserVotedProposalsPaginate( 62 userId: UserId, 63 filterVotes: Option[Seq[VoteKey]] = None, 64 filterQualifications: Option[Seq[QualificationKey]] = None, 65 proposalsIds: Option[Seq[ProposalId]] = None, 66 limit: Pagination.Limit, 67 offset: Pagination.Offset, 68 replyTo: ActorRef[UserHistoryResponse[Seq[ProposalId]]] 69 ) extends UserHistoryCommand 70 71 final case class UserHistoryTransactionalEnvelope[T <: TransactionalUserHistoryEvent[_]]( 72 userId: UserId, 73 event: T, 74 replyTo: ActorRef[UserHistoryResponse[Ack.type]] 75 ) extends UserHistoryCommand 76 77 final case class UserHistoryEnvelope[T <: UserHistoryEvent[_]](userId: UserId, event: T) extends UserHistoryCommand 78 79 final case class InjectSessionEvents( 80 userId: UserId, 81 events: Seq[UserHistoryEvent[_]], 82 replyTo: ActorRef[UserHistoryResponse[SessionEventsInjected.type]] 83 ) extends UserHistoryCommand 84 85 final case class Stop(userId: UserId, replyTo: ActorRef[UserHistoryResponse[Unit]]) extends UserHistoryCommand 86 87 // Responses 88 89 final case class UserHistoryResponse[T](value: T) extends UserHistoryActorProtocol 90 91 object UserHistoryResponse { 92 case object SessionEventsInjected 93 }
| Line | Stmt Id | Pos | Tree | Symbol | Tests | Code |
|---|---|---|---|---|---|---|
| 41 | 15502 | 1620 - 1620 | Select | org.make.core.history.HistoryActions.VoteAndQualifications.formatter | org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest | HistoryActions.this.VoteAndQualifications.formatter |
| 41 | 12047 | 1620 - 1620 | ApplyToImplicitArgs | spray.json.CollectionFormats.mapFormat | org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest | spray.json.DefaultJsonProtocol.mapFormat[org.make.core.proposal.ProposalId, org.make.core.history.HistoryActions.VoteAndQualifications](proposal.this.ProposalId.proposalFormat, HistoryActions.this.VoteAndQualifications.formatter) |
| 41 | 9511 | 1621 - 1653 | Apply | org.make.api.userhistory.UserVotesAndQualifications.apply | org.scalatest.testsuite | UserVotesAndQualifications.apply(votesAndQualifications) |
| 41 | 18336 | 1589 - 1654 | ApplyToImplicitArgs | spray.json.ProductFormatsInstances.jsonFormat1 | org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest | spray.json.DefaultJsonProtocol.jsonFormat1[Map[org.make.core.proposal.ProposalId,org.make.core.history.HistoryActions.VoteAndQualifications], org.make.api.userhistory.UserVotesAndQualifications](((votesAndQualifications: Map[org.make.core.proposal.ProposalId,org.make.core.history.HistoryActions.VoteAndQualifications]) => UserVotesAndQualifications.apply(votesAndQualifications)))(spray.json.DefaultJsonProtocol.mapFormat[org.make.core.proposal.ProposalId, org.make.core.history.HistoryActions.VoteAndQualifications](proposal.this.ProposalId.proposalFormat, HistoryActions.this.VoteAndQualifications.formatter), (ClassTag.apply[org.make.api.userhistory.UserVotesAndQualifications](classOf[org.make.api.userhistory.UserVotesAndQualifications]): scala.reflect.ClassTag[org.make.api.userhistory.UserVotesAndQualifications])) |
| 51 | 16549 | 1857 - 1863 | Select | org.make.api.userhistory.UserHistoryCommand.userId | UserHistoryCommand.this.userId |