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

35 lines
621 B
Go
Raw Normal View History

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