NOTE: You should have completed GoLang-1.
- Create an account on ElephantSQL (use your GitHub or gmail account).
- Create a new PostgresSQL instance, and name appropriately. Screenshot
- Go to the newly created instance. Take note of the URL.
- Download and install PostgreSQL.
- Use GoLand IDE if possible. If not, no problem, install PgAdmin4 - will be used for connecting to the cloud db instance.
- In your repository, get
sqlx
package by runninggo get github.com/jmoiron/sqlx
- Get the sql driver by running
go get github.com/lib/pq
- In your go repository, create folder
scripts
. Inside it, add this PostgresSQL schema file. - Connect to your db instance. Use GoLand or PgAdmin4 as mentioned above. See this tutorial.
- Run the script using PgAdmin's
Query Tool
. - Insert 2 hospitals in
hospital
table. - Insert at least 4 locations in
location
table (can use locations shown here). 2 locations for each hospital. - Insert 9 patients in
patient
table, with at least 1 patient in each location. - In
main.go
, create a functioninitDatabase()
which initializes a global variabledb *sql.DB
. Hint: usesql.Open()
anddb.Ping()
. - Move all endpoint creation to function
initAPI()
, withrouter *gin.Engine
as a global variable. - Create an endpoint
/patient/all
. It should display all patients in the db, in JSON format. Name the functionGetAllPatients(c *gin.Context)
- Create endpoint
/location/all
to display all locations in JSON format. Name the functionGetAllLocations(c *gin.Context)
- Create endpoint
/hospital/all
to display all hospitals in JSON format. Name the functionGetAllHospitals(c *gin.Context)
- In
main()
function, call the init methods and run therouter
. - Commit and create a new PR for this task.
INSERT
operations must be shown in the .sql
file
Commit message should be GCI-<gci-id>: <your_message>
- Your PR link
- Three screenshots showing the responses in Postman for
/patient/all
,/location/all
and/hospital/all
endpoints, pretty format.
Hii everybody, the link to demo server is not working right now, you can try this link https://refapp.openmrs.org/openmrs/login.htm to see location util demo server is back