1) Clone this git repo
2) Do mvn clean install -U locally
3) Go to CostmanagementservApplication.java, right click to start application
4) Use below Postman Collection link to trigger requests
5) For database use, I used in-memory h2 relational database. Table creation is located at data.sql.
Once application started, you can visit http://localhost:8080/h2-console to see the table UI. Below are the username and password to login:
username=sa
password=password
Note: This info is stored in application.properties, feel free to change to your own on your local.
https://www.getpostman.com/collections/918c7e6b50da8c5482a2
Description: Get a list of aggregated costs of each episode for one show, excluding amortized costs, {id} is the show id. This endpoint is designed to work for both episodic or non-episodic shows
Response:
- 200 ok
[{
id:"",
episode_code:"",
amount:""
} ,
{
id:"",
episode_code:"",
amount:""
},
{
id:"",
episode_code:"",
amount:""
}...
]
Note: each amount is the aggregated amount here. episode_code is unique
- 404 not found
Scenario when there is no episode cost for a show. Therefore no corresponding record in our database, throw NOT FOUND exception.
This endpoint is to create a cost transaction for an episode (an episode of a show, you need to provide which show this episode is for.) This endpoint is designed to work for both episodic or non-episodic shows
Response:
- 201 Created Request Body:
{
{
show_id:"",
episode_code:"",
amount:""
}
}
- 400 Validation error can be thrown, See detail in the 'bad data' section
- 200 Ok, scenario when no data is inserted
url path: /prodcosts/{id} This endpoint is to get production costs of each episode for a show, including amortized costs. This endpoint is designed to work for both episodic or non-episodic shows
Response: Note: response body is the same pattern as GET /costs/{id}
- 200 Ok
- 404 Not found, Scenario when there is no episode cost for a show. Therefore no corresponding record in our database, throw NOT FOUND exception.
- show_episode_amount(table name): this table stores each cost transaction for an episode, this table can have multiple shows, a show can have multiple episodes, a episode of a show can have multiple cost amount. Index on show_id, it can return multiple rows.
show_id | episode_code| amount
- POST creation, unrecognized request body calling POST, return 400 bad request
[{
"id":"4",
"episode_co":"2",
"amount":"200"
}
]
- POST creation, Episode code length != 3, , return 400 bad request
[{
"id":"4",
"episode_code":"1111",
"amount":"200"
}
]
- POST creation, request object missing field
[{
"episode_code":"1111",
"amount":"200"
}
]
1) POST creation, if no record created, it should return 200 instead of 201.
2) GET operation, if no record found, it should retun 404.
3) POST creation, able to receive empty list, however it returns 200.
1) Mentioned corner cases/error case scenarios are all tested by postman. Only partial unit tests are covered. Could have better coverage on UT. FT is not added, DAO test is not added here either.
2) For 400 validation errors, could have add detail error msgs to clients, due to limited time, won't add here.
3) If to scale this service, could modulize the code into different modules. This current model is intended only for this code practice.
4) Used jackson JSON library here, would better have submodule for api data model definitions as well as api definitions.
Email: [email protected]