- Java
- MongoDB
- Spring Boot
- MongoDB
- Java
- Used Java+SprintBoot to start the application.
- To store the data I used MongoDB as my database.
- I configured mongo as
localhost
(not added any authentication) and database asendor
. - Added two models as
Person
andAnimal
and both are pointing to the same collection calleditem
. - The two models have the fields like
id
,name
andkind
and proper getters and setters and added index for required fields. - Now coming to DAO's. Defined a
GenericDao
interface and it has common methods and added anAbstractDao
. AbstractDao
is responsible to maintain the common implementation. Along with this abstract class I define two more Dao classes.- Those are
PersonDao
andAnimalDao
. These classes have methods where which doesn't have common methods. - Then added corresponding controllers
PersonController
andAnimalController
. Where these controller are responsible to serve the HTTP requests. - Also, added test cases for both Dao's and Controllers. The test cases includes both unit test and e2e (end-to-end) test cases. Created seperate folders for both.
- Run the application by using the class called
EndorMain
under thesrc/
folder.
-
Save Person:
curl --location --request POST 'http://localhost:8080/person/' \ --header 'Content-Type: application/json' \ --data-raw '{ "id": "123", "name": "Endor" }'
-
Get Person By ID:
curl --location --request GET 'http://localhost:8080/person/{ID}'
-
Get Persons:
curl --location --request GET 'http://localhost:8080/person/'
-
Delete Person By ID:
curl --location --request DELETE 'http://localhost:8080/person/{ID}'
-
Save Animal:
curl --location --request POST 'http://localhost:8080/animal/' \ --header 'Content-Type: application/json' \ --data-raw '{ "id": "456", "name": "Lion" }'
-
Get Animal By ID:
curl --location --request GET 'http://localhost:8080/animal/{ID}'
-
Get Animals:
curl --location --request GET 'http://localhost:8080/animal/'
-
Delete Animal By ID:
curl --location --request DELETE 'http://localhost:8080/animal/{ID}'