Skip to content

Commit 9f893e9

Browse files
committed
auth: added context for auth check if the user has permission
1 parent 57e8ccd commit 9f893e9

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

cmd/api/contex.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"github.com/kunalkumar-1/Evently/internals/database"
66
)
77

8-
func(app *application) GetUserFromContext(c *gin.Context) *database.User {
8+
func (app *application) GetUserFromContext(c *gin.Context) *database.User {
99
contextUser, exist := c.Get("user")
1010
if !exist {
1111
return &database.User{}
@@ -15,4 +15,4 @@ func(app *application) GetUserFromContext(c *gin.Context) *database.User {
1515
return &database.User{}
1616
}
1717
return user
18-
}
18+
}

cmd/api/events.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ func (app *application) createEvent(c *gin.Context) {
2424

2525
user := app.GetUserFromContext(c)
2626
event.OwnerId = user.Id
27-
2827

2928
// Insert into db
3029
err := app.models.Events.Insert(&event)
@@ -112,7 +111,7 @@ func (app *application) updateEvent(c *gin.Context) {
112111
})
113112
return
114113
}
115-
114+
116115
updatedEvent := &database.Event{}
117116

118117
fmt.Println("Existing Event:", existingEvent)
@@ -153,8 +152,8 @@ func (app *application) deleteEvent(c *gin.Context) {
153152
if err != nil {
154153
c.JSON(http.StatusInternalServerError, gin.H{
155154
"error": "Failed to retireve event",
156-
})
157-
}
155+
})
156+
}
158157
if existingEvent == nil {
159158
c.JSON(http.StatusNotFound, gin.H{
160159
"erorr": "Event not found",
@@ -176,7 +175,7 @@ func (app *application) deleteEvent(c *gin.Context) {
176175
}
177176

178177
c.JSON(http.StatusNoContent, nil)
179-
178+
180179
}
181180

182181
func (app *application) addAttendeeToEvent(c *gin.Context) {

0 commit comments

Comments
 (0)