Giter Site home page Giter Site logo

lfarci / journal-de-bord-rest-api Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 157 KB

API of the Journal de bord porject.

Home Page: https://journal-de-bord.netlify.app/

Java 99.59% HTML 0.41%
hibernate java maven oauth2 openid-connect rest-api spring spring-boot

journal-de-bord-rest-api's Introduction

About me

Passionate and results-driven Software Engineer specializing in Microsoft technologies, with a focus on C#, .NET, Visual Studio, and Azure. With three years of hands-on experience in the public, banking, and energy sectors in Belgium, I've demonstrated expertise in crafting robust solutions and driving digital innovation.

journal-de-bord-rest-api's People

Contributors

lfarci avatar

Watchers

 avatar  avatar

journal-de-bord-rest-api's Issues

Driver statistics endpoint

Objective

The statistics endpoint should contains computed pieces of information concerning the specified driver. For now the most urgent piece of information that should be provided is the total number of kilometers driven. Some interesting data would be: the total number of rides or the total number of visited locations.

This would be used by the Journal de Bord web application to show a simple overview of the driver progress. The driver has an objective of kilometers to drive. Knowing the total driven distance, we can compute its progress.

Implementation

The data should be exposed at <host>/api/drivers/<driverId>/statistics. And the response body should contain a JSON schema close to the this:

{
    "totalDistance": 576,
    "rides": 12,
    "locations": 5
}

The error handling should be similar to the GET driver endpoint.

Tasks

  • Create the <host>/api/drivers/<driverId>/statistics endpoint in the DriverController class.
  • Create a countDriverRides method in the RideRepository class.
  • Create a sumDriverRidesDistance method in the RideRepository class.
  • Create a countDriverLocations method in the LocationRepository class.
  • Create a new DriverStatistics class that can be used as a response, its field are the one described here above.
  • Create a getDriverStatisticsFor(String identifier) method in the DriverService.
  • Implement the endpoint method in the DriverController with the created symbols.

Resources

Rides pagination

Objectives

  • Get the last n rides.
  • Order the rides by the ride's departure date when getting a list of rides (descending order: from the most recent ride).
  • Paginate rides: we should be able to specify a page index and its size in the URL parameters
  • Discoverability: a client should be able to know about the number of available pages.

Expected URLs

You should be able to get the last ride at this location: <host>/api/drivers/<driverId>/rides?page=0&size=1. Here we assume that the rides are ordered by the ride's departure date. The page at 0 of size 1 should contain the last ride that was started by the driver.

You should be able to rides for a given page using: <host>/api/drivers/<driverId>/rides?page=<page>&size=5. The URL would results in a page of 5 rides.

Note: the ordering by the ride's departure is preferred because it can be used to both order unfinished and finished rides.

Resources

Implement security

Overview

The application is a resource server. It should be secured so that each user can only access its journal. The following tutorial can be used to implement that: OAuth 2.0 Resource Server With Spring Security 5.

Tasks

  • Add a dependency to spring-boot-starter-oauth2-resource-server package (2.4.2).
  • Create the security configuration class: we want to use JWT tokens.
  • Document the required application properties.
  • Create a drive controller
  • test user id against the resources to determine if a user can access it

Partial ride guard

Description

It is possible to create partial rides. Partial rides are rides that only have a departure. Their arrival, traffic condition, and comment field are null.

When one of them has been created, it should not be allowed to directly create a new partial ride without completing the last one.

A driver's ride cannot be associated to the stops and the locations of another driver.

Current behavior

It is possible to create a new ride for a driver with stops owned by another driver.

Expected behavior

  • An error is thrown when the create endpoint is called with a ride associated with a different driver resources.
  • An error is thrown when the update endpoint is called with a ride associated with a different driver resources.

Ride controller create endpoint bug

Description

It is currently not possible to submit a ride that has no arrival because of the Ride.isValid method. It is called in the create API endpoint. If a ride results as invalid then the 422 Http code is returned.

Fix

Here is the Ride.isValid method.

public boolean isValid() {
-    return arrival.isAfter(departure)
-            && arrival.getOdometerValue() > departure.getOdometerValue();
+   return !hasArrival() || arrival.isAfter(departure)
+            && arrival.getOdometerValue() > departure.getOdometerValue(); 
}

Wrong HTTP response on the driver endpoint with get method

Current behavior

When we get an unknown driver, the 403: Forbidden HTTP code is returned even though the driver does not exist.

Expected behavior

The 404: Not found should be returned in stead.

Example

After a request to the URL <host>/api/drivers/<unknown identifier>.

{
    "timestamp": "2020-01-11T10:30:00.000+00:00",
    "status": 403,
    "error": "Forbidden",
    "message": "",
    "path": "/api/drivers/unknown"
}

Wrong error code is returned in the driver controller

401 (unauthorized) is returned when a driver tries to access a resource it does not own. It should be 403 Forbidden.

In the DriverController, we can read the following.

@GetMapping(path = DRIVER_RESOURCE_PATH)
public ResponseEntity driver(
        Authentication authentication,
        @PathVariable("identifier") String identifier
) {
    try {
        String userId = authentication.getName();
        if (userId.equals(identifier)) {
            return ResponseEntity.ok(driverService.findById(identifier));
        } else {
            // **************************************** UPDATE THIS ***************************************
            throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "Restricted to the owner.");
            //**************************************************************************************************
        }
    } catch (NullPointerException | IllegalArgumentException exception) {
        throw new ResponseStatusException(HttpStatus.NOT_FOUND, exception.getMessage());
    }
}

Disabled the Spring REST HAL interface.

Current behavior

The HAL interface is available and totally bypasses the rest controllers that I have implemented.

Expected behavior

The HAL interface should be disabled all together as it is not used in the context of this simple project.

Tasks

  • Remove the Spring REST dependency in the pom.xml file.

Resources

Export/ import journal as a CSV file

Description

A client should be able to request a CSV file of the journal. The file should contain every data for the specified user.

Objective

The file can be used by end-users to export their data. CSV files can be imported into a sheet and edited or used for visualization. They could also use it to restore their journal to the state contained in an uploaded CSV file.

Export a journal as a PDF document

Description

The journal de bord first objective was to offer a way to create a learner driver diary for the students in the Brussels region. The region requires them to fill printable tables during each of their ride. The documents provided by the region can be found on this page.

Here are the documents:

The idea would be to automate this process and make it possible for the service to produce those documents. The user should be able to download a PDF documents with the data that was provided the app.

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.