Pet Clinic Application using Spring Boot

The Pet Clinic application plays an important role in the real world in saving pets from different situations. Mostly, online Pet Clinic applications are developed with the required business logic. Here, we’ve created a simple Spring Boot Application for the Pet Clinic Application. This application provides basic functionalities for understanding the Pet Clinic Application, which is used to book an appointment, search for appointment information, get information about available appointments, and other features.

For this application, we use the Spring MVC pattern with the Thymeleaf Java library. Here, we use Thymeleaf to create a Java library which is used in this application to handle the rendering of dynamic data using the Spring MVC pattern. We’ve also created a Book domain class for handling database relations with the help of Repository.

In real-time, there are several services available in the market to save pets from different situations like health issues, cleaning, and others. In this application, we use different information to track the appointment like:

  • slot id: This is automatically generated and assigned to every new appointment, This ID is generated by the Java Script
  • date time: Data and Time of Booking Appointment
  • duration:
    • 30 Minutes
    • 45 Minutes
    • 60 Minutes
    • 2 Hour
    • 3 Hour
    • 4 Hour
    • 5 Hour
  • service type:
    • General Check-up
    • Vaccination
    • Surgery
    • Grooming
  • staff: Staff to Pet to look after
  • status: It gives Booking Status like Available
  • client id: This is automatically generated and assigned to every new client, This Id is generated by the Java-Script
  • client name: Customer Name
  • phone: Customer phone number
  • email: Customer email address
  • pet id: This is automatically generated and assigned to every new pet, This Id is generated by the Java-Script
  • pet name: It is used for gather pet name
  • pet-age: It is used for gather pet age
  • medical history: It is used for gather pet previous medical information
  • microchip: It is used know the pet Micro chip Id
  • payment method: It is used for know the payment method
    • UPI
    • Net Banking
    • Credit Card
    • Debit Card
  • reason: To know the reason to visit the Service.

Prerequisites:

  • Spring Boot Framework: For building the backend services.
  • Thymeleaf: For server-side rendering of HTML.
  • MongoDB: As the NoSQL database to store pet clinic data.
  • Spring MVC Pattern: For handling web requests and responses.
  • Bootstrap Framework: For responsive and styled HTML pages.
  • Project Type is Gradle
  • Spring Tool Suite IDE (STS)

Gradle Dependencies:

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

Spring Initializr:

Using Spring Initializr, we will create the Project .

  • Here we select Project type which is Gradle.
  • We then filled in the Metadata of the Project consisting of: Group Id, Artifact Id, Name, Description, Java version.
  • Also, we added all the important Gradle dependencies that can be found in the build.gradle file here.




Project Structure:

After creating the project, the structure will be like below.

Model Layer

Here we created a POJO class to handle database operations with a repository interface. The POJO class is called PET and we used a dependency of lombok in Spring Boot. Used for Parameterized and non-Parameterized constructors using @Data, @AllArgsConstructor, @NoArgsConstructor, @Document.

Pet.java:

Java
package com.pet.clinic.app;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Document(collection = "petdata")
public class Pet {
    @Id
    private String id;
    private String slotid;
    private String datetime;
    private String duration;
    private String servicetype;
    private String staff;
    private String status;
    private String clientid;
    private String clientname;
    private String phone;
    private String email;
    private String petid;
    private String petname;
    private String petage;
    private String medicalhistory;
    private String microchip;
    private String paymentmethod;
    private String reason;
    
    
}

This domain class have multiple fields to gather information about pet and other information like payment details and customer details.

View Layer

In this layer we display the entire application in the form HTML pages with integration Thymeleaf. The Thymeleaf is used for rendering the data dynamically when controller layer responds. We created these HTML files in the Template which is located in the resource folder of Project. Here we create

  • Index page: This is used for display the default index page while run the spring project
  • Pet Registration page: This page is used for register the pet details to conform the Appointment
  • Search page: This page is used for search the booked Appointment
  • Dashboard page: This page is display the all booked Appointments.


index.html:

HTML
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<link
    href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
    rel="stylesheet">
