Skip to content

Rational Data assignment a service to navigate a robotic hoover through a room.

Notifications You must be signed in to change notification settings

lazarosfs/backend-hoover-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hoover Service

Hoover Service is a Spring Boot application that simulates the navigation of a robotic hoover (similar to a Roomba) within a room, cleaning dirt patches based on given instructions.

Table of Contents

Overview

The Hoover Service processes a JSON payload containing:

  • Room dimensions (X, Y)
  • Initial hoover position (X, Y)
  • Dirt patches' coordinates (X, Y)
  • Driving instructions (N, S, E, W)

The service then outputs:

  • Final hoover position (X, Y)
  • Number of cleaned patches

Prerequisites

Before you begin, ensure you have the following installed:

  • Java Development Kit (JDK) 11 or later
  • Apache Maven

Setup

  1. Clone the repository:

    git clone https://github.com/your-username/backend-hoover-service.git
    cd backend-hoover-service
  2. Set up JDK 11 and Maven:

Ensure JDK 11 and Maven are properly installed and configured.

Building the Application

Build the project

mvn clean install

This command compiles the code, runs tests, and packages the application into a JAR file located in the target directory.

Running Tests

To execute tests, use Maven:

mvn test

This command runs all unit tests to ensure the application behaves as expected.

To manually do a test request: First run the application and then you can use command line tools like curl:

curl -X POST http://localhost:8080/api/hoover/navigate \
  -H "Content-Type: application/json" \
  -d '{
        "roomSize" : [5, 5],
        "coords" : [1, 2],
        "patches" : [
            [1, 2]
        ],
        "instructions" : "NNSS"
      }'

Response body should be

{"coords":[1,2],"patches":1}

Running the Application

To run the application locally, use Maven:

mvn spring-boot:run

You can also use the executable .jar directly in target directory if it is already built.

java -jar target/backend-hoover-service-0.0.1-SNAPSHOT.jar

The application will start locally on http://localhost:8080.

API Documentation

Endpoint

  • Method: POST
  • Description: Navigate the hoover within a specified room with defined instructions.

Request Body:

{
   "roomSize": [width, height],
   "coords": [x, y],
   "patches": [
      [x1, y1],
      [x2, y2]
   ],
   "instructions": "NNEESSWW"
}

Responses:

  • 200 OK
    • Description: Successfully navigated the hoover.
    • Example Response:
      {
      "status": 200,
      "message": "Hoover navigated successfully.",
      "cleanedPatches": 2,
      "finalPosition": [x, y]
      }
      
  • 400 Bad Request
    • Description: The request was invalid. This may occur if the room size or coordinates are incorrect, or if the instructions contain invalid characters.
    • Example Response:
      {
      "status": 400,
      "message": "Invalid direction: X",
      "timestamp": "2024-10-16T09:17:50.4562456"
      }
      
  • 500 Internal Server Error
    • Description: An unexpected error occurred on the server while processing the request.
    • Example Response
      {
      "status": 500,
      "message": "An unexpected error occurred.",
      "timestamp": "2024-10-16T09:17:50.4562456"
      }
    

Example Usage

Here’s how you can execute a request to navigate the hoover:

curl -X POST http://localhost:8080/api/hoover/navigate \
  -H "Content-Type: application/json" \
  -d '{
        "roomSize": [5, 5],
        "coords": [1, 2],
        "patches": [[1, 2]],
        "instructions": "NNSX"
      }'

Coverage Report

A current Coverage Report is in folder htmlReport/index.html which was generated by IntelliJ IDEA (not automatically updated during build).

Contact

For any queries or issues, please contact [email protected]

About

Rational Data assignment a service to navigate a robotic hoover through a room.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published