Skip to content

Commit

Permalink
fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
SuliR123 committed Dec 4, 2024
2 parents 3b916dd + 8582c56 commit 81b9682
Show file tree
Hide file tree
Showing 119 changed files with 7,305 additions and 7,280 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ backend-build:
.PHONY: backend-ngrok
backend-ngrok:
@echo ${EXPO_PUBLIC_API_DOMAIN}
cd backend && ngrok http --url=${EXPO_PUBLIC_API_DOMAIN} 8080
cd backend && ngrok http --url=${EXPO_PUBLIC_API_DOMAIN} 8080
4 changes: 2 additions & 2 deletions backend/.golangci.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[linters]
enable = ["revive", "errcheck"]
[linters]
enable = ["revive", "errcheck"]
57 changes: 57 additions & 0 deletions backend/internal/handlers/bookmarks/bookmarks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package bookmarks

import (
"fmt"
"net/http"

"github.com/GenerateNU/nightlife/internal/errs"
"github.com/GenerateNU/nightlife/internal/models"
"github.com/gofiber/fiber/v2"
"github.com/google/uuid"
)

func (s *Service) GetBookmarkFromID(c *fiber.Ctx) error {
fmt.Println("Pinging correct service")

userID := c.Params("userId")
fmt.Println("----", userID)
if userID == "" {
c.Status(http.StatusBadRequest)
return fiber.NewError(400)
}
UserIDFormatted, err := uuid.Parse(userID)

if err != nil {
c.Status(http.StatusBadRequest)
return fiber.NewError(400, "Malformed User ID")
}

Bookmarks, err := s.store.GetBookmarkFromID(c.Context(), UserIDFormatted)

if err != nil {
fmt.Println("Error is on service line 26" + err.Error())
c.Status(http.StatusInternalServerError)
return err
}

return c.Status(http.StatusOK).JSON(Bookmarks)

}

func (s *Service) CreateBookmark(c *fiber.Ctx) error {
var p models.Bookmarks
fmt.Println("****")
if err := c.BodyParser(&p); err != nil {
fmt.Println("HERE")
return errs.BadRequest(err)
}

if err := s.store.CreateBookmark(c.Context(), p); err != nil {
fmt.Println("error: ", err.Error())
return err
}

// close out with success status
return c.Status(fiber.StatusCreated).JSON(p)

}
22 changes: 22 additions & 0 deletions backend/internal/handlers/bookmarks/routes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package bookmarks

import (
"github.com/GenerateNU/nightlife/internal/types"
"github.com/gofiber/fiber/v2"
)

// Create HelloGroup fiber route group
func Routes(app *fiber.App, params types.Params) {
service := newService(params.Store)

// Create Protected Grouping
protected := app.Group("/bookmarks")

// Register Middleware
// protected.Use(auth.Protected(&params.Supabase))

//Endpoints
protected.Get("/:userId", service.GetBookmarkFromID)
protected.Post("/:venueId/:userId", service.CreateBookmark)

}
11 changes: 11 additions & 0 deletions backend/internal/handlers/bookmarks/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package bookmarks

import "github.com/GenerateNU/nightlife/internal/storage"

type Service struct {
store storage.Storage
}

func newService(store storage.Storage) *Service {
return &Service{store: store}
}
35 changes: 35 additions & 0 deletions backend/internal/handlers/event/event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package event

import (
"net/http"

"github.com/GenerateNU/nightlife/internal/errs"
"github.com/gofiber/fiber/v2"
"github.com/google/uuid"
)

func (s *Service) GetEventForVenue(c *fiber.Ctx) error {

venueID := c.Params("venue_id")

if venueID == "" {
c.Status(http.StatusBadRequest)
return errs.APIError{StatusCode: fiber.StatusBadRequest, Message: "username is required"}
}

VenueIDFormatted, err := uuid.Parse(venueID)

if err != nil {
c.Status(http.StatusInternalServerError)
return errs.APIError{StatusCode: fiber.StatusNotFound, Message: "profile not found"}
}

VenueEvents, err := s.store.GetEventForVenue(c.Context(), VenueIDFormatted)

if err != nil {
c.Status(http.StatusInternalServerError)
return err
}

return c.Status(http.StatusOK).JSON(VenueEvents)
}
20 changes: 20 additions & 0 deletions backend/internal/handlers/event/routes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package event