<link rel="stylesheet"
    href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">
<link rel="shortcut icon"
    href="https://png.pngtree.com/element_our/20190530/ourmid/pngtree-pet-icon-image_1267663.jpg">
<script
    src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
<title>Pet Clinic | Home</title>

</head>

<style>
body {
    font-family: 'Poppins', sans-serif;
}

.navbar-brand {
    color: white !important;
    font-weight: bold;
}

.hero {
    background-image: url('https://wallpaper.forfun.com/fetch/86/86407e4ce2b7e675b833cb23cabce312.jpeg');
    background-size: cover;
    background-position: center;
    height: 80vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: whitesmoke;
}

.hero h1 {
    font-size: 3em;
    font-weight: 700;
}

.services {
    padding: 40px;
    background-color: #f5f5f5;
}

.services h2 {
    text-align: center;
    margin-bottom: 20px;
}

.testimonial {
    background-color: white;
    padding: 40px;
}

.testimonial p {
    font-style: italic;
    text-align: center;
}

.contact {
    padding: 40px;
    text-align: center;
}

.footer {
    background-color: #333;
    color: white;
    text-align: center;
    padding: 20px;
}
</style>

<body>
    <nav class="navbar navbar-expand-sm navbar-light bg-success">
        <div class="container">
            <a class="navbar-brand" href="#"> <i class="fa fa-paw"
                aria-hidden="true"></i> Pet Clinic
            </a>
        </div>
    </nav>

    <section class="hero">
        <div class="container text-center">
            <h1>Welcome to Our Pet Clinic</h1>
            <p>Providing top-notch care for your beloved pets</p>
            <br>
        <a th:href="@{/register}" class="btn btn-success" role="button">Book Appointment</a> &nbsp; &nbsp;
        <a th:href="@{/search}" class="btn btn-light" role="button">Search Appointment</a> &nbsp; &nbsp;
        <a th:href="@{/dashboard}" class="btn btn-primary" role="button">All Appointment</a> &nbsp; &nbsp;
        </div>
        
    </section>
    
    <section class="services">
        <div class="container">
            <h2>Our Services</h2>
            <div class="row">
                <div class="col-md-4 text-center">
                    <i class="fa fa-stethoscope fa-3x" aria-hidden="true"></i>
                    <h3>Veterinary Care</h3>
                    <p>Expert care for all types of pets.</p>
                </div>
                <div class="col-md-4 text-center">
                    <i class="fa fa-cut fa-3x" aria-hidden="true"></i>
                    <h3>Grooming Services</h3>
                    <p>Keep your pet looking and feeling great.</p>
                </div>
                <div class="col-md-4 text-center">
                    <i class="fa fa-heart fa-3x" aria-hidden="true"></i>
                    <h3>Boarding Services</h3>
                    <p>Safe and comfortable boarding for your pets.</p>
                </div>
            </div>
        </div>
    </section>

    <section class="testimonial">
        <div class="container">
            <h2>What Our Clients Say</h2>
            <p>"The best clinic in town! The staff is friendly, and they
                truly care about the pets."</p>
        </div>
    </section>

    <section class="contact">
        <div class="container">
            <h2>Contact Us</h2>
            <p>Email: contact@petclinic.com | Phone: (123) 123-5678</p>
            <p>Address: 123 Pet Street, Petville</p>
        </div>
    </section>

    <div class="footer">
        <p>&copy; 2024 Pet Clinic. All rights reserved.</p>
    </div>
</html>


Output:


Below is the image of service section.


register.html:

