roberson-miguel / zmovies

Código do desafio backend

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What is this

Just a study project based on a interview challenge I took years ago.

I use it to experiment with a few architecture ideas and to practice TDD.

Also, used as example on classes I give.

arch

Getting Started

These instructions will get the project up and running on your local machine for testing purposes.

Running

Use gradle to raise the docker container with MongoDB and run the application

gradle composeUp run

API endpoints

These endpoints allow you to save and retrieve movie information. There is a a Postman collection supplied with the code that has sample requests for convenience.

GET

Retrieve movies by rate [/movies/:rate]

Request

GET /movies/SEM_CENSURA

curl -i -H 'Accept: application/json' http://localhost:7000/movies/SEM_CENSURA

Response

HTTP/1.1 200 OK
Date: Sat, 08 Feb 2020 16:37:25 GMT
Server: Javalin
Content-Type: application/json
Content-Length: 138

[{"title":"ET","releaseDate":390960000000,"rate":"SEM_CENSURA","director":"Steven Spielberg","actors":["Drew Barrymore","Henry Thomas"]}]n

POST

Save a new movie [/movie]

Request

POST /movie/

curl -X POST \
 http://localhost:7000/movie \
 -H 'Accept: */*' \
 -H 'Accept-Encoding: gzip, deflate' \
 -H 'Cache-Control: no-cache' \
 -H 'Connection: keep-alive' \
 -H 'Content-Length: 190' \
 -H 'Content-Type: application/json' \
 -H 'Host: localhost:7000' \
 -H 'Postman-Token: eaf509f3-4802-43b0-82a2-6a171e200a76,5b491353-6532-4e61-9020-f19226132ca3' \
 -H 'User-Agent: PostmanRuntime/7.19.0' \
 -H 'cache-control: no-cache' \
 -d '{
   "actors": [
       "Drew Barrymore",
       "Henry Thomas"
   ],
   "director": "Steven Spielberg",
   "rate": "SEM_CENSURA",
   "releaseDate": "1982-05-23",
   "title": "ET"
    }'

Response

 {
    "title": "ET",
    "releaseDate": 390960000000,
    "rate": "SEM_CENSURA",
    "director": "Steven Spielberg",
    "actors": [
      "Drew Barrymore",
      "Henry Thomas"
      ]
   }

Running the tests

The code was done relying heavily on TDD, so we have a comprehensive code coverage. You can run the unit tests using gradle

gradle test

Automatic end-to-end testing is supplied by component testing, that evaluates the business rules supplied on the challenge. You can run the components tests also by using gradle

gradle componentTest

Integration tests

Integration tests can be achieved by using the postman collection supplied with the code. testResults

On the joice of the web framework

I chose Javalin, a lightweight web framework that I have been using lately.

The learning curve is flat and the amount of boiler plate code tends to be among the lower for java or kotlin web frameworks. It's style resembles Express.

It runs over a jetty server.

Built With

  • Kotlin - The programming language that does more with less code
  • Javalin - A lightweight web framework for Java and Kotlin
  • MongoDB - NoSQL document based database
  • Koin - Dependency injection for Kotlin
  • Gradle - More than just a building toolkit

Author

  • Sidharta Rezende

About

Código do desafio backend


Languages

Language:Kotlin 99.6%Language:Shell 0.4%