import (
"github.com/GenerateNU/nightlife/internal/types"
"github.com/gofiber/fiber/v2"
)

// Create Event fiber route group
func Routes(app *fiber.App, params types.Params) {
service := newService(params.Store)

// Create Protected Grouping
protected := app.Group("/event")

// Register Middleware
//protected.Use(auth.Protected(&params.Supabase))

//Endpoints
protected.Get("/:venue_id", service.GetEventForVenue)
}
11 changes: 11 additions & 0 deletions backend/internal/handlers/event/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package event

import "github.com/GenerateNU/nightlife/internal/storage"

type Service struct {
store storage.Storage
}

func newService(store storage.Storage) *Service {
return &Service{store: store}
}
28 changes: 27 additions & 1 deletion backend/internal/handlers/friendship/friendship.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package friendship

import (
"fmt"
"log"

"github.com/GenerateNU/nightlife/internal/models"
"github.com/gofiber/fiber/v2"
"log"
"github.com/google/uuid"
)

// POST endpoint to create friendship between two users in DB
Expand All @@ -26,3 +28,27 @@ func (s *Service) CreateFriendship(c *fiber.Ctx) error {

return c.Status(fiber.StatusCreated).JSON(req)
}

func (s *Service) GetFriendshipsByUserID(c *fiber.Ctx) error {
fmt.Println("Getting friendships by user ID")

var userID uuid.UUID

fmt.Print(c.Params("userID"))

if err := userID.UnmarshalText([]byte(c.Params("userID"))); err != nil {
log.Printf("Error parsing UUID: %v, Request: %+v", err, userID)
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
"error": "Cannot parse UUID",
})
}

friendships, err := s.store.GetFriendshipsByUserID(c.Context(), userID)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": "Failed to get friendships",
})
}

return c.Status(fiber.StatusOK).JSON(friendships)
}
8 changes: 2 additions & 6 deletions backend/internal/handlers/friendship/routes.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package friendship

import (
//"github.com/GenerateNU/nightlife/internal/auth"
"github.com/GenerateNU/nightlife/internal/types"
"github.com/gofiber/fiber/v2"
)

func Routes(app *fiber.App, params types.Params) {

//create a service
service := newService(params.Store)

//create a grouping
protected := app.Group("/friendships")
//.Use(auth.Protected(&params.Supabase))

//create a route
protected.Post("/api/friendship", service.CreateFriendship)
protected.Post("/", service.CreateFriendship)
protected.Get("/:userID", service.GetFriendshipsByUserID)

}
45 changes: 22 additions & 23 deletions backend/internal/handlers/profiles/profiles.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//nolint
// nolint
package profiles

import (
Expand Down Expand Up @@ -158,7 +158,7 @@ func (s *Service) UpdateProfile(c *fiber.Ctx) error {
}

err = s.store.PatchProfile(c.Context(), userID, req.FirstName,
req.Username, req.Email, req.Age, req.Location, req.ProfilePictureURL, req.PersonalityType, req.Pronouns, req.Biography, req.InstagramURL, req.TikTokURL, req.TwitterURL, req.Phone, req.Privacy)
req.Username, req.Email, req.Age, req.Location, req.ProfilePictureURL, req.PersonalityType, req.Pronouns, req.Biography, req.InstagramURL, req.TikTokURL, req.TwitterURL, req.Phone, req.Privacy)

