Giter Club home page Giter Club logo

car-rent's Introduction

Rent A Car

Rent A Car is a sample Spring Boot MVC (Thymeleaf + REST) project.

Description

Rent A Car is an application which provides the user with a web application and a REST API to perform CRUD operations on customers, cars, rentals and many more.

Technologies

The goal of this application is to get an in-depth feeling for the usage of the Spring framework. The following subjects were applied inside this project:

  • Spring Boot
  • Spring Security
  • Spring MVC
  • H2 in memory database
  • JPA ORM (Hibernate impl.)
    • With the usage of the Bean Validation Framework

(Maven) project structure

There are many packages inside the project, in order to keep the code clean:

src/main/java/...

  • bean: Contains all form backing beans.
  • configuration: Contains all configuration classes. In particular messages and security.
  • controller: This package is divided into two subpackages
    • rest: Classes annotated with @RestController, which contain REST endpoints.
    • view: Classes annotated with @Controller, which are used to return dynamically rendered HTML views.
  • exception: Contains logic to handle exceptions.
  • model: Contains all JPA entity classes.
  • repository: Contains all repositories to access the database.
  • service: Contains all service classes which perform further business logic.
  • util: Contains classes that help reducing code repeating.

src/main/resources/...

Contains templates, insert scripts and configuration files.

  • data.sql: Used for initial test data.
  • application.properties: Contains the server configuration.
  • messages_xx.properties: Message files used to internationalize the application.
  • templates: This package consists of the root layout file index.html (using the Thymeleaf Layout Dialect). This root layout consists of fragments, which are seperated in static content that should be visible on every page and dynamic content that should only be rendered depending on the current request.
    • The static content consists of the HTML5 tag <head>, a sidenav and a topnav.
    • The dynamic content is used for the specific requests. E. g. search-rentals.html or create-rental.html.

Domain model (JPA entity classes)

The main entity class is Rental.java. This class contains several unidirectional @ManyToOne mappings to the other entities. It was decided to do unidirectional mapping because any sort of dependency to other classes is done through this class only. Thus, all other classes do not need an extra reference to this class.

Messages and internationalization

Many fields of form backing beans and entity classes contain validation steps done with the Java Bean Validation Framework. To make the application accessable and user friendly for several regions, corresponding messages_xx.properties files can be created. Until now the only supported language is English, however, adapting the properties file to another locale prevents from hardcoding strings inside the bean validation annotations.

Authentication

- Roles

There are three access types (user roles) in this application:

Employee

By logging in as a user that has the role of ROLE_EMPLOYEE the user can issue new rentals. Also, the employee has the possibility to finish those. Employees can access all paths starting with /employee/**.

Admin

Users with the role of ROLE_ADMIN have access to several REST endpoints. Admins can access all paths starting with /admin/**. Admins cannot visit employee roles and vice versa employees do not have access to the REST endpoints.

Public

Anyone can call the root website. The user can see a form in which he can select a city. After submitting the form, the server will return a new website where all free cars in the selected city are displayed in a pretty way.

Public users do not have a role defined in the code. They have access to all paths different from the mentioned ones. Those would be /**.

- In memory users

To keep things simple, two users were created with Spring Security HTTP basic auth. (username, password)

  • ROLE_EMPLOYEE: This user has (emp, emp) as credentials.
  • ROLE_ADMIN: This user has (admin, admin) as credentials.

Redirection

If unauthenticated users try to access paths of a specific role, which they are not part of, they will be redirected to the login screen.

car-rent's People

Contributors

aslary avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.