-
Notifications
You must be signed in to change notification settings - Fork 0
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
User crud #17
User crud #17
Conversation
@@ -22,7 +22,7 @@ func main() { | |||
dsn := "host=localhost user=user password=pwd dbname=algo port=5434 sslmode=disable" | |||
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{}) | |||
if err != nil { | |||
panic("Failed to connect to database") | |||
panic("Failed to connect to database") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason it added so much spacing? I'm wondering if you're set on tab spacing instead of space
@@ -1,17 +1,19 @@ | |||
-- init.sql | |||
DROP TABLE IF EXISTS users; | |||
|
|||
CREATE TYPE risk_tolerance_enum AS ENUM ('low', 'medium', 'high'); | |||
CREATE TYPE risk_tolerance_enum AS ENUM ('low', 'medium', 'high', ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We recently made the goals enum a table, I think this one makes sense as an enum but @aniamisiorek what are your thoughts here?
return nil, err | ||
} | ||
|
||
// Save the updated user back to the database |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going to check this, but does this update the row entry or save a new entry in the DB?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checked it does not add the entry and keep the old one all clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks to be all good, just check the Delete User case since something might be up there
userRoutes.POST("/", userController.CreateUser) | ||
userRoutes.GET("/:id", userController.GetUserById) | ||
userRoutes.PUT("/:id", userController.UpdateUserById) | ||
userRoutes.DELETE("/:id", userController.DeleteUserById) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was delete working for you It wasn't for me on my computer. Everything else is working good awesome job.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok update this is what I'm currently getting when trying to delete;
2024/02/08 19:18:55 /Users/leroyshaigorodsky/Documents/GitHub/Algo/backend/src/services/user.go:59 ERROR: update or delete on table "users" violates foreign key constraint "scores_user_id_fkey" on table "scores" (SQLSTATE 23503) - I think that table will need the cascade thing too (could be good to make sure that tables that reference this table will have the ON DELETE CASCADE sql stuff to make sure that those rows get deleted when a user gets deleted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if its working lets merge it in🕺
Description
Link to Ticket
Created user CRUD routes for GET, POST, PUT, DELETE. Fixed user schema to match unique/non-unique constraints. Updated go types/enums to allow null values.
How Has This Been Tested?
Verified route functionality using Postman.
Checklist