{"id":18283027,"url":"https://github.com/nikoletaxvs/countriesapi","last_synced_at":"2025-04-09T05:41:31.269Z","repository":{"id":213705035,"uuid":"734726064","full_name":"nikoletaxvs/CountriesApi","owner":"nikoletaxvs","description":"REST API in .net 6 ,using redis for caching ","archived":false,"fork":false,"pushed_at":"2024-08-03T07:10:29.000Z","size":8335,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-15T00:17:17.080Z","etag":null,"topics":["cache-redis","dotnet-6","rest-api"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nikoletaxvs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-22T12:52:49.000Z","updated_at":"2024-08-03T07:10:33.000Z","dependencies_parsed_at":"2024-08-03T08:41:21.400Z","dependency_job_id":null,"html_url":"https://github.com/nikoletaxvs/CountriesApi","commit_stats":null,"previous_names":["nikoletaxvs/assesment","nikoletaxvs/assessment","nikoletaxvs/countriesapi"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikoletaxvs%2FCountriesApi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikoletaxvs%2FCountriesApi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikoletaxvs%2FCountriesApi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikoletaxvs%2FCountriesApi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nikoletaxvs","download_url":"https://codeload.github.com/nikoletaxvs/CountriesApi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247987096,"owners_count":21028891,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache-redis","dotnet-6","rest-api"],"created_at":"2024-11-05T13:07:01.772Z","updated_at":"2025-04-09T05:41:31.246Z","avatar_url":"https://github.com/nikoletaxvs.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿\n# Countries API \n\n## Table of Contents\n\n- [Introduction](#introduction)\n- [Installation](#installation)\n- [Endpoints](#endpoints)\n- [Architecture](#architecture)\n- [Testing](#testing)\n\n## Introduction\nThis REST API is exposing FindSecondLargest and GetCountries endpoints.Its fetching it's data for the latter from the 3rd party api \n\u003ca href=\"https://restcountries.com/v3.1/all\"\u003eRest Countries\u003c/a\u003e and saves it to a cache using a Docker Redis container. \nIt also stores the data inside a Microsoft SQL Server database.\nFinally the endpoints are unit tested.\n## Installation\n\nFollow these 5 easy steps to install and set up the project:\n###### Step 1. Clone the Repository\n```bash\n# Clone the repository\ngit clone https://github.com/nikoletaxvs/Assessment\ncd Assessment\n```\n###### Step2 .Install necessary NuGet packages\n```bash\n#Restore NuGet Packages\ndotnet restore\n```\n###### Step 3.Create a database migration\n```bash\n# Create a database migration\ndotnet ef migrations add InitialCreate -c ApplicationDbContext\n\n# Update the database\ndotnet ef database update -c ApplicationDbContext\n```\n###### Step 4.Setup Redis with Docker\n```bash\n#If redis is not pulled yet, open powershell as an administrator and run, otherwise skip this step\ndocker pull redis\n\n#Then run\ndocker run -p 6379:6379 --name my-redis -d redis #if that's done use docker start\n```\n\n###### Step 5.Build and Run the API\n```bash\n# Build the project\ndotnet build\n\n# Run the API\ndotnet run\n```\n\n## Endpoints\n\n##### 1. FindSecondLargest\n\nEndpoint: POST /FindSecondLargest\n\n###### Input:\n\n    A JSON body of RequestObj.\n\n###### Output:\n\n    The second largest integer of the array gets returned.\n\n###### Response:\n\n    Status 200: Success. Returns the second largest integer.\n    Status 400: Bad Request. The given array should have at least two integers.\n    Status 500: Internal Server Error.\n\n###### Example:\n```json\n\n{\n  \"RequestArrayObj\": [4, 7, 1, 9, 3]\n}\n```\n###### Response:\n```json\n{\n  \"secondLargest\": 7\n}\n```\n\n##### 2. GetCountries\n\nEndpoint: GET /GetCountries\n\n###### Output:\n\n    IEnumerable\u003cCountryDto\u003e with common name, capital, and borders as its fields, retrieved from the third-party API, cache, or the database.\n\n###### Response:\n\n    Status 200: Success. Returns the list of country dtos.\n    Status 500: Internal Server Error.\n###### Example:\n###### Response:\n\n  ```json\n[\n  {\n    \"commonName\": \"string\",\n    \"capital\": \"string\",\n    \"borders\": [\n      {\n        \"name\": \"string\"\n      }\n    ]\n  }\n]\n```\n##### 3. DeleteCountriesUtility\n\nEndpoint: GET /DeleteAllCountriesUtility\n\n###### Description:\nThis utility endpoint deletes all countries and their borders.\n\n###### Response:\n\n    Status 200: Success. Deleted all countries and their borders.\n    Status 400: Bad Request. There was some issue.\n    Status 500: Internal Server Error.\n## Architecture \n\n##### Database\nThe `Country` class has a one-to-many relationship with the `Border` class\n```mermaid\nerDiagram\n    Country ||--o{ Border : \"1\" Id\n    Country {\n        int Id\n        string CommonName\n        string Capital\n    }\n    Border {\n        int Id\n        string Name\n        int CountryId\n    }\n\n```\n#####  Classes\n\n```mermaid\nclassDiagram\n    ApplicationDbContext --\u003e CountryRepository :Dependency Injection\n    ICountryApiService  \u003c|--  CountryApiService\n    ICacheService  \u003c|--  CacheService\n    ICountryRepository  \u003c|--  CountryRepository\n    CountryRepository  --\u003e AssesmentController: Dependency Injection\n    CountryApiService  --\u003e AssesmentController: Dependency Injection\n    CacheService  --\u003e AssesmentController: Dependency Injection\n```\nIn the application's architecture:\n\n-   **Data Layer:** The `ApplicationDbContext` facilitates database operations by injecting the `CountryRepository`.\n    \n-   **Service Layer:** Services (`CountryApiService`, `CacheService`, `CountryRepository`) implement interfaces (`ICountryApiService`, `ICacheService`, `ICountryRepository`) for structured functionality.\n    \n-   **Dependency Injection:** Services are injected into `AssesmentController` to manage HTTP requests. This design emphasizes modularity and separation of concerns, enhancing the application's maintainability and scalability.\n\n## Testing \nThis rest api has been tested with XUnit. The xunit test project can be found in this repository : \u003ca href=\"https://github.com/nikoletaxvs/Assessment.Tests\"\u003eTests Repository\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikoletaxvs%2Fcountriesapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikoletaxvs%2Fcountriesapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikoletaxvs%2Fcountriesapi/lists"}