Skip to content

Commit

Permalink
Finish endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
joey-tsai authored and matherg committed Nov 7, 2023
1 parent 2915801 commit 5e90844
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions api/src/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ func (pg *PgController) Serve() *gin.Engine {
c.JSON(http.StatusOK, collections)
})
// Create an endpoint that takes in a customerID and returns all collections with no customerID or a matching customerID.
r.GET("/collections/:id", func(c * gin.Context) {
r.GET("/collections/:customerId", func(c * gin.Context) {

// Get Customer ID
id := c.Param("id")
id := c.Param("customerId")
intId, err := strconv.Atoi(id)
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion api/src/model/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func GetAllCollectionsFromDB(db *gorm.DB) ([]GiftCollection, error) {
// GetAllCustomerCollectionsFromDB fetches all GiftCollections that associated with the customer ID or none
func GetAllCustomerCollectionsFromDB(db *gorm.DB, id int64) ([]GiftCollection, error) {
var collections []GiftCollection
if err := db.Where("id = ? OR id IS NULL", id).Preload("Gifts").Find(&collections).Error; err != nil {
if err := db.Where("customer_id = ? OR customer_id IS NULL", id).Preload("Gifts").Find(&collections).Error; err != nil {
return nil, err
}
return collections, nil
Expand Down

0 comments on commit 5e90844

Please sign in to comment.