version 1
Build and Deploy / test-backend (push) Successful in 1m11s
Build and Deploy / lint-frontend (push) Successful in 21s
Build and Deploy / build-backend (push) Successful in 58s
Build and Deploy / deploy (push) Canceled after 0s
Build and Deploy / build-frontend (push) Canceled after 5m38s
Build and Deploy / test-backend (push) Successful in 1m11s
Build and Deploy / lint-frontend (push) Successful in 21s
Build and Deploy / build-backend (push) Successful in 58s
Build and Deploy / deploy (push) Canceled after 0s
Build and Deploy / build-frontend (push) Canceled after 5m38s
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/dusiburg/fancy-api/internal/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type UsageHandler struct {
|
||||
service *service.UsageService
|
||||
}
|
||||
|
||||
func NewUsageHandler(svc *service.UsageService) *UsageHandler {
|
||||
return &UsageHandler{service: svc}
|
||||
}
|
||||
|
||||
func (h *UsageHandler) Get(c *gin.Context) {
|
||||
userID, ok := userIDFromContext(c)
|
||||
if !ok {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
|
||||
return
|
||||
}
|
||||
|
||||
usage, err := h.service.GetUsage(c.Request.Context(), userID)
|
||||
if err != nil {
|
||||
log.Printf("getting usage: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "getting usage failed"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, usage)
|
||||
}
|
||||
Reference in New Issue
Block a user