skip to content
all projects

Backend and domain / 2025

Scheduling API

Delivery scheduling is more than storing dates: availability, permissions and conflicts in a Go API.

context
API project, public code
role
Go API development
state
Prototype; build blocked
stack
Go / Gin / GORM / PostgreSQL
view code

what it is

The API models appointments between suppliers and employees. The repository contains JWT authentication, operation and product models, validation services and GORM queries.

the problem

Accepting a delivery requires checking entities, operating hours and overlaps in both employee and supplier schedules. An isolated availability query does not guarantee exclusivity under concurrency.

the constraints

Validation before writing
The service checks entities and hours; the repository checks conflicts before creating an appointment.
Two calendars
HasConflict queries employees and suppliers, ignoring cancelled appointments.

the architecture

Layers identifiable in the prototype code.

  1. HTTP

    internal/api

    Gin, handlers and JWT/RBAC middleware.

  2. Service

    internal/service

    Entities, operating hours and appointment state.

  3. Repository

    internal/repository

    Conflict queries and GORM writes.

  4. Domain

    internal/models

    Appointment, employee, supplier and operation.

This is a code map, not evidence of a production service. Files contain truncated sections and the clone does not build.

technical decisions

  1. Separate transport, rules and data

    why
    Handlers delegate to the service; queries live in the repository. This makes each validation location explicit.
    instead of
    Keeping data access and rules in HTTP handlers.
    the price
    The separation has no tests protecting its contracts yet.
  2. Query conflicts before inserting

    why
    HasConflict queries overlaps without loading the entire schedule into memory.
    instead of
    Enforcing exclusivity through a PostgreSQL exclusion constraint.
    the price
    The check precedes the write transaction. Concurrent requests can pass the same check.

limits and lessons

The clone does not build

go.sum contains invalid comments. Repository and service files also contain truncated sections and duplicate declarations. The first build error is transcribed below.

Untested rule

There are no _test.go files. The central rule needs cases for boundaries, overlap, cancellation and concurrency.

current state

The available artifact is a backend prototype and its domain model. There is no deployment, usage or performance evidence. Review on 1 October 2026 reproduced the initial build failure.

next questions

  • Restore files and go.sum before expanding the domain.
  • Test intervals and concurrency; evaluate database-level overlap exclusion.

evidence

go build ./... · 2026-10-01state

malformed go.sum:
go.sum:1: wrong number of fields 7
Clone output; absolute path omitted. No source files were repaired during this audit.

internal/repository/appointment_repository.go

hasConflict, err := r.HasConflict(appointment)
// ...
err = r.db.Transaction(func(tx *gorm.DB) error {
    if err := tx.Create(appointment).Error; err != nil {
        return err
    }
    return nil
})
Create excerpt: the conflict query precedes the transaction. These calls are an excerpt, not a complete file.

next: PsyPredict