Skip to content

Commit

Permalink
refactor: pull main
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviaseds committed Mar 25, 2024
2 parents ac069db + dd9547c commit ee5f408
Show file tree
Hide file tree
Showing 53 changed files with 1,128 additions and 301 deletions.
48 changes: 33 additions & 15 deletions backend/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,51 @@ package db

import (
"carewallet/configuration"
"context"
"fmt"
"log"
"os"
"time"

"github.com/jackc/pgx"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
)

func ConnectPosgresDatabase(settings configuration.Settings) *pgx.Conn {
func ConnectPosgresDatabase(settings configuration.Settings) *pgxpool.Pool {
db_url, exists := os.LookupEnv("DATABASE_URL")

cfg := pgx.ConnConfig{
User: settings.Database.Username,
Database: settings.Database.DatabaseName,
Password: settings.Database.Password,
Host: settings.Database.Host,
Port: settings.Database.Port,
}
// TODO: move these to the configuration file
const defaultMaxConns = int32(10)
const defaultMinConns = int32(0)
const defaultMaxConnLifetime = time.Hour
const defaultMaxConnIdleTime = time.Minute * 30
const defaultHealthCheckPeriod = time.Minute
const defaultConnectTimeout = time.Second * 5

var err error
if exists {
cfg, err = pgx.ParseConnectionString(db_url)
var conn *pgxpool.Pool
if !exists {
db_url = fmt.Sprintf("postgres://%s:%s@%s:%d/%s", settings.Database.Username, settings.Database.Password, settings.Database.Host, settings.Database.Port, settings.Database.DatabaseName)
}

if err != nil {
panic(err)
}
dbConfig, err := pgxpool.ParseConfig(db_url)
if err != nil {
log.Fatal("Failed to create a config, error: ", err)
}

conn, err := pgx.Connect(cfg)
dbConfig.MaxConns = defaultMaxConns
dbConfig.MinConns = defaultMinConns
dbConfig.MaxConnLifetime = defaultMaxConnLifetime
dbConfig.MaxConnIdleTime = defaultMaxConnIdleTime
dbConfig.HealthCheckPeriod = defaultHealthCheckPeriod
dbConfig.ConnConfig.ConnectTimeout = defaultConnectTimeout

dbConfig.BeforeClose = func(c *pgx.Conn) {
log.Println("Closed the connection pool to the database!!")
}

conn, err = pgxpool.NewWithConfig(context.Background(), dbConfig)

if err != nil {
fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err)
os.Exit(1)
Expand Down
4 changes: 3 additions & 1 deletion backend/db/migrations/1.user.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ VALUES
('onrQs8HVGBVMPNz4Fk1uE94bSxg1', 'Danny', 'Rollo', '[email protected]', '', ''),
('8Sy7xBkGiGQv4ZKphcQfY8PxAqw1', 'Narayan', 'Sharma', '[email protected]', '', ''),
('iL7PnjS4axQffmlPceobjUUZ9DF2', 'Caitlin', 'Flynn', '[email protected]', '', ''),
('5JgN2PQxCRM9VoCiiFPlQPNqkL32', 'Linwood', 'Blaisdell', '[email protected]', '', '')
('5JgN2PQxCRM9VoCiiFPlQPNqkL32', 'Linwood', 'Blaisdell', '[email protected]', '', ''),
('9rIMSUo6qNf8ToTABkCfNqnByRv1', 'Haley', 'Martin', '[email protected]', '', '')

-- End Care-Wallet Team
;
4 changes: 3 additions & 1 deletion backend/db/migrations/2.group.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ VALUES
(5, 'mPeo3d3MiXfnpPJADWgFD9ZcB2M2', 'SECONDARY'),
(5, 'onrQs8HVGBVMPNz4Fk1uE94bSxg1', 'SECONDARY'),
(5, '8Sy7xBkGiGQv4ZKphcQfY8PxAqw1', 'SECONDARY'),
(5, 'iL7PnjS4axQffmlPceobjUUZ9DF2', 'SECONDARY')
(5, 'iL7PnjS4axQffmlPceobjUUZ9DF2', 'SECONDARY'),
(5, '9rIMSUo6qNf8ToTABkCfNqnByRv1', 'SECONDARY')

-- End Care-Wallet Team
;
18 changes: 13 additions & 5 deletions backend/db/migrations/3.task.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ CREATE TYPE task_type AS ENUM ('med_mgmt', 'dr_appt', 'financial', 'other');

CREATE TABLE IF NOT EXISTS task (
task_id serial NOT NULL,
task_title varchar NOT NULL,
group_id integer NOT NULL,
created_by varchar NOT NULL,
created_date timestamp NOT NULL, -- add default val with current timestamp?
start_date timestamp,
end_date timestamp,
quick_task BOOLEAN DEFAULT FALSE,
notes varchar,
repeating BOOLEAN DEFAULT FALSE,
repeating_interval varchar,
Expand All @@ -38,12 +40,18 @@ CREATE TABLE IF NOT EXISTS task_assignees (
FOREIGN KEY (assigned_by) REFERENCES users (user_id)
);

INSERT INTO task (group_id, created_by, created_date, start_date, end_date, notes, task_status, task_type)
INSERT INTO task (task_title, group_id, created_by, created_date, start_date, end_date, notes, task_status, task_type, quick_task)
VALUES
(1, 'user2', '2024-02-03 10:45:00', '2024-02-05 10:00:00', '2024-02-05 11:00:00', 'Pick up medication from pharmacy', 'INCOMPLETE', 'med_mgmt'),
(2, 'user3', '2024-02-20 23:59:59', '2024-02-10 14:30:00', NULL, 'Schedule doctor appointment', 'INCOMPLETE', 'other'),
(3, 'user4', '2020-02-05 11:00:00', NULL, '2024-02-20 23:59:59', 'Submit insurance claim', 'PARTIAL', 'financial'),
(4, 'user1', '2006-01-02 15:04:05', NULL, NULL, 'Refill water pitcher', 'COMPLETE', 'other')
('task 1', 1, 'user2', '2024-02-03 10:45:00', '2024-02-05 10:00:00', '2024-02-05 11:00:00', 'Pick up medication from pharmacy', 'INCOMPLETE', 'med_mgmt', FALSE),
('task 2', 2, 'user3', '2024-02-20 23:59:59', '2024-02-10 14:30:00', NULL, 'Schedule doctor appointment', 'INCOMPLETE', 'other', FALSE),
('task 3', 3, 'user4', '2020-02-05 11:00:00', NULL, '2024-02-20 23:59:59', 'Submit insurance claim', 'PARTIAL', 'financial', FALSE),
('task 4', 4, 'user1', '2006-01-02 15:04:05', NULL, NULL, 'Refill water pitcher', 'COMPLETE', 'other', TRUE),
('task 5', 5, 'user1', '2024-03-19 11:00:00', '2024-03-19 15:00:00', '2024-03-19 19:00:00', 'Get medications', 'INCOMPLETE', 'dr_appt', TRUE),
('task 6', 5, 'user2', '2024-03-19 11:00:00', '2024-03-19 11:00:00', '2024-03-19 13:00:00', 'File Papers', 'INCOMPLETE', 'med_mgmt', TRUE),
('task 7', 5, 'user3', '2024-03-19 11:00:00', '2024-03-19 07:00:00', '2024-03-19 09:00:00', 'Send check to Drs', 'INCOMPLETE', 'financial', TRUE),
('task 8', 5, 'user1', '2024-03-19 11:00:00', '2024-03-19 15:00:00', '2024-03-19 19:00:00', 'Get medications', 'INCOMPLETE', 'dr_appt', FALSE),
('task 9', 5, 'user2', '2024-03-19 11:00:00', '2024-03-19 11:00:00', '2024-03-19 13:00:00', 'File Papers', 'INCOMPLETE', 'med_mgmt', FALSE),
('task 10', 5, 'user3', '2024-03-19 11:00:00', '2024-03-19 07:00:00', '2024-03-19 09:00:00', 'Send check to Drs', 'INCOMPLETE', 'financial', FALSE)
;

INSERT INTO task_assignees (task_id, user_id, assignment_status, assigned_by, assigned_date)
Expand Down
19 changes: 19 additions & 0 deletions backend/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,11 @@ const docTemplate = `{
"name": "groupID",
"in": "query"
},
{
"type": "string",
"name": "quickTask",
"in": "query"
},
{
"type": "string",
"name": "startDate",
Expand All @@ -535,6 +540,11 @@ const docTemplate = `{
"name": "taskStatus",
"in": "query"
},
{
"type": "string",
"name": "taskTitle",
"in": "query"
},
{
"type": "string",
"name": "taskType",
Expand Down Expand Up @@ -1166,6 +1176,9 @@ const docTemplate = `{
"notes": {
"type": "string"
},
"quick_task": {
"type": "boolean"
},
"repeating": {
"type": "boolean"
},
Expand All @@ -1187,6 +1200,9 @@ const docTemplate = `{
"task_status": {
"type": "string"
},
"task_title": {
"type": "string"
},
"task_type": {
"type": "string"
}
Expand Down Expand Up @@ -1304,6 +1320,9 @@ const docTemplate = `{
"notes": {
"type": "string"
},
"quick_task": {
"type": "boolean"
},
"repeating": {
"type": "boolean"
},
Expand Down
19 changes: 19 additions & 0 deletions backend/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,11 @@
"name": "groupID",
"in": "query"
},
{
"type": "string",
"name": "quickTask",
"in": "query"
},
{
"type": "string",
"name": "startDate",
Expand All @@ -528,6 +533,11 @@
"name": "taskStatus",
"in": "query"
},
{
"type": "string",
"name": "taskTitle",
"in": "query"
},
{
"type": "string",
"name": "taskType",
Expand Down Expand Up @@ -1159,6 +1169,9 @@
"notes": {
"type": "string"
},
"quick_task": {
"type": "boolean"
},
"repeating": {
"type": "boolean"
},
Expand All @@ -1180,6 +1193,9 @@
"task_status": {
"type": "string"
},
"task_title": {
"type": "string"
},
"task_type": {
"type": "string"
}
Expand Down Expand Up @@ -1297,6 +1313,9 @@
"notes": {
"type": "string"
},
"quick_task": {
"type": "boolean"
},
"repeating": {
"type": "boolean"
},
Expand Down
12 changes: 12 additions & 0 deletions backend/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ definitions:
type: integer
notes:
type: string
quick_task:
type: boolean
repeating:
type: boolean
repeating_end_date:
Expand All @@ -102,6 +104,8 @@ definitions:
type: string
task_status:
type: string
task_title:
type: string
task_type:
type: string
type: object
Expand Down Expand Up @@ -178,6 +182,8 @@ definitions:
type: integer
notes:
type: string
quick_task:
type: boolean
repeating:
type: boolean
repeating_end_date:
Expand Down Expand Up @@ -757,6 +763,9 @@ paths:
- in: query
name: groupID
type: string
- in: query
name: quickTask
type: string
- in: query
name: startDate
type: string
Expand All @@ -766,6 +775,9 @@ paths:
- in: query
name: taskStatus
type: string
- in: query
name: taskTitle
type: string
- in: query
name: taskType
type: string
Expand Down
79 changes: 40 additions & 39 deletions backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,75 @@ module carewallet
go 1.21.5

require (
github.com/gin-contrib/cors v1.5.0
github.com/gin-gonic/gin v1.9.1
github.com/jackc/pgx v3.6.2+incompatible
github.com/lib/pq v1.10.9
github.com/spf13/viper v1.18.2
github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0
github.com/swaggo/swag v1.16.2
github.com/swaggo/swag v1.16.3
)

require github.com/jmespath/go-jmespath v0.4.0 // indirect

require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/aws/aws-sdk-go v1.50.2
github.com/bytedance/sonic v1.10.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/cockroachdb/apd v1.1.0 // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/spec v0.20.4 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.15.5 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jackc/fake v0.0.0-20150926172116-812a484cc733 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/arch v0.5.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/tools v0.13.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

require (
github.com/aws/aws-sdk-go v1.51.3
github.com/bytedance/sonic v1.11.2 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/cors v1.7.0
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.19.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.5.5
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/lib/pq v1.10.9
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/spf13/viper v1.18.2
github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.7.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit ee5f408

Please sign in to comment.