NEGO

NEGO is a UFPB SIGAA Restful API created with Golang for study purposes only, but it may fit your needs.
Feel free to use and contribute.
MAIN FEATURES
- Readable and simple code;
- Uses GORM as the default database management tool for a more dynamic and generic approach to databases;
- Router specification created with CHI reliable router structure;
- Caching;
- Generic repository and middlewares;
- Multi database support for each resource;
- Created with both REST and gRPC support in mind;
- Auth with JWT;
- Complete fetching capabilities: pagination, sorting, filtering.
AVAILABLE RESOURCES
/centers
or /centers/1856
{
"id": 1856,
"nome": "CENTRO DE INFORMÁTICA (CI)"
}
/departments
or /departments/2151
{
"id": 2151,
"nome": "DEPARTAMENTO DE INFORMÁTICA", "idCentro": "1856"
}
/teachers
or /teachers/1743917
{
"id": 1743917,
"nome": "THAIS GAUDENCIO DO REGO",
"grau": "DOUTOR",
"idDepartamento": 2151
}
/courses
or /courses/1626865
{
"id": 1626865,
"nome": "ENGENHARIA DE COMPUTAÇÃO/CI",
"local": "João Pessoa",
"tipo": "Presencial",
"coordenador": "CHRISTIAN AZAMBUJA PAGOT",
"idCentro": 1856
}
/students
or /students/11409558
{
"matricula": 11409558,
"nome": "CLEANDERSON LINS COUTINHO",
"idCurso": 1626865
}
/classes
or /classes/GDSCO0081
{
"id": "GDSCO0081",
"nome": "SISTEMAS EMBARCADOS I",
"turma": "01",
"professor": "ALISSON VASCONCELOS DE BRITO",
"horario": "24T23",
"idCurso": 1626865
}
FETCHING FEATURES
Type |
Example |
Sorting |
students?sort=nome , students?sort=idCurso |
Filtering |
students?nome=cleanderson , students?idCurso=1626865 |
Pagination |
students?page=3 |
And of course, you can use all of them at the same time:
/teachers?nome=mardson&sort=nome&page=0
It would give us:
{
"totalElements": 1,
"totalPages": 1,
"limit": 10,
"page": 0,
"payloadSize": 1,
"payload": [
{
"id": 1122252,
"nome": "MARDSON FREITAS DE AMORIM",
"grau": "DOUTOR",
"idDepartamento": 1858
}
]
}
...and more to come.
OBSERVATIONS
- The
page
parameter starts by index zero, until {totalPages
- 1};
totalElements
will change dinamically based on your filtering, if you have one, and not by the resource amount or the payload.
- Any field of the models described above can be used as a filter as long as it is written in lower camel case:
idCurso
;
- If more than one value to any parameter was provided, only the last will be considered, except for the
sort
parameter.
MODELS RELATION LOGIC
CREATE TABLE CENTROS (
id INT NOT NULL PRIMARY KEY,
nome VARCHAR (100) NOT NULL
);
CREATE TABLE DEPARTAMENTOS (
id INT NOT NULL PRIMARY KEY,
nome VARCHAR (100) NOT NULL,
id_centro INT NOT NULL,
FOREIGN KEY (id_centro) REFERENCES centros(id)
);
CREATE TABLE CURSOS (
id INT NOT NULL PRIMARY KEY,
nome VARCHAR (100) NOT NULL,
cidade VARCHAR (100),
tipo VARCHAR (100),
coordenador VARCHAR (100) NOT NULL,
id_centro INT NOT NULL,
FOREIGN KEY (id_centro) REFERENCES centros(id)
);
CREATE TABLE TURMAS (
codigo VARCHAR(10) NOT NULL PRIMARY KEY,
disciplina VARCHAR (100) NOT NULL,
turma INT NOT NULL,
professor VARCHAR (50) NOT NULL,
horario VARCHAR (10) NOT NULL,
--sala VARCHAR(10),
id_curso INT NOT NULL,
FOREIGN KEY (id_curso) REFERENCES cursos(id)
);
CREATE TABLE ALUNOS (
matricula BIGINT NOT NULL PRIMARY KEY,
nome VARCHAR(100) NOT NULL,
id_curso INT NOT NULL,
FOREIGN KEY (id_curso) REFERENCES cursos(id)
);
CREATE TABLE PROFESSORES (
id INT NOT NULL PRIMARY KEY,
nome VARCHAR(100) NOT NULL,
grau VARCHAR(20),
id_departamento INT NOT NULL,
FOREIGN KEY (id_departamento) REFERENCES departamentos(id)
);
USAGE DETAILS
Before everything:
- You need at least an empty PostgreSQL database created with the basic model logic above.
- There's also a custom scrapper created just for this project, called SUS, so you can populate your database with real data.
- You must fill the
app.env
file on root folder with:
- database credentials;
- keys for JWT and user registration.
And then, you can run this project by:
go build .
./nego
Available runtime flags:
Flag |
Description |
Type |
Default |
Usage |
debug |
SQL debug mode flag |
boolean |
false |
./nego -debug true |
port |
API port |
string |
8080 |
./nego -port 8080 |
prod |
TLS connection flag |
boolean |
false |
./nego -prod |
And of course you make requests with any REST client, like Insomnia or any web application at your localhost:port/{resource}
.
TODOS
- Create an unified request model (query + model) - DTO
- Setup a generic middleware for DTO
- Setup caching for GET page requests
- Setup docker with PostgreSQL instance