Skip to content

Commit 97fc61c

Browse files
committed
upgrade persistence dependencies + update resource endpoints
1 parent 5aa8e16 commit 97fc61c

File tree

4 files changed

+50
-38
lines changed

4 files changed

+50
-38
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ThisBuild / organization := "app.softnetwork"
3131

3232
name := "resource"
3333

34-
ThisBuild / version := "0.2.2"
34+
ThisBuild / version := "0.2.2.1"
3535

3636
ThisBuild / scalaVersion := "2.12.15"
3737

core/src/main/scala/app/softnetwork/resource/service/ResourceServiceEndpoints.scala

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ trait ResourceServiceEndpoints extends LoadResourceService with ApiEndpoint {
7171
}
7272
}
7373

74-
val libraryEndpoint: ServerEndpoint[Any with AkkaStreams, Future] =
74+
val library: ServerEndpoint[Any with AkkaStreams, Future] =
7575
rootEndpoint.get
7676
.in("library")
7777
.in(paths)
@@ -95,15 +95,15 @@ trait ResourceServiceEndpoints extends LoadResourceService with ApiEndpoint {
9595
case _ => Left(error(ResourceNotFound))
9696
}
9797

98-
val getResourceEndpoint: ServerEndpoint[Any with AkkaStreams, Future] =
98+
val getResource: ServerEndpoint[Any with AkkaStreams, Future] =
9999
rootEndpoint.get
100100
.in(paths)
101101
.out(streamBinaryBody(AkkaStreams)(CodecFormat.OctetStream()))
102102
.serverLogic(principal =>
103103
segments => Future.successful(loadResourceBusinessLogic(principal)(segments))
104104
)
105105

106-
val getImageEndpoint: ServerEndpoint[Any with AkkaStreams, Future] =
106+
val getImage: ServerEndpoint[Any with AkkaStreams, Future] =
107107
rootEndpoint.get
108108
.in("images")
109109
.in(paths)
@@ -114,18 +114,20 @@ trait ResourceServiceEndpoints extends LoadResourceService with ApiEndpoint {
114114
segments => Future.successful(loadResourceBusinessLogic(principal)(segments))
115115
)
116116

