Skip to content

GenesisEducationKyiv/software-engineering-school-5-0-velosypedno

Repository files navigation

Weather Forecast API

Weather API application that allows users to subscribe to weather updates for their city.

Table of Contents

Install

Dependencies

Ensure you have the following installed:

Steps

  1. Clone the repository:

    git clone https://github.com/velosypedno/genesis-weather-api.git
  2. Change work directory:

    cd genesis-weather-api
  3. Configure environmental variables:

    Copy .env.sample

    go-task copy:env

    NOTE: .env must be edited manually. You need to set smtp credentials, API key, etc.

  4. Build and up services by Docker Compose:

    go-task up

    This will start the following services:

    • postgres-wether - container with postgres database
    • migrator - waits for the database to start and then runs the migrations
    • api-weather - starts after the migrator finishes working, contains API
    • cron-wether - starts after the migrator finishes working, contains cron tasks to send email

Testing

  • To run all tests:

    go-task test

Setup Git hook

  • To install the pre-commit Git hook that runs linter automatically before each commit:

    go-task copy:hooks:pre-commit
  • To remove the pre-commit Git hook:

    go-task rm:hooks:pre-commit

API

Swagger scheme

All routes are prefixed with /api.

Method Endpoint Description
GET /weather Get current weather for a given city. Requires ?city=CityName query.
POST /subscribe Subscribe a user to weather updates. Expects JSON body with email, city, and frequency (hourly or daily).
GET /confirm/:token Confirm a subscription via token received by email.
GET /unsubscribe/:token Unsubscribe from weather notifications using the token.

Architecture

This project follows layered architecture with a clear division of responsibilities. The structure is organized into the following layers:

  • Handlers – handle HTTP requests, validate input, and return responses.
  • Services – contain business logic (e.g., subscriptions, confirmation, weather processing).
  • Repositories – provide access to PostgreSQL and external APIs.
.
├── cmd/               
│   ├── api/            # Main HTTP server startup
│   └── cron/           # Scheduled tasks for sending weather emails
└── internal/
    ├── config/          
    ├── handlers/       # HTTP requests handlers
    ├── ioc/            # Dependency injection 
    ├── models/         
    ├── repos/          # Repositories
    ├── scheduler/      # Cron tasks setup
    ├── server/         # HTTP server setup
    └── services/       # Business logic layer

License

This project is licensed under the MIT License - see the LICENSE file for details

About

software-engineering-school-5-0-velosypedno created by GitHub Classroom

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •