From 9e02a606098f96a1bd972d238ae514feaeee8805 Mon Sep 17 00:00:00 2001 From: Ben Petrillo Date: Mon, 30 Sep 2024 12:12:07 -0400 Subject: [PATCH 1/2] fix: profile preferences typo --- backend/internal/handlers/profiles/profiles.go | 4 ++-- backend/internal/storage/storage.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/internal/handlers/profiles/profiles.go b/backend/internal/handlers/profiles/profiles.go index 0c5a80f..c00de01 100644 --- a/backend/internal/handlers/profiles/profiles.go +++ b/backend/internal/handlers/profiles/profiles.go @@ -9,7 +9,7 @@ import ( "github.com/google/uuid" ) -func (s *Service) UpdateProfilePrefences(c *fiber.Ctx) error { +func (s *Service) UpdateProfilePreferences(c *fiber.Ctx) error { // Parse the request body var req models.UpdateProfilePrefencesRequest @@ -20,7 +20,7 @@ func (s *Service) UpdateProfilePrefences(c *fiber.Ctx) error { }) } - err := s.store.UpdateProfilePrefences(c.Context(), req.UserID, req.PreferenceTypeTo, req.PreferenceValueTo, req.PreferenceType, req.PreferenceValue) + err := s.store.UpdateProfilePreferences(c.Context(), req.UserID, req.PreferenceTypeTo, req.PreferenceValueTo, req.PreferenceType, req.PreferenceValue) if err != nil { return c.Status(http.StatusInternalServerError).JSON(fiber.Map{ "error": "Failed to update review", diff --git a/backend/internal/storage/storage.go b/backend/internal/storage/storage.go index 86883f0..0d309fb 100644 --- a/backend/internal/storage/storage.go +++ b/backend/internal/storage/storage.go @@ -21,7 +21,7 @@ type Test interface { type Profile interface { CreatePreferences(context.Context, models.Preferences) error - UpdateProfilePrefences(context.Context, uuid.UUID, string, string, string, string) error + UpdateProfilePreferences(context.Context, uuid.UUID, string, string, string, string) error DeleteAccount(context.Context, uuid.UUID) error RemoveFriend(context.Context, uuid.UUID, string) error } From d44c854bd285b33f03d71a823b0408df83115ef5 Mon Sep 17 00:00:00 2001 From: Ben Petrillo Date: Mon, 30 Sep 2024 13:56:06 -0400 Subject: [PATCH 2/2] fix(health.go): remove possible vulnerability - publishing system arch information can lead to vulnerabilities being exploited - also fixed some typos --- backend/internal/handlers/health/health.go | 31 ++----------------- backend/internal/handlers/profiles/routes.go | 2 +- backend/internal/storage/postgres/profiles.go | 6 ++-- 3 files changed, 5 insertions(+), 34 deletions(-) diff --git a/backend/internal/handlers/health/health.go b/backend/internal/handlers/health/health.go index fdf8532..aad310b 100644 --- a/backend/internal/handlers/health/health.go +++ b/backend/internal/handlers/health/health.go @@ -1,37 +1,10 @@ package health import ( - "net/http" - "runtime" - - "github.com/GenerateNU/nightlife/internal/types" "github.com/gofiber/fiber/v2" - - go_json "github.com/goccy/go-json" + "net/http" ) -var healthBody []byte - -func init() { - body := fiber.Map{ - "status": "ok", - "system": &types.SysInfo{ - OS: runtime.GOOS, - Architecture: runtime.GOARCH, - CPUCores: runtime.NumCPU(), - GoVersion: runtime.Version(), - }, - } - - bodyBytes, err := go_json.Marshal(body) - if err != nil { - panic(err) - } - - healthBody = bodyBytes -} - func (s *Service) GetHealth(c *fiber.Ctx) error { - c.Set(fiber.HeaderContentType, fiber.MIMEApplicationJSON) - return c.Status(http.StatusOK).Send(healthBody) + return c.SendStatus(http.StatusOK) } diff --git a/backend/internal/handlers/profiles/routes.go b/backend/internal/handlers/profiles/routes.go index ee92bd2..94533d8 100644 --- a/backend/internal/handlers/profiles/routes.go +++ b/backend/internal/handlers/profiles/routes.go @@ -19,7 +19,7 @@ func Routes(app *fiber.App, params types.Params) { protected.Use(auth.Protected(¶ms.Supabase)) //Endpoints - protected.Patch("/preferences", service.UpdateProfilePrefences) + protected.Patch("/preferences", service.UpdateProfilePreferences) protected.Delete("/:userId", service.DeleteUser) protected.Delete("/friends/:username", service.RemoveFriend) } diff --git a/backend/internal/storage/postgres/profiles.go b/backend/internal/storage/postgres/profiles.go index 8c3f863..1f36c19 100644 --- a/backend/internal/storage/postgres/profiles.go +++ b/backend/internal/storage/postgres/profiles.go @@ -8,7 +8,7 @@ import ( "github.com/google/uuid" ) -func (db *DB) UpdateProfilePrefences(ctx context.Context, userID uuid.UUID, preferencetypeto string, preferencevalueto string, preferenceType string, preferenceValue string) error { +func (db *DB) UpdateProfilePreferences(ctx context.Context, userID uuid.UUID, preferencetypeto string, preferencevalueto string, preferenceType string, preferenceValue string) error { // SQL query execution _, err := db.conn.Exec(ctx, ` @@ -43,7 +43,7 @@ func (db *DB) DeleteAccount(ctx context.Context, userID uuid.UUID) error { return nil } -/* +/* RemoveFriend removes a friend from the user's friend list based on the friend's username */ func (db *DB) RemoveFriend(ctx context.Context, userID uuid.UUID, friendUsername string) error { @@ -58,5 +58,3 @@ func (db *DB) RemoveFriend(ctx context.Context, userID uuid.UUID, friendUsername } return nil } - -