Library Book Management Web Application
Tags: atlashackathon22
Published: 2022-12-08 17:25:38

### Overview of My Submission

**About the web app (functionalities and flow)**

- This is a small web application for a library. The main goal of this web application is to allow users to add/view books and organize them into a table. The data can then be updated and deleted as needed.

**Used technologies/languages and reasons**

To create this web application, I used spring boot with the mongo DB. As a client, to test the web application we used POSTMAN.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eh7utkv25ncozeesa76r.png)

In the very first I went to start.spring.io, which is a spring initializer. In there I had to enter the relevant details of the project, which programming language I used to implement this, Spring Boot version likewise .Then I havd to generate this file. This is downloading as a zip file. After that I had to open it using Eclipse. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/itugao6iovwiuv7fzrzt.png)

**Testing and Results with explaining CRUD operations **

•CRUD operations have been viewed in computer programming as the four core functions of persistent storage: creation, read, update, and delete (CRUD).

•For testing, I utilized Postman, which is more versatile and allows us to test all endpoints.

**Create Operation:**

The create operation is a POST request that takes a BookLibrary model object as an input and saves it to Mongo DB using the repository's save() method. It returns the saved instance, which will have the unique id.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ezc0w4r37wjfssesva8d.png)

 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6c6tfwg4g4o6fa3f1b9f.png)

**Read Operation:**

The read operation is a GET request to return all of a collection's documents.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6lffzxk2e0m4r3wtfoo.png)

**Update Operation:**

The update operation makes use of a PUT request, accepts book Id as a path variable, and utilizes the same save method (). Because the id is contained in the model object, it will be updated in the database in this scenario.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n9r4w46fjnj7435pe97x.png)

**Delete Operation: **

The delete action makes use of the delete request. The controller implementation is shown below.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5rgbedxid52luccovkzp.png)

Further I used validations to this web application.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q1q1bqzlhywpuc4nf59h.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/715fu6cecd5hcmei1gl5.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w1zuoy2yh5cvez0vgauf.png)

**Guidelines to test the app**

Open the main application file and run it as a Java program to launch the Spring Boot application. The message appears in the console after the application runs correctly, as illustrated below. Now open the browser and type http://localhost:8080 into the address bar.

Open postman and click the ‘create’ button.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/crgsf6q3rn8aybdy66w5.png)

1.First, click the ‘new’ button.
2.After that click on the ‘Get request’.

Fill in the form to create the Get Request
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/25ut0xtmib1aei4yjkt3.png)

Fill in the request name and store it to a collection; if one doesn't exist, make one. 

We'd get an empty postman request now:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l1oiib35xb8xqo2pcdko.png)

Send a simple restful get request to the spring boot service using Postman. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v3w2nzols7hy53i0tmtq.png)

We'd get the following result if we ran across the breakpoint. 

**Add http post api to codes.**

**Add this code to the controller:**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j38v3x5tswe0i7mv1rml.png)

It contains two features:

1.It has a new endpoint named ‘/book’ which accepts an json object and call the service to save it
2.It has a new endpoint named ‘/book/{id}’ which accepts an id and return the specified book object as json.

**Add this code to the service:**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yqe0amzaui6wroh73y7h.png)

To save and query the Book object, it simply uses Spring data JPA.

**Test the post api with postman**

Create a new http request in postman

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7rpchsyv1yo9g5t1ee72.png)

Ensure that the POST http method is selected.

Input the post url and headers.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pkc1plwetqp58p7de5on.png)

The following http headers are required by the Spring Boot restful post api:

1.Content Type -application/json
2.Accept- application/json

It signifies that the server expects the client to send the item in json format.

Input the body of the http post Instead of using the http url to pass the request body, the http post protocol uses the http body to do so.

If we don't want to manually construct the json string, go to (localhost:8080/BookLibrary/Book/1) to acquire a json template for the Book class.


### Submission Category: 

Own Adventure

### Link to Code

{% embed https://github.com/kithminiii/MongoAtlas-Hackathon %}