jokes-bapak2/api/handler/joke/total.go

24 lines
641 B
Go
Raw Normal View History

2022-09-03 10:53:46 +00:00
package joke
import (
"net/http"
"strconv"
2023-08-12 05:36:08 +00:00
core "jokes-bapak2-api/core/joke"
2022-09-03 10:53:46 +00:00
)
2022-09-03 14:29:52 +00:00
// TotalJokes provides a HTTP handler for acquiring total jokes
2022-09-03 10:53:46 +00:00
func (d *Dependencies) TotalJokes(w http.ResponseWriter, r *http.Request) {
total, err := core.GetTotalJoke(r.Context(), d.Bucket, d.Redis, d.Memory)
if err != nil {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(`{"error":` + strconv.Quote(err.Error()) + `}`))
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"message":` + strconv.Itoa(total) + `}`))
}