The Solar API is a .NET backend service that provides weather-related information, including sunrise and sunset times for cities. It features user authentication and registration using JWT tokens and roles. The API is designed to support secure access for both regular users and administrators.
- User registration and login with JWT authentication
- Role-based access control (User, Admin)
- Fetch sunrise and sunset times based on city names
- Weather forecast functionality (restricted to Admin users)
- Well-structured and documented codebase
-
Clone the repository:
cd solar cd solar
-
Set up environment variables: Create a
.envfile in the root directory and add your API keys:WEATHER_API_KEY=your_weather_api_key ISSUING_KEY=your_jwt_signing_key -
Install dependencies: Make sure you have the .NET SDK installed. Then run:
dotnet restore
-
Run the database migrations:
dotnet ef database update
-
Run the application:
dotnet run
Once the API is running, you can access the documentation at http://localhost:5000/swagger to see all available endpoints and test them directly.
-
Register a user:
POST /auth/register Content-Type: application/json { "email": "user@example.com", "username": "exampleUser", "password": "yourPassword" }
-
Login a user:
POST /auth/login Content-Type: application/json { "email": "user@example.com", "password": "yourPassword" }
-
Get sunrise and sunset times:
GET /weather/times?cityName=London Authorization: Bearer your_jwt_token
POST /auth/register: Registers a new user `űPOST /auth/login: Authenticates a user and returns a JWT token
GET /weather/times: Fetches sunrise and sunset times for a specified city (accessible to User and Admin roles)GET /weather/GetWeatherForecast: Returns weather forecast data (accessible to Admin role)