117-
val uploadResourceEndpoint: PartialServerEndpoint[
117+
def uploadResource[T <: Upload](implicit
118+
multipartCodec: MultipartCodec[T]
119+
): PartialServerEndpoint[
118120
(Seq[Option[String]], Option[String], Method, Option[String]),
119121
((Seq[Option[String]], Option[CookieValueWithMeta]), Session),
120-
(List[String], UploadResource),
122+
(List[String], T),
121123
ApiErrors.ErrorInfo,
122124
(Seq[Option[String]], Option[CookieValueWithMeta], ResourceResult),
123-
Any with AkkaStreams,
125+
Any,
124126
Future
125127
] =
126128
rootEndpoint
127129
.in(paths.description("URI of the resource"))
128-
.in(multipartBody[UploadResource].description("Multipart file to upload"))
130+
.in(multipartBody[T].description("Multipart file to upload"))
129131
.out(
130132
oneOf[ResourceResult](
131133
oneOfVariant[ResourceCreated.type](
@@ -139,8 +141,10 @@ trait ResourceServiceEndpoints extends LoadResourceService with ApiEndpoint {
139141
)
140142
)
141143

142-
val addResourceEndpoint: ServerEndpoint[Any with AkkaStreams, Future] =
143-
uploadResourceEndpoint.post
144+
def addResource[T <: Upload](implicit
145+
multipartCodec: MultipartCodec[T]
146+
): ServerEndpoint[Any with AkkaStreams, Future] =
147+
uploadResource[T].post
144148
.description("Add a resource")
145149
.serverLogic(principal => { case (segments, upload) =>
146150
uploadResource(principal._2, segments, upload.bytes, update = false) map {
@@ -149,8 +153,10 @@ trait ResourceServiceEndpoints extends LoadResourceService with ApiEndpoint {
149153
}
150154
})
151155

152-
val updateResourceEndpoint: ServerEndpoint[Any with AkkaStreams, Future] =
153-
uploadResourceEndpoint.put
156+
def updateResource[T <: Upload](implicit
157+
multipartCodec: MultipartCodec[T]
158+
): ServerEndpoint[Any with AkkaStreams, Future] =
159+
uploadResource[T].put
154160
.description("Update the resource")
155161
.serverLogic(principal => { case (segments, upload) =>
156162
uploadResource(principal._2, segments, upload.bytes, update = true) map {
@@ -159,10 +165,12 @@ trait ResourceServiceEndpoints extends LoadResourceService with ApiEndpoint {
159165
}
160166
})
161167

162-
val uploadImageEndpoint: PartialServerEndpoint[
168+
def uploadImage[T <: Upload](implicit
169+
multipartCodec: MultipartCodec[T]
170+
): PartialServerEndpoint[
163171
(Seq[Option[String]], Option[String], Method, Option[String]),
164172
((Seq[Option[String]], Option[CookieValueWithMeta]), Session),
165-
(List[String], UploadImage),
173+
(List[String], T),
166174
ApiErrors.ErrorInfo,
167175
(Seq[Option[String]], Option[CookieValueWithMeta], ResourceResult),
168176
Any,
@@ -171,7 +179,7 @@ trait ResourceServiceEndpoints extends LoadResourceService with ApiEndpoint {
171179
rootEndpoint
172180
.in("images")
173181
.in(paths.description("URI of the image"))
174-
.in(multipartBody[UploadImage].description("Multipart image to upload"))
182+
.in(multipartBody[T].description("Multipart image to upload"))
175183
.out(
176184
oneOf[ResourceResult](
177185
oneOfVariant[ResourceCreated.type](
@@ -185,8 +193,10 @@ trait ResourceServiceEndpoints extends LoadResourceService with ApiEndpoint {
185193
)
186194
)
187195

188-
val addImageEndpoint: ServerEndpoint[Any with AkkaStreams, Future] =
189-
uploadImageEndpoint.post
196+
def addImage[T <: Upload](implicit
197+
multipartCodec: MultipartCodec[T]
198+
): ServerEndpoint[Any with AkkaStreams, Future] =
199+
uploadImage[T].post
190200
.description("Add an image")
191201
.serverLogic(principal => { case (segments, upload) =>
192202
uploadResource(principal._2, segments, upload.bytes, update = false) map {
@@ -195,8 +205,10 @@ trait ResourceServiceEndpoints extends LoadResourceService with ApiEndpoint {
195205
}
196206
})
197207

198-
val updateImageEndpoint: ServerEndpoint[Any with AkkaStreams, Future] =
199-
uploadImageEndpoint.put
208+
def updateImage[T <: Upload](implicit
209+
multipartCodec: MultipartCodec[T]
210+
): ServerEndpoint[Any with AkkaStreams, Future] =
211+
uploadImage[T].put
200212
.description("Update the image")
201213
.serverLogic(principal => { case (segments, upload) =>
202214
uploadResource(principal._2, segments, upload.bytes, update = true) map {
@@ -216,7 +228,7 @@ trait ResourceServiceEndpoints extends LoadResourceService with ApiEndpoint {
216228
}
217229
}
218230

219-
val deleteResourceEndpoint: ServerEndpoint[Any with AkkaStreams, Future] =
231+
val deleteResource: ServerEndpoint[Any with AkkaStreams, Future] =
220232
rootEndpoint
221233
.in(paths)
222234
.delete
@@ -228,7 +240,7 @@ trait ResourceServiceEndpoints extends LoadResourceService with ApiEndpoint {
228240
}
229241
)
230242

231-
val deleteImageEndpoint: ServerEndpoint[Any with AkkaStreams, Future] =
243+
val deleteImage: ServerEndpoint[Any with AkkaStreams, Future] =
232244
rootEndpoint
233245
.in("images")
234246
.in(paths)
@@ -241,28 +253,22 @@ trait ResourceServiceEndpoints extends LoadResourceService with ApiEndpoint {
241253
}
242254
)
243255

244-
def innerEndpoints: List[ServerEndpoint[Any with AkkaStreams, Future]] = List(
245-
libraryEndpoint,
246-
getResourceEndpoint,
247-
getImageEndpoint
248-
)
249-
250256
override def endpoints: List[ServerEndpoint[Any with AkkaStreams, Future]] = List(
251-
libraryEndpoint,
252-
addImageEndpoint,
253-
updateImageEndpoint,
254-
getImageEndpoint,
255-
deleteImageEndpoint,
256-
addResourceEndpoint,
257-
updateResourceEndpoint,
258-
getResourceEndpoint,
259-
deleteResourceEndpoint
257+
library,
258+
addImage[UploadImage],
259+
updateImage[UploadImage],
260+
getImage,
261+
deleteImage,
262+
addResource[UploadResource],
263+
updateResource[UploadResource],
264+
getResource,
265+
deleteResource
260266
)
261267

262268
lazy val route: Route = apiRoute
263269
}
264270

265-
trait Upload {
271+
sealed trait Upload {
266272
def bytes: Array[Byte]
267273
}
268274

project/src/main/scala/app/softnetwork/sbt/build/Versions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package app.softnetwork.sbt.build
22

33
object Versions {
44

5-
val genericPersistence = "0.3.2.2"
5+
val genericPersistence = "0.3.2.3"
66

77
val scalatest = "3.1.1"
88
}

testkit/src/main/scala/app/softnetwork/resource/scalatest/ResourceRouteTestKit.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ trait ResourceRouteTestKit[Resource <: GenericResource]
1313
extends SessionTestKit
1414
with ResourceTestKit[Resource] { _: Suite with ApiRoutes =>
1515

16+
override def beforeAll(): Unit = {
17+
super.beforeAll()
18+
// pre load routes
19+
apiRoutes(typedSystem())
20+
}
21+
1622
def resourceEntities: ActorSystem[_] => Seq[PersistentEntity[_, _, _, _]] = sys =>
1723
Seq(resourceEntity(sys)) :+ implicitly[PersistentEntity[_, _, _, _]](
1824
SessionRefreshTokenBehavior

0 commit comments

Comments
 (0)