2021-07-09 06:11:11 +00:00
|
|
|
package routes
|
|
|
|
|
|
|
|
import (
|
2021-08-03 18:14:32 +00:00
|
|
|
"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
|
2021-08-03 18:14:32 +00:00
|
|
|
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
|
2021-08-03 18:14:32 +00:00
|
|
|
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
|
2021-08-03 18:14:32 +00:00
|
|
|
app.Put("/", middleware.RequireAuth(), joke.AddNewJoke)
|
2021-07-09 06:11:11 +00:00
|
|
|
|
|
|
|
// Update a joke
|
2021-08-03 18:14:32 +00:00
|
|
|
app.Patch("/id/:id", middleware.RequireAuth(), middleware.OnlyIntegerAsID(), joke.UpdateJoke)
|
2021-07-09 06:11:11 +00:00
|
|
|
|
|
|
|
// Delete a joke
|
2021-08-03 18:14:32 +00:00
|
|
|
app.Delete("/id/:id", middleware.RequireAuth(), middleware.OnlyIntegerAsID(), joke.DeleteJoke)
|
2021-07-09 06:11:11 +00:00
|
|
|
|
|
|
|
return app
|
|
|
|
}
|