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
sqlxpackage 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
hospitaltable. - Insert at least 4 locations in
locationtable (can use locations shown here). 2 locations for each hospital. - Insert 9 patients in
patienttable, 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.Engineas 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/allto display all locations in JSON format. Name the functionGetAllLocations(c *gin.Context) - Create endpoint
/hospital/allto 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/alland/hospital/allendpoints, pretty format.
Yes @PrathameshMutkure, you can either create a new
.sqlfile or place it in the schema file.Ok, I believe it's fixed now: https://demo.openmrs.org/openmrs/login.htm