Skip to content

Commit 38bcb51

Browse files
committed
chore: events and database
1 parent 5c920c5 commit 38bcb51

File tree

7 files changed

+15
-6
lines changed

7 files changed

+15
-6
lines changed

server/cmd/api/events.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func (app *application) createEvent(c *gin.Context) {
3636
c.JSON(http.StatusCreated, event)
3737
}
3838

39+
//get all events
3940
func (app *application) getAllEvent(c *gin.Context) {
4041
events, err := app.models.Events.GetAll()
4142
if err != nil {
@@ -76,7 +77,7 @@ func (app *application) getEvent(c *gin.Context) {
7677

7778
// update event
7879
func (app *application) updateEvent(c *gin.Context) {
79-
id, err := strconv.Atoi(c.Param("id"))
80+
id, err := strconv.Atoi(c.Param("id")) // get event id from url
8081
if err != nil {
8182
c.JSON(http.StatusBadRequest, gin.H{
8283
"error": "Invalid event Id",
@@ -85,6 +86,7 @@ func (app *application) updateEvent(c *gin.Context) {
8586
}
8687

8788
existingEvent, err := app.models.Events.Get(id)
89+
8890
if err != nil {
8991
c.JSON(http.StatusInternalServerError, gin.H{
9092
"error": "Failed to retireve event " + err.Error(),
@@ -101,6 +103,9 @@ func (app *application) updateEvent(c *gin.Context) {
101103

102104
updatedEvent := &database.Event{}
103105

106+
fmt.Println("Existing Event:", existingEvent)
107+
fmt.Println("upadtedEvent:", updatedEvent)
108+
104109
if err := c.ShouldBindJSON(updatedEvent); err != nil {
105110
c.JSON(http.StatusBadGateway, gin.H{
106111
"error": err.Error(),
@@ -121,6 +126,7 @@ func (app *application) updateEvent(c *gin.Context) {
121126
c.JSON(http.StatusOK, updatedEvent)
122127
}
123128

129+
// delete event
124130
func (app *application) deleteEvent(c *gin.Context) {
125131
id, err := strconv.Atoi(c.Param("id"))
126132
if err != nil {

server/data.db

0 Bytes
Binary file not shown.

server/internals/database/event.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type Event struct {
2020
Location string `json:"location" binding:"required,min=3"`
2121
}
2222

23+
// Insert a new event into the database
2324
func (e *EventModel) Insert(event *Event) error {
2425
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
2526
defer cancel()
@@ -34,6 +35,7 @@ func (e *EventModel) Insert(event *Event) error {
3435
return e.Db.QueryRowContext(ctx, query, event.OwnerId, event.Name, event.Description, parsedDate, event.Location).Scan(&event.Id)
3536
}
3637

38+
// GetAll retrieves all events from the database
3739
func (e *EventModel) GetAll() ([]*Event, error) {
3840
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
3941
defer cancel()
@@ -64,7 +66,7 @@ func (e *EventModel) GetAll() ([]*Event, error) {
6466

6567
return events, nil
6668
}
67-
69+
// Get retrieves a specific event by its ID
6870
func (e *EventModel) Get(id int) (*Event, error) {
6971
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
7072
defer cancel()
@@ -81,7 +83,7 @@ func (e *EventModel) Get(id int) (*Event, error) {
8183
}
8284
return &event, nil
8385
}
84-
86+
// Update modifies an existing event in the database
8587
func (e *EventModel) Update(event *Event) error {
8688
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
8789
defer cancel()
@@ -99,7 +101,7 @@ func (e *EventModel) Update(event *Event) error {
99101

100102
return nil
101103
}
102-
104+
// Delete removes an event from the database by its ID
103105
func (e *EventModel) Delete(id int) error {
104106
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
105107
defer cancel()

server/internals/env/env.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ func GetEnvInt(key string, defaultValue int) int {
2121
}
2222

2323
return defaultValue
24-
}
24+
}

server/tmp/build-errors.log

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1
1+
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1

server/tmp/main

-90.4 KB
Binary file not shown.

tmp/build-errors.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exit status 1exit status 1exit status 1exit status 1

0 commit comments

Comments
 (0)