HTML
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">
    <link rel="shortcut icon" href="https://png.pngtree.com/element_our/20190530/ourmid/pngtree-pet-icon-image_1267663.jpg">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
    <title>Book Your Slot</title>
    <script>
        // Function to generate a random alphanumeric string of a given length
        function generateRandomString(length) {
            const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
            let result = '';
            for (let i = 0; i < length; i++) {
                result += characters.charAt(Math.floor(Math.random() * characters.length));
            }
            return result;
        }

        // Function to generate a random Slot ID
        function generateSlotID() {
            return 'SLT-' + generateRandomString(6);
        }

        // Function to generate a random Client ID
        function generateClientID() {
            return 'CLT-' + generateRandomString(6);
        }

        // Function to generate a random Pet ID
        function generatePetID() {
            return 'PET-' + generateRandomString(6);
        }

        // Function to get a random availability status
        function generateAvailabilityStatus() {
            const statuses = ['Available'];
            return statuses[Math.floor(Math.random() * statuses.length)];
        }

        // Function to set random values to specific fields in the form
        function populateFields() {
            document.getElementById('slot-id').value = generateSlotID();
            document.getElementById('client-id').value = generateClientID();
            document.getElementById('pet-id').value = generatePetID();
            document.getElementById('availability-status').value = generateAvailabilityStatus();
        }

        // Call the function to populate fields when the document is ready
        document.addEventListener('DOMContentLoaded', populateFields);
    </script>
</head>

<style>
    .navbar-brand{
        color: white !important;
        font-weight: bold;
    }
    form {
        box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
    }

    label {
        margin-bottom: 5px;
        color: black;
        font-weight: 500;
        font-size: 14px;
    }
</style>

<body>
    <nav class="navbar navbar-expand-sm navbar-light bg-success">
        <div class="container">
            <a class="navbar-brand" href="#"><i class="fa fa-paw" aria-hidden="true"></i> Pet Clinic</a>

        </div>
    </nav>
    <main>
        <div class="container p-5">
        <div th:if="${message}" class="alert alert-success alert-dismissible fade show" role="alert">
            <span th:text="${message}"></span>
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
            <form th:action="@{/register}" th:object="${pet}" method="post" class="form-control p-5">
                <h4 class="text-center text-success p-2 mb-3" style="font-weight: bolder; font-family: 'Times New Roman', Times, serif;">Book Your Slot</h4>
                <p class="text text-center text-secondary" style="margin-top: -12px; font-weight: 400;">Save your Pet</p>
                <br><br>
                <h6 class="text-success mb-3"><i class="fa fa-star text-warning" aria-hidden="true"></i> Booking Slot Information</h6>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="mb-3">
                            <label>Slot ID</label>
                            <input type="text" th:field="*{slotid}" readonly class="form-control" id="slot-id" required>
                        </div>
                        <div class="mb-3">
                            <label>Date and Time</label>
                            <input type="datetime-local" th:field="*{datetime}"  class="form-control" name="" required>
                        </div>
                        <div class="mb-3">
                            <label>Duration</label>
                            <select th:field="*{duration}" class="form-control form-select" name="" required>
                                <option value="">Select Duration</option>
                                <option value="30min">30 Minutes</option>
                                <option value="45min">45 Minutes</option>
                                <option value="60min">1 Hour</option>
                                <option value="2hr">2 Hours</option>
                                <option value="3hr">3 Hours</option>
                                <option value="4hr">4 Hours</option>
                                <option value="5hr">5 Hours</option>
                            </select>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <div class="mb-3">
                            <label>Service Type</label>
                            <select th:field="*{servicetype}" class="form-control form-select" name="" required>
                                <option value="">Select Service Type</option>
                                <option value="checkup">General Check-up</option>
                                <option value="vaccination">Vaccination</option>
                                <option value="surgery">Surgery</option>
                                <option value="grooming">Grooming</option>
                            </select>
                        </div>
                        <div class="mb-3">
                            <label>Staff Assigned</label>
                            <input type="text" th:field="*{staff}" class="form-control" required>
                        </div>
                        <div class="mb-3">
                            <label>Availability Status</label>
                            <input type="text" th:field="*{status}" readonly class="form-control" id="availability-status" required>
                        </div>
                    </div>
                </div>
                <br>
                <h6 class="text-success mb-3 mt-3"><i class="fa fa-star text-warning" aria-hidden="true"></i> Client Information</h6>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="mb-3">
                            <label>Client ID</label>
                            <input type="text" th:field="*{clientid}" readonly class="form-control" id="client-id" required>
                        </div>
                        <div class="mb-3">
                            <label>Client Name</label>
                            <input type="text" th:field="*{clientname}" class="form-control" name="" required>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <div class="mb-3">
                            <label>Phone Number</label>
                            <input type="tel" th:field="*{phone}" class="form-control" required>
                        </div>
                        <div class="mb-3">
                            <label>Email Address</label>
                            <input type="email" th:field="*{email}" class="form-control" required>
                        </div>
                    </div>
                </div>
                <br>
                <h6 class="text-success mb-3 mt-3"><i class="fa fa-star text-warning" aria-hidden="true"></i> Pet Information</h6>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="mb-3">
                            <label>Pet ID</label>
                            <input type="text" th:field="*{petid}" readonly class="form-control" id="pet-id" required>
                        </div>
                        <div class="mb-3">
                            <label>Pet Name</label>
                            <input type="text" th:field="*{petname}" class="form-control" required>
                        </div>
                        <div class="mb-3">
                            <label>Pet Age</label>
                            <input type="number" th:field="*{petage}" class="form-control" required>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <div class="mb-3">
                            <label>Medical History</label>
                            <input type="text" th:field="*{medicalhistory}" class="form-control" required>
                        </div>
                        <div class="mb-3">
                            <label>Microchip Number</label>
                            <input type="text" th:field="*{microchip}" class="form-control" required>
                        </div>
                    </div>
                </div>
                <br>
                <div class="row">
                    <div class="col-sm-6">
                        <h6 class="text-success mb-3 mt-3"><i class="fa fa-star text-warning" aria-hidden="true"></i> Payment Method</h6>
                        <div class="mb-3 mt-1">
                            <label>Payment Method</label> 
                            <select th:field="*{paymentmethod}" class="form-control form-select" name="paymentMethod" required>
                                <option value="">Select Payment Method</option>
                                <option value="creditcard">Credit Card</option>
                                <option value="debitcard">Debit card</option>
                                <option value="upi">UPI</option>
                                <option value="banking">Online Banking</option>
                            </select>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <h6 class="text-success mb-3 mt-3"><i class="fa fa-star text-warning" aria-hidden="true"></i> Reason For Visit</h6>
                        <div class="mb-3 mt-1">
                            <label>Reason</label>
                            <input type="text" th:field="*{reason}" class="form-control" required>
                        </div>
                    </div>
                </div>
                <br>
                <button class="btn btn-success">Book My Slot</button>
            </form>
        </div>
    </main>
