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.partner
21 
22 import org.make.api.technical.IdGeneratorComponent
23 import org.make.core.partner.{Partner, PartnerId, PartnerKind}
24 import org.make.core.question.QuestionId
25 import org.make.core.user.UserId
26 import org.make.core.Order
27 
28 import scala.concurrent.ExecutionContext.Implicits.global
29 import scala.concurrent.Future
30 import org.make.core.technical.Pagination
31 
32 trait DefaultPartnerServiceComponent extends PartnerServiceComponent {
33   this: PersistentPartnerServiceComponent with IdGeneratorComponent =>
34 
35   override lazy val partnerService: DefaultPartnerService = new DefaultPartnerService
36 
37   class DefaultPartnerService extends PartnerService {
38 
39     override def getPartner(partnerId: PartnerId): Future[Option[Partner]] = {
40       persistentPartnerService.getById(partnerId)
41     }
42 
43     override def createPartner(request: CreatePartnerRequest): Future[Partner] = {
44       val partner: Partner = Partner(
45         partnerId = idGenerator.nextPartnerId(),
46         name = request.name,
47         logo = request.logo,
48         link = request.link,
49         organisationId = request.organisationId,
50         partnerKind = request.partnerKind,
51         questionId = request.questionId,
52         weight = request.weight
53       )
54       persistentPartnerService.persist(partner)
55     }
56 
57     override def updatePartner(partnerId: PartnerId, request: UpdatePartnerRequest): Future[Option[Partner]] = {
58       persistentPartnerService.getById(partnerId).flatMap {
59         case Some(partner) =>
60           persistentPartnerService
61             .modify(
62               partner.copy(
63                 name = request.name,
64                 logo = request.logo,
65                 link = request.link,
66                 organisationId = request.organisationId,
67                 partnerKind = request.partnerKind,
68                 weight = request.weight
69               )
70             )
71             .map(Some.apply)
72         case None => Future.successful(None)
73       }
74     }
75 
76     override def find(
77       offset: Pagination.Offset,
78       end: Option[Pagination.End],
79       sort: Option[String],
80       order: Option[Order],
81       questionId: Option[QuestionId],
82       organisationId: Option[UserId],
83       partnerKind: Option[PartnerKind]
84     ): Future[Seq[Partner]] = {
85       persistentPartnerService.find(offset, end, sort, order, questionId, organisationId, partnerKind)
86     }
87 
88     override def count(
89       questionId: Option[QuestionId],
90       organisationId: Option[UserId],
91       partnerKind: Option[PartnerKind]
92     ): Future[Int] = {
93       persistentPartnerService.count(questionId, organisationId, partnerKind)
94     }
95 
96     override def deletePartner(partnerId: PartnerId): Future[Unit] = {
97       persistentPartnerService.delete(partnerId)
98     }
99 
100   }
101 }
Line Stmt Id Pos Tree Symbol Tests Code
40 25699 1494 - 1537 Apply org.make.api.partner.PersistentPartnerService.getById DefaultPartnerServiceComponent.this.persistentPartnerService.getById(partnerId)
44 25927 1657 - 1974 Apply org.make.core.partner.Partner.apply org.make.api.partner.partnerservicetest org.make.core.partner.Partner.apply(DefaultPartnerServiceComponent.this.idGenerator.nextPartnerId(), request.name, request.logo, request.link, request.organisationId, request.partnerKind, request.questionId, request.weight)
45 23511 1686 - 1713 Apply org.make.core.technical.IdGenerator.nextPartnerId org.make.api.partner.partnerservicetest DefaultPartnerServiceComponent.this.idGenerator.nextPartnerId()
46 27332 1730 - 1742 Select org.make.api.partner.CreatePartnerRequest.name org.make.api.partner.partnerservicetest request.name
47 24927 1759 - 1771 Select org.make.api.partner.CreatePartnerRequest.logo org.make.api.partner.partnerservicetest request.logo
48 23823 1788 - 1800 Select org.make.api.partner.CreatePartnerRequest.link org.make.api.partner.partnerservicetest request.link
49 27765 1827 - 1849 Select org.make.api.partner.CreatePartnerRequest.organisationId org.make.api.partner.partnerservicetest request.organisationId
50 25393 1873 - 1892 Select org.make.api.partner.CreatePartnerRequest.partnerKind org.make.api.partner.partnerservicetest request.partnerKind
51 23053 1915 - 1933 Select org.make.api.partner.CreatePartnerRequest.questionId org.make.api.partner.partnerservicetest request.questionId
52 28243 1952 - 1966 Select org.make.api.partner.CreatePartnerRequest.weight org.make.api.partner.partnerservicetest request.weight
54 23640 1981 - 2022 Apply org.make.api.partner.PersistentPartnerService.persist org.make.api.partner.partnerservicetest DefaultPartnerServiceComponent.this.persistentPartnerService.persist(partner)
58 27120 2149 - 2687 ApplyToImplicitArgs scala.concurrent.Future.flatMap org.make.api.partner.partnerservicetest DefaultPartnerServiceComponent.this.persistentPartnerService.getById(partnerId).flatMap[Option[org.make.core.partner.Partner]](((x0$1: Option[org.make.core.partner.Partner]) => x0$1 match { case (value: org.make.core.partner.Partner): Some[org.make.core.partner.Partner]((partner @ _)) => DefaultPartnerServiceComponent.this.persistentPartnerService.modify({ <artifact> val x$1: String = request.name; <artifact> val x$2: Option[String] @scala.reflect.internal.annotations.uncheckedBounds = request.logo; <artifact> val x$3: Option[String] @scala.reflect.internal.annotations.uncheckedBounds = request.link; <artifact> val x$4: Option[org.make.core.user.UserId] @scala.reflect.internal.annotations.uncheckedBounds = request.organisationId; <artifact> val x$5: org.make.core.partner.PartnerKind = request.partnerKind; <artifact> val x$6: Float = request.weight; <artifact> val x$7: org.make.core.partner.PartnerId = partner.copy$default$1; <artifact> val x$8: org.make.core.question.QuestionId = partner.copy$default$7; partner.copy(x$7, x$1, x$2, x$3, x$4, x$5, x$8, x$6) }).map[Some[org.make.core.partner.Partner]](((value: org.make.core.partner.Partner) => scala.Some.apply[org.make.core.partner.Partner](value)))(scala.concurrent.ExecutionContext.Implicits.global) case scala.None => scala.concurrent.Future.successful[None.type](scala.None) }))(scala.concurrent.ExecutionContext.Implicits.global)
58 23202 2201 - 2201 Select scala.concurrent.ExecutionContext.Implicits.global org.make.api.partner.partnerservicetest scala.concurrent.ExecutionContext.Implicits.global
62 25870 2311 - 2311 Select org.make.core.partner.Partner.copy$default$7 partner.copy$default$7
62 26824 2311 - 2311 Select org.make.core.partner.Partner.copy$default$1 partner.copy$default$1
62 23653 2303 - 2591 Apply org.make.core.partner.Partner.copy partner.copy(x$7, x$1, x$2, x$3, x$4, x$5, x$8, x$6)
63 27262 2340 - 2352 Select org.make.api.partner.UpdatePartnerRequest.name request.name
64 24938 2377 - 2389 Select org.make.api.partner.UpdatePartnerRequest.logo request.logo
65 24123 2414 - 2426 Select org.make.api.partner.UpdatePartnerRequest.link request.link
66 27777 2461 - 2483 Select org.make.api.partner.UpdatePartnerRequest.organisationId request.organisationId
67 25615 2515 - 2534 Select org.make.api.partner.UpdatePartnerRequest.partnerKind request.partnerKind
68 23366 2561 - 2575 Select org.make.api.partner.UpdatePartnerRequest.weight request.weight
71 23998 2243 - 2634 ApplyToImplicitArgs scala.concurrent.Future.map DefaultPartnerServiceComponent.this.persistentPartnerService.modify({ <artifact> val x$1: String = request.name; <artifact> val x$2: Option[String] @scala.reflect.internal.annotations.uncheckedBounds = request.logo; <artifact> val x$3: Option[String] @scala.reflect.internal.annotations.uncheckedBounds = request.link; <artifact> val x$4: Option[org.make.core.user.UserId] @scala.reflect.internal.annotations.uncheckedBounds = request.organisationId; <artifact> val x$5: org.make.core.partner.PartnerKind = request.partnerKind; <artifact> val x$6: Float = request.weight; <artifact> val x$7: org.make.core.partner.PartnerId = partner.copy$default$1; <artifact> val x$8: org.make.core.question.QuestionId = partner.copy$default$7; partner.copy(x$7, x$1, x$2, x$3, x$4, x$5, x$8, x$6) }).map[Some[org.make.core.partner.Partner]](((value: org.make.core.partner.Partner) => scala.Some.apply[org.make.core.partner.Partner](value)))(scala.concurrent.ExecutionContext.Implicits.global)
71 25253 2622 - 2622 Select scala.concurrent.ExecutionContext.Implicits.global scala.concurrent.ExecutionContext.Implicits.global
71 27316 2623 - 2633 Apply scala.Some.apply scala.Some.apply[org.make.core.partner.Partner](value)
72 25539 2656 - 2679 Apply scala.concurrent.Future.successful scala.concurrent.Future.successful[None.type](scala.None)
72 27788 2674 - 2678 Select scala.None scala.None
85 25880 2995 - 3091 Apply org.make.api.partner.PersistentPartnerService.find DefaultPartnerServiceComponent.this.persistentPartnerService.find(offset, end, sort, order, questionId, organisationId, partnerKind)
93 23658 3267 - 3338 Apply org.make.api.partner.PersistentPartnerService.count DefaultPartnerServiceComponent.this.persistentPartnerService.count(questionId, organisationId, partnerKind)
97 27251 3423 - 3465 Apply org.make.api.partner.PersistentPartnerService.delete DefaultPartnerServiceComponent.this.persistentPartnerService.delete(partnerId)