if err != nil {
if handlerErr := errs.ErrorHandler(c, err); handlerErr != nil {
Expand Down Expand Up @@ -203,26 +203,26 @@ func (s *Service) GetAllUsers(c *fiber.Ctx) error {
Get all reviews authored by a given user
*/
func (s *Service) GetUserAuthoredReviews(c *fiber.Ctx) error {
// Extract the user ID from the URL parameter
userID := c.Params("userId")
if userID == "" {
return fiber.NewError(fiber.StatusBadRequest, "User ID is required")
}

// Convert the user ID to a UUID
userUUID, err := uuid.Parse(userID)
if err != nil {
return fiber.NewError(fiber.StatusBadRequest, "Invalid User ID format")
}

// Call the store to get the reviews authored by the user
reviews, err := s.store.GetUserAuthoredReviews(c.Context(), userUUID)
if err != nil {
return fiber.NewError(fiber.StatusInternalServerError, "Failed to get user reviews")
}

// Return the list of reviews
return c.Status(fiber.StatusOK).JSON(reviews)
// Extract the user ID from the URL parameter
userID := c.Params("userId")
if userID == "" {
return fiber.NewError(fiber.StatusBadRequest, "User ID is required")
}

// Convert the user ID to a UUID
userUUID, err := uuid.Parse(userID)
if err != nil {
return fiber.NewError(fiber.StatusBadRequest, "Invalid User ID format")
}

// Call the store to get the reviews authored by the user
reviews, err := s.store.GetUserAuthoredReviews(c.Context(), userUUID)
if err != nil {
return fiber.NewError(fiber.StatusInternalServerError, "Failed to get user reviews")
}

// Return the list of reviews
return c.Status(fiber.StatusOK).JSON(reviews)
}

func (s *Service) GetUserReviewsWithVenueData(c *fiber.Ctx) error {
Expand Down Expand Up @@ -287,4 +287,3 @@ func (s *Service) GetUserVisitedVenues(c *fiber.Ctx) error {

return c.Status(fiber.StatusOK).JSON(venues)
}

3 changes: 1 addition & 2 deletions backend/internal/handlers/profiles/routes.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package profiles

import (
"github.com/GenerateNU/nightlife/internal/auth"
"github.com/GenerateNU/nightlife/internal/types"
"github.com/gofiber/fiber/v2"
)
Expand All @@ -14,7 +13,7 @@ func Routes(app *fiber.App, params types.Params) {
protected := app.Group("/profiles")

// Register Middleware
protected.Use(auth.Protected(&params.Supabase))
// protected.Use(auth.Protected(&params.Supabase))

//Endpoints
protected.Get("/", service.GetAllUsers)
Expand Down
4 changes: 2 additions & 2 deletions backend/internal/handlers/user_ratings/routes.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package userratings

import (
"github.com/GenerateNU/nightlife/internal/auth"
"github.com/GenerateNU/nightlife/internal/types"
"github.com/gofiber/fiber/v2"
)
Expand All @@ -12,9 +11,10 @@ func Routes(app *fiber.App, params types.Params) {
service := newService(params.Store)

//create a grouping
protected := app.Group("/userratings").Use(auth.Protected(&params.Supabase))
protected := app.Group("/userratings") //.Use(auth.Protected(&params.Supabase))

//create a route
protected.Get("/user/:user_id", service.GetAllUserRatings)

protected.Post("/user/:user_id/:venue_id", service.CreateReview)
}
17 changes: 17 additions & 0 deletions backend/internal/handlers/user_ratings/user_ratings.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"net/http"

"github.com/GenerateNU/nightlife/internal/errs"
"github.com/GenerateNU/nightlife/internal/models"
"github.com/gofiber/fiber/v2"
"github.com/google/uuid"
)
Expand Down Expand Up @@ -34,3 +36,18 @@ func (s *Service) GetAllUserRatings(c *fiber.Ctx) error {
return c.Status(http.StatusOK).JSON(UserRatings)

}

func (s *Service) CreateReview(c *fiber.Ctx) error {
var p models.Review
if err := c.BodyParser(&p); err != nil {
return errs.BadRequest(err)
}

if err := s.store.CreateReview(c.Context(), p); err != nil {
return err
}

// close out with success status
return c.Status(fiber.StatusCreated).JSON(p)

}
Loading

0 comments on commit 81b9682

Please sign in to comment.