</body>

</html>


Output:


search.html:

HTML
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<link
    href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
    rel="stylesheet">
<link rel="stylesheet"
    href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">
<link rel="shortcut icon"
    href="https://png.pngtree.com/element_our/20190530/ourmid/pngtree-pet-icon-image_1267663.jpg">
<script
    src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
<title>Pet Clinic | Search Your Booking</title>

<!-- Move style definitions to the head -->
<style>
.navbar-brand {
    color: white !important;
    font-weight: bold;
}
</style>
</head>

<body>
    <nav class="navbar navbar-expand-sm navbar-light bg-success">
        <div class="container">
            <a class="navbar-brand" href="#"><i class="fa fa-paw"
                aria-hidden="true"></i> Pet Clinic</a>
        </div>
    </nav>

    <main>
        <div class="container p-5">

            <h5 class="text mt-4 mb-3">Search Booking by Slot ID</h5>
            <br>
            <form method="post" th:action="@{/search}" th:object="${petSearch}"
                class="form-control">
                <div class="mb-3">
                    <label for="slotid" class="form-label">Slot ID:</label> <input
                        type="text" class="form-control" id="slotid" th:field="*{slotid}">
                </div>
                <button type="submit" class="btn btn-success">Search</button>
            </form>

            <div th:if="${#lists.isEmpty(petList)}"
                class="alert alert-warning mt-3 alert-dismissible fade show"
                role="alert">
                No results found for the given slot ID.
                <button type="button" class="btn-close" data-bs-dismiss="alert"
                    aria-label="Close"></button>
            </div>
            <br>
            <div class="table-responsive">
                <table class="table mt-5" th:if="${!#lists.isEmpty(petList)}">
                    <thead class="bg-success text-light">
                        <tr>
                            <th>Slot ID</th>
                            <th>Client Name</th>
                            <th>Pet Name</th>
                            <th>Date Time</th>
                        </tr>
                    </thead>
                    <tbody class="bg-light">
                        <tr th:each="pet : ${petList}">
                            <td th:text="${pet.slotid}"></td>
                            <td th:text="${pet.clientname}"></td>
                            <td th:text="${pet.petname}"></td>
                            <td th:text="${pet.datetime}"></td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </main>
