-
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
POST Profile Preferences Endpoint #25
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dc17378
post profile preferences endpoint
ihysi2024 967afc4
post profile prefs endpoint
ihysi2024 417eb90
post prefs profile endpoint pr fix
ihysi2024 bad0a0b
preferences endpoint
ihysi2024 c76d424
Merge branch 'main' into feature/profile-endpoint
CamPlume1 386b645
Small fixes to resolve merge conflict
CamPlume1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package profile | ||
|
||
import ( | ||
"github.com/GenerateNU/nightlife/internal/errs" | ||
"github.com/GenerateNU/nightlife/internal/models" | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
// POST Endpoint -> allows users to add their preferences to the db | ||
func (s *Service) CreatePreferences(c *fiber.Ctx) error { | ||
var p models.Preferences | ||
if err := c.BodyParser(&p); err != nil { | ||
return errs.BadRequest(err) | ||
} | ||
|
||
if verrs := p.Validate(); verrs != nil { | ||
return errs.InvalidRequestData(verrs) | ||
} | ||
|
||
if err := s.store.CreatePreferences(c.Context(), p); err != nil { | ||
return err | ||
} | ||
|
||
// close out with success status | ||
return c.Status(fiber.StatusCreated).JSON(p) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package profile | ||
|
||
import ( | ||
"github.com/GenerateNU/nightlife/internal/auth" | ||
"github.com/GenerateNU/nightlife/internal/types" | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
// Create Profile fiber route group (no unprotected routes) | ||
func Routes(app *fiber.App, params types.Params) { | ||
service := newService(params.Store) | ||
|
||
// Create Protected Grouping | ||
protected := app.Group("/profile") | ||
|
||
// Register Middleware | ||
protected.Use(auth.Protected(¶ms.Supabase)) | ||
|
||
//Endpoints | ||
protected.Post("/preferences", service.CreatePreferences) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package profile | ||
|
||
import "github.com/GenerateNU/nightlife/internal/storage" | ||
|
||
type Service struct { | ||
store storage.Storage | ||
} | ||
|
||
func newService(store storage.Storage) *Service { | ||
return &Service{store: store} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package models | ||
|
||
// Represents User Preferences | ||
type Preferences struct { | ||
UserID int `json:"user_id"` // assuming 1:1/1:* relationship | ||
Location string `json:"location"` //city/state combo? not sure how this is getting defined | ||
Age int `json:"age"` | ||
Music string `json:"music"` | ||
Ambiance string `json:"ambiance"` | ||
Notifs bool `json:"notifs"` // is this part of the preferences? | ||
} | ||
|
||
func (p *Preferences) Validate() map[string]string { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package postgres | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/GenerateNU/nightlife/internal/models" | ||
) | ||
|
||
func (db *DB) CreatePreferences(ctx context.Context, p models.Preferences) error { | ||
// query to save user data to db | ||
query := `INSERT INTO preferences (userID, location, age, music, ambiance, notifs) | ||
VALUES ($1, $2, $3, $4, $5, $6)` | ||
|
||
_, err := db.conn.Query(ctx, query, p.UserID, p.Location, p.Age, p.Music, p.Ambiance, p.Notifs) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 like this is a stub - Are you planning on adding form validation?