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.feature
21 
22 import org.make.api.technical._
23 import org.make.core.technical.Pagination
24 import org.make.core.feature._
25 import org.make.core.Order
26 
27 import scala.concurrent.ExecutionContext.Implicits.global
28 import scala.concurrent.Future
29 
30 trait DefaultFeatureServiceComponent extends FeatureServiceComponent with ShortenedNames {
31   this: PersistentFeatureServiceComponent with IdGeneratorComponent =>
32 
33   override lazy val featureService: FeatureService = new DefaultFeatureService
34 
35   class DefaultFeatureService extends FeatureService {
36 
37     override def getFeature(featureId: FeatureId): Future[Option[Feature]] = {
38       persistentFeatureService.get(featureId)
39     }
40 
41     override def createFeature(slug: FeatureSlug, name: String): Future[Feature] = {
42       persistentFeatureService.persist(Feature(featureId = idGenerator.nextFeatureId(), slug = slug, name = name))
43     }
44 
45     override def findBySlug(slug: FeatureSlug): Future[Seq[Feature]] = {
46       persistentFeatureService.findBySlug(slug)
47     }
48 
49     override def updateFeature(featureId: FeatureId, slug: FeatureSlug, name: String): Future[Option[Feature]] = {
50       persistentFeatureService.get(featureId).flatMap {
51         case Some(feature) =>
52           persistentFeatureService.update(feature.copy(slug = slug, name = name))
53         case None => Future.successful(None)
54       }
55     }
56 
57     override def deleteFeature(featureId: FeatureId): Future[Unit] = {
58       persistentFeatureService.remove(featureId)
59     }
60 
61     override def findByFeatureIds(featureIds: Seq[FeatureId]): Future[Seq[Feature]] = {
62       persistentFeatureService.findByFeatureIds(featureIds)
63     }
64 
65     override def find(
66       offset: Pagination.Offset = Pagination.Offset.zero,
67       end: Option[Pagination.End] = None,
68       sort: Option[String] = None,
69       order: Option[Order] = None,
70       slug: Option[String]
71     ): Future[Seq[Feature]] =
72       persistentFeatureService.find(offset, end, sort, order, slug)
73 
74     override def count(slug: Option[String]): Future[Int] = {
75       persistentFeatureService.count(slug)
76     }
77   }
78 }
Line Stmt Id Pos Tree Symbol Tests Code
38 22500 1382 - 1421 Apply org.make.api.feature.PersistentFeatureService.get org.make.api.feature.featureservicetest DefaultFeatureServiceComponent.this.persistentFeatureService.get(featureId)
42 22834 1520 - 1628 Apply org.make.api.feature.PersistentFeatureService.persist org.make.api.feature.featureservicetest DefaultFeatureServiceComponent.this.persistentFeatureService.persist({ <artifact> val x$1: org.make.core.feature.FeatureId = DefaultFeatureServiceComponent.this.idGenerator.nextFeatureId(); <artifact> val x$2: org.make.core.feature.FeatureSlug = slug; <artifact> val x$3: String = name; org.make.core.feature.Feature.apply(x$1, x$3, x$2) })
42 25175 1553 - 1627 Apply org.make.core.feature.Feature.apply org.make.api.feature.featureservicetest org.make.core.feature.Feature.apply(x$1, x$3, x$2)
42 26192 1573 - 1600 Apply org.make.core.technical.IdGenerator.nextFeatureId org.make.api.feature.featureservicetest DefaultFeatureServiceComponent.this.idGenerator.nextFeatureId()
46 26650 1715 - 1756 Apply org.make.api.feature.PersistentFeatureService.findBySlug org.make.api.feature.featureservicetest DefaultFeatureServiceComponent.this.persistentFeatureService.findBySlug(slug)
50 24990 1885 - 2099 ApplyToImplicitArgs scala.concurrent.Future.flatMap org.make.api.feature.featureservicetest DefaultFeatureServiceComponent.this.persistentFeatureService.get(featureId).flatMap[Option[org.make.core.feature.Feature]](((x0$1: Option[org.make.core.feature.Feature]) => x0$1 match { case (value: org.make.core.feature.Feature): Some[org.make.core.feature.Feature]((feature @ _)) => DefaultFeatureServiceComponent.this.persistentFeatureService.update({ <artifact> val x$1: org.make.core.feature.FeatureSlug = slug; <artifact> val x$2: String = name; <artifact> val x$3: org.make.core.feature.FeatureId = feature.copy$default$1; feature.copy(x$3, x$2, x$1) }) case scala.None => scala.concurrent.Future.successful[None.type](scala.None) }))(scala.concurrent.ExecutionContext.Implicits.global)
50 26120 1933 - 1933 Select scala.concurrent.ExecutionContext.Implicits.global org.make.api.feature.featureservicetest scala.concurrent.ExecutionContext.Implicits.global
52 24228 2015 - 2015 Select org.make.core.feature.Feature.copy$default$1 feature.copy$default$1
52 23106 2007 - 2045 Apply org.make.core.feature.Feature.copy feature.copy(x$3, x$2, x$1)
52 27045 1975 - 2046 Apply org.make.api.feature.PersistentFeatureService.update DefaultFeatureServiceComponent.this.persistentFeatureService.update({ <artifact> val x$1: org.make.core.feature.FeatureSlug = slug; <artifact> val x$2: String = name; <artifact> val x$3: org.make.core.feature.FeatureId = feature.copy$default$1; feature.copy(x$3, x$2, x$1) })
53 24707 2086 - 2090 Select scala.None scala.None
53 22512 2068 - 2091 Apply scala.concurrent.Future.successful scala.concurrent.Future.successful[None.type](scala.None)
58 22758 2184 - 2226 Apply org.make.api.feature.PersistentFeatureService.remove DefaultFeatureServiceComponent.this.persistentFeatureService.remove(featureId)
62 26584 2328 - 2381 Apply org.make.api.feature.PersistentFeatureService.findByFeatureIds DefaultFeatureServiceComponent.this.persistentFeatureService.findByFeatureIds(featureIds)
72 24241 2645 - 2706 Apply org.make.api.feature.PersistentFeatureService.find DefaultFeatureServiceComponent.this.persistentFeatureService.find(offset, end, sort, order, slug)
75 23041 2776 - 2812 Apply org.make.api.feature.PersistentFeatureService.count DefaultFeatureServiceComponent.this.persistentFeatureService.count(slug)