Skip to content

L4ncelot-R/University_API

Repository files navigation

University Directory API in ASP.Net 8

Dependencies

UniversityDirectory

  • Microsoft.EntityFrameworkCore 9.0.3
  • Microsoft.EntityFrameworkCore.Design 9.0.3
  • Microsoft.EntityFrameworkCore.SqlServer 9.0.3 (for docker deployment)
  • Microsoft.EntityFrameworkCore.Sqlite 9.0.3 (for local deployment)
  • Swashbuckle.AspNetCore 8.1.0
  • Microsoft.AspNetCore.Identity.EntityFrameworkCore 8.0.2

UniversityUnitTest

  • xunit 2.5.3
  • xunit.runner.visualstudio 2.5.3
  • Microsoft.NET.Test.Sdk 17.8.0
  • Microsoft.EntityFrameworkCore.InMemory 9.0.3
  • coverlet.collector 6.0.0

Deployment

Docker

Under solution directory (where you see the UniversityDirectory.sln), run the following commands:

  1. docker-compose up -d mssql
    

Check the log to ensure the database is initialised before running the next command.

  1. dotnet ef migrations add Initial --project UniversityDirectory
    dotnet ef database update --project UniversityDirectory
    
  2. docker-compose up -d univerisitydirectory --build
    

Local

  1. Edit the connectionString in Program.cs:
var connectionString = builder.Configuration.GetConnectionString("Sqlite");

and change the options.UseSqlServer to options.UseSqlite.

  1. Run the following commands:
    dotnet build 
    
  2. dotnet ef migrations add Initial --project UniversityDirectory
    dotnet ef database update --project UniversityDirectory
    
  3. dotnet run --project UniversityDirectory
    

Or simply run the program from Visual Studio.

Test

Unit Test

In Visual Studio, run the UniversityTests.cs under UniversityUnitTest to check the test results.

Swagger test

  1. Navigate to http://localhost:[port]/swagger/index.html, where [port] can be found in the terminal output (port 5000 for docker).
  2. Register an account under /register.
  3. Login using the registered account to obtain the accessToken from the response body.
  4. Look for the green Authorize button at the top right corner, paste the accessToken with format: Bearer [acccessToken]
  5. Test the various university api endpoints.

API endpoints

GET/university

Retrieve a list of all universities. Bookmarked universities will appear in the beginning and deleted universities will not be shown by default.

Does not require accessToken.

Supports parameter filtering:

  • ?name=[Name]: return university with the given name.
  • ?country=[Country]: return universities of the given country.
  • ?isBookmark=[true/false]: return bookmarked/not bookmarked universities.
  • ?isActive=[true/false]: return active/non-active universities.
  • ?isDeleted=[true/false]: return deleted/not deleted universities.
  • ?pageNumber=[number]&pageSize=[number]: for pagination, default pageNumber=1&pageSize=10

POST/university

Add a university. The UTC time of creation will be recorded.

Require accessToken

Request body:

  • name (required): Name of the university.
  • country (required): Country of the university.
  • webpage: Webpage of the university.
  • isBookmark: default false.
  • isActive: default true.

GET/university/{id}

Retrive the university of the given id.

If the id is not found, returns 404.

Will return deleted university.

Does not require accessToken.

PUT/university/{id}

Updates the university of the given id. The UTC time of update will be recorded in lastModified.

If the id is not found, returns 404.

If the id is deleted, returns 400.

Else, return the university updated.

Requires accessToken.

DELETE/university/{id}

Soft delete the university of the given id by setting the deletedAt property to the UTC time of delete action.

If the id is not found, returns 404.

If the id is already deleted, returns 204.

Else, return the university deleted.

Requires accessToken.

POST/university/bookmark/{id}

Bookmark the university of the given id. This action is similar to the PUT action but only changes isBookmark and lastModified.

If the id is not found, returns 404.

If the id is deleted, returns 400.

Requires accessToken.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors