Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI

on:
push:
branches: ["main", "feat/**"]
pull_request:
branches: ["main"]

jobs:
test:
name: Run pytest
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Upgrade pip
run: python -m pip install --upgrade pip

- name: Install project and test dependencies
run: python -m pip install -e . pytest httpx

- name: Run tests
run: python -m pytest
142 changes: 127 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,65 @@
# ticket-api
# Ticket-API

Backend API de tickets e incidentes orientada a portafolio para roles junior de backend, cloud o platform. Esta primera fase entrega una base limpia de FastAPI con versionado de rutas, healthcheck y manejo básico de errores.
Ticket-API is a backend API for a portfolio-oriented ticketing and incident management system. It is designed for junior backend, cloud, and platform engineering roles.

## Requisitos
This first phase provides a clean FastAPI foundation with versioned routes, a health check endpoint, basic error handling, automated testing with `pytest`, and a GitHub Actions CI workflow.

## Project Goals

This project is being built to demonstrate practical backend and cloud-readiness skills, including:

- Python backend development with FastAPI
- Clean API structure and versioned routing
- Basic service health checks
- Consistent error handling
- Automated testing with `pytest`
- Continuous Integration with GitHub Actions
- Preparation for future PostgreSQL persistence
- Preparation for Docker and cloud deployment

## Requirements

- Python 3.11+
- `pip`

## Instalacion local
## Local Installation

Create and activate a virtual environment:

```bash
python -m venv .venv
.venv\Scripts\activate
```

Install the project locally:

```bash
pip install -e .
```

## Ejecutar la API
For testing, install the testing dependencies:

```bash
pip install pytest httpx
```

## Run the API

```bash
uvicorn app.main:app --reload
```

La API quedara disponible en:
The API will be available at:

- `http://127.0.0.1:8000/docs`
- `http://127.0.0.1:8000/redoc`
- `http://127.0.0.1:8000/api/v1/health`

## Endpoint disponible
## Available Endpoint

### `GET /api/v1/health`

Respuesta esperada:
Expected response:

```json
{
Expand All @@ -41,7 +69,62 @@ Respuesta esperada:
}
```

## Estructura actual
This endpoint is used to verify that the API is running correctly.

## Testing

The project includes automated tests using `pytest`.

Run the tests locally:

```bash
python -m pytest
```

Current test coverage includes the health check endpoint:

```http
GET /api/v1/health
```

The test validates that the API:

- Returns HTTP status code `200`
- Returns `status: "ok"`
- Returns `service: "ticket-api"`
- Includes a `version` field

Test file:

```text
tests/test_health.py
```

## Continuous Integration

The project includes a GitHub Actions CI workflow located at:

```text
.github/workflows/ci.yml
```

The workflow runs automatically on:

- Pushes to `main`
- Pushes to branches matching `feat/**`
- Pull requests targeting `main`

The CI pipeline performs the following steps:

1. Checks out the repository.
2. Sets up Python.
3. Upgrades `pip`.
4. Installs the project and test dependencies.
5. Runs the test suite with `pytest`.

This helps verify that the project continues to work after each change.

## Current Project Structure

```text
app/
Expand All @@ -50,14 +133,43 @@ app/
core/
schemas/
main.py

tests/
test_health.py

.github/
workflows/
ci.yml
```

## Manejo de errores incluido
## Error Handling Included

The API currently includes basic error handling for:

- `404` responses in a consistent JSON format
- `422` validation errors
- `500` internal server errors with a generic message that avoids exposing internal details

## Current Status

Completed:

- FastAPI project skeleton
- Versioned API routing
- Health check endpoint
- Basic error handling
- Initial README
- Automated health endpoint test with `pytest`
- GitHub Actions CI workflow

## Next Phase

The next phase will add persistence with PostgreSQL and initial domain models without breaking the current project structure.

- `404` en formato JSON consistente
- `422` para errores de validacion
- `500` con mensaje generico sin exponer detalles internos
Planned models:

## Siguiente fase
- User
- Ticket
- Incident

La siguiente fase agregara persistencia con PostgreSQL y modelos de dominio, sin romper la estructura creada aqui.
Future phases will include authentication, role-based access control, Docker, CI/CD improvements, and cloud deployment.
18 changes: 18 additions & 0 deletions tests/test_health.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from fastapi.testclient import TestClient

from app.main import app


client = TestClient(app)


def test_health_endpoint_returns_ok():
response = client.get("/api/v1/health")

assert response.status_code == 200

data = response.json()

assert data["status"] == "ok"
assert data["service"] == "ticket-api"
assert "version" in data
Loading