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.core.question 21 22 import cats.data.NonEmptyList 23 import enumeratum.values.{StringCirceEnum, StringEnum, StringEnumEntry} 24 import io.circe.{Decoder, Encoder, Json, KeyDecoder, KeyEncoder} 25 import org.make.core.{SprayJsonFormatters, StringValue} 26 import org.make.core.technical.Multilingual 27 import org.make.core.operation.OperationId 28 import org.make.core.reference.{Country, Language} 29 import spray.json.JsonFormat 30 import com.github.plokhotnyuk.jsoniter_scala.core._ 31 32 import eu.timepit.refined.api.Refined 33 import eu.timepit.refined.collection._ 34 35 final case class Question( 36 questionId: QuestionId, 37 slug: String, 38 countries: NonEmptyList[Country], 39 defaultLanguage: Language, 40 languages: NonEmptyList[Language], 41 questions: Multilingual[String Refined NonEmpty], 42 shortTitles: Option[Multilingual[String Refined NonEmpty]], 43 operationId: Option[OperationId] 44 ) 45 46 final case class QuestionId(value: String) extends StringValue 47 48 object QuestionId { 49 implicit lazy val QuestionIdEncoder: Encoder[QuestionId] = 50 (a: QuestionId) => Json.fromString(a.value) 51 implicit lazy val QuestionIdDecoder: Decoder[QuestionId] = 52 Decoder.decodeString.map(QuestionId(_)) 53 54 implicit val questionIdCodec: JsonValueCodec[QuestionId] = 55 StringValue.makeCodec(QuestionId.apply) 56 57 implicit val QuestionIdFormatter: JsonFormat[QuestionId] = SprayJsonFormatters.forStringValue(QuestionId.apply) 58 59 implicit val questionIdKeyEncoder: KeyEncoder[QuestionId] = new KeyEncoder[QuestionId] { 60 override def apply(questionId: QuestionId): String = questionId.value 61 } 62 implicit val questionIdKeyDecoder: KeyDecoder[QuestionId] = new KeyDecoder[QuestionId] { 63 override def apply(key: String): Option[QuestionId] = Some(QuestionId(key)) 64 } 65 } 66 67 sealed abstract class TopProposalsMode(val value: String) extends StringEnumEntry 68 69 object TopProposalsMode extends StringEnum[TopProposalsMode] with StringCirceEnum[TopProposalsMode] { 70 71 case object IdeaMode extends TopProposalsMode("idea") 72 case object StakeTagMode extends TopProposalsMode("tag") 73 74 override val values: IndexedSeq[TopProposalsMode] = findValues 75 final val swaggerAllowableValues = "idea,tag" 76 }
| Line | Stmt Id | Pos | Tree | Symbol | Tests | Code |
|---|---|---|---|---|---|---|
| 55 | 2933 | 1985 - 2024 | Apply | org.make.core.StringValue.makeCodec | org.make.api.avro.avrocompatibilitytest,akka.http.scaladsl.testkit.routetest,org.make.api.technical.elasticsearch.proposalindexationstreamtest,org.make.api.makekafkatest,org.make.api.tag.tagservicetest,org.make.core.proposal.indexed.proposaltest,org.make.api.sessionhistory.sessionhistorycoordinatortest | org.make.core.StringValue.makeCodec[org.make.core.question.QuestionId](((value: String) => QuestionId.apply(value))) |
| 55 | 4966 | 2007 - 2023 | Apply | org.make.core.question.QuestionId.apply | org.make.core.proposal.indexed.proposaltest | QuestionId.apply(value) |
| 57 | 5214 | 2087 - 2139 | Apply | org.make.core.SprayJsonFormatters.forStringValue | org.make.api.avro.avrocompatibilitytest,akka.http.scaladsl.testkit.routetest,org.make.api.technical.elasticsearch.proposalindexationstreamtest,org.make.api.makekafkatest,org.make.api.tag.tagservicetest,org.make.core.proposal.indexed.proposaltest,org.make.api.sessionhistory.sessionhistorycoordinatortest | org.make.core.SprayJsonFormatters.forStringValue[org.make.core.question.QuestionId](((value: String) => QuestionId.apply(value))) |
| 57 | 1954 | 2122 - 2138 | Apply | org.make.core.question.QuestionId.apply | QuestionId.apply(value) | |
| 59 | 1204 | 2203 - 2206 | Apply | org.make.core.question.QuestionId.$anon.<init> | org.make.api.avro.avrocompatibilitytest,akka.http.scaladsl.testkit.routetest,org.make.api.technical.elasticsearch.proposalindexationstreamtest,org.make.api.makekafkatest,org.make.api.tag.tagservicetest,org.make.core.proposal.indexed.proposaltest,org.make.api.sessionhistory.sessionhistorycoordinatortest | new $anon() |
| 60 | 3331 | 2289 - 2305 | Select | org.make.core.question.QuestionId.value | questionId.value | |
| 62 | 1603 | 2372 - 2375 | Apply | org.make.core.question.QuestionId.$anon.<init> | org.make.api.avro.avrocompatibilitytest,akka.http.scaladsl.testkit.routetest,org.make.api.technical.elasticsearch.proposalindexationstreamtest,org.make.api.makekafkatest,org.make.api.tag.tagservicetest,org.make.core.proposal.indexed.proposaltest,org.make.api.sessionhistory.sessionhistorycoordinatortest | new $anon() |
| 63 | 3474 | 2459 - 2480 | Apply | scala.Some.apply | scala.Some.apply[org.make.core.question.QuestionId](QuestionId.apply(key)) | |
| 63 | 5501 | 2464 - 2479 | Apply | org.make.core.question.QuestionId.apply | QuestionId.apply(key) | |
| 75 | 4975 | 2892 - 2902 | Literal | <nosymbol> | "idea,tag" |