Giter Club home page Giter Club logo

studentapi_project's Introduction

Student WEB API

Environment setup

  1. Make sure to install .NET 7 SDK (https://dotnet.microsoft.com/en-us/download/dotnet/7.0)
  2. Install dotnet tools if not installed yet:
 dotnet tool install --global dotnet-ef --version 7.0.14

  1. Make sure Docker is installed & running in background (Which hosts our API service, API Database and Auth Database for our service)

    It's okay for no containers to be running right now within docker

Build Application

  1. Clone the github repo into local VS code

  2. Build the application to check for any errors:

     dotnet build
    
  3. Run Docker Containers Within terminal, run:

     docker-compose up --build
    
    
  4. Updating Database with Migrations Within terminal, run:

     dotnet ef database update --context "StudentAPIDbContext"
     dotnet ef database update --context "StudentAPIAuthDbContext"
    
    
  5. Run Application once containers are running

    dotnet run
    
    

    might look like terminal is stuck but the build is completed

    Go to port: http://localhost:5288/swagger/index.html

Setup For API services

Once the application can build succesfully and application is running, we can access it through chrome at port 5288:(http://localhost:5288/swagger/index.html). For testing in POSTMAN, simply copy the JSON StudentAPI collection file in the root directory of this project and paste it in postman.

Register and Login

The Student API web service can handle client Login and Registry. The service is built around ASP.NET Core JWT Authentication flowKnow More, hence a client would need to Register and login in order to get authorized for all the Web API functionalities.

Register

For registering client needs to put in 3 informations:

  1. Username (Any form of email address)
  2. Password (Minimum 6 characters with Uppercase, Lowercase & Numeric characters )
  3. Role (Either Admin or Student)

After Executing, Should get a 200 Response back with comment Succesfully Registerd.

Login

Once registered, User can Login to get the JWT token.

For testing through Swagger, Copy and paste the token within the Authorize Header in format "Bearer ".

For testing through POSTMAN,

  1. Click on the StudentAPI_Test Collection in Postman
  2. Click Authorization (right besides Overview panel)
  3. Select Type API Key
  4. For Key type in -> Authorization
  5. For Value type in -> Bearer //Copied Jwt Token
  6. Add to -> Header

Then save it.

Now we should be set for sending requests within Swagger or Postman, whichever preffered.

Note: The token expires in 30 mins, hence will need to login again to get new JWT token

Student API Functionalities

We can apply basic CRUD functionalities now that we are logged in within the Student API service, however it depends on the Role assigned: Admin -> Should be able to work with all the CRUD functionalities as is authorized. Student -> Can only implement GetAllStudents and GetStudentById functionalities as they are not authorized for all the tasks.

GetAllStudents

Route to get all Students: http://localhost:5288/api/Student

Route to get or filter Student by Name: http://localhost:5288/api/Student?filterOn=Name&filterQuery=Name

(Replace "Name" (Name you want to search) for filterQuery=Name property in URL)

Route to sort all students by Name in Ascending or Descending: http://localhost:5288/api/Student?sortBy=Name&isAscending=true

(put "true" or "false" in isAscending=true to sort accordingly)

CreateStudent

Route: POST request http://localhost:5288/api/Student

Initially there is nothing in the database so we can start storing in Students.

name -> name of Student
email -> valid email address
nationality -> any country
isEnabled -> true or false (Based on whether you want to enable this student or disable)
ClassId -> Choose a Guid Class Id based on the table below

Id Name
0d06acb7-5ad4-458c-b26e-a3b390994335 Object Oriented Programming
0d06acb7-5ad4-458c-b26e-a3b390994447 Calculus
0d06acb7-5ad4-458c-b26e-a3b390995678 Data Structure and Algorythm
237b0357-dfb0-49e9-90a9-0a25933c439e Introduction to programming
5c47bab3-293b-4b64-8860-bdeb1516ed43 Web Programming and Implementation
69e61e7e-6b80-4cde-b016-3a253e9a0c45 Java Programming

RankingId -> Choose a Guid Ranking Id based on table below

Id Name
044677d4-ec73-4c97-a007-86530e9c0769 Needs more work
b9de3c6d-55e8-4857-9e8e-87a8c35f5ae0 Brilliant
df1228e3-b8e6-4bd5-95a3-5b54e19b3a88 Average

Should respond with 201 status code with the created object Student.

If you put in invalid or unknown Guid, ModelValidation should handle it and explain no such Id exists.

GetStudentById

Route: Get Request http://localhost:5288/api/Student/{ID}

Replace {ID} with actual Student ID you want to get

GetStudentById

Route: PUT request http://localhost:5288/api/Student/{ID}

Replace {ID} with actual Student ID you want to update

pass in body in raw JSON format similar to CreateStudent

DeleteStudent

Route: Delete request http://localhost:5288/api/Student/{ID}

Replace {ID} with actual Student ID you want to delete

EnableDisableStudent

Route: PATCH request http://localhost:5288/api/Student/{ID}?enableStudent=true

Replace {ID} with actual Student ID you want to enable or disable change enableStudent property to true or false based on if you want to enable or disable student.

studentapi_project's People

Contributors

tuladhar2002 avatar xluucaaa avatar fehmiay avatar zander53 avatar

Watchers

 avatar

Forkers

zander53

studentapi_project's Issues

Document Endpoints with Summaries and Response Codes incl. API Endpoint Testing

Document each API endpoint in the project with detailed summaries and associated response codes. Furthermore, test our API Endpoints with postman and create a collection.

Requirements

  • For each endpoint in each controller, add an endpoint summary.
  • For each endpoint in each controller, add all response codes either currently in use or that will be available in the future (if working with a group changing responses).
  • Common codes include 200 (OK), 400 (Bad Request), 401 (Unauthorized), 404 (Not Found), and 500 (Internal Server Error).
  • Related Documentation Swashbuckle.AspNetCore Documentation

Risks

  • Not really many risks in this task
  • Mr. Carlin prepared us well for that task with Homework 3, where we did API Testing already
  • This procedure I want to apply, so for now I dont see any risks

Implement JWT Authentication and Authorization

Create Auth Database for handling users and tokens

Implement Authentication to the StudentAPI service

Create 2 roles (Admin, Student)

Implement Authorization to the API service

Provide Authorization attributes with roles to the Action Methods

Implement Auth within Swagger

Create StudentAPI service with CRUD functionalities

Users should be able to Create Student, Delete Student by id, Get all Students, Get Student by id, update Student by id.

Seed Entities within the database

Add Migrations and Update Database

Implement DbContext within Repository for database interacting with action methods

Improve Test Coverage for the StudentAPi Service

Ensure that our StudentApi Service class is fully covered by unit tests.

Step by Step

  • Set up the Unit Testing Environment
  • Think about the test-cases that I need to cover
  • Write the Unit Tests
  • Edit the tests, until it passes
  • After changing some things, make sure that the old tests still pass!

Requirements:

  • Test Authenticate method.
  • Test RegisterAsync method.

Risks:

  • This semester I started to learn how Unit testing works in general (in Java)
  • Because of this reason, I dont have much experience in Software Testing and I have never done it in C# before
  • Therefor I need to educate myself with certain YouTube Video about the Unit testing procedure in C# and apply it in a further step

Installation Guide in the README file

Add Installation Guide to README - 1
Create a detailed and user-friendly Installation Guide section for the CIS 355 Lab 2 README file.

Content Requirements:
Software and Tools
List all software, tools, and libraries required for the project, including links to downloads/external guides where applicable.
Step-by-Step Instructions
Provide clear, sequential instructions for installing each piece of software and setting up the development environment.
Verification Steps
Offer simple steps to verify that the installation was successful (e.g., running a project or checking the status of Docker).

Implement Disable User Account Functionality

Steps:

  • Add a IsDisabled property to the Student model.
  • Update the IStudentRepositories interface to include the new method for disabling a student.
  • Implement the disableStudent/enableStudent methods in the PGSQLStudentsRepository
  • Add disableStudent/enableStudent actions to controller

Requirements:

  • Add new database columns or tables for account status.
  • Add methods for disabling and enabling user accounts.

Add Build and Test Automation to the Project

Add build and test automation to the project using GitHub Actions.

Steps:

  • Under actions create a new workflow with .NET configuration
  • Inside this folder, create a YAML file (e.g., test.yml) to define our workflow.
  • write steps for set up, restore, build, test for our dotnet project
  • commit and push the changes
  • run workflow
  • report the results

Requirements:

  • Build the project.
  • Run the unit tests.
  • Report the results of the build and tests.

Implement DTO for user Data implementation

Create StudentDto, CreateStudentDto, UpdateStudentDto for handling Data from Client Side requests

Implement AutoMapper to map Client side data into Student Objects, in order to interact within the database.

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.