</body>
</html>


Output:


dashboard.html:

HTML
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">
    <link rel="shortcut icon" href="https://cdn-icons-png.flaticon.com/512/2037/2037551.png">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
    <title>Pet Bookings</title>
</head>

<style>
    .navbar-brand {
        color: white !important;
        font-weight: bold;
    }
    table {
        box-shadow: rgba(0, 0, 0, 0.02) 0px 1px 3px 0px, rgba(27, 31, 35, 0.15) 0px 0px 0px 1px;
    }
    th{
    font-size:14px
    }
    
    td{
        font-size:14px
    }
    
</style>

<body>
    <nav class="navbar navbar-expand-sm navbar-light bg-success">
        <div class="container">
            <a class="navbar-brand" href="#"><i class="fa fa-paw" aria-hidden="true"></i> Pet Clinic</a>
        </div>
    </nav>

    <main>
        <div class="container-fluid">
            <div class="table-responsive mt-5">
                <table class="table table-bordered">
                    <thead class="bg-success text-white">
                        <tr>
                            <th>SI.No</th>
                            <th>Slot ID</th>
                            <th>Date and Time</th>
                            <th>Duration</th>
                            <th>Service Type</th>
                            <th>Staff Assigned</th>
                            <th>Status</th>
                            <th>Client Id</th>
                            <th>Client Name</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Pet Id</th>
                            <th>Pet Name</th>
                            <th>Pet Age</th>
                            <th>Medical History</th>
                            <th>Pet Microchip</th>
                            <th>Payment Method</th>
                            <th>Visiting Reason</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr th:each="pet, iterStat : ${pets}">
                            <td th:text="${iterStat.count}"></td>
                            <td th:text="${pet.slotid}"></td>
                            <td th:text="${pet.datetime}"></td>
                            <td th:text="${pet.duration}"></td>
                            <td th:text="${pet.servicetype}"></td>
                            <td th:text="${pet.staff}"></td>
                            <td th:text="${pet.status}"></td>
                            <td th:text="${pet.clientid}"></td>
                            <td th:text="${pet.clientname}"></td>
                            <td th:text="${pet.phone}"></td>
                            <td th:text="${pet.email}"></td>
                            <td th:text="${pet.petid}"></td>
                            <td th:text="${pet.petname}"></td>
                            <td th:text="${pet.petage}"></td>
                            <td th:text="${pet.medicalhistory}"></td>
                            <td th:text="${pet.microchip}"></td>
                            <td th:text="${pet.paymentmethod}"></td>
                            <td th:text="${pet.reason}"></td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </main>
</body>
</html>


Output:


Repository Interface

The repository interface will extend MongoRepository and will allow CRUD operations on the Pet collection.

PetRepo.java:

Java
package com.pet.clinic.app;

import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface PetRepo extends MongoRepository<Pet, String> {
    // Additional query methods can be defined here if needed
}


Control Layer

In Pet Clinic application, we have created one Controller class with name PetController by using @Controller Spring Annotations.

  • This class is used to define API endpoints for creating API using Web Browser.
  • Here, each API has different requests like GET and POST.
  • It holds all the business logic and provides output to the web through the Thymeleaf Framework.

PetController.java:

Java
package com.pet.clinic.app;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

@Controller
public class PetController {

    @Autowired
    private PetRepo repo;

