Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
maantje committed Sep 25, 2023
1 parent 9050ce5 commit 3d2e4a0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
14 changes: 10 additions & 4 deletions action/update_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

type UpdateTaskInput struct {
ID string
Name string `json:"name" validate:"required"`
ExpiresAt time.Time `json:"expires_at" validate:"required"`
Name string `json:"name" validate:"required"`
ExpiresAt string `json:"expires_at" validate:"required"`
}

func UpdateTask(input *UpdateTaskInput) (*model.Task, error) {
Expand All @@ -23,9 +23,15 @@ func UpdateTask(input *UpdateTaskInput) (*model.Task, error) {
return task, err
}

err := database.ORM().Model(&task).Updates(model.Task{
exp, err := time.Parse(time.DateTime, input.ExpiresAt)

if err != nil {
return &model.Task{}, err
}

err = database.ORM().Model(&task).Updates(model.Task{
Name: input.Name,
ExpiresAt: input.ExpiresAt,
ExpiresAt: exp,
}).Error

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion controller/task_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (t *TaskController) Read(c echo.Context) error {
var task *model.Task

err := database.ORM().Where(
"users_id = ?",
"user_id = ?",
authentication.AuthID(c),
).First(&task, c.Param("id")).Error

Expand Down
2 changes: 1 addition & 1 deletion model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type User struct {
}

func (u *User) IsEmailUnique(email string) bool {
err := database.ORM().First(u, "email = ?", email).Error
err := database.ORM().Where("id != ?", u.ID).First(&User{}, "email = ?", email).Error

return errors.Is(err, gorm.ErrRecordNotFound)
}
Expand Down
7 changes: 4 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ func main() {
c.JSON(http.StatusNotFound, map[string]interface{}{
"message": "not found",
})

return
}

c.JSON(http.StatusInternalServerError, map[string]interface{}{
"message": "Internal server error",
})
e.DefaultHTTPErrorHandler(err, c)
}

e.Use(echojwt.WithConfig(echojwt.Config{
Expand All @@ -45,6 +45,7 @@ func main() {
return new(authentication.Claims)
},
}))

e.Use(middleware.Logger())
e.Use(middleware.Recover())

Expand Down

0 comments on commit 3d2e4a0

Please sign in to comment.