Skip to content

jeremymaya/Code-401-Async-Inn-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code-401-Async-Inn-API

Actions Status
Actions Status

Author: Kyungrae Kim

Endpoint: https://asyncinn.herokuapp.com


Async Inn API

  • Lab 18 - Roles
  • Lab 17 - Identity
  • Lab 14 - Navigation Properties & Routing
  • Lab 13 - Dependency Injection
  • Lab 12 - Intro to Entity Framework Core and APIs

Description

This is a RESTful API server built using ASP.NET Core to allow Async Hotel management to better manage the assets in their hotels. This application can modify and manage rooms, amenities, and new hotel locations. The data entered by the user will persist across a relational database and maintain its integrity as changes are made to the system.

The Below is link to the MVC web application version of the assignment:

https://github.com/jeremymaya/Code-401-Async-Inn


Getting Started

Clone this repository to your local machine.

git clone https://github.com/jeremymaya/Code-401-Async-Inn-API.git

To run the program from Visual Studio

Select File -> Open -> Code-401-Async-Inn-API

Next navigate to the location you cloned the Repository.

Double click on the AsyncInnAPI directory.

Then select and open AsyncInnAPI.sln


Entity Relationship Diagram

Entity Relationship Diagram

Diagram Credit: Amanda Iverson

  • Hotel table has one to many relationship with HotelRoom table
  • Room table has one to many relationship with HotelRoom table
  • Amenities table has one to many relationship with RoomAmenities table
  • HotelRoom table is a joint table with a payload
  • RoomAmenities table is a pure join table
  • Layout is an enum

Features

  • RESTful API
  • Entity Framework Core
  • Dependency Injection
  • Data Transfer Objects
  • Identity
  • Authorization
  • JSON Web Token (JWT)

Endpoints

Account

Method EndPoint Description
POST /api/Account/Register
POST /api/Account/Assign/Role
POST /api/Account/Login
Sample Request Body of POST /api/Account/Register

{
   "email": "user@example.com",
   "password": "string",
   "firstName": "string",
   "lastName": "string",
   "role": "string"
}

Amenities

Method EndPoint Description
GET /api/Amenities
POST /api/Amenities
GET /api/Amenities/{id}
PUT /api/Amenities/{id}
DELETE /api/Amenities/{id}
Sample Response of GET /api/Amenities

[
    {
        "id": 0,
        "name": "string"
    }
]

HotelRooms

Method EndPoint Description
GET /api/Hotels/{hotelId}/Rooms
POST /api/Hotels/{hotelId}/Rooms
GET /api/Hotels/{hotelId}/Rooms/{roomNumber}
PUT /api/Hotels/{hotelId}/Rooms/{roomNumber}
DELETE /api/Hotels/{hotelId}/Rooms/{roomNumber}
Sample Response of GET /api/Hotels/{hotelId}/Rooms

[
    {
        "hotelId": 0,
        "roomNumber": 0,
        "rate": 0,
        "petFriendly": true,
        "roomId": 0,
        "room": {
            "id": 0,
            "name": "string",
            "layout": "string",
            "amenities": [
                {
                    "id": 0,
                    "name": "string"
                }
            ]
        }
    }
]

Hotels

Method EndPoint Description
GET /api/Hotels
POST /api/Hotels
GET /api/Hotels/{id}
PUT /api/Hotels/{id}
DELETE /api/Hotels/{id}
Sample Response of GET /api/Hotels

[
    {
        "id": 0,
        "name": "string",
        "streetAddress": "string",
        "city": "string",
        "state": "string",
        "phone": "string",
        "rooms": [
            {
                "hotelId": 0,
                "roomNumber": 0,
                "rate": 0,
                "petFriendly": true,
                "roomId": 0,
                "room": {
                    "id": 0,
                    "name": "string",
                    "layout": "string",
                    "amenities": [
                        {
                            "id": 0,
                            "name": "string"
                        }
                    ]
                }
            }
        ]
    }
]

Rooms

Method EndPoint Description
GET /api/Rooms/
POST /api/Rooms/
GET /api/Rooms/{id}
PUT /api/Rooms/{id}
DELETE /api/Rooms/{id}
POST /api/Rooms/{roomId}/Amenity/{amenityId}
DELETE /api/Rooms/{roomId}/Amenity/{amenityId}
Sample Response of GET /api/Rooms

[
    {
        "id": 0,
        "name": "string",
        "layout": "string",
        "amenities": [
            {
                "id": 0,
                "name": "string"
            }
        ]
    }
]

Using Postgres Instead of SQL Server on Docker

Go to ASP.NET Core Development with macOS for more details.

If you have not already, download the Docker Desktop for Mac.

  1. Download Postgres with the following command:

    docker pull postgres:latest
  2. Launch the Docker Image with the following command:

    docker run --name psql -e POSTGRES_USER=sa -e POSTGRES_PASSWORD=ReallyStrongPassword1234! -p 5432:5432 -d postgres
  3. Update the connection string with the following:

    "ConnectionStrings": {
        "DefaultConnection": "Host=localhost;Database=DbName;Username=sa;Password=ReallyStrongPassword1234!"
    }
  4. Add a dependency on Npgsql.EntityFrameworkCore.PostgreSQL


Credits


Change Log

  • 1.7: Deployed to Heroku - 12 October 2020
  • 1.6: Lab 18 Completed - 5 Aug 2020
  • 1.5: Lab 17 Completed - 3 Aug 2020
  • 1.4: Lab 16 Completed - 2 Aug 2020
  • 1.3: Lab 14 Completed - 30 Jul 2020
  • 1.2: Lab 13 Completed - 30 Jul 2020
  • 1.1: Lab 12 Completed - 29 Jul 2020