jokes-bapak2/api/routes/joke.go

36 lines
669 B
Go
Raw Permalink Normal View History

2021-09-27 10:10:19 +00:00
package routes
import (
2021-10-30 03:24:53 +00:00
"jokes-bapak2-api/handler/joke"
2021-09-27 10:10:19 +00:00
2022-09-03 10:53:46 +00:00
"github.com/allegro/bigcache/v3"
"github.com/go-chi/chi/v5"
"github.com/go-redis/redis/v8"
"github.com/minio/minio-go/v7"
2021-09-27 10:10:19 +00:00
)
2022-09-03 14:09:26 +00:00
// Joke provides route for jokes.
2022-09-03 10:53:46 +00:00
func Joke(bucket *minio.Client, cache *redis.Client, memory *bigcache.BigCache) *chi.Mux {
deps := &joke.Dependencies{
Memory: memory,
Bucket: bucket,
Redis: cache,
2021-09-27 10:10:19 +00:00
}
2022-09-03 10:53:46 +00:00
router := chi.NewRouter()
2021-09-27 10:10:19 +00:00
// Single route
2022-09-03 10:53:46 +00:00
router.Get("/", deps.SingleJoke)
2021-09-27 10:10:19 +00:00
// Today's joke
2022-09-03 10:53:46 +00:00
router.Get("/today", deps.TodayJoke)
2021-09-27 10:10:19 +00:00
// Joke by ID
2022-09-03 10:53:46 +00:00
router.Get("/id/{id}", deps.JokeByID)
2021-09-27 10:10:19 +00:00
// Count total jokes
2022-09-03 10:53:46 +00:00
router.Get("/total", deps.TotalJokes)
2021-09-27 10:10:19 +00:00
2022-09-03 10:53:46 +00:00
return router
2021-09-27 10:10:19 +00:00
}