{"id":24979571,"url":"https://github.com/sifatsakib007/appointmentapi","last_synced_at":"2026-05-13T21:36:07.348Z","repository":{"id":275569986,"uuid":"926484784","full_name":"SifatSakib007/AppointmentAPI","owner":"SifatSakib007","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-03T10:54:57.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-03T11:37:26.569Z","etag":null,"topics":["asp-net-web-api","ef-core","mssql-database"],"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/SifatSakib007.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":"2025-02-03T10:41:29.000Z","updated_at":"2025-02-03T11:15:55.000Z","dependencies_parsed_at":"2025-02-03T11:48:32.111Z","dependency_job_id":null,"html_url":"https://github.com/SifatSakib007/AppointmentAPI","commit_stats":null,"previous_names":["sifatsakib007/appointmentapi"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SifatSakib007%2FAppointmentAPI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SifatSakib007%2FAppointmentAPI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SifatSakib007%2FAppointmentAPI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SifatSakib007%2FAppointmentAPI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SifatSakib007","download_url":"https://codeload.github.com/SifatSakib007/AppointmentAPI/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246164577,"owners_count":20733832,"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":["asp-net-web-api","ef-core","mssql-database"],"created_at":"2025-02-04T01:19:33.248Z","updated_at":"2026-05-13T21:36:07.311Z","avatar_url":"https://github.com/SifatSakib007.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Appointment Management API Documentation\n\nThis document provides a comprehensive guide to the **Appointment Management API**, a RESTful service built using **.NET Core**. \nThe API is designed to manage patient appointments for a healthcare clinic, featuring **JWT-based authentication** to ensure secure access to protected endpoints.\n\n---\n\n## Table of Contents\n1. [Introduction](#introduction)\n2. [Features](#features)\n3. [Technologies Used](#technologies-used)\n4. [API Endpoints](#api-endpoints)\n5. [Authentication](#authentication)\n6. [Database Schema](#database-schema)\n7. [Setup Instructions](#setup-instructions)\n8. [Testing the API](#testing-the-api)\n9. [Error Handling](#error-handling)\n10. [Bonus Features](#bonus-features)\n\n---\n\n## Introduction\nThe **Appointment Management API** is a robust solution for managing patient appointments in a healthcare clinic. It provides endpoints for user authentication and appointment management, \nensuring secure and efficient operations. The API is built with scalability and security in mind, leveraging modern technologies and best practices.\n\n---\n\n## Features\n- **User Authentication**:\n  - Register new users.\n  - Login and generate JWT tokens.\n- **Appointment Management**:\n  - Create, read, update, and delete appointments.\n  - Validate appointment dates (must be in the future).\n- **Secure Access**:\n  - All appointment-related endpoints require a valid JWT token.\n- **Database Integration**:\n  - Uses **Entity Framework Core** with **MSSQL** for data persistence.\n- **Error Handling**:\n  - Proper error messages for invalid inputs, missing data, or unauthorized access.\n\n---\n\n## Technologies Used\n- **Backend Framework**: ASP.NET Core WebAPI\n- **Database**: MSSQL with Entity Framework Core\n- **Authentication**: JWT (JSON Web Tokens)\n- **Password Hashing**: BCrypt.Net\n- **Testing**: NUnit, Moq, and Postman\n- **Logging**: Console logging for debugging\n\n---\n\nHere’s the modified **API Endpoints** section with clearer instructions on how to register, log in, and use the JWT token to access protected endpoints. \nThe steps are explicitly outlined for better clarity and usability.\n\n---\n\n## API Endpoints\n\n### 1. User Authentication\n\n#### Register a User\n- **Endpoint**: `POST /api/Auth/register`\n- **Request Body**:\n  ```json\n  {\n    \"username\": \"testuser\",\n    \"password\": \"Password123\"\n  }\n  ```\n- **Response**:\n  ```json\n  {\n    \"message\": \"User registered successfully\"\n  }\n  ```\n- **Steps**:\n  1. Open **Postman**.\n  2. Set the request type to `POST`.\n  3. Enter the URL: `http://localhost:5087/api/Auth/register`.\n  4. Go to the **Body** tab, select **raw**, and choose **JSON**.\n  5. Paste the request body JSON (as shown above).\n  6. Click **Send**.\n  7. If successful, you will receive a confirmation message.\n\n---\n\n#### Login\n- **Endpoint**: `POST /api/Auth/login`\n- **Request Body**:\n  ```json\n  {\n    \"username\": \"testuser\",\n    \"password\": \"Password123\"\n  }\n  ```\n- **Response**:\n  ```json\n  {\n    \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...\",\n    \"message\": \"JWT Token generated successfully\"\n  }\n  ```\n- **Steps**:\n  1. Open **Postman**.\n  2. Set the request type to `POST`.\n  3. Enter the URL: `http://localhost:5087/api/Auth/login`.\n  4. Go to the **Body** tab, select **raw**, and choose **JSON**.\n  5. Paste the request body JSON (as shown above).\n  6. Click **Send**.\n  7. If successful, you will receive a JWT token in the response. Copy this token for future requests.\n\n---\n\n### 2. Appointment Management\n\n#### Create an Appointment\n- **Endpoint**: `POST /api/Appointment`\n- **Headers**:\n  - `Authorization: Bearer \u003ctoken\u003e`\n- **Request Body**:\n  ```json\n  {\n    \"patientName\": \"John Doe\",\n    \"patentContact\": \"john@example.com\",\n    \"appointmentDateTime\": \"2025-01-15T10:30:00\",\n    \"doctorId\": 1\n  }\n  ```\n- **Response**:\n  ```json\n  {\n    \"id\": 1,\n    \"patientName\": \"John Doe\",\n    \"patentContact\": \"john@example.com\",\n    \"appointmentDateTime\": \"2025-01-15T10:30:00\",\n    \"doctorId\": 1\n  }\n  ```\n- **Steps**:\n  1. Open **Postman**.\n  2. Set the request type to `POST`.\n  3. Enter the URL: `http://localhost:5087/api/Appointment`.\n  4. Go to the **Headers** tab.\n  5. Add a new header:\n     - **Key**: `Authorization`\n     - **Value**: `Bearer \u003cpaste-your-token-here\u003e`\n  6. Go to the **Body** tab, select **raw**, and choose **JSON**.\n  7. Paste the request body JSON (as shown above).\n  8. Click **Send**.\n  9. If successful, you will receive the created appointment details.\n\n---\n\n#### Get All Appointments\n- **Endpoint**: `GET /api/Appointment`\n- **Headers**:\n  - `Authorization: Bearer \u003ctoken\u003e`\n- **Response**:\n  ```json\n  [\n    {\n      \"id\": 1,\n      \"patientName\": \"John Doe\",\n      \"patentContact\": \"john@example.com\",\n      \"appointmentDateTime\": \"2025-01-15T10:30:00\",\n      \"doctorId\": 1\n    },\n    {\n      \"id\": 2,\n      \"patientName\": \"Jane Smith\",\n      \"patentContact\": \"jane@example.com\",\n      \"appointmentDateTime\": \"2025-01-16T11:00:00\",\n      \"doctorId\": 2\n    }\n  ]\n  ```\n- **Steps**:\n  1. Open **Postman**.\n  2. Set the request type to `GET`.\n  3. Enter the URL: `http://localhost:5087/api/Appointment`.\n  4. Go to the **Headers** tab.\n  5. Add a new header:\n     - **Key**: `Authorization`\n     - **Value**: `Bearer \u003cpaste-your-token-here\u003e`\n  6. Click **Send**.\n  7. If successful, you will receive a list of all appointments.\n\n---\n\n#### Get Appointment by ID\n- **Endpoint**: `GET /api/Appointment/{id}`\n- **Headers**:\n  - `Authorization: Bearer \u003ctoken\u003e`\n- **Response**:\n  ```json\n  {\n    \"id\": 1,\n    \"patientName\": \"John Doe\",\n    \"patentContact\": \"john@example.com\",\n    \"appointmentDateTime\": \"2025-01-15T10:30:00\",\n    \"doctorId\": 1\n  }\n  ```\n- **Steps**:\n  1. Open **Postman**.\n  2. Set the request type to `GET`.\n  3. Enter the URL: `http://localhost:5087/api/Appointment/1` (replace `1` with the desired appointment ID).\n  4. Go to the **Headers** tab.\n  5. Add a new header:\n     - **Key**: `Authorization`\n     - **Value**: `Bearer \u003cpaste-your-token-here\u003e`\n  6. Click **Send**.\n  7. If successful, you will receive the details of the specified appointment.\n\n---\n\n#### Update an Appointment\n- **Endpoint**: `PUT /api/Appointment/{id}`\n- **Headers**:\n  - `Authorization: Bearer \u003ctoken\u003e`\n- **Request Body**:\n  ```json\n  {\n    \"patientName\": \"John Doe\",\n    \"patentContact\": \"john@example.com\",\n    \"appointmentDateTime\": \"2025-01-15T12:00:00\",\n    \"doctorId\": 2\n  }\n  ```\n- **Response**:\n  ```json\n  {\n    \"id\": 1,\n    \"patientName\": \"John Doe\",\n    \"patentContact\": \"john@example.com\",\n    \"appointmentDateTime\": \"2025-01-15T12:00:00\",\n    \"doctorId\": 2\n  }\n  ```\n- **Steps**:\n  1. Open **Postman**.\n  2. Set the request type to `PUT`.\n  3. Enter the URL: `http://localhost:5087/api/Appointment/1` (replace `1` with the desired appointment ID).\n  4. Go to the **Headers** tab.\n  5. Add a new header:\n     - **Key**: `Authorization`\n     - **Value**: `Bearer \u003cpaste-your-token-here\u003e`\n  6. Go to the **Body** tab, select **raw**, and choose **JSON**.\n  7. Paste the request body JSON (as shown above).\n  8. Click **Send**.\n  9. If successful, you will receive the updated appointment details.\n\n---\n\n#### Delete an Appointment\n- **Endpoint**: `DELETE /api/Appointment/{id}`\n- **Headers**:\n  - `Authorization: Bearer \u003ctoken\u003e`\n- **Response**:\n  ```json\n  {\n    \"message\": \"Appointment deleted successfully\"\n  }\n  ```\n- **Steps**:\n  1. Open **Postman**.\n  2. Set the request type to `DELETE`.\n  3. Enter the URL: `http://localhost:5087/api/Appointment/1` (replace `1` with the desired appointment ID).\n  4. Go to the **Headers** tab.\n  5. Add a new header:\n     - **Key**: `Authorization`\n     - **Value**: `Bearer \u003cpaste-your-token-here\u003e`\n  6. Click **Send**.\n  7. If successful, you will receive a confirmation message.\n\n---\n## Database Schema\n### Tables\n1. **Users**:\n   - `UserId` (Primary Key)\n   - `Username`\n   - `PasswordHash` (hashed using BCrypt)\n2. **Doctors**:\n   - `DoctorId` (Primary Key)\n   - `DoctorName`\n3. **Appointments**:\n   - `AppointmentId` (Primary Key)\n   - `PatientName`\n   - `PatientContact`\n   - `AppointmentDateTime`\n   - `DoctorId` (Foreign Key)\n\n---\n\n## Setup Instructions\n1. **Clone the Repository**:\n   ```bash\n   git clone \u003crepository-url\u003e\n   cd AppointmentAPI\n   ```\n2. **Install Dependencies**:\n   ```bash\n   dotnet restore\n   ```\n3. **Configure Database**:\n   - Update the `DefaultConnection` in `appsettings.json` with your MSSQL connection string.\n   - Run migrations:\n     ```bash\n     dotnet ef database update\n     ```\n4. **Run the Application**:\n   ```bash\n   dotnet run\n   ```\n5. **Access the API**:\n   - The API will be available at `http://localhost:5087`.\n\n---\n\nHere’s the **Testing the API** section rewritten in detail, incorporating your NUnit test code and explaining how the tests are structured and executed. This section is designed to be clear, concise, and informative for developers who want to understand and run the tests.\n\n---\n\n## Testing the API\n\nThe API includes a comprehensive suite of **unit tests** written using **NUnit** and **Moq**. These tests ensure the functionality of the API endpoints, including user authentication and appointment management. The tests use an **in-memory database** for isolated and efficient testing.\n\n---\n\n### Test Setup\n\n#### Test Project Structure\n- The test project is named `Test`.\n- It contains two test classes:\n  1. **`AppointmentControllerTest`**: Tests the appointment-related endpoints.\n  2. **`AuthControllerTest`**: Tests the authentication-related endpoints.\n\n#### Key Dependencies\n- **NUnit**: For writing and running unit tests.\n- **Moq**: For mocking dependencies like `IAuthService`.\n- **Entity Framework Core In-Memory Database**: For simulating database operations without requiring a real database.\n\n---\n\n### Running the Tests\n\nTo run the tests, use the following command in the terminal:\n\n```bash\ndotnet test\n```\n\nThis command executes all the unit tests in the `Test` project and provides a summary of the results.\n\n---\n\n### Best Practices\n- **Isolation**: Each test is isolated and does not depend on the state of other tests.\n- **Cleanup**: The `TearDown` method ensures the in-memory database is reset after each test.\n- **Readability**: Test methods are named descriptively to indicate their purpose.\n\n---\n\nThis detailed **Testing the API** section provides a clear guide for running, understanding, and extending the unit tests. It aligns with industry standards and ensures the documentation is both informative and actionable.\n\n---\n\n## Error Handling\n- **400 Bad Request**: Invalid input (e.g., past appointment date).\n- **401 Unauthorized**: Missing or invalid JWT token.\n- **404 Not Found**: Resource not found (e.g., invalid appointment ID).\n- **500 Internal Server Error**: Server-side errors.\n\n---\n\n## Bonus Features\n- **Input Validation**:\n  - Appointment dates must be in the future.\n- **Password Hashing**:\n  - Passwords are securely hashed using BCrypt.\n- **Automated Tests**:\n  - Unit tests for controllers and services.\n- **Error Handling**:\n  - Custom error messages for invalid inputs or missing data.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsifatsakib007%2Fappointmentapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsifatsakib007%2Fappointmentapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsifatsakib007%2Fappointmentapi/lists"}