Skip to content

Commit

Permalink
get users
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirari04 committed May 28, 2024
1 parent c390f23 commit 87b94a6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions controllers/GetUsers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package controllers

import (
"ch/kirari04/videocms/inits"
"ch/kirari04/videocms/models"
"log"
"net/http"

"github.com/labstack/echo/v4"
)

func GetUsers(c echo.Context) error {
users := make([]models.User, 0)
if res := inits.DB.First(&users); res.Error != nil {
log.Println("Failed to fetch users")
return c.NoContent(http.StatusInternalServerError)
}

return c.JSON(http.StatusOK, &users)
}
2 changes: 2 additions & 0 deletions routes/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func Api() {
protectedApi.GET("/settings", controllers.GetSettings, middlewares.IsAdmin())
protectedApi.PUT("/settings", controllers.UpdateSettings, middlewares.IsAdmin())

protectedApi.GET("/users", controllers.GetUsers, middlewares.IsAdmin())

protectedApi.POST("/webhook", controllers.CreateWebhook)
protectedApi.PUT("/webhook", controllers.UpdateWebhook)
protectedApi.DELETE("/webhook", controllers.DeleteWebhook)
Expand Down

0 comments on commit 87b94a6

Please sign in to comment.