1 /*
2  *  Make.org Core API
3  *  Copyright (C) 2020 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.technical
21 
22 import akka.http.scaladsl.common.RepeatedValueReceptacle
23 import akka.http.scaladsl.server.directives.ParameterDirectives.ParamSpec
24 import akka.http.scaladsl.server.Directives
25 import akka.http.scaladsl.unmarshalling.FromStringUnmarshaller
26 
27 final case class CsvReceptacle[T](underlying: RepeatedValueReceptacle[Seq[T]])
28 
29 object CsvReceptacle extends Directives {
30 
31   implicit class RepeatedCsvFlatteningParamOps(val name: String) extends AnyVal {
32     def csv[T]: CsvReceptacle[T] = CsvReceptacle(name.as[Seq[T]].*)
33   }
34 
35   implicit def paramSpec[T: FromStringUnmarshaller](a: CsvReceptacle[T]): ParamSpec.Aux[Option[Seq[T]]] =
36     ParamSpec(
37       ParamSpec.forRepVR(a.underlying).get.map(nested => if (nested.isEmpty) None else Some(nested.flatten.toSeq))
38     )
39 
40 }
Line Stmt Id Pos Tree Symbol Tests Code
32 42654 1256 - 1288 Apply org.make.api.technical.CsvReceptacle.apply org.make.api.user.adminuserapitest CsvReceptacle.apply[T](CsvReceptacle.this._string2NR(RepeatedCsvFlatteningParamOps.this.name).as[Seq[T]].*)
32 37144 1270 - 1274 Select org.make.api.technical.CsvReceptacle.RepeatedCsvFlatteningParamOps.name org.make.api.user.adminuserapitest RepeatedCsvFlatteningParamOps.this.name
32 51053 1270 - 1287 Select akka.http.scaladsl.common.NameReceptacle.* org.make.api.user.adminuserapitest CsvReceptacle.this._string2NR(RepeatedCsvFlatteningParamOps.this.name).as[Seq[T]].*
36 36633 1404 - 1535 Apply akka.http.scaladsl.server.directives.ParameterDirectives.ParamSpec.apply org.make.api.user.adminuserapitest akka.http.scaladsl.server.directives.ParameterDirectives.ParamSpec.apply[Option[Seq[T]]](server.this.Directive.SingleValueTransformers[Iterable[Seq[T]]](akka.http.scaladsl.server.directives.ParameterDirectives.ParamSpec.forRepVR[Seq[T]](a.underlying)(unmarshalling.this.Unmarshaller.CsvSeq[T](evidence$1)).get).map[Option[Seq[T]]](((nested: Iterable[Seq[T]]) => if (nested.isEmpty) scala.None else scala.Some.apply[Seq[T]](nested.flatten[T](scala.Predef.$conforms[Seq[T]]).toSeq)))(util.this.Tupler.forAnyRef[Option[Seq[T]]]))
37 36177 1476 - 1490 Select scala.collection.IterableOnceOps.isEmpty org.make.api.user.adminuserapitest nested.isEmpty
37 35067 1440 - 1452 Select org.make.api.technical.CsvReceptacle.underlying org.make.api.user.adminuserapitest a.underlying
37 43707 1421 - 1529 ApplyToImplicitArgs akka.http.scaladsl.server.Directive.SingleValueTransformers.map org.make.api.user.adminuserapitest server.this.Directive.SingleValueTransformers[Iterable[Seq[T]]](akka.http.scaladsl.server.directives.ParameterDirectives.ParamSpec.forRepVR[Seq[T]](a.underlying)(unmarshalling.this.Unmarshaller.CsvSeq[T](evidence$1)).get).map[Option[Seq[T]]](((nested: Iterable[Seq[T]]) => if (nested.isEmpty) scala.None else scala.Some.apply[Seq[T]](nested.flatten[T](scala.Predef.$conforms[Seq[T]]).toSeq)))(util.this.Tupler.forAnyRef[Option[Seq[T]]])
37 47594 1461 - 1461 TypeApply akka.http.scaladsl.server.util.LowerPriorityTupler.forAnyRef org.make.api.user.adminuserapitest util.this.Tupler.forAnyRef[Option[Seq[T]]]
37 37178 1514 - 1514 TypeApply scala.Predef.$conforms org.make.api.demographics.admindemographicscardapitest scala.Predef.$conforms[Seq[T]]
37 34824 1502 - 1528 Block scala.Some.apply org.make.api.demographics.admindemographicscardapitest scala.Some.apply[Seq[T]](nested.flatten[T](scala.Predef.$conforms[Seq[T]]).toSeq)
37 30616 1439 - 1439 ApplyToImplicitArgs akka.http.scaladsl.unmarshalling.PredefinedFromStringUnmarshallers.CsvSeq org.make.api.user.adminuserapitest unmarshalling.this.Unmarshaller.CsvSeq[T](evidence$1)
37 43670 1421 - 1457 Select akka.http.scaladsl.server.directives.ParameterDirectives.ParamSpec.get org.make.api.user.adminuserapitest akka.http.scaladsl.server.directives.ParameterDirectives.ParamSpec.forRepVR[Seq[T]](a.underlying)(unmarshalling.this.Unmarshaller.CsvSeq[T](evidence$1)).get
37 41071 1492 - 1496 Block scala.None org.make.api.user.adminuserapitest scala.None
37 50210 1507 - 1527 Select scala.collection.IterableOnceOps.toSeq org.make.api.demographics.admindemographicscardapitest nested.flatten[T](scala.Predef.$conforms[Seq[T]]).toSeq
37 49175 1492 - 1496 Select scala.None org.make.api.user.adminuserapitest scala.None
37 42685 1502 - 1528 Apply scala.Some.apply org.make.api.demographics.admindemographicscardapitest scala.Some.apply[Seq[T]](nested.flatten[T](scala.Predef.$conforms[Seq[T]]).toSeq)