2021-08-04 02:51:22 +00:00
|
|
|
package routes
|
|
|
|
|
|
|
|
import (
|
2021-09-27 10:10:19 +00:00
|
|
|
"jokes-bapak2-api/app/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
|
|
|
)
|
|
|
|
|
2021-09-27 10:10:19 +00:00
|
|
|
func (d *Dependencies) Submit() {
|
2021-09-26 19:13:38 +00:00
|
|
|
deps := submit.Dependencies{
|
2021-10-18 08:31:17 +00:00
|
|
|
DB: d.DB,
|
|
|
|
Redis: d.Redis,
|
|
|
|
Memory: d.Memory,
|
|
|
|
HTTP: d.HTTP,
|
|
|
|
Query: d.Query,
|
2021-09-26 19:13:38 +00:00
|
|
|
}
|
2021-09-27 13:02:58 +00:00
|
|
|
|
2021-08-04 02:51:22 +00:00
|
|
|
// Get pending submitted joke
|
2021-09-26 19:13:38 +00:00
|
|
|
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()
|
|
|
|
},
|
|
|
|
}),
|
2021-09-26 19:13:38 +00:00
|
|
|
deps.GetSubmission)
|
2021-08-04 02:51:22 +00:00
|
|
|
|
|
|
|
// Add a joke
|
2021-09-26 19:13:38 +00:00
|
|
|
d.App.Post("/submit", deps.SubmitJoke)
|
2021-08-04 02:51:22 +00:00
|
|
|
}
|