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

35 lines
621 B
Go

package routes
import (
"jokes-bapak2-api/app/v1/handler/submit"
"time"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cache"
)
func (d *Dependencies) Submit() *fiber.App {
deps := submit.Dependencies{
DB: d.DB,
Redis: d.Redis,
Memory: d.Memory,
HTTP: d.HTTP,
Query: d.Query,
}
// Get pending submitted joke
d.App.Get(
"/submit",
cache.New(cache.Config{
Expiration: 5 * time.Minute,
KeyGenerator: func(c *fiber.Ctx) string {
return c.OriginalURL()
},
}),
deps.GetSubmission)
// Add a joke
d.App.Post("/submit", deps.SubmitJoke)
return d.App
}