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.partner
21 
22 import enumeratum.values.{StringCirceEnum, StringEnum, StringEnumEntry}
23 import io.circe.{Decoder, Encoder, Json}
24 import org.make.core.{SprayJsonFormatters, StringValue}
25 import org.make.core.question.QuestionId
26 import org.make.core.user.UserId
27 import spray.json.JsonFormat
28 
29 final case class Partner(
30   partnerId: PartnerId,
31   name: String,
32   logo: Option[String],
33   link: Option[String],
34   organisationId: Option[UserId],
35   partnerKind: PartnerKind,
36   questionId: QuestionId,
37   weight: Float
38 )
39 
40 final case class PartnerId(value: String) extends StringValue
41 
42 object PartnerId {
43   implicit lazy val partnerIdEncoder: Encoder[PartnerId] =
44     (a: PartnerId) => Json.fromString(a.value)
45   implicit lazy val partnerIdDecoder: Decoder[PartnerId] =
46     Decoder.decodeString.map(PartnerId(_))
47 
48   implicit val partnerIdFormatter: JsonFormat[PartnerId] = SprayJsonFormatters.forStringValue(PartnerId.apply)
49 }
50 
51 sealed abstract class PartnerKind(val value: String) extends StringEnumEntry with Product with Serializable
52 
53 object PartnerKind extends StringEnum[PartnerKind] with StringCirceEnum[PartnerKind] {
54 
55   case object Media extends PartnerKind("MEDIA")
56   case object ActionPartner extends PartnerKind("ACTION_PARTNER")
57   case object Founder extends PartnerKind("FOUNDER")
58   case object Actor extends PartnerKind("ACTOR")
59 
60   override val values: IndexedSeq[PartnerKind] = findValues
61   final val swaggerAllowableValues = "MEDIA,ACTION_PARTNER,FOUNDER,ACTOR"
62 }
Line Stmt Id Pos Tree Symbol Tests Code
48 3940 1620 - 1671 Apply org.make.core.SprayJsonFormatters.forStringValue org.make.core.SprayJsonFormatters.forStringValue[org.make.core.partner.PartnerId](((value: String) => PartnerId.apply(value)))
48 620 1655 - 1670 Apply org.make.core.partner.PartnerId.apply PartnerId.apply(value)
61 2029 2187 - 2223 Literal <nosymbol> "MEDIA,ACTION_PARTNER,FOUNDER,ACTOR"