-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update readme inputformat v2 #6
Open
AminJELLADParticeep
wants to merge
10
commits into
master
Choose a base branch
from
update-readme-inputformat-v2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2ec4dd6
WIP: added more explication about input format
AminJELLADParticeep 3004642
deleted french sentence
AminJELLADParticeep 638d93a
added example
AminJELLADParticeep 25d083e
updated readme according to pull request
AminJELLADParticeep 53c1acb
deleted useless sentence
AminJELLADParticeep 2052520
deleted automatic format, add new sentences
AminJELLADParticeep 5f43100
deleted last automatic format
AminJELLADParticeep b7b6822
I promise this time all automatic format has been deleted
AminJELLADParticeep 2b6379b
wip
AminJELLADParticeep a948c40
take count comment from pr
AminJELLADParticeep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,10 @@ There are 3 sbt modules | |
|
||
The main goal is to complete the module `/modules/03-newpricer` with code that implements the pricer assigned to you. | ||
|
||
Important : | ||
* You should not change any code outside the 03-newpricer module | ||
* You should not rename the module `newpricer`, the rule apply to class like NewPricerConfig | ||
|
||
Especially this part which contains an unimplemented method, i.e. with `???` as a body | ||
|
||
* `InputFormatFactory.input_format_quote` | ||
|
@@ -64,17 +68,29 @@ And empty case class | |
# InputFormat | ||
|
||
InputFormat is a schema that describes json in a way that suits our needs. | ||
InputFormat is a schema that describes the json input needed by the webservice. It's a static constant. | ||
|
||
InputFormat describes the json input needed by the webservice. It's a static constant. | ||
The building blocks are defined in the domain module | ||
|
||
* `input_format_quote` describes the json input of the `quote` endpoint | ||
* `input_format_select` describes the json input of the `select` endpoint, minus any fields already defined in `input_format_quote` | ||
|
||
## Basic structure | ||
### how does it work ? | ||
You can see input format like a schema and not a function. What you put in define a case class. This schema is parsed by another application, and you do not have to think about it. | ||
For your perimeter you just have to translate into input format your case class. Case class you have to transform into input format are case class for quote and case class for select. | ||
|
||
```scala | ||
All the data you are going to receive comes from an external server, let's call it X. | ||
the purpose of the server X is to send you the JSON-formatted representation of your classes. | ||
Therefore, it will suffice to use play json to transform the JSON into the format of the expected class | ||
For this, it will send you the JSON depending on how you defined the input format. | ||
|
||
Note : Server X will always send you all input you need to implement quote and select. It includes your input format for quote, select and external data if you defined one. | ||
|
||
As mentioned above, you are not going to dialogue with the server X, to check the input_format you have to do a unit test that takes a json as input | ||
and sees if by transforming the json into the expected class there is no problem | ||
|
||
## Basic structure | ||
Input format is defined in module "domain" : | ||
```scala | ||
case class InputFormat( | ||
// The name of the field, like the name of a field in an HTML form. It's the unique identifier of the field | ||
name: String, | ||
|
@@ -111,7 +127,27 @@ NB 1: if `is_array` is true, then the json type is an array and the elements of | |
NB 2: if `is_array` is false and `multiple` is true then this is the case where it creates a checkbox, and fields defined by data in the "option" attribute. | ||
|
||
## Sample Code | ||
|
||
Let's see an example. | ||
In input, we received a JSON. | ||
|
||
```JSON | ||
{ | ||
"assures" : [ { | ||
"civility" : "MR", | ||
"first_name" : "Patrick", | ||
"last_name" : "smile", | ||
"birthdate" : "2002-08-24T07:52:54Z", | ||
"is_smoking" : true | ||
}, { | ||
"civility" : "MME", | ||
"first_name" : "Sofia", | ||
"last_name" : "smile", | ||
"birthdate" : "1992-08-24T07:52:54Z", | ||
"is_smoking" : false | ||
} ] | ||
} | ||
``` | ||
This input correspond to this input format : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This input will be validated in success with this input format |
||
```scala | ||
|
||
val insureds_format = { | ||
|
@@ -153,6 +189,43 @@ private[this] def smoker_format: InputFormat = { | |
} | ||
|
||
``` | ||
If needed, you can create a case class corresponding to your input format | ||
```scala | ||
|
||
final case class InsuredInformation( | ||
civility : String, | ||
first_name : String, | ||
last_name : String, | ||
birthdate : OffsetDateTime, | ||
s_smoking : Option[Boolean] | ||
) | ||
final case class Data(assures : List[InsuredInformation]) | ||
``` | ||
And then, you can use .validate to parse your JSON. | ||
````scala | ||
val data_from_server_x : JsValue = { | ||
"assures" : [ { | ||
"civility" : "MR", | ||
"first_name" : "Patrick", | ||
"last_name" : "smile", | ||
"birthdate" : "2002-08-24T07:52:54Z", | ||
"is_smoking" : true | ||
}, { | ||
"civility" : "MME", | ||
"first_name" : "Sofia", | ||
"last_name" : "smile", | ||
"birthdate" : "1992-08-24T07:52:54Z", | ||
"is_smoking" : false | ||
} ] | ||
} | ||
|
||
for { | ||
value : Data <- data_from_server_x.validate[Data] ?| "error during parsing" | ||
??? | ||
}yield { | ||
??? | ||
} | ||
```` | ||
|
||
# Quote endpoint | ||
|
||
|
@@ -414,6 +487,8 @@ For more detail, see this article : https://medium.com/@adriencrovetto/error-han | |
* enforce encapsulation as much as possible, e.g. use private[newpricer] except for the three methods implemented by `PricerService`. Use private[this] if needed. | ||
* run `sbt scalastyle` and clean up the warning | ||
* run `sbt fmt` and format the code | ||
* no `.as` use `.validate` | ||
* no `asInstanceOf`or all types of method which break immutable principe | ||
|
||
# error management and log | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Le commentaire a sauté mais reste vrai : il faut enlever tout ce paragraphe, ca donne des infos peu clair qui vont embrouiller les gens
Tu peux remplacer par qlc de simple