Skip to content

il-blood-donation-info/blood-donation-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Updating the API and generating code

In order to modify the API, edit the api/openapi.yaml file. Then, run the following commands to generate the code:

oapi-codegen -config api/api.cfg.yaml api/openapi.yaml

Installing the code-gen dependency

go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest

Creating a Database

CREATE DATABASE bloodinfo;
CREATE USER mada WITH PASSWORD <your password>; # change this
GRANT ALL PRIVILEGES ON DATABASE bloodinfo TO mada;

Running the server

export DB_HOST=localhost
export DB_PORT=5432
export DB_USER=mada
export DB_NAME=bloodinfo
export DB_PASSWORD= # your password
go run  cert/tls-self-signed-cert.go
go run main.go

Running using docker-compose

Building the image and running the containers

Edit or change the db.env file to your liking. Then, run the following command:

docker-compose --env_file db.env up --build

Stopping the containers

docker-compose --env_file db.env down --remove-orphans --volumes --rmi local

Testing the API

Creating a user

curl --cacert ./cert.pem -X POST https://localhost:8443/users -H "Content-Type: application/json" -d '{"description": "User description",
    "email": "[email protected]",
    "first_name": "John",
    "id": 1,
    "last_name": "Doe",
    "phone": "1234567890",
    "role": "Admin"}'

Getting a user

curl --cacert ./cert.pem -s -X GET https://localhost:8443/users | jq
[
  {
    "description": "User description",
    "email": "[email protected]",
    "first_name": "John",
    "id": 1,
    "last_name": "Doe",
    "phone": "1234567890",
    "role": "Admin"
  }
]

Running Scrapper test against real DB

export DB_HOST=localhost
export DB_PORT=5432
export DB_USER_TEST=mada_test
export DB_NAME_TEST=bloodinfo_test
export DB_PASSWORD=mada

# Create the test database
TEST_DB_COMMANDS=$(cat <<EOF
CREATE DATABASE $DB_NAME_TEST;
CREATE USER $DB_USER_TEST WITH PASSWORD '$DB_PASSWORD';
GRANT ALL PRIVILEGES ON DATABASE $DB_NAME_TEST TO $DB_USER_TEST;
EOF
)

# Use echo to pass the commands to psql
echo "$TEST_DB_COMMANDS" | psql -U postgres

go test ./scraper/... -v

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published