diff --git a/backend/schema/files/routes.go b/backend/schema/files/routes.go index 6db4f46..1d3ed62 100644 --- a/backend/schema/files/routes.go +++ b/backend/schema/files/routes.go @@ -17,7 +17,7 @@ func FileGroup(v1 *gin.RouterGroup, c *PgModel) *gin.RouterGroup { files := v1.Group("files") { - files.POST("/upload", c.UploadFile) + files.POST("/upload", c.uploadFile) } return files @@ -38,7 +38,7 @@ func FileGroup(v1 *gin.RouterGroup, c *PgModel) *gin.RouterGroup { // @success 200 {object} models.File // @failure 400 {object} string // @router /files/upload [post] -func (pg *PgModel) UploadFile(c *gin.Context) { +func (pg *PgModel) uploadFile(c *gin.Context) { var file models.File form, err := c.MultipartForm() @@ -66,7 +66,7 @@ func (pg *PgModel) UploadFile(c *gin.Context) { defer fileData.Close() - err = UploadFile(pg.Conn, file, fileResponse, fileData) + err = uploadFile(pg.Conn, file, fileResponse, fileData) if err != nil { c.JSON(http.StatusBadRequest, "Failed to create file: "+err.Error()) return diff --git a/backend/schema/files/transactions.go b/backend/schema/files/transactions.go index 348ba07..5da0585 100644 --- a/backend/schema/files/transactions.go +++ b/backend/schema/files/transactions.go @@ -19,7 +19,7 @@ import ( var AWS_BUCKET_NAME = "care-wallet-storage" -func UploadFile(pool *pgxpool.Pool, file models.File, data *multipart.FileHeader, reader io.Reader) error { +func uploadFile(pool *pgxpool.Pool, file models.File, data *multipart.FileHeader, reader io.Reader) error { file.FileName = data.Filename file.UploadDate = time.Now().Format("2006-01-02 15:04:05") diff --git a/backend/schema/group-roles/routes.go b/backend/schema/group-roles/routes.go index 28db025..9b2cc04 100644 --- a/backend/schema/group-roles/routes.go +++ b/backend/schema/group-roles/routes.go @@ -15,26 +15,18 @@ type PgModel struct { func GroupRolesGroup(v1 *gin.RouterGroup, c *PgModel) *gin.RouterGroup { groupRoles := v1.Group("") { - groupRoles.GET("/:groupId/roles", c.GetGroupRoles) + groupRoles.GET("/:groupId/roles", c.getGroupRoles) group := v1.Group(":groupId") { user := group.Group(":uid") { - user.DELETE("", c.RemoveUserFromGroup) - user.PATCH(":role", c.ChangeUserGroupRole) - user.PUT(":role", c.AddUserToGroup) + user.DELETE("", c.removeUserFromGroup) + user.PATCH(":role", c.changeUserGroupRole) + user.PUT(":role", c.addUserToGroup) } } - - member := v1.Group("member") - { - user := member.Group(":uid") - { - user.GET("", c.GetGroupByUID) - } - } - + groupRoles.GET("/member/:uid", c.getGroupByUID) } return groupRoles @@ -53,7 +45,7 @@ func GroupRolesGroup(v1 *gin.RouterGroup, c *PgModel) *gin.RouterGroup { // @success 200 {object} string // @failure 400 {object} string // @router /group/{groupId}/{uid}/{role} [patch] -func (pg *PgModel) ChangeUserGroupRole(c *gin.Context) { +func (pg *PgModel) changeUserGroupRole(c *gin.Context) { gid := c.Param("groupId") gidInt, err := strconv.Atoi(gid) uid := c.Param("uid") @@ -64,7 +56,7 @@ func (pg *PgModel) ChangeUserGroupRole(c *gin.Context) { return } - err = ChangeUserGroupRoleInDB(pg.Conn, gidInt, uid, role) + err = changeUserGroupRoleInDB(pg.Conn, gidInt, uid, role) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) @@ -87,7 +79,7 @@ func (pg *PgModel) ChangeUserGroupRole(c *gin.Context) { // @success 200 {object} models.GroupRole // @failure 400 {object} string // @router /group/{groupId}/{uid}/{role} [put] -func (pg *PgModel) AddUserToGroup(c *gin.Context) { +func (pg *PgModel) addUserToGroup(c *gin.Context) { gid := c.Param("groupId") gidInt, err := strconv.Atoi(gid) uid := c.Param("uid") @@ -98,7 +90,7 @@ func (pg *PgModel) AddUserToGroup(c *gin.Context) { return } - groupRole, err := AddUserToGroupInDB(pg.Conn, gidInt, uid, role) + groupRole, err := addUserToGroupInDB(pg.Conn, gidInt, uid, role) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) @@ -120,7 +112,7 @@ func (pg *PgModel) AddUserToGroup(c *gin.Context) { // @success 200 {object} models.GroupRole // @failure 400 {object} string // @router /group/{groupId}/{uid} [delete] -func (pg *PgModel) RemoveUserFromGroup(c *gin.Context) { +func (pg *PgModel) removeUserFromGroup(c *gin.Context) { gid := c.Param("groupId") gidInt, err := strconv.Atoi(gid) uid := c.Param("uid") @@ -130,7 +122,7 @@ func (pg *PgModel) RemoveUserFromGroup(c *gin.Context) { return } - err = RemoveUserFromGroupInDB(pg.Conn, gidInt, uid) + err = removeUserFromGroupInDB(pg.Conn, gidInt, uid) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) @@ -151,9 +143,9 @@ func (pg *PgModel) RemoveUserFromGroup(c *gin.Context) { // @success 200 {object} string // @failure 400 {object} string // @router /group/member/{uid} [get] -func (pg *PgModel) GetGroupByUID(c *gin.Context) { +func (pg *PgModel) getGroupByUID(c *gin.Context) { uid := c.Param("uid") - groupRole, err := GetGroupMemberByUIDFromDB(pg.Conn, uid) + groupRole, err := getGroupMemberByUIDFromDB(pg.Conn, uid) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) @@ -173,7 +165,7 @@ func (pg *PgModel) GetGroupByUID(c *gin.Context) { // // @success 200 {array} models.GroupRole // @router /group/{groupId}/roles [get] -func (pg *PgModel) GetGroupRoles(c *gin.Context) { +func (pg *PgModel) getGroupRoles(c *gin.Context) { gid := c.Param("groupId") gidInt, err := strconv.Atoi(gid) @@ -182,7 +174,7 @@ func (pg *PgModel) GetGroupRoles(c *gin.Context) { return } - careGroups, err := GetAllGroupRolesFromDB(pg.Conn, gidInt) + careGroups, err := getAllGroupRolesFromDB(pg.Conn, gidInt) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) diff --git a/backend/schema/group-roles/transactions.go b/backend/schema/group-roles/transactions.go index 1626222..cb61876 100644 --- a/backend/schema/group-roles/transactions.go +++ b/backend/schema/group-roles/transactions.go @@ -8,14 +8,18 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -func ChangeUserGroupRoleInDB(pool *pgxpool.Pool, gid int, uid string, role string) error { - fmt.Println(role) +func changeUserGroupRoleInDB(pool *pgxpool.Pool, gid int, uid string, role string) error { _, err := pool.Exec(context.Background(), "UPDATE group_roles SET role = $1 WHERE group_id = $2 AND user_id = $3", role, gid, uid) - return err + if err != nil { + fmt.Printf("Error changing group role: %v", err) + return err + } + + return nil } -func AddUserToGroupInDB(pool *pgxpool.Pool, gid int, uid string, role string) (models.GroupRole, error) { +func addUserToGroupInDB(pool *pgxpool.Pool, gid int, uid string, role string) (models.GroupRole, error) { var groupMember models.GroupRole err := pool.QueryRow(context.Background(), "INSERT into group_roles (group_id, user_id, role) VALUES ($1, $2, $3) RETURNING *", gid, uid, role).Scan(&groupMember.GroupID, &groupMember.UserID, &groupMember.Role) @@ -27,7 +31,7 @@ func AddUserToGroupInDB(pool *pgxpool.Pool, gid int, uid string, role string) (m return groupMember, nil } -func RemoveUserFromGroupInDB(pool *pgxpool.Pool, gid int, uid string) error { +func removeUserFromGroupInDB(pool *pgxpool.Pool, gid int, uid string) error { _, err := pool.Exec(context.Background(), "DELETE from group_roles WHERE group_id = $1 AND user_id = $2", gid, uid) if err != nil { @@ -39,7 +43,7 @@ func RemoveUserFromGroupInDB(pool *pgxpool.Pool, gid int, uid string) error { } // GetGroupIDByUIDFromDB returns the groupID of a user given their UID -func GetGroupMemberByUIDFromDB(pool *pgxpool.Pool, uid string) (models.GroupRole, error) { +func getGroupMemberByUIDFromDB(pool *pgxpool.Pool, uid string) (models.GroupRole, error) { var groupMember models.GroupRole err := pool.QueryRow(context.Background(), "SELECT * FROM group_roles WHERE user_id = $1", uid).Scan(&groupMember.GroupID, &groupMember.UserID, &groupMember.Role) @@ -52,7 +56,7 @@ func GetGroupMemberByUIDFromDB(pool *pgxpool.Pool, uid string) (models.GroupRole } // Get all group roles from the DB -func GetAllGroupRolesFromDB(pool *pgxpool.Pool, gid int) ([]models.GroupRole, error) { +func getAllGroupRolesFromDB(pool *pgxpool.Pool, gid int) ([]models.GroupRole, error) { rows, err := pool.Query(context.Background(), "SELECT group_id, user_id, role FROM group_roles WHERE group_id = $1;", gid) if err != nil { diff --git a/backend/schema/groups/routes.go b/backend/schema/groups/routes.go index 8e7bbe6..a4be449 100644 --- a/backend/schema/groups/routes.go +++ b/backend/schema/groups/routes.go @@ -16,12 +16,12 @@ type PgModel struct { func CareGroups(v1 *gin.RouterGroup, c *PgModel) *gin.RouterGroup { careGroups := v1.Group("") { - careGroups.POST("/create/:groupName", c.CreateCareGroups) + careGroups.POST("/create/:groupName", c.createCareGroups) group := v1.Group("/:groupId") { - group.GET("", c.GetGroupByGroupId) - group.POST("add", c.AddUserCareGroup) + group.GET("", c.getGroupByGroupId) + group.POST("add", c.addUserCareGroup) } } @@ -39,9 +39,9 @@ func CareGroups(v1 *gin.RouterGroup, c *PgModel) *gin.RouterGroup { // // @success 200 {object} int // @router /group/create/{groupName} [post] -func (pg *PgModel) CreateCareGroups(c *gin.Context) { +func (pg *PgModel) createCareGroups(c *gin.Context) { groupName := c.Param("groupName") - careGroups, err := CreateCareGroupsFromDB(pg.Conn, groupName) + careGroups, err := createCareGroupsFromDB(pg.Conn, groupName) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) @@ -68,7 +68,7 @@ type GroupMember struct { // @success 200 {object} int // @failure 400 {object} string // @router /group/{groupId}/add [post] -func (pg *PgModel) AddUserCareGroup(c *gin.Context) { +func (pg *PgModel) addUserCareGroup(c *gin.Context) { var requestBody GroupMember groupId := c.Param("groupId") @@ -78,7 +78,7 @@ func (pg *PgModel) AddUserCareGroup(c *gin.Context) { return } - id, err := AddUserCareGroupFromDB(pg.Conn, groupId, requestBody) + id, err := addUserCareGroupFromDB(pg.Conn, groupId, requestBody) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) @@ -100,9 +100,9 @@ func (pg *PgModel) AddUserCareGroup(c *gin.Context) { // @success 200 {object} models.CareGroup // @failure 400 {object} string // @router /group/{groupId} [get] -func (pg *PgModel) GetGroupByGroupId(c *gin.Context) { +func (pg *PgModel) getGroupByGroupId(c *gin.Context) { groupId := c.Param("groupId") - group, err := GetGroupFromDB(pg.Conn, groupId) + group, err := getGroupFromDB(pg.Conn, groupId) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) diff --git a/backend/schema/groups/transactions.go b/backend/schema/groups/transactions.go index 1754fb3..6cfb664 100644 --- a/backend/schema/groups/transactions.go +++ b/backend/schema/groups/transactions.go @@ -8,7 +8,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -func CreateCareGroupsFromDB(conn *pgxpool.Pool, groupName string) (int, error) { +func createCareGroupsFromDB(conn *pgxpool.Pool, groupName string) (int, error) { var caregroup models.CareGroup @@ -24,7 +24,7 @@ func CreateCareGroupsFromDB(conn *pgxpool.Pool, groupName string) (int, error) { } -func AddUserCareGroupFromDB(conn *pgxpool.Pool, groupId string, groupMember GroupMember) (int, error) { +func addUserCareGroupFromDB(conn *pgxpool.Pool, groupId string, groupMember GroupMember) (int, error) { var returningGroupId int err := conn.QueryRow(context.Background(), "INSERT INTO group_roles (group_id, user_id, role) VALUES ($1, $2, $3) RETURNING group_id", groupId, groupMember.UserId, groupMember.Role).Scan(&returningGroupId) @@ -39,7 +39,7 @@ func AddUserCareGroupFromDB(conn *pgxpool.Pool, groupId string, groupMember Grou } // Return all members of a group (by user_id) -func GetGroupFromDB(conn *pgxpool.Pool, groupId string) (models.CareGroup, error) { +func getGroupFromDB(conn *pgxpool.Pool, groupId string) (models.CareGroup, error) { var caregroup models.CareGroup groupIdInt, _ := strconv.Atoi(groupId) err := conn.QueryRow(context.Background(), "SELECT * FROM care_group WHERE group_id = $1", groupIdInt).Scan(&caregroup.GroupID, &caregroup.GroupName, &caregroup.DateCreated) diff --git a/backend/schema/labels/routes.go b/backend/schema/labels/routes.go index 60b1745..7290ec2 100644 --- a/backend/schema/labels/routes.go +++ b/backend/schema/labels/routes.go @@ -17,10 +17,10 @@ func LabelGroup(v1 *gin.RouterGroup, c *PgModel) *gin.RouterGroup { labels := v1.Group(":groupId/labels") { - labels.POST("", c.CreateNewLabel) - labels.GET("", c.GetLabelsByGroup) - labels.DELETE(":lname", c.DeleteLabel) - labels.PATCH(":lname", c.EditLabel) + labels.POST("", c.createNewLabel) + labels.GET("", c.getLabelsByGroup) + labels.DELETE(":lname", c.deleteLabel) + labels.PATCH(":lname", c.editLabel) } return labels @@ -37,10 +37,10 @@ func LabelGroup(v1 *gin.RouterGroup, c *PgModel) *gin.RouterGroup { // @success 200 {array} models.Label // @failure 400 {object} string // @router /group/{groupId}/labels [GET] -func (pg *PgModel) GetLabelsByGroup(c *gin.Context) { +func (pg *PgModel) getLabelsByGroup(c *gin.Context) { group_id := c.Param("groupId") - labels, err := GetLabelsByGroupFromDB(pg.Conn, group_id) + labels, err := getLabelsByGroupFromDB(pg.Conn, group_id) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) return @@ -66,7 +66,7 @@ type LabelData struct { // @success 200 {object} models.Label // @failure 400 {object} string // @router /group/{groupId}/labels [POST] -func (pg *PgModel) CreateNewLabel(c *gin.Context) { +func (pg *PgModel) createNewLabel(c *gin.Context) { var requestBody LabelData group_id := c.Param("groupId") @@ -78,7 +78,7 @@ func (pg *PgModel) CreateNewLabel(c *gin.Context) { id, _ := strconv.Atoi(group_id) - label, err := CreateNewLabelInDB(pg.Conn, id, requestBody) + label, err := createNewLabelInDB(pg.Conn, id, requestBody) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) return @@ -99,11 +99,11 @@ func (pg *PgModel) CreateNewLabel(c *gin.Context) { // @success 200 {object} string // @failure 400 {object} string // @router /group/{groupId}/labels/{lname} [DELETE] -func (pg *PgModel) DeleteLabel(c *gin.Context) { +func (pg *PgModel) deleteLabel(c *gin.Context) { group_id := c.Param("groupId") label_name := c.Param("lname") - err := DeleteLabelFromDB(pg.Conn, group_id, label_name) + err := deleteLabelFromDB(pg.Conn, group_id, label_name) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) return @@ -125,7 +125,7 @@ func (pg *PgModel) DeleteLabel(c *gin.Context) { // @success 200 {object} models.Label // @failure 400 {object} string // @router /group/{groupId}/labels/{lname} [PATCH] -func (pg *PgModel) EditLabel(c *gin.Context) { +func (pg *PgModel) editLabel(c *gin.Context) { group_id := c.Param("groupId") label_name := c.Param("lname") @@ -136,7 +136,7 @@ func (pg *PgModel) EditLabel(c *gin.Context) { return } - label, err := EditLabelInDB(pg.Conn, group_id, label_name, requestBody) + label, err := editLabelInDB(pg.Conn, group_id, label_name, requestBody) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) return diff --git a/backend/schema/labels/transactions.go b/backend/schema/labels/transactions.go index 1d1c28e..bab03f4 100644 --- a/backend/schema/labels/transactions.go +++ b/backend/schema/labels/transactions.go @@ -8,7 +8,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -func GetLabelsByGroupFromDB(pool *pgxpool.Pool, groupID string) ([]models.Label, error) { +func getLabelsByGroupFromDB(pool *pgxpool.Pool, groupID string) ([]models.Label, error) { groupIDInt, err := strconv.Atoi(groupID) if err != nil { return nil, err @@ -37,7 +37,7 @@ func GetLabelsByGroupFromDB(pool *pgxpool.Pool, groupID string) ([]models.Label, } -func CreateNewLabelInDB(pool *pgxpool.Pool, groupID int, requestBody LabelData) (models.Label, error) { +func createNewLabelInDB(pool *pgxpool.Pool, groupID int, requestBody LabelData) (models.Label, error) { labelName := requestBody.LabelName labelColor := requestBody.LabelColor @@ -56,7 +56,7 @@ func CreateNewLabelInDB(pool *pgxpool.Pool, groupID int, requestBody LabelData) return label, nil } -func DeleteLabelFromDB(pool *pgxpool.Pool, groupID string, labelName string) error { +func deleteLabelFromDB(pool *pgxpool.Pool, groupID string, labelName string) error { groupIDInt, err := strconv.Atoi(groupID) if err != nil { return err @@ -70,7 +70,7 @@ func DeleteLabelFromDB(pool *pgxpool.Pool, groupID string, labelName string) err return nil } -func EditLabelInDB(pool *pgxpool.Pool, groupID string, labelName string, data LabelData) (models.Label, error) { +func editLabelInDB(pool *pgxpool.Pool, groupID string, labelName string, data LabelData) (models.Label, error) { groupIDInt, err := strconv.Atoi(groupID) if err != nil { return models.Label{}, err diff --git a/backend/schema/task_labels/routes.go b/backend/schema/task_labels/routes.go index 7d7ef02..87567be 100644 --- a/backend/schema/task_labels/routes.go +++ b/backend/schema/task_labels/routes.go @@ -15,9 +15,9 @@ func TaskGroup(v1 *gin.RouterGroup, c *PgModel) *gin.RouterGroup { tasks := v1.Group(":tid/labels") { - tasks.POST("", c.AddLabelToTask) - tasks.DELETE("", c.RemoveLabelFromTask) - tasks.GET("", c.GetLabelsByTask) + tasks.POST("", c.addLabelToTask) + tasks.DELETE("", c.removeLabelFromTask) + tasks.GET("", c.getLabelsByTask) } return tasks @@ -34,8 +34,8 @@ func TaskGroup(v1 *gin.RouterGroup, c *PgModel) *gin.RouterGroup { // @success 200 {array} models.Task_Label // @failure 400 {object} string // @router /tasks/{tid}/labels [GET] -func (pg *PgModel) GetLabelsByTask(c *gin.Context) { - taskLabels, err := GetLabelsByTaskInDB(pg.Conn, c.Param("tid")) +func (pg *PgModel) getLabelsByTask(c *gin.Context) { + taskLabels, err := getLabelsByTaskInDB(pg.Conn, c.Param("tid")) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) @@ -62,7 +62,7 @@ type LabelData struct { // @success 200 {object} models.Task_Label // @failure 400 {object} string // @router /tasks/{tid}/labels [POST] -func (pg *PgModel) AddLabelToTask(c *gin.Context) { +func (pg *PgModel) addLabelToTask(c *gin.Context) { var requestBody LabelData if err := c.BindJSON(&requestBody); err != nil { @@ -70,7 +70,7 @@ func (pg *PgModel) AddLabelToTask(c *gin.Context) { return } - updatedTaskLabel, err := AddLabelToTaskInDB(pg.Conn, requestBody, c.Param("tid")) + updatedTaskLabel, err := addLabelToTaskInDB(pg.Conn, requestBody, c.Param("tid")) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) @@ -92,7 +92,7 @@ func (pg *PgModel) AddLabelToTask(c *gin.Context) { // @success 200 {object} string // @failure 400 {object} string // @router /tasks/{tid}/labels [DELETE] -func (pg *PgModel) RemoveLabelFromTask(c *gin.Context) { +func (pg *PgModel) removeLabelFromTask(c *gin.Context) { var requestBody LabelData if err := c.BindJSON(&requestBody); err != nil { @@ -100,7 +100,7 @@ func (pg *PgModel) RemoveLabelFromTask(c *gin.Context) { return } - err := RemoveLabelFromTaskInDB(pg.Conn, requestBody, c.Param("tid")) + err := removeLabelFromTaskInDB(pg.Conn, requestBody, c.Param("tid")) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) diff --git a/backend/schema/task_labels/transactions.go b/backend/schema/task_labels/transactions.go index e7d7fdf..2b392b4 100644 --- a/backend/schema/task_labels/transactions.go +++ b/backend/schema/task_labels/transactions.go @@ -7,7 +7,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -func GetLabelsByTaskInDB(conn *pgxpool.Pool, taskId string) ([]models.Task_Label, error) { +func getLabelsByTaskInDB(conn *pgxpool.Pool, taskId string) ([]models.Task_Label, error) { rows, err := conn.Query(context.Background(), "SELECT * FROM task_labels WHERE task_id = $1", taskId) if err != nil { @@ -34,7 +34,7 @@ func GetLabelsByTaskInDB(conn *pgxpool.Pool, taskId string) ([]models.Task_Label return results, nil } -func AddLabelToTaskInDB(conn *pgxpool.Pool, requestBody LabelData, taskid string) (models.Task_Label, error) { +func addLabelToTaskInDB(conn *pgxpool.Pool, requestBody LabelData, taskid string) (models.Task_Label, error) { var task_label models.Task_Label err := conn.QueryRow(context.Background(), "INSERT INTO task_labels (task_id, group_id, label_name) VALUES ($1, $2, $3) RETURNING *;", taskid, requestBody.GroupID, requestBody.LabelName).Scan(&task_label.TaskId, &task_label.GroupId, &task_label.LabelName) @@ -47,7 +47,7 @@ func AddLabelToTaskInDB(conn *pgxpool.Pool, requestBody LabelData, taskid string return task_label, nil } -func RemoveLabelFromTaskInDB(conn *pgxpool.Pool, requestBody LabelData, taskId string) error { +func removeLabelFromTaskInDB(conn *pgxpool.Pool, requestBody LabelData, taskId string) error { _, err := conn.Exec(context.Background(), "DELETE FROM task_labels WHERE task_id = $1 AND group_id = $2 AND label_name = $3", taskId, requestBody.GroupID, requestBody.LabelName) if err != nil { diff --git a/backend/schema/tasks/routes.go b/backend/schema/tasks/routes.go index 0ee7a5a..041dcf3 100644 --- a/backend/schema/tasks/routes.go +++ b/backend/schema/tasks/routes.go @@ -19,18 +19,18 @@ type PgModel struct { func TaskGroup(v1 *gin.RouterGroup, c *PgModel) *gin.RouterGroup { tasks := v1.Group("") { - tasks.GET("/filtered", c.GetFilteredTasks) - tasks.GET("/assigned", c.GetTasksByAssignedUsers) - tasks.POST("", c.CreateTask) + tasks.GET("/filtered", c.getFilteredTasks) + tasks.GET("/assigned", c.getTasksByAssignedUsers) + tasks.POST("", c.createTask) byId := tasks.Group("/:tid") { - byId.GET("", c.GetTaskByID) - byId.DELETE("", c.DeleteTask) - byId.PUT("", c.UpdateTaskInfo) - byId.GET("/assigned", c.GetUsersAssignedToTask) - byId.POST("/assign", c.AssignUsersToTask) - byId.DELETE("/remove", c.RemoveUsersFromTask) + byId.GET("", c.getTaskByID) + byId.DELETE("", c.deleteTask) + byId.PUT("", c.updateTaskInfo) + byId.GET("/assigned", c.getUsersAssignedToTask) + byId.POST("/assign", c.assignUsersToTask) + byId.DELETE("/remove", c.removeUsersFromTask) } } return tasks @@ -47,13 +47,13 @@ func TaskGroup(v1 *gin.RouterGroup, c *PgModel) *gin.RouterGroup { // @success 200 {object} models.Task // @failure 400 {object} string // @router /tasks/{tid} [GET] -func (pg *PgModel) GetTaskByID(c *gin.Context) { +func (pg *PgModel) getTaskByID(c *gin.Context) { taskID, err := strconv.Atoi(c.Param("tid")) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) return } - task, err := GetTaskByID(pg.Conn, taskID) + task, err := getTaskByID(pg.Conn, taskID) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) return @@ -84,14 +84,14 @@ type TaskQuery struct { // @success 200 {array} models.Task // @failure 400 {object} string // @router /tasks/filtered [get] -func (pg *PgModel) GetFilteredTasks(c *gin.Context) { +func (pg *PgModel) getFilteredTasks(c *gin.Context) { var filterQuery TaskQuery if err := c.ShouldBindQuery(&filterQuery); err != nil { c.JSON(http.StatusBadRequest, err.Error()) return } - tasks, err := GetTasksByQueryFromDB(pg.Conn, filterQuery) + tasks, err := getTasksByQueryFromDB(pg.Conn, filterQuery) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) @@ -117,13 +117,13 @@ type Assignment struct { // @success 200 {array} models.TaskUser // @failure 400 {object} string // @router /tasks/{tid}/assign [post] -func (pg *PgModel) AssignUsersToTask(c *gin.Context) { +func (pg *PgModel) assignUsersToTask(c *gin.Context) { var requestBody Assignment if err := c.BindJSON(&requestBody); err != nil { c.JSON(http.StatusBadRequest, err.Error()) return } - assignedUsers, err := AssignUsersToTaskInDB(pg.Conn, requestBody.UserIDs, c.Param("tid"), requestBody.Assigner) + assignedUsers, err := assignUsersToTaskInDB(pg.Conn, requestBody.UserIDs, c.Param("tid"), requestBody.Assigner) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) return @@ -147,13 +147,13 @@ type Removal struct { // @success 200 {array} models.TaskUser // @failure 400 {object} string // @router /tasks/{tid}/remove [delete] -func (pg *PgModel) RemoveUsersFromTask(c *gin.Context) { +func (pg *PgModel) removeUsersFromTask(c *gin.Context) { var requestBody Removal if err := c.BindJSON(&requestBody); err != nil { c.JSON(http.StatusBadRequest, err.Error()) return } - removedUsers, err := RemoveUsersFromTaskInDB(pg.Conn, requestBody.UserIDs, c.Param("tid")) + removedUsers, err := removeUsersFromTaskInDB(pg.Conn, requestBody.UserIDs, c.Param("tid")) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) return @@ -176,12 +176,12 @@ type AssignedQuery struct { // @success 200 {array} models.Task // @failure 400 {object} string // @router /tasks/assigned [get] -func (pg *PgModel) GetTasksByAssignedUsers(c *gin.Context) { +func (pg *PgModel) getTasksByAssignedUsers(c *gin.Context) { userIDs := c.Query("userIDs") assignedQuery := AssignedQuery{ UserIDs: strings.Split(userIDs, ","), } - tasks, err := GetTasksByAssignedFromDB(pg.Conn, assignedQuery.UserIDs) + tasks, err := getTasksByAssignedFromDB(pg.Conn, assignedQuery.UserIDs) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) return @@ -215,7 +215,7 @@ type TaskBody struct { // // @success 201 {object} models.Task "Created Task" // @router /tasks [post] -func (pg *PgModel) CreateTask(c *gin.Context) { +func (pg *PgModel) createTask(c *gin.Context) { // Bind the request body to the CreateTaskRequest struct var requestBody models.Task if err := c.BindJSON(&requestBody); err != nil { @@ -225,7 +225,7 @@ func (pg *PgModel) CreateTask(c *gin.Context) { } // Create the new task in the database - newTaskID, err := CreateTaskInDB(pg.Conn, requestBody) + newTaskID, err := createTaskInDB(pg.Conn, requestBody) if err != nil { fmt.Println("error creating task in the database:", err) c.JSON(http.StatusBadRequest, err.Error()) @@ -233,7 +233,7 @@ func (pg *PgModel) CreateTask(c *gin.Context) { } // Fetch the created task from the database - createdTask, err := GetTaskByID(pg.Conn, newTaskID) + createdTask, err := getTaskByID(pg.Conn, newTaskID) if err != nil { fmt.Println("error fetching created task from the database:", err) c.JSON(http.StatusBadRequest, err.Error()) @@ -251,7 +251,7 @@ func (pg *PgModel) CreateTask(c *gin.Context) { // @param tid path int true "Task ID" // @success 204 "No Content" // @router /tasks/{tid} [delete] -func (pg *PgModel) DeleteTask(c *gin.Context) { +func (pg *PgModel) deleteTask(c *gin.Context) { // Extract task ID from the path parameter taskID, err := strconv.Atoi(c.Param("tid")) if err != nil { @@ -260,13 +260,13 @@ func (pg *PgModel) DeleteTask(c *gin.Context) { } // Check if the task exists before attempting to delete - if _, err := GetTaskByID(pg.Conn, taskID); err != nil { + if _, err := getTaskByID(pg.Conn, taskID); err != nil { c.JSON(http.StatusBadRequest, err.Error()) return } // Delete the task from the database - if err := DeleteTaskInDB(pg.Conn, taskID); err != nil { + if err := deleteTaskInDB(pg.Conn, taskID); err != nil { fmt.Println("error deleting task from the database:", err) c.JSON(http.StatusBadRequest, err.Error()) return @@ -284,7 +284,7 @@ func (pg *PgModel) DeleteTask(c *gin.Context) { // @param request_body body TaskBody true "Update Task Info Request" // @success 200 {object} models.Task "Updated Task" // @router /tasks/{tid} [put] -func (pg *PgModel) UpdateTaskInfo(c *gin.Context) { +func (pg *PgModel) updateTaskInfo(c *gin.Context) { // Extract task ID from the path parameter taskID, err := strconv.Atoi(c.Param("tid")) if err != nil { @@ -302,14 +302,14 @@ func (pg *PgModel) UpdateTaskInfo(c *gin.Context) { } // Update the task_info field in the database - if err := UpdateTaskInfoInDB(pg.Conn, taskID, requestBody); err != nil { + if err := updateTaskInfoInDB(pg.Conn, taskID, requestBody); err != nil { fmt.Println("error updating task info in the database:", err) c.JSON(http.StatusBadRequest, err.Error()) return } // Fetch the updated task from the database - updatedTask, err := GetTaskByID(pg.Conn, taskID) + updatedTask, err := getTaskByID(pg.Conn, taskID) if err != nil { fmt.Println("error fetching updated task from the database:", err) c.JSON(http.StatusBadRequest, err.Error()) @@ -333,7 +333,7 @@ type TaskUser struct { // @success 200 {array} string "List of user IDs assigned to the task" // @failure 400 {object} string // @router /tasks/{tid}/assigned [get] -func (pg *PgModel) GetUsersAssignedToTask(c *gin.Context) { +func (pg *PgModel) getUsersAssignedToTask(c *gin.Context) { // Extract task ID from the path parameter taskIDStr := c.Param("tid") taskID, err := strconv.Atoi(taskIDStr) @@ -343,7 +343,7 @@ func (pg *PgModel) GetUsersAssignedToTask(c *gin.Context) { } // Get list of users assigned to the task - userIDs, err := GetUsersAssignedToTaskFromDB(pg.Conn, taskID) + userIDs, err := getUsersAssignedToTaskFromDB(pg.Conn, taskID) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) return diff --git a/backend/schema/tasks/transactions.go b/backend/schema/tasks/transactions.go index 10f36fd..aa28ca3 100644 --- a/backend/schema/tasks/transactions.go +++ b/backend/schema/tasks/transactions.go @@ -11,7 +11,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -func GetTasksByQueryFromDB(pool *pgxpool.Pool, filterQuery TaskQuery) ([]models.Task, error) { +func getTasksByQueryFromDB(pool *pgxpool.Pool, filterQuery TaskQuery) ([]models.Task, error) { query_fields := []string{ filterQuery.TaskID, filterQuery.TaskTitle, @@ -65,7 +65,7 @@ func GetTasksByQueryFromDB(pool *pgxpool.Pool, filterQuery TaskQuery) ([]models. return results, nil } -func AssignUsersToTaskInDB(pool *pgxpool.Pool, users []string, taskID string, assigner string) ([]models.TaskUser, error) { +func assignUsersToTaskInDB(pool *pgxpool.Pool, users []string, taskID string, assigner string) ([]models.TaskUser, error) { task_id, err := strconv.Atoi(taskID) if err != nil { return nil, err @@ -87,7 +87,7 @@ func AssignUsersToTaskInDB(pool *pgxpool.Pool, users []string, taskID string, as return assignedUsers, nil } -func RemoveUsersFromTaskInDB(pool *pgxpool.Pool, users []string, taskID string) ([]models.TaskUser, error) { +func removeUsersFromTaskInDB(pool *pgxpool.Pool, users []string, taskID string) ([]models.TaskUser, error) { task_id, err := strconv.Atoi(taskID) if err != nil { print(err, "error converting task ID to int") @@ -119,7 +119,7 @@ func RemoveUsersFromTaskInDB(pool *pgxpool.Pool, users []string, taskID string) return removedUsers, nil } -func GetTasksByAssignedFromDB(pool *pgxpool.Pool, userIDs []string) ([]models.Task, error) { +func getTasksByAssignedFromDB(pool *pgxpool.Pool, userIDs []string) ([]models.Task, error) { var task_ids []int var tasks []models.Task @@ -161,7 +161,7 @@ func GetTasksByAssignedFromDB(pool *pgxpool.Pool, userIDs []string) ([]models.Ta } // CreateTaskInDB creates a new task in the database and returns its ID -func CreateTaskInDB(pool *pgxpool.Pool, newTask models.Task) (int, error) { +func createTaskInDB(pool *pgxpool.Pool, newTask models.Task) (int, error) { query := ` INSERT INTO task (group_id, created_by, created_date, start_date, end_date, quick_task, notes, repeating, repeating_interval, repeating_end_date, task_status, task_type, task_info, task_title) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) RETURNING task_id` @@ -188,7 +188,7 @@ func CreateTaskInDB(pool *pgxpool.Pool, newTask models.Task) (int, error) { } // DeleteTaskInDB deletes a task from the database by ID -func DeleteTaskInDB(pool *pgxpool.Pool, taskID int) error { +func deleteTaskInDB(pool *pgxpool.Pool, taskID int) error { // Assuming "task" table structure, adjust the query based on your schema query := "DELETE FROM task WHERE task_id = $1" @@ -197,7 +197,7 @@ func DeleteTaskInDB(pool *pgxpool.Pool, taskID int) error { } // UpdateTaskInfoInDB updates all fields of a task in the database -func UpdateTaskInfoInDB(pool *pgxpool.Pool, taskID int, taskFields models.Task) error { +func updateTaskInfoInDB(pool *pgxpool.Pool, taskID int, taskFields models.Task) error { // Construct the SQL query dynamically based on the task_fields parameter query := ` UPDATE task SET task_title = $1, group_id = $2, created_by = $3, created_date = $4, start_date = $5, end_date = $6, quick_task = $7, notes = $8, repeating = $9, repeating_interval = $10, repeating_end_date = $11, task_status = $12, task_type = $13, task_info = $14 WHERE task_id = $15 @@ -225,7 +225,7 @@ func UpdateTaskInfoInDB(pool *pgxpool.Pool, taskID int, taskFields models.Task) } // GetTaskByID fetches a task from the database by its ID -func GetTaskByID(pool *pgxpool.Pool, taskID int) (models.Task, error) { +func getTaskByID(pool *pgxpool.Pool, taskID int) (models.Task, error) { query := `SELECT * FROM task WHERE task_id = $1` var task models.Task @@ -249,7 +249,7 @@ func GetTaskByID(pool *pgxpool.Pool, taskID int) (models.Task, error) { return task, err } -func GetUsersAssignedToTaskFromDB(pool *pgxpool.Pool, taskID int) ([]string, error) { +func getUsersAssignedToTaskFromDB(pool *pgxpool.Pool, taskID int) ([]string, error) { var userIDs []string // Get all user IDs assigned to the task diff --git a/backend/schema/user/routes.go b/backend/schema/user/routes.go index 3c3d0fa..0a57cef 100644 --- a/backend/schema/user/routes.go +++ b/backend/schema/user/routes.go @@ -16,10 +16,10 @@ type PgModel struct { func UserGroup(v1 *gin.RouterGroup, c *PgModel) *gin.RouterGroup { userGroup := v1.Group("user") { - userGroup.GET("/:uid", c.GetUser) - userGroup.GET("", c.GetUsers) - userGroup.POST("/:uid", c.CreateUser) - userGroup.PUT("/:uid", c.UpdateUser) + userGroup.GET("/:uid", c.getUser) + userGroup.GET("", c.getUsers) + userGroup.POST("/:uid", c.createUser) + userGroup.PUT("/:uid", c.updateUser) } return userGroup @@ -45,7 +45,7 @@ type UserInfoBody struct { // @success 200 {object} models.User // @failure 400 {object} string // @router /user/{uid} [POST] -func (pg *PgModel) CreateUser(c *gin.Context) { +func (pg *PgModel) createUser(c *gin.Context) { var requestBody UserInfoBody if err := c.BindJSON(&requestBody); err != nil { @@ -53,7 +53,7 @@ func (pg *PgModel) CreateUser(c *gin.Context) { return } - user, err := CreateUserInDB(pg.Conn, c.Param("uid"), requestBody) + user, err := createUserInDB(pg.Conn, c.Param("uid"), requestBody) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) @@ -74,8 +74,8 @@ func (pg *PgModel) CreateUser(c *gin.Context) { // @success 200 {object} models.User // @failure 400 {object} string // @router /user/{uid} [GET] -func (pg *PgModel) GetUser(c *gin.Context) { - user, err := GetUserInDB(pg.Conn, c.Param("uid")) +func (pg *PgModel) getUser(c *gin.Context) { + user, err := getUserInDB(pg.Conn, c.Param("uid")) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) @@ -100,7 +100,7 @@ type UsersQuery struct { // @success 200 {array} models.User // @failure 400 {object} string // @router /user [GET] -func (pg *PgModel) GetUsers(c *gin.Context) { +func (pg *PgModel) getUsers(c *gin.Context) { userIDs := c.Query("userIDs") userQuery := UsersQuery{ @@ -110,7 +110,7 @@ func (pg *PgModel) GetUsers(c *gin.Context) { var users []models.User for _, element := range userQuery.UserIDs { - user, err := GetUserInDB(pg.Conn, element) + user, err := getUserInDB(pg.Conn, element) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) return @@ -133,7 +133,7 @@ func (pg *PgModel) GetUsers(c *gin.Context) { // @success 200 {object} models.User // @failure 400 {object} string // @router /user/{uid} [PUT] -func (pg *PgModel) UpdateUser(c *gin.Context) { +func (pg *PgModel) updateUser(c *gin.Context) { var requestBody UserInfoBody if err := c.BindJSON(&requestBody); err != nil { @@ -141,7 +141,7 @@ func (pg *PgModel) UpdateUser(c *gin.Context) { return } - user, err := UpdateUserInDB(pg.Conn, c.Param("uid"), requestBody) + user, err := updateUserInDB(pg.Conn, requestBody) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) diff --git a/backend/schema/user/transactions.go b/backend/schema/user/transactions.go index ef41d4d..3cae8d4 100644 --- a/backend/schema/user/transactions.go +++ b/backend/schema/user/transactions.go @@ -7,7 +7,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -func CreateUserInDB(conn *pgxpool.Pool, uid string, requestBody UserInfoBody) (models.User, error) { +func createUserInDB(conn *pgxpool.Pool, uid string, requestBody UserInfoBody) (models.User, error) { var user models.User err := conn.QueryRow(context.Background(), "INSERT INTO users (user_id, first_name, last_name, phone, email, address) VALUES ($1, $2, $3, $4, $5, $6) RETURNING user_id, first_name, last_name, phone, email, address", uid, requestBody.FirstName, requestBody.LastName, requestBody.Phone, requestBody.Email, requestBody.Address).Scan(&user.UserID, &user.FirstName, &user.LastName, &user.Phone, &user.Email, &user.Address) @@ -20,7 +20,7 @@ func CreateUserInDB(conn *pgxpool.Pool, uid string, requestBody UserInfoBody) (m return user, nil } -func UpdateUserInDB(conn *pgxpool.Pool, uid string, requestBody UserInfoBody) (models.User, error) { +func updateUserInDB(conn *pgxpool.Pool, requestBody UserInfoBody) (models.User, error) { var user models.User err := conn.QueryRow(context.Background(), "UPDATE users SET first_name = $1, last_name = $2, phone = $3, email = $4, address = $5 RETURNING user_id, first_name, last_name, phone, email, address", requestBody.FirstName, requestBody.LastName, requestBody.Phone, requestBody.Email, requestBody.Address).Scan(&user.UserID, &user.FirstName, &user.LastName, &user.Phone, &user.Email, &user.Address) @@ -32,7 +32,7 @@ func UpdateUserInDB(conn *pgxpool.Pool, uid string, requestBody UserInfoBody) (m return user, nil } -func GetUserInDB(conn *pgxpool.Pool, uid string) (models.User, error) { +func getUserInDB(conn *pgxpool.Pool, uid string) (models.User, error) { var user models.User err := conn.QueryRow(context.Background(), "SELECT user_id, first_name, last_name, phone, email, address FROM users WHERE user_id = $1", uid).Scan(&user.UserID, &user.FirstName, &user.LastName, &user.Phone, &user.Email, &user.Address)