ClockAPI is an ASP.NET Core Web API that calculates the angles of clock hands (hour and minute) based on user-provided time inputs. It also supports the reverse operation, calculating the time from given clock hand angles.
-
Calculate Clock Hand Angles:
- Given hours and minutes, the API calculates the angles of the hour and minute hands.
- Input validation ensures hours are between 0 and 23, and minutes are between 0 and 59.
-
Calculate Time from Clock Hand Angles:
- Given hour and minute angles, the API calculates the corresponding time.
- Input validation ensures angles are between 0 and 359.
-
Swagger Documentation:
- Automatically generates API documentation using Swagger.
-
Unit Testing:
- Fully tested with unit tests to ensure reliability.
ClockAPI/
├── src/
│ └── ClockHandAPI/
│ ├── Controllers/
│ │ └── ClockController.cs # API endpoints
│ ├── DTOs/
│ │ └── ClockHandsDto.cs # Data Transfer Objects for input validation
│ ├── Models/
│ │ └── ClockHands.cs # Domain models
│ ├── Services/
│ │ ├── ClockService.cs # Business logic for calculating angles and time
│ │ └── IClockService.cs # Interface for ClockService
│ ├── Program.cs # Entry point of the application
│ └── ClockHandAPI.csproj # Project file
├── tests/
│ └── ClockHandAPI.Tests/
│ ├── ClockControllerTests.cs # Tests for ClockController
│ ├── ClockHandsDtoTests.cs # Tests for ClockHandsDto validation
│ ├── ClockServiceTests.cs # Tests for ClockService
│ └── ClockHandAPI.Tests.csproj # Test project file
├── ClockAPI.http # HTTP requests for testing the API
├── appsettings.json # Application configuration
├── appsettings.Development.json # Development-specific configuration
├── Properties/
│ └── launchSettings.json # Configuration for launch profiles
└── README.md # Project documentation
- .NET 8 SDK
- An IDE (e.g., Visual Studio, Visual Studio Code, or JetBrains Rider)
-
Clone the Repository:
git clone https://github.com/your-repo/ClockAPI.git cd ClockAPI
-
Restore Dependencies:
dotnet restore
-
Run the Application:
dotnet run --project src/ClockHandAPI/ClockHandAPI.csproj
-
Access Swagger UI:
- Open your browser and navigate to
https://localhost:5001/swagger
(orhttp://localhost:5000/swagger
). - Explore the API endpoints and test them interactively.
- Open your browser and navigate to
- Endpoint:
GET /api/clock/hands
- Query Parameters:
hours
(int): The hour value (0–23).minutes
(int): The minute value (0–59).
- Example Request:
GET /api/clock/hands?hours=12&minutes=30
- Example Response:
{ "hour": 195, "minute": 180 }
- Endpoint:
GET /api/clock/time
- Query Parameters:
hourAngle
(int): The hour hand angle (0–359).minuteAngle
(int): The minute hand angle (0–359).
- Example Request:
GET /api/clock/time?hourAngle=195&minuteAngle=180
- Example Response:
{ "hours": 12, "minutes": 30 }
To run the unit tests, use the following command:
dotnet test tests/ClockHandAPI.Tests/ClockHandAPI.Tests.csproj
- ClockController: Tests for valid and invalid inputs.
- ClockService: Tests for calculating angles and time.
- ClockHandsDto: Tests for input validation.
- ASP.NET Core: For building the Web API.
- Swagger: For API documentation.
- xUnit: For unit testing.
- Moq: For mocking dependencies in unit tests.
Use DTOs for the reverse operation endpoint to encapsulate input parameters.