-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into devops/deployment
- Loading branch information
Showing
10 changed files
with
67 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
# GoLand IDE | ||
.idea/ | ||
|
||
# Fleet IDE | ||
.fleet/ | ||
|
||
# Compiled Go programs and executables | ||
*.exe | ||
*.out | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,65 @@ | ||
# Updating the API and generating code | ||
[![Build Status](https://github.com/il-blood-donation-info/blood-donation-backend/actions/workflows/on_push.yml/badge.svg)](https://github.com/il-blood-donation-info/blood-donation-backend/actions/workflows/on_push.yml) | ||
|
||
# Blood Donation Backend Service | ||
The project is used to collect and persist blood donation stations, and offers an API to manage stations availability. | ||
It also allows querying for the stations. | ||
|
||
View OpenAPI definition using Swagger UI [here](https://generator.swagger.io/?url=https://raw.githubusercontent.com/il-blood-donation-info/blood-donation-backend/main/pkg/api/openapi.yaml#/). | ||
|
||
## 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: | ||
```bash | ||
oapi-codegen -config api/api.cfg.yaml api/openapi.yaml | ||
oapi-codegen -config pkg/api/api.cfg.yaml pkg/api/openapi.yaml | ||
``` | ||
|
||
## Installing the code-gen dependency | ||
If `oapi-codegen` isn't available, install the code-gen dependency: | ||
```bash | ||
go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest | ||
``` | ||
|
||
# Creating a Database | ||
## Setting development environment | ||
|
||
### Creating a Database | ||
```postgresql | ||
CREATE DATABASE bloodinfo; | ||
CREATE USER mada WITH PASSWORD <your password>; # change this | ||
GRANT ALL PRIVILEGES ON DATABASE bloodinfo TO mada; | ||
``` | ||
|
||
# Running the server | ||
### Running the server | ||
```bash | ||
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 | ||
go run cmd/cert/tls-self-signed-cert.go | ||
go run cmd/server/main.go | ||
``` | ||
|
||
# Running using docker-compose | ||
## Running using docker-compose | ||
|
||
## Building the image and running the containers | ||
### Building the image and running the containers | ||
Edit or change the db.env file to your liking. Then, run the following command: | ||
|
||
```bash | ||
docker-compose --env_file db.env up --build | ||
docker-compose --env-file db.env up --build | ||
``` | ||
## Stopping the containers | ||
|
||
Note this generates a self-signed cert & key during the build, separate from anything you might have in cert.pem file. | ||
So once it built, you want to run this to get the same ./cert.pem: | ||
``` | ||
docker run blood-donation-backend_blood-info /bin/cat cert.pem > cert.pem | ||
``` | ||
|
||
### Stopping the containers | ||
```bash | ||
docker-compose --env_file db.env down --remove-orphans --volumes --rmi local | ||
docker-compose --env-file db.env down --remove-orphans --volumes --rmi local | ||
``` | ||
|
||
# Testing the API | ||
## Testing the API | ||
|
||
## Creating a user | ||
### Creating a user | ||
```bash | ||
curl --cacert ./cert.pem -X POST https://localhost:8443/users -H "Content-Type: application/json" -d '{"description": "User description", | ||
"email": "[email protected]", | ||
|
@@ -53,7 +70,7 @@ curl --cacert ./cert.pem -X POST https://localhost:8443/users -H "Content-Type: | |
"role": "Admin"}' | ||
``` | ||
|
||
## Getting a user | ||
### Getting a user | ||
```bash | ||
curl --cacert ./cert.pem -s -X GET https://localhost:8443/users | jq | ||
[ | ||
|
@@ -88,5 +105,5 @@ EOF | |
# Use echo to pass the commands to psql | ||
echo "$TEST_DB_COMMANDS" | psql -U postgres | ||
|
||
go test ./scraper/... -v | ||
``` | ||
go test ./pkg/scraper/... -v | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters