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

36 lines
900 B
Go
Raw Normal View History

2021-07-09 06:11:11 +00:00
package routes
import (
"jokes-bapak2-api/app/v1/handler/joke"
2021-07-14 18:17:01 +00:00
"jokes-bapak2-api/app/v1/middleware"
2021-08-04 09:03:53 +00:00
"time"
2021-07-09 06:11:11 +00:00
"github.com/gofiber/fiber/v2"
2021-08-04 09:03:53 +00:00
"github.com/gofiber/fiber/v2/middleware/cache"
2021-07-09 06:11:11 +00:00
)
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
app.Get("/", joke.SingleJoke)
2021-07-09 06:11:11 +00:00
// Today's joke
2021-08-04 09:03:53 +00:00
app.Get("/today", cache.New(cache.Config{Expiration: 6 * time.Hour}), joke.TodayJoke)
2021-07-09 06:11:11 +00:00
// Joke by ID
app.Get("/id/:id", middleware.OnlyIntegerAsID(), joke.JokeByID)
2021-07-17 14:37:01 +00:00
// Count total jokes
2021-08-04 09:03:53 +00:00
app.Get("/total", cache.New(cache.Config{Expiration: 15 * time.Minute}), joke.TotalJokes)
2021-07-09 06:11:11 +00:00
// Add new joke
app.Put("/", middleware.RequireAuth(), joke.AddNewJoke)
2021-07-09 06:11:11 +00:00
// Update a joke
app.Patch("/id/:id", middleware.RequireAuth(), middleware.OnlyIntegerAsID(), joke.UpdateJoke)
2021-07-09 06:11:11 +00:00
// Delete a joke
app.Delete("/id/:id", middleware.RequireAuth(), middleware.OnlyIntegerAsID(), joke.DeleteJoke)
2021-07-09 06:11:11 +00:00
return app
}