GithubHelp home page GithubHelp logo

rocket-elevators-rest-api's Introduction

alt text

Rocket Elevators Rest API

CLICK TO EXPAND

In this project we Created Rest Apis for Rocket Elevators. and the link for our differents Apis are below and you can test it in Postman here is example of how u can access our api

  1. For Elevator to retrive, for example elevator with id==3, you use GET

https://sirinerocketelevatorsrestapi.azurewebsites.net/api/elevators/3 and for Changing ITS status you will use PUT and in Body => raw change on of elevator status ("Active" or "Inactive" or "Intervention") in Json format like this: { "status" : "Inactive" }

If the results input is Success, use GET to see the resluts of the changed status.

To get the elevators in Interventio use : https://sirinerocketelevatorsrestapi.azurewebsites.net/api/elevators/status/intervention, and to GET inactive you can use https://sirinerocketelevatorsrestapi.azurewebsites.net/api/elevators/status/inactive

2.This will be the same for Batteries and Columns. If you want to see all the batteries for example, use GET https://sirinerocketelevatorsrestapi.azurewebsites.net/api/Batteries , and for columns https://sirinerocketelevatorsrestapi.azurewebsites.net/api/Columns

to retrieve the information use the same link /(the id in numbers of the battery you want) for example here we want one so we use https://sirinerocketelevatorsrestapi.azurewebsites.net/api/Batteries/1 to change the information you do the same as abose USE PUT and choose in (Online, Offline or Intervention")

{

"Status": "Online" }

  1. For The building if you want to get all the Buildings use GET https://sirinerocketelevatorsrestapi.azurewebsites.net/api/Buildings to get building that contain at least one battery, column or elevator requiring intervention https://sirinerocketelevatorsrestapi.azurewebsites.net/api/Buildings/Intervention

  2. For the Lead, to Get all the Leads https://sirinerocketelevatorsrestapi.azurewebsites.net/api/Leads and to retrieve a list of Leads created in the last 30 days who have not yet become customers https://sirinerocketelevatorsrestapi.azurewebsites.net/api/Leads/30daysnotcustomers

So in more Details with Codes:

We Scaffolded our The entities which are the Models folder That we had in Mysql Server.and every model is a set of classes that represent the data that the app manages. for example in Batteries Class we have:

    public long Id { get; set; }
    public long? BuildingId { get; set; }
    public string Status { get; set; }
    public DateTime? DateCommissioning { get; set; }
    public DateTime? DateLastInspection { get; set; }
    public string CertificateOfOperations { get; set; }
    public string Information { get; set; }
    public string Notes { get; set; }
    public string BatteryType { get; set; }

We have a database context(rocketelevators_developmentContext) is the main class that coordinates Entity Framework functionality for a data model.and for our Batteries Class, its relation is: modelBuilder.Entity(entity => { entity.ToTable("batteries");

            entity.HasIndex(e => e.BuildingId)
                .HasName("index_batteries_on_building_id");

            entity.Property(e => e.Id)
                .HasColumnName("id")
                .HasColumnType("bigint(20)");

            entity.Property(e => e.BatteryType)
                .HasColumnName("battery_type")
                .HasMaxLength(255);

            entity.Property(e => e.BuildingId)
                .HasColumnName("building_id")
                .HasColumnType("bigint(20)");

We use difference Controllers to expose Async API Endpoints for CRUD operations. For example in Batteries controller, [HttpGet("{id}")] public async Task<ActionResult> GetBattery(long id) { var battery = await _context.Batteries.FindAsync(id);

        if (battery == null)
        {
            return NotFound();
        }

        return battery;
    }

And we can see the results our our request in Postman.

Consolidation

Following the same structure, I built two different requests:

  • GET request to retrieve all on the interventions that have a "Pending" status and no start date.
  • PUT request to change the status of an intervention and either the start date or end date.

GET Request:

    [HttpGet]
    public async Task<ActionResult<IEnumerable<Interventions>>> GetInterventions()
    {
        var _intervention = await _context.interventions.ToListAsync();
        var interventionsList = new List<Interventions>(){};

        foreach(Interventions interventions in _intervention)
        {
            if(interventions.start_of_intervention == null && interventions.status == "Pending")
            {
                interventionsList.Add(interventions);
            }
        }
        
        return interventionsList;
    }

PUT Request:

    [HttpPut("{id}/{status}")]
    public async Task<ActionResult<Interventions>> StartIntervention(long id, string status)
    {
        var intervention = await _context.interventions.FindAsync(id);
        intervention.status = status;

        if(status == "InProgress")
        {
            intervention.start_of_intervention = DateTime.Now;
            await _context.SaveChangesAsync();
            return intervention;
        }
        else if(status == "Completed")
        {
            intervention.end_of_intervention = DateTime.Now;
            await _context.SaveChangesAsync();
            return intervention;
        }

        return Ok("Invalid Endpoint!");
    }

The endpoints can be tested on postman with the deployed api:

The intervention id can be changed between 1 and 9.

rocket-elevators-rest-api's People

Watchers

Pat Tibo avatar Dave 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.