jokes-bapak2/api/app/v1/routes/joke.go

36 lines
820 B
Go
Raw Normal View History

2021-07-09 06:11:11 +00:00
package routes
import (
"github.com/aldy505/jokes-bapak2-api/api/app/v1/handler"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/middleware"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/platform/cache"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/platform/database"
"github.com/gofiber/fiber/v2"
)
var db = database.New()
var redis = cache.New()
2021-07-09 12:13:19 +00:00
func Joke(app *fiber.App) *fiber.App {
2021-07-09 06:11:11 +00:00
// Single route
2021-07-09 12:13:19 +00:00
app.Get("/", handler.SingleJoke)
2021-07-09 06:11:11 +00:00
// Today's joke
2021-07-09 12:13:19 +00:00
app.Get("/today", handler.TodayJoke)
2021-07-09 06:11:11 +00:00
// Joke by ID
2021-07-09 12:13:19 +00:00
app.Get("/:id", handler.JokeByID)
2021-07-09 06:11:11 +00:00
// Add new joke
2021-07-09 12:13:19 +00:00
app.Put("/", middleware.RequireAuth(), handler.AddNewJoke)
2021-07-09 06:11:11 +00:00
// Update a joke
2021-07-09 12:13:19 +00:00
app.Patch("/:id", middleware.RequireAuth(), handler.UpdateJoke)
2021-07-09 06:11:11 +00:00
// Delete a joke
2021-07-09 12:13:19 +00:00
app.Delete("/:id", middleware.RequireAuth(), handler.DeleteJoke)
2021-07-09 06:11:11 +00:00
return app
}