scozv / bolero Goto Github PK
View Code? Open in Web Editor NEWBolero, a RESTful Scaffold with Scala, Play! and ReactMongo
License: Other
Bolero, a RESTful Scaffold with Scala, Play! and ReactMongo
License: Other
Bolero recommends an uniform HTTP Response design, that is all HTTP Response will be formatted as:
{
ok: Boolean,
data: T
error: String
}
see
app/controllers/CanResponse.scala
app/models/interop/HTTPResponse.scala
need to add a script:
name
bolero
to name
playGenerateSecret
The codes for challenge assignment are written within 3 consecutive day.
Percisely, they are started from Sep 3, 08:47
to Sep 4, 19:46
. (see picture below)
The codes written before Sep 3, 08:47
are extracted from my SJTU project of last year
as a RESTful Code Template named Bolero
.
Read more about Bolero
from my posts:
The codes in test/WithApplication.scala
are copied from Play! 2.3
in order to make the Specs2
tests of Play! 2.3
even when I upgraded
project to Play! 2.4
.
I created 2 solutions for code challenge: liq-v1
and liq-v2
.
They are corresponding to the branches (see picture below):
feature/liq-v1
feature/liq-v2
and to the deployments:
liq-v1.cloudapp.net
liq-v2.cloudapp.net
liq-v1
works as expected as the challenage assignment.
I prefer to liq-v2
that has 2 major differents from liq-v1
:
liq-v2
Transaction
model (tx for short) is defined as:
{
_id: String, amount: Double, type: String, pranrent_id: String
}
Lists all tx data (generated by activator test
).
HTTP Response:
{
ok: true,
data: List[Transaction],
error: ""
}
Creates tx.
HTTP Payload data is Transaction
.
HTTP Response:
{
ok: true,
data: Transaction
error: ""
}
error
Response will be returned when PUT
duplicated _id
.
Gets a specific tx data.
HTTP Response:
{
ok: true,
data: Transaction,
error: ""
}
NOT_FOUND
Response will be returned if _id
is not existed, such as:
{"ok":false,"error":"201","data":"not found record in MongoDB from GET /transactionservice/transaction/1024"}
Lists the transaction_id
of specific type.
If :type
is not existed, empty array will be returned.
HTTP Response:
{
ok: true,
data: List[String],
error: ""
}
Gets the total amount of related tx data.
If :id
is not existed, 0 will be returned.
HTTP Response:
{
ok: true,
data: Double,
error: ""
}
we need the Tests
I prefer to String _id
other than Numeric _id
, because:
_id
contains A
, B
... that can be used as the categories,RegEx
on String _id
, especially when we are using MongoDB
ModelOrError[A].map(A => B): ModelOrError[B]
ModelOrError[A].flatMap(A => ModelOrError[B]): ModelOrError[B]
See biz.rules
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.