Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: FE Demo / How to prep #26

Merged
merged 23 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a30617f
fix(file-upload): refactor fileupload to use params instead of header
MattCMcCoy Feb 6, 2024
29d6371
feat: I NO LONGER NEED TO LOGIN
MattCMcCoy Feb 6, 2024
6eac1ce
feat: fe requests using transquery
MattCMcCoy Feb 7, 2024
a630f9b
feat: install clsx bc I like it w/ tailwind
MattCMcCoy Feb 7, 2024
dfba554
refactor: general cleanup for fe demo
MattCMcCoy Feb 8, 2024
6d81b3b
docs: readme changes
MattCMcCoy Feb 8, 2024
e59c123
ci: remove over complicated name
MattCMcCoy Feb 8, 2024
7c39eda
docs: readme update to remove bullets from contributing section
MattCMcCoy Feb 8, 2024
bb203ce
fix: remove extra fetch after post request for med
MattCMcCoy Feb 8, 2024
f859873
refactor: use tan stack in file and login service routes
MattCMcCoy Feb 9, 2024
7465944
test: fix test
MattCMcCoy Feb 9, 2024
8b05e75
docs(pull_request_template): revert changes
MattCMcCoy Feb 9, 2024
59ee500
refactor: general import cleanup, removing default exports, and follo…
MattCMcCoy Feb 9, 2024
b9cb683
refactor: remove unused hook stuff from the useMedication api hook
MattCMcCoy Feb 9, 2024
9a536c1
refactor: combine all three popup hooks into one
MattCMcCoy Feb 9, 2024
74e4146
refactor: revert prev commit (I didnt like it)
MattCMcCoy Feb 9, 2024
6f7af32
ci: try at separating ci stuff
MattCMcCoy Feb 9, 2024
62ca9fd
ci: replace prettier with node package, add paths to fe and be CI stu…
MattCMcCoy Feb 9, 2024
dc224da
ci: fix fe format?
MattCMcCoy Feb 9, 2024
9604e27
ci: pls work
MattCMcCoy Feb 9, 2024
049b875
Merge branch 'main' into bugfix/file-upload
MattCMcCoy Feb 10, 2024
391f7b1
feat: medlist with optimistic updating
MattCMcCoy Feb 12, 2024
ad33c40
Feature/eslint -- Dependent on FE Demo branch (#28)
MattCMcCoy Feb 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion backend/db/migrations/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,34 @@ VALUES
(2, 'Medication B'),
(3, 'Medication C'),
(4, 'Medication D'),
(5, 'Medication E')
(5, 'Medication E');

INSERT INTO
care_group (group_id, group_name, date_created)
VALUES
(999, 'GROUP DE MATT', '2024-02-08 06:36:00');

INSERT INTO
users (
user_id,
first_name,
last_name,
email,
phone,
address,
pfp_s3_url,
device_id,
push_notification_enabled
)
VALUES
(
'fIoFY26mJnYWH8sNdfuVoxpnVnr1',
'Matt',
'McCoy',
'',
'',
'',
'',
'',
FALSE
);
53 changes: 51 additions & 2 deletions backend/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ const docTemplate = `{
"name": "file_data",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "The userId of the uploader",
"name": "upload_by",
"in": "formData",
"required": true
},
{
"type": "integer",
"description": "The groupId of the uploader",
"name": "group_id",
"in": "formData",
"required": true
}
],
"responses": {
Expand All @@ -39,7 +53,10 @@ const docTemplate = `{
}
},
"400": {
"description": "Bad Request"
"description": "Bad Request",
"schema": {
"type": "string"
}
}
}
}
Expand All @@ -62,6 +79,38 @@ const docTemplate = `{
}
}
}
},
"post": {
"description": "add a medication to a users medlist",
"tags": [
"medications"
],
"summary": "add a medication",
"parameters": [
{
"description": "a medication",
"name": "_",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.Medication"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.Medication"
}
},
"400": {
"description": "Bad Request",
"schema": {
"type": "string"
}
}
}
}
}
},
Expand All @@ -85,7 +134,7 @@ const docTemplate = `{
"type": "integer"
},
"upload_by": {
"type": "integer"
"type": "string"
},
"upload_date": {
"type": "string"
Expand Down
53 changes: 51 additions & 2 deletions backend/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@
"name": "file_data",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "The userId of the uploader",
"name": "upload_by",
"in": "formData",
"required": true
},
{
"type": "integer",
"description": "The groupId of the uploader",
"name": "group_id",
"in": "formData",
"required": true
}
],
"responses": {
Expand All @@ -32,7 +46,10 @@
}
},
"400": {
"description": "Bad Request"
"description": "Bad Request",
"schema": {
"type": "string"
}
}
}
}
Expand All @@ -55,6 +72,38 @@
}
}
}
},
"post": {
"description": "add a medication to a users medlist",
"tags": [
"medications"
],
"summary": "add a medication",
"parameters": [
{
"description": "a medication",
"name": "_",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.Medication"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.Medication"
}
},
"400": {
"description": "Bad Request",
"schema": {
"type": "string"
}
}
}
}
}
},
Expand All @@ -78,7 +127,7 @@
"type": "integer"
},
"upload_by": {
"type": "integer"
"type": "string"
},
"upload_date": {
"type": "string"
Expand Down
35 changes: 34 additions & 1 deletion backend/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ definitions:
task_id:
type: integer
upload_by:
type: integer
type: string
upload_date:
type: string
type: object
Expand All @@ -39,13 +39,25 @@ paths:
name: file_data
required: true
type: file
- description: The userId of the uploader
in: formData
name: upload_by
required: true
type: string
- description: The groupId of the uploader
in: formData
name: group_id
required: true
type: integer
responses:
"200":
description: OK
schema:
$ref: '#/definitions/models.File'
"400":
description: Bad Request
schema:
type: string
summary: Upload a file
tags:
- file
Expand All @@ -62,4 +74,25 @@ paths:
summary: Get All Meds
tags:
- medications
post:
description: add a medication to a users medlist
parameters:
- description: a medication
in: body
name: _
required: true
schema:
$ref: '#/definitions/models.Medication'
responses:
"200":
description: OK
schema:
$ref: '#/definitions/models.Medication'
"400":
description: Bad Request
schema:
type: string
summary: add a medication
tags:
- medications
swagger: "2.0"
2 changes: 1 addition & 1 deletion backend/models/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ type File struct {
FileID int `json:"file_id"`
FileName string `json:"file_name"`
GroupID int `json:"group_id"`
UploadBy int `json:"upload_by"`
UploadBy string `json:"upload_by"`
UploadDate string `json:"upload_date"`
FileSize int64 `json:"file_size"`
TaskID int `json:"task_id"`
Expand Down
29 changes: 15 additions & 14 deletions backend/schema/files/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,43 @@ func GetFileGroup(v1 *gin.RouterGroup, c *PgModel) *gin.RouterGroup {

files := v1.Group("files")
{
files.POST("/upload", c.UploadFileRoute)
files.POST("/upload", c.UploadFile)
}

return files
}

// GetFiles godoc
// UploadFile godoc
//
// @summary Upload a file
// @description Upload a file to database and S3 bucket
// @tags file
//
// @param file_data formData file true "Body with file zip"
// @param upload_by formData string true "The userId of the uploader"
// @param group_id formData int true "The groupId of the uploader"
//
// @success 200 {object} models.File
// @failure 400
// @failure 400 {object} string
// @router /files/upload [post]
func (pg *PgModel) UploadFileRoute(c *gin.Context) {
// TODO: Ensure Swagger Knows about the bad request returns!!!
func (pg *PgModel) UploadFile(c *gin.Context) {
var file models.File

if err := c.Bind(&file); err != nil {
c.JSON(http.StatusBadRequest, "Failed to process the request")
return
}
userID := c.GetHeader("user_id")
groupID := c.GetHeader("group_id")
file.UploadBy, _ = strconv.Atoi(userID)
file.GroupID, _ = strconv.Atoi(groupID)

form, err := c.MultipartForm()
if err != nil {
c.JSON(http.StatusBadRequest, "Failed to get form")
return
}

fileResponse := form.File["file_data"][0]
file.UploadBy = form.Value["upload_by"][0]
file.GroupID, err = strconv.Atoi(form.Value["group_id"][0])

if err != nil {
c.JSON(http.StatusBadRequest, "Failed to parse groupid")
return
}

fileData, err := fileResponse.Open()
if err != nil {
c.JSON(http.StatusBadRequest, "Failed to open file")
Expand Down
27 changes: 27 additions & 0 deletions backend/schema/medication/routes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package medication

import (
"carewallet/models"
"net/http"

"github.com/gin-gonic/gin"
Expand All @@ -16,6 +17,7 @@ func GetMedicationGroup(v1 *gin.RouterGroup, c *PgModel) *gin.RouterGroup {
medications := v1.Group("medications")
{
medications.GET("", c.GetMedications)
medications.POST("", c.AddMedications)
}

return medications
Expand All @@ -37,3 +39,28 @@ func (pg *PgModel) GetMedications(c *gin.Context) {

c.JSON(http.StatusOK, med)
}

// AddMedications godoc
//
// @summary add a medication
// @description add a medication to a users medlist
// @tags medications
//
// @param _ body models.Medication true "a medication"
//
// @success 200 {object} models.Medication
// @failure 400 {object} string
// @router /medications [post]
func (pg *PgModel) AddMedications(c *gin.Context) {
var medbody models.Medication
c.Bind(&medbody)

med, err := AddMedToDB(pg.Conn, medbody)

if err != nil {
c.JSON(http.StatusBadRequest, err.Error())
return
}

c.JSON(http.StatusOK, med)
}
12 changes: 12 additions & 0 deletions backend/schema/medication/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,15 @@ func GetAllMedsFromDB(pool *pgx.Conn) ([]models.Medication, error) {

return results, nil
}

func AddMedToDB(pool *pgx.Conn, med models.Medication) (models.Medication, error) {
err := pool.QueryRow("INSERT INTO medication (medication_id, medication_name) VALUES ($1, $2) RETURNING medication_id;",
med.MedicationID, med.MedicationName).Scan(&med.MedicationID)

if err != nil {
print(err.Error())
return models.Medication{}, err
}

return med, nil
}
Loading
Loading