    @GetMapping("/")
    public String getIndexPage(Model model) {
        return "index";
    }

    @GetMapping("/register")
    public String getRegisterPage(Model model) {
        model.addAttribute("pet", new Pet());
        return "register";
    }
    
    @GetMapping("/search")
    public String getSearchPage(Model model) {
        model.addAttribute("petSearch", new Pet());
        return "search"; 
    }
    
    @GetMapping("/dashboard")
    public String getDashboardPage(Model model) {
        model.addAttribute("pets", repo.findAll());
        return "dashboard";
    }

    @PostMapping("/register")
    public String savePet(@ModelAttribute("pet") Pet pet, RedirectAttributes redirectAttributes) {
        repo.save(pet);
        redirectAttributes.addFlashAttribute("message", "Your Appointment successful Booked!");
        return "redirect:/register";
    }

    @PostMapping("/search")
    public String postSearchPage(@ModelAttribute("petSearch") Pet pet, Model model) {
        String slotId = pet.getSlotid();
        List<Pet> petList = repo.findBySlotid(slotId);
        
        model.addAttribute("petList", petList);
        return "search";
    }
    
}


APIs Information:

In this application, we use different APIs with different mappings for different purposes. Below we provide details for each API included and what it is about to better understand the concept.

1. @GetMapping(“/”):

This API is used by default to display the home page for the end user who hits this URL through the browser. and its mapping type is GET Mapping then only user can view the HTML page. In this home we provide three buttons namely Book Appointment, Search Appointment, All Appointment to access the application service.

http://localhost:8080/
@GetMapping("/")
    public String getIndexPage(Model model) {
        return "index";
    }

Output:


2. @GetMapping(“/register”):

This API is used for display the Pet Registration page to the end user where Hit this URL through browser, and its mapping type is GET Mapping then only user can view the HTML page.

http://localhost:8080/register
    @GetMapping("/register")
    public String getRegisterPage(Model model) {
        model.addAttribute("pet", new Pet());
        return "register";
    }

Output:


3. @GetMapping(“/search”):

This API is used for display search page to the end user where Hit this URL through browser. And Its mapping type is GET Mapping then only user can view the HTML page and we can search our appointment through this business logic by providing slot id.

http://localhost:8080/search
    @GetMapping("/search")
    public String getSearchPage(Model model) {
        model.addAttribute("petSearch", new Pet());
        return "search"; 
    }

Output:


4. @GetMapping(“/dashboard”):

This API is used for display the dashboard page to the end user where Hit this URL through browser. And Its mapping type is GET Mapping then only user can view the HTML page. And It provide all available appointments in the database.

http://localhost:8080/dashboard
    @GetMapping("/dashboard")
    public String getDashboardPage(Model model) {
        model.addAttribute("pets", repo.findAll());
        return "dashboard";
    }


Output:


5. @PostMapping(“/register”):

This API is used for save the Pet, User, payment and other details in the MongoDB by using POST request. When data is successfully saved into db the we get one alert message on the same page for conformation.

http://localhost:8080/register
    @PostMapping("/register")
    public String savePet(@ModelAttribute("pet") Pet pet, RedirectAttributes redirectAttributes) {
        repo.save(pet);
        redirectAttributes.addFlashAttribute("message", "Your Appointment successful Booked!");
        return "redirect:/register";
    }


Output:


6. @PostMapping(“/search”):

This API is used for search the appointment information by using Slot ID in the MongoDB by using POST request. When data is available in database, This search feature returns that information in the form row.

http://localhost:8080/search
    @PostMapping("/search")
    public String postSearchPage(@ModelAttribute("petSearch") Pet pet, Model model) {
        String slotId = pet.getSlotid();
        List<Pet> petList = repo.findBySlotid(slotId);
        
        model.addAttribute("petList", petList);
        return "search";
    }


Output:

If the given Slot Id is available in database then we return that row as output in the table.


In case the given Slot Id is not available in database then we show a alert message for not available.

Download the Project:

To download the entire project, here we have attached the project GitHub link – Pet Clinic Application using Spring Boot



Contact Us