Organization Employees API is a simple CRUD API developed using .NET Core for managing an organization's employees. This project is part of an assessment for Zimozi Solutions, a leading software development company with a global presence in Singapore, India, and Australia. The API allows for the creation, retrieval, updating, and deletion of employee records, and uses PostgreSQL as the database.
- Requirements
- Endpoints
- Data Model
- Database Setup
- Validation
- Error Handling
- Testing
- Running the Application
- .NET Core 8.0
- PostgreSQL
- GET /api/Employees: Return a list of all employees.
- GET /api/Employees/{id}: Get a specific employee by ID.
- POST /api/Employees: Add a new employee.
- PUT /api/Employees/{id}: Update an existing employee.
- DELETE /api/Employees/{id}: Delete an employee.
- EmployeeID (int, primary key)
- Name (string, max length 100)
- Department (string, max length 100)
- Salary (decimal)
-
Install PostgreSQL if you haven't already.
-
Update the connection string in
appsettings.jsonif necessary -
Run the following command in the project directory to apply migrations:
dotnet ef database update
- The Name and Department fields are validated to ensure they are not empty.
- Salary is validated to be a positive number.
The API implements proper error handling, including cases where an employee is not found for update or deletion. A global exception handling middleware is used to catch and format errors consistently.
- Unit tests for the service layer are implemented in the
organizationEmployeesAPI.Testsproject. - Integration tests for the API endpoints are also included in the same project.
-
Clone the repository:
git clone https://github.com/your-username/organizationEmployeesAPI.git -
Navigate to the project directory:
cd organizationEmployeesAPI -
Restore dependencies:
dotnet restore -
Update the database (as mentioned in the Database Setup section).
-
Run the application:
dotnet run --project organizationEmployeesAPI -
The API will be available at
https://localhost:5001orhttp://localhost:5000. -
You can use Swagger UI to test the API endpoints by navigating to
https://localhost:5001/swaggerin your browser.