Git Product home page Git Product logo

spring-boot-async-demo's Introduction

SiriusXM_code challenge

Problem Statement

REST API Implementation

  • Valid payload should be printed in the console from the method.
  • Return corresponding http response code including vehicle id(something like UUID.randomUUID() would be enough) to the client as a part of location header
Path: /vehicle-api/v1/vehicles/vehicle
Content-Type: application/json
Request body: 
{
  "vin": "1A4AABBC5KD501999",
  "year": 2019,
  "make": "FCA",
  "model": "RAM"
  "transmissionType": "MANUAL",
}

Error Handling

  • Implement validation for "transmissionType" from the task 2 "Create Vehicle" , MUST accept only "MANUAL" or "AUTO" in the request body.
  • Invalid payload use case:
    • Invalid payload MUST be thrown with a corresponding error code and error message in the response body
    • Any other error MUST throw 500 "Internal Server Error" http response code with some info message in the response body

Logging

Logging Cross-cutting concern

We want to keep logging before and after method, however we don't want to put log statement in every method. As a example below are given two classes "DBServiceA" and "HttpServiceB" and the corresponding methods getData(int id) and sendMessage(String message)

Implement Java logging - cross-cutting concern solution for those two classes. Feel free to use any framework and libraries (however Spring preferably). You can create/modify existing

Please explain briefly what are the pros and cons for your solution?


public class DBServiceA {
        
    public String getData(int id) {
        log.debug(id);

        /*
         assume that some data has been retrieved from DB by id
        */
        String resultData = "resultData";
        
        log.debug(resultData);
        return resultData;
    }
}

public class HttpServiceB {

    public String sendMessage(String message) {
        log.debug(message);
        
        /*
         assume that some message sends via rest client and gets "httpResponse"
        */
        String httpResponse = "httpResponse";
        
        log.debug(httpResponse);
        return httpResponse;

    }
}

Problem Solution

  • Lombok is used as an annotation-processor to avoid boiler plate codes.

  • Asynchronous REST API is implemented through @EnableAsync annotation-based configuration in java class DemoApplication along with VehicleService as a dummy service.
  • Valid payload is printed in the console using logger.
  • Corresponding response code along with random UUID is returned as a part of location header. (UUID is included in location header, not in response body)

  • Transmission type accepts only MANUAL or AUTO. It is implemented through javax constraint validator. Custom annotation @TransmissionType is used for validating transmissionType in Vehicle payload.
  • Invalid payload is validated as per javax validation and corresponding error code and message is thrown in response body.
  • Any other error is throw with error code 500 through controller.

  • slf4j is used for logging.
  • With reference to the problem statement, logging is implemented in both Controller and Service layers.
  • DBServiceA is referenced as VehicleService whereas HttpServiceB is referenced as VehicleController with logging kept before and after method.

spring-boot-async-demo's People

Contributors

elwyncrestha avatar

Watchers

 avatar  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.