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.sequence
21 
22 import io.circe.Encoder
23 import io.circe.generic.semiauto.deriveEncoder
24 import org.make.api.demographics.DemographicsCardForSequence
25 import org.make.api.proposal.ProposalResponse
26 import org.make.core.proposal._
27 import org.make.core.question.Question
28 import org.make.core.user._
29 import org.make.core.RequestContext
30 import org.make.core.reference.Language
31 import org.make.core.demographics.DemographicsCardId
32 import org.make.core.proposal.indexed.IndexedProposal
33 import org.make.core.sequence.SequenceConfiguration
34 import org.make.core.session.SessionId
35 
36 import scala.concurrent.Future
37 
38 trait SequenceServiceComponent {
39   def sequenceService: SequenceService
40 }
41 
42 trait SequenceService {
43   def startNewSequence[T: SequenceBehaviourProvider](
44     behaviourParam: T,
45     maybeUserId: Option[UserId],
46     includedProposalsIds: Seq[ProposalId],
47     requestContext: RequestContext,
48     cardId: Option[DemographicsCardId],
49     token: Option[String],
50     configurationOverride: Option[SequenceConfiguration] = None,
51     preferredLanguage: Option[Language],
52     question: Question
53   ): Future[SequenceResult]
54 
55   def simpleSequence(
56     includedProposalsIds: Seq[ProposalId],
57     behaviour: SequenceBehaviour,
58     proposalsToExclude: Seq[ProposalId],
59     sessionId: Option[SessionId]
60   ): Future[Seq[IndexedProposal]]
61 }
62 
63 final case class SequenceResult(
64   proposals: Seq[ProposalResponse],
65   demographics: Seq[DemographicsCardForSequence],
66   sessionBindingMode: Boolean
67 )
68 
69 object SequenceResult {
70   implicit val encoder: Encoder[SequenceResult] = deriveEncoder
71 
72   val empty: SequenceResult =
73     SequenceResult(proposals = Seq.empty, demographics = Seq.empty, sessionBindingMode = false)
74 }
Line Stmt Id Pos Tree Symbol Tests Code
70 30069 2309 - 2322 ApplyToImplicitArgs io.circe.generic.semiauto.deriveEncoder org.make.api.sequence.sequenceapitest io.circe.generic.semiauto.deriveEncoder[org.make.api.sequence.SequenceResult]({ val inst$macro$16: io.circe.generic.encoding.DerivedAsObjectEncoder[org.make.api.sequence.SequenceResult] = { final class anon$lazy$macro$15 extends AnyRef with Serializable { def <init>(): anon$lazy$macro$15 = { anon$lazy$macro$15.super.<init>(); () }; <stable> <accessor> lazy val inst$macro$1: io.circe.generic.encoding.DerivedAsObjectEncoder[org.make.api.sequence.SequenceResult] = encoding.this.DerivedAsObjectEncoder.deriveEncoder[org.make.api.sequence.SequenceResult, shapeless.labelled.FieldType[Symbol @@ String("proposals"),Seq[org.make.api.proposal.ProposalResponse]] :: shapeless.labelled.FieldType[Symbol @@ String("demographics"),Seq[org.make.api.demographics.DemographicsCardForSequence]] :: shapeless.labelled.FieldType[Symbol @@ String("sessionBindingMode"),Boolean] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out](shapeless.this.LabelledGeneric.materializeProduct[org.make.api.sequence.SequenceResult, (Symbol @@ String("proposals")) :: (Symbol @@ String("demographics")) :: (Symbol @@ String("sessionBindingMode")) :: shapeless.HNil, Seq[org.make.api.proposal.ProposalResponse] :: Seq[org.make.api.demographics.DemographicsCardForSequence] :: Boolean :: shapeless.HNil, shapeless.labelled.FieldType[Symbol @@ String("proposals"),Seq[org.make.api.proposal.ProposalResponse]] :: shapeless.labelled.FieldType[Symbol @@ String("demographics"),Seq[org.make.api.demographics.DemographicsCardForSequence]] :: shapeless.labelled.FieldType[Symbol @@ String("sessionBindingMode"),Boolean] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out](DefaultSymbolicLabelling.instance[org.make.api.sequence.SequenceResult, (Symbol @@ String("proposals")) :: (Symbol @@ String("demographics")) :: (Symbol @@ String("sessionBindingMode")) :: shapeless.HNil](::.apply[Symbol @@ String("proposals"), (Symbol @@ String("demographics")) :: (Symbol @@ String("sessionBindingMode")) :: shapeless.HNil.type](scala.Symbol.apply("proposals").asInstanceOf[Symbol @@ String("proposals")], ::.apply[Symbol @@ String("demographics"), (Symbol @@ String("sessionBindingMode")) :: shapeless.HNil.type](scala.Symbol.apply("demographics").asInstanceOf[Symbol @@ String("demographics")], ::.apply[Symbol @@ String("sessionBindingMode"), shapeless.HNil.type](scala.Symbol.apply("sessionBindingMode").asInstanceOf[Symbol @@ String("sessionBindingMode")], HNil)))), Generic.instance[org.make.api.sequence.SequenceResult, Seq[org.make.api.proposal.ProposalResponse] :: Seq[org.make.api.demographics.DemographicsCardForSequence] :: Boolean :: shapeless.HNil](((x0$3: org.make.api.sequence.SequenceResult) => x0$3 match { case (proposals: Seq[org.make.api.proposal.ProposalResponse], demographics: Seq[org.make.api.demographics.DemographicsCardForSequence], sessionBindingMode: Boolean): org.make.api.sequence.SequenceResult((proposals$macro$11 @ _), (demographics$macro$12 @ _), (sessionBindingMode$macro$13 @ _)) => ::.apply[Seq[org.make.api.proposal.ProposalResponse], Seq[org.make.api.demographics.DemographicsCardForSequence] :: Boolean :: shapeless.HNil.type](proposals$macro$11, ::.apply[Seq[org.make.api.demographics.DemographicsCardForSequence], Boolean :: shapeless.HNil.type](demographics$macro$12, ::.apply[Boolean, shapeless.HNil.type](sessionBindingMode$macro$13, HNil))).asInstanceOf[Seq[org.make.api.proposal.ProposalResponse] :: Seq[org.make.api.demographics.DemographicsCardForSequence] :: Boolean :: shapeless.HNil] }), ((x0$4: Seq[org.make.api.proposal.ProposalResponse] :: Seq[org.make.api.demographics.DemographicsCardForSequence] :: Boolean :: shapeless.HNil) => x0$4 match { case (head: Seq[org.make.api.proposal.ProposalResponse], tail: Seq[org.make.api.demographics.DemographicsCardForSequence] :: Boolean :: shapeless.HNil): Seq[org.make.api.proposal.ProposalResponse] :: Seq[org.make.api.demographics.DemographicsCardForSequence] :: Boolean :: shapeless.HNil((proposals$macro$8 @ _), (head: Seq[org.make.api.demographics.DemographicsCardForSequence], tail: Boolean :: shapeless.HNil): Seq[org.make.api.demographics.DemographicsCardForSequence] :: Boolean :: shapeless.HNil((demographics$macro$9 @ _), (head: Boolean, tail: shapeless.HNil): Boolean :: shapeless.HNil((sessionBindingMode$macro$10 @ _), HNil))) => sequence.this.SequenceResult.apply(proposals$macro$8, demographics$macro$9, sessionBindingMode$macro$10) })), hlist.this.ZipWithKeys.hconsZipWithKeys[Symbol @@ String("proposals"), Seq[org.make.api.proposal.ProposalResponse], (Symbol @@ String("demographics")) :: (Symbol @@ String("sessionBindingMode")) :: shapeless.HNil, Seq[org.make.api.demographics.DemographicsCardForSequence] :: Boolean :: shapeless.HNil, shapeless.labelled.FieldType[Symbol @@ String("demographics"),Seq[org.make.api.demographics.DemographicsCardForSequence]] :: shapeless.labelled.FieldType[Symbol @@ String("sessionBindingMode"),Boolean] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out](hlist.this.ZipWithKeys.hconsZipWithKeys[Symbol @@ String("demographics"), Seq[org.make.api.demographics.DemographicsCardForSequence], (Symbol @@ String("sessionBindingMode")) :: shapeless.HNil, Boolean :: shapeless.HNil, shapeless.labelled.FieldType[Symbol @@ String("sessionBindingMode"),Boolean] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out](hlist.this.ZipWithKeys.hconsZipWithKeys[Symbol @@ String("sessionBindingMode"), Boolean, shapeless.HNil, shapeless.HNil, shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out](hlist.this.ZipWithKeys.hnilZipWithKeys, Witness.mkWitness[Symbol with shapeless.tag.Tagged[String("sessionBindingMode")]](scala.Symbol.apply("sessionBindingMode").asInstanceOf[Symbol @@ String("sessionBindingMode")].asInstanceOf[Symbol with shapeless.tag.Tagged[String("sessionBindingMode")]])), Witness.mkWitness[Symbol with shapeless.tag.Tagged[String("demographics")]](scala.Symbol.apply("demographics").asInstanceOf[Symbol @@ String("demographics")].asInstanceOf[Symbol with shapeless.tag.Tagged[String("demographics")]])), Witness.mkWitness[Symbol with shapeless.tag.Tagged[String("proposals")]](scala.Symbol.apply("proposals").asInstanceOf[Symbol @@ String("proposals")].asInstanceOf[Symbol with shapeless.tag.Tagged[String("proposals")]])), scala.this.<:<.refl[shapeless.labelled.FieldType[Symbol @@ String("proposals"),Seq[org.make.api.proposal.ProposalResponse]] :: shapeless.labelled.FieldType[Symbol @@ String("demographics"),Seq[org.make.api.demographics.DemographicsCardForSequence]] :: shapeless.labelled.FieldType[Symbol @@ String("sessionBindingMode"),Boolean] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out]), shapeless.Lazy.apply[io.circe.generic.encoding.ReprAsObjectEncoder[shapeless.labelled.FieldType[Symbol @@ String("proposals"),Seq[org.make.api.proposal.ProposalResponse]] :: shapeless.labelled.FieldType[Symbol @@ String("demographics"),Seq[org.make.api.demographics.DemographicsCardForSequence]] :: shapeless.labelled.FieldType[Symbol @@ String("sessionBindingMode"),Boolean] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out]](anon$lazy$macro$15.this.inst$macro$14)).asInstanceOf[io.circe.generic.encoding.DerivedAsObjectEncoder[org.make.api.sequence.SequenceResult]]; <stable> <accessor> lazy val inst$macro$14: io.circe.generic.encoding.ReprAsObjectEncoder[shapeless.labelled.FieldType[Symbol @@ String("proposals"),Seq[org.make.api.proposal.ProposalResponse]] :: shapeless.labelled.FieldType[Symbol @@ String("demographics"),Seq[org.make.api.demographics.DemographicsCardForSequence]] :: shapeless.labelled.FieldType[Symbol @@ String("sessionBindingMode"),Boolean] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out] = ({ final class $anon extends io.circe.generic.encoding.ReprAsObjectEncoder[shapeless.labelled.FieldType[Symbol @@ String("proposals"),Seq[org.make.api.proposal.ProposalResponse]] :: shapeless.labelled.FieldType[Symbol @@ String("demographics"),Seq[org.make.api.demographics.DemographicsCardForSequence]] :: shapeless.labelled.FieldType[Symbol @@ String("sessionBindingMode"),Boolean] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out] { def <init>(): <$anon: io.circe.generic.encoding.ReprAsObjectEncoder[shapeless.labelled.FieldType[Symbol @@ String("proposals"),Seq[org.make.api.proposal.ProposalResponse]] :: shapeless.labelled.FieldType[Symbol @@ String("demographics"),Seq[org.make.api.demographics.DemographicsCardForSequence]] :: shapeless.labelled.FieldType[Symbol @@ String("sessionBindingMode"),Boolean] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out]> = { $anon.super.<init>(); () }; private[this] val circeGenericEncoderForproposals: io.circe.Encoder.AsArray[Seq[org.make.api.proposal.ProposalResponse]] = circe.this.Encoder.encodeSeq[org.make.api.proposal.ProposalResponse](proposal.this.ProposalResponse.codec); private[this] val circeGenericEncoderFordemographics: io.circe.Encoder.AsArray[Seq[org.make.api.demographics.DemographicsCardForSequence]] = circe.this.Encoder.encodeSeq[org.make.api.demographics.DemographicsCardForSequence](demographics.this.DemographicsCardForSequence.encoder); private[this] val circeGenericEncoderForsessionBindingMode: io.circe.Encoder[Boolean] = circe.this.Encoder.encodeBoolean; final def encodeObject(a: shapeless.labelled.FieldType[Symbol @@ String("proposals"),Seq[org.make.api.proposal.ProposalResponse]] :: shapeless.labelled.FieldType[Symbol @@ String("demographics"),Seq[org.make.api.demographics.DemographicsCardForSequence]] :: shapeless.labelled.FieldType[Symbol @@ String("sessionBindingMode"),Boolean] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out): io.circe.JsonObject = a match { case (head: shapeless.labelled.FieldType[Symbol @@ String("proposals"),Seq[org.make.api.proposal.ProposalResponse]], tail: shapeless.labelled.FieldType[Symbol @@ String("demographics"),Seq[org.make.api.demographics.DemographicsCardForSequence]] :: shapeless.labelled.FieldType[Symbol @@ String("sessionBindingMode"),Boolean] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out): shapeless.labelled.FieldType[Symbol @@ String("proposals"),Seq[org.make.api.proposal.ProposalResponse]] :: shapeless.labelled.FieldType[Symbol @@ String("demographics"),Seq[org.make.api.demographics.DemographicsCardForSequence]] :: shapeless.labelled.FieldType[Symbol @@ String("sessionBindingMode"),Boolean] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out((circeGenericHListBindingForproposals @ _), (head: shapeless.labelled.FieldType[Symbol @@ String("demographics"),Seq[org.make.api.demographics.DemographicsCardForSequence]], tail: shapeless.labelled.FieldType[Symbol @@ String("sessionBindingMode"),Boolean] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out): shapeless.labelled.FieldType[Symbol @@ String("demographics"),Seq[org.make.api.demographics.DemographicsCardForSequence]] :: shapeless.labelled.FieldType[Symbol @@ String("sessionBindingMode"),Boolean] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out((circeGenericHListBindingFordemographics @ _), (head: shapeless.labelled.FieldType[Symbol @@ String("sessionBindingMode"),Boolean], tail: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out): shapeless.labelled.FieldType[Symbol @@ String("sessionBindingMode"),Boolean] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out((circeGenericHListBindingForsessionBindingMode @ _), shapeless.HNil))) => io.circe.JsonObject.fromIterable(scala.collection.immutable.Vector.apply[(String, io.circe.Json)](scala.Tuple2.apply[String, io.circe.Json]("proposals", $anon.this.circeGenericEncoderForproposals.apply(circeGenericHListBindingForproposals)), scala.Tuple2.apply[String, io.circe.Json]("demographics", $anon.this.circeGenericEncoderFordemographics.apply(circeGenericHListBindingFordemographics)), scala.Tuple2.apply[String, io.circe.Json]("sessionBindingMode", $anon.this.circeGenericEncoderForsessionBindingMode.apply(circeGenericHListBindingForsessionBindingMode)))) } }; new $anon() }: io.circe.generic.encoding.ReprAsObjectEncoder[shapeless.labelled.FieldType[Symbol @@ String("proposals"),Seq[org.make.api.proposal.ProposalResponse]] :: shapeless.labelled.FieldType[Symbol @@ String("demographics"),Seq[org.make.api.demographics.DemographicsCardForSequence]] :: shapeless.labelled.FieldType[Symbol @@ String("sessionBindingMode"),Boolean] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out]).asInstanceOf[io.circe.generic.encoding.ReprAsObjectEncoder[shapeless.labelled.FieldType[Symbol @@ String("proposals"),Seq[org.make.api.proposal.ProposalResponse]] :: shapeless.labelled.FieldType[Symbol @@ String("demographics"),Seq[org.make.api.demographics.DemographicsCardForSequence]] :: shapeless.labelled.FieldType[Symbol @@ String("sessionBindingMode"),Boolean] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out]] }; new anon$lazy$macro$15().inst$macro$1 }; shapeless.Lazy.apply[io.circe.generic.encoding.DerivedAsObjectEncoder[org.make.api.sequence.SequenceResult]](inst$macro$16) })
73 29471 2358 - 2449 Apply org.make.api.sequence.SequenceResult.apply org.make.api.sequence.sequenceapitest SequenceResult.apply(scala.`package`.Seq.empty[Nothing], scala.`package`.Seq.empty[Nothing], false)
73 29781 2443 - 2448 Literal <nosymbol> org.make.api.sequence.sequenceapitest false
73 28516 2411 - 2420 TypeApply scala.collection.SeqFactory.Delegate.empty org.make.api.sequence.sequenceapitest scala.`package`.Seq.empty[Nothing]
73 29290 2385 - 2394 TypeApply scala.collection.SeqFactory.Delegate.empty org.make.api.sequence.sequenceapitest scala.`package`.Seq.empty[Nothing]