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

Vulnerability Fix: CRUD /health #44

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 2 additions & 29 deletions backend/internal/handlers/health/health.go
Original file line number Diff line number Diff line change
@@ -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)
}
4 changes: 2 additions & 2 deletions backend/internal/handlers/profiles/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion backend/internal/handlers/profiles/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func Routes(app *fiber.App, params types.Params) {
protected.Use(auth.Protected(&params.Supabase))

//Endpoints
protected.Patch("/preferences", service.UpdateProfilePrefences)
protected.Patch("/preferences", service.UpdateProfilePreferences)
protected.Delete("/:userId", service.DeleteUser)
protected.Delete("/friends/:username", service.RemoveFriend)
}
6 changes: 2 additions & 4 deletions backend/internal/storage/postgres/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, `
Expand Down Expand Up @@ -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 {
Expand All @@ -58,5 +58,3 @@ func (db *DB) RemoveFriend(ctx context.Context, userID uuid.UUID, friendUsername
}
return nil
}


2 changes: 1 addition & 1 deletion backend/internal/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading