Code Monkey home page Code Monkey logo

swapi-assignment's Introduction

swapi-project

project for Partior

Overview

Greetings, Jedi Master!
According to our sources, Darth Vader is planning an attack on the planet Alderaan with the Death Star.
We'd need your help to figure out which starships he's using and how many crew are aboard the Death Star.
Please double-check if Princess Leia Leia Organa is still on the planetAlderaan.

The Jedi Master has to gather the requested information and inform the Jedi High Council.

This project sets out to do just that. It gathers the following information:

  • Darth Vader's starship
  • Number of crew on the Death Star
  • Is princess Leia Organa on planet Alderaan

Setting up and running

This project is built using Spring boot, Java 17 & Maven. The setup steps for Java and Maven can be found:

To run, download this project as a zip and extract it. Alternatively, clone this project. Head to the folder where it resides and run the follow:

mvn spring-boot:run

This command should start a web server and provide the requested information for the Jedi High Council.

The web server would run on port 8080, providing the information on /information. To access it from the machine it is running in, enter the following in a web browser.

http://localhost:8080/information

How it works

This project queries The Star Wars API for its data. Here are the queries made to get the information.

  • Darth Vader's starship
    • People API would return URLs to the starships they have piloted. A separate call to the starship API is required to get the required information.
    • Queries made:
      • Search for Darth Vader: https://swapi.dev/api/people/?search=Darth Vader
      • Direct starship URL: https://swapi.dev/api/starships/1/
  • Number of crew on the Death Star
    • Information is available in the starship response
    • Query made:
      • Search for Death Star: https://swapi.dev/api/starships/?search=Death Star
  • Is princess Leia Organa on planet Alderaan
    • Planet API would return URLs to the residents who reside there. Checking if it contains the URL of the people we are after would determine if they are there.
    • Queries made:
      • Search for Alderaan: https://swapi.dev/api/planets/?search=Alderaan
      • Search for Leia Organa: https://swapi.dev/api/people/?search=Leia Organa

Validations and business logic

There are certain validations and business logic stated in the assignment. The project serves a single URL with no way to change any input. As such. it is not possible to alter inputs and test the validations and business logic.

The validations and business logic are tested against within the project tests. Here are the following tests which caters to them.

  • If no starships were found, set the value for starship as an empty object {}.
    • Test class: InformationControllerTest
    • Test method: getInformation_shouldReturnStarshipValueAsEmptyJsonObject_givenPeopleHasNoStarship()
    • Note: null is used to represent empty in the test method. To understand this behavior, look into InformationServiceTest test class for methods with getFirstStarshipPilotedBy_shouldReturnNull prefix.
  • If there is no crew on board the death star, set the crew value to 0.
    • Test class: InformationServiceTest
    • Test methods: methods with getStarshipCrew_shouldReturnCrewAsZero prefix
  • If Princess Leia is on the planet, then set "true" else set "false".
    • Test class: InformationServiceTest
    • Test method: methods with isPeopleOnPlanet prefix

Assumptions made

Here are the assumptions made, since not all cases are stated in the assignments.

  • A person would always use the 1st starship they have piloted within the array of starships.
  • When searching, only a single result with the exact search terms would be considered.
    • This is to address situations where searching returns an array of results
    • E.g 'https://swapi.dev/api/people/?search=Darth' would return Darth Vader and Darth Maul. Both would be rejected since it is ambiguous which is the person we are looking for.
  • If any required data to make a decision is not found, return its default failure value. The default failure value is taken from Validations and business logic
    • E.g. When finding Darth Vader's starship, the starship URL ends up as a dead link. The default failure value would be returned.
    • For "Darth Vader's starship"
      • return empty object {}
    • For "Number of crew on the Death Star"
      • return 0
    • For "Is princess Leia Organa on planet Alderaan"
      • return false

swapi-assignment's People

Contributors

fuqiang8 avatar

Watchers

 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.