diff --git a/Dependencies.toml b/Dependencies.toml index faf08de..77c869c 100644 --- a/Dependencies.toml +++ b/Dependencies.toml @@ -9,7 +9,7 @@ dependencies-toml-version = "2" [[package]] org = "ballerina" name = "auth" -version = "2.2.1" +version = "2.3.1" dependencies = [ {org = "ballerina", name = "crypto"}, {org = "ballerina", name = "jballerina.java"}, @@ -41,7 +41,7 @@ dependencies = [ [[package]] org = "ballerina" name = "file" -version = "1.2.2" +version = "1.3.0" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, @@ -54,7 +54,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.2.2" +version = "2.3.0" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -101,7 +101,7 @@ version = "0.0.0" [[package]] org = "ballerina" name = "jwt" -version = "2.2.1" +version = "2.3.1" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, @@ -214,7 +214,7 @@ modules = [ [[package]] org = "ballerina" name = "oauth2" -version = "2.2.1" +version = "2.3.1" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, @@ -234,7 +234,7 @@ dependencies = [ [[package]] org = "ballerina" name = "os" -version = "1.2.1" +version = "1.3.0" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c249856 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +from ballerina/ballerina:latest + +COPY . /app +WORKDIR /app +RUN mkdir /home/ballerina/.ballerina + +EXPOSE 9090 + +ENTRYPOINT ["bal", "run"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..5a064d2 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +## Medicines for LK - Admin API + +The medicines LK app is comprised of a [React Frontend](https://github.com/LSFLK/MedicinesforLK), [Ballerina Donor API](https://github.com/LSFLK/MedicinesforLK-DonorAPI) and [Ballerina Admin API](https://github.com/LSFLK/MedicinesforLK-AdminAPI). + +### Development + +- [Set up Ballerina](https://ballerina.io/learn/install-ballerina/set-up-ballerina/) +- Run a MySQL server and execute the script `mysql-scripts/creation-ddl.sql` on it to bring up the DDL for the db. You need to have a `medicinesforlk` db in your MySQL server to set up the DDL in. +- Modify `config.bal` with the values for the MySQL server you set up. +- `bal run` (runs the API on port 9090) +- Test the API http://localhost:9090/admin/medicalneeds + +### Run using Docker Compose + +- `docker-compose up -d` +- Test the API http://localhost:9090/admin/medicalneeds diff --git a/config.bal b/config.bal index a54d06e..405107f 100644 --- a/config.bal +++ b/config.bal @@ -1,5 +1,5 @@ -configurable string dbHost = "dbHost"; +configurable string dbHost = "medicinesforlk-mysql"; configurable int dbPort = 3306; -configurable string dbUser = "dbUser"; -configurable string dbPass = "dbPass"; -configurable string db = "db"; \ No newline at end of file +configurable string dbUser = "root"; +configurable string dbPass = "root"; +configurable string db = "medicinesforlk"; diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..26b8f7c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,44 @@ +version: "3.5" + +services: + medicinesforlk-adminapi: + build: + context: ./ + restart: unless-stopped + container_name: medicinesforlk-adminapi + image: medicinesforlk-adminapi + ports: + - "9090:9090" + volumes: + - "./:/home" + - "./target:/app/target" + - "./Dependencies.toml:/app/Dependencies.toml" + networks: + medicinesforlk-network: + ipv4_address: 172.16.238.10 + + + mysql: + image: mysql + container_name: medicinesforlk-mysql + command: --default-authentication-plugin=mysql_native_password + environment: + MYSQL_ROOT_PASSWORD: root + ports: + - "3306:3306" + volumes: + - "./mysql-scripts/create-database.sql:/docker-entrypoint-initdb.d/1.sql" + - "./mysql-scripts/creation-ddl.sql:/docker-entrypoint-initdb.d/2.sql" + networks: + medicinesforlk-network: + ipv4_address: 172.16.238.11 + + +networks: + medicinesforlk-network: + name: medicinesforlk-network + driver: bridge + ipam: + driver: default + config: + - subnet: 172.16.238.0/24 diff --git a/mysql-scripts/create-database.sql b/mysql-scripts/create-database.sql new file mode 100644 index 0000000..c278fff --- /dev/null +++ b/mysql-scripts/create-database.sql @@ -0,0 +1 @@ +CREATE DATABASE IF NOT EXISTS medicinesforlk; diff --git a/mysql-scripts/creation-ddl.sql b/mysql-scripts/creation-ddl.sql index 2f5c41a..53d0a39 100644 --- a/mysql-scripts/creation-ddl.sql +++ b/mysql-scripts/creation-ddl.sql @@ -1,3 +1,5 @@ +USE medicinesforlk; + CREATE TABLE IF NOT EXISTS SUPPLIER ( SUPPLIERID INT NOT NULL AUTO_INCREMENT, `NAME` VARCHAR (255) NOT NULL,