Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ARSnova Scala Prototype
Manage
Activity
Members
Labels
Plan
Issues
16
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Privacy
Imprint
Contact
Snippets
Groups
Projects
Show more breadcrumbs
ARSnova
ARSnova Scala Prototype
Commits
fdba2557
Commit
fdba2557
authored
8 years ago
by
Tom Käsler
Browse files
Options
Downloads
Patches
Plain Diff
add api definition for global motd
parent
53f1e7ad
1 merge request
!13
Motd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/scala/de/thm/arsnova/api/GlobalMotdApi.scala
+57
-3
57 additions, 3 deletions
src/main/scala/de/thm/arsnova/api/GlobalMotdApi.scala
with
57 additions
and
3 deletions
src/main/scala/de/thm/arsnova/api/GlobalMotdApi.scala
+
57
−
3
View file @
fdba2557
package
de.thm.arsnova.api
/**
* Created by tekay on 3/22/17.
*/
import
de.thm.arsnova.services.GlobalMotdService
import
de.thm.arsnova.models._
import
de.thm.arsnova.hateoas.
{
ApiRoutes
,
ResourceAdapter
,
Link
}
import
scala.concurrent.ExecutionContext.Implicits.global
import
akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
import
akka.http.scaladsl.server.Directives._
import
spray.json._
/*
The API Interface regarding global messages.
Only an admin should post these motd
*/
trait
GlobalMotdApi
{
// protocol for serializing data
import
de.thm.arsnova.mappings.GlobalMotdJsonProtocol._
// add the "top level" endpoint to ApiRoutes
ApiRoutes
.
addRoute
(
"globalmotd"
,
"globalmotd"
)
// function to generate the model links
def
globalMotdLinks
(
motd
:
GlobalMotd
)
:
Seq
[
Link
]
=
{
Seq
(
Link
(
"self"
,
s
"/${ApiRoutes.getRoute("
globalmotd
")}/${motd.id.get}"
)
)
}
// the HATEOAS Adapter
val
globalMotdAdapter
=
new
ResourceAdapter
[
GlobalMotd
](
globalMotdFormat
,
globalMotdLinks
)
val
globalMotdApi
=
pathPrefix
(
ApiRoutes
.
getRoute
(
"globalmotd"
))
{
pathEndOrSingleSlash
{
get
{
parameter
(
"audience"
.
as
[
String
])
{
audience
=>
complete
(
GlobalMotdService
.
getByAudience
(
audience
).
map
(
globalMotdAdapter
.
toResources
(
_
)))
}
}
~
post
{
entity
(
as
[
GlobalMotd
])
{
motd
=>
complete
(
GlobalMotdService
.
create
(
motd
).
map
(
_
.
toJson
))
}
}
}
~
pathPrefix
(
IntNumber
)
{
motdId
=>
pathEndOrSingleSlash
{
get
{
complete
(
GlobalMotdService
.
getById
(
motdId
).
map
(
globalMotdAdapter
.
toResource
(
_
)))
}
~
put
{
entity
(
as
[
GlobalMotd
])
{
motd
=>
complete
(
GlobalMotdService
.
update
(
motd
).
map
(
_
.
toJson
))
}
}
~
delete
{
complete
(
GlobalMotdService
.
delete
(
motdId
).
map
(
_
.
toJson
))
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment