Skip to content

CodecoolGlobal/solarwatch-api-csharp-BalintCoder

Repository files navigation

Solar API

Overview

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.

Table of Contents

Features

  • 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

Technologies

Installation

  1. Clone the repository:

    cd solar
    cd solar
  2. Set up environment variables: Create a .env file in the root directory and add your API keys:

    WEATHER_API_KEY=your_weather_api_key
    ISSUING_KEY=your_jwt_signing_key
    
  3. Install dependencies: Make sure you have the .NET SDK installed. Then run:

    dotnet restore
  4. Run the database migrations:

    dotnet ef database update
  5. Run the application:

    dotnet run

Usage

Once the API is running, you can access the documentation at http://localhost:5000/swagger to see all available endpoints and test them directly.

Example Requests

  • 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

API Endpoints

Authentication

  • POST /auth/register: Registers a new user `ű
  • POST /auth/login: Authenticates a user and returns a JWT token

Weather

  • 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)

Contributing

BalintCoder's GitHub Profile

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published