ugent-library / projects-service

A service that publishes a directory of research projects at Ghent University.
Apache License 2.0
1 stars 0 forks source link

Project service

A service that publishes a directory of research projects at Ghent University.

Setup

Database

Create a new database and a user.

This application uses PostgreSQL's text search feature. You need to create a custom TEXT CONFIGURATION using these queries:

CREATE EXTENSION IF NOT EXISTS unaccent;
CREATE TEXT SEARCH CONFIGURATION usimple ( COPY = simple );
ALTER TEXT SEARCH CONFIGURATION usimple ALTER MAPPING FOR hword, hword_part, word WITH unaccent, simple;

Environment variables

Copy .env.example to .env and ensure these variables are present:

PROJECTS_ENV               # environment (local, production, development, default:production)
PROJECTS_HOST              # host or IP (default: localhost)
PROJECTS_PORT              # host port (default: 3000)
PROJECTS_API_KEY           # REST API Key
PROJECTS_REPO_CONN         # PostgreSQL DSN connection string
PROJECTS_REPO_SECRET       # PostgreSQL secret seed

Application boot

Via Reflex:

cp reflex.conf.example .reflex.conf
reflex -d none -c .reflex.conf

Or via Docker:

cd docker && docker build -f app.Dockerfile -t ugentlib/projects ../
docker run ugentlib/projects /dist/app server

Use tern to initalize the database:

cd etc/migrations && tern migrate apply

Either create a tern.conf file in the etc/migrations directory, or use tern with PG environment variables.

Development

Live reload

go install github.com/cespare/reflex@latest
cp reflex.example.conf reflex.conf
reflex -c reflex.conf

Database

Making changes to the database schema:

This projects uses sqlc.

OpenAPI

The REST API is described through OpenAPI. The code is generated with ogen.

When making changes to the API specification in api/v1/openapi.yaml, you must regenerate the API server code: cd api/v1 && go generate ./....

The implementation of the handler resides in api/v1/service.go. Make sure all methods of the Handler interface are implemented.