Skip to content

Commit

Permalink
finally search
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyKomarovCoder committed Nov 22, 2023
1 parent 85f1d8e commit 0ee98e7
Show file tree
Hide file tree
Showing 12 changed files with 1,775 additions and 1,519 deletions.
1 change: 1 addition & 0 deletions cmd/api/init/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func InitRouter(auth *auth.Handler,
transactionRouter.Use(csrfMid.CheckCSRF)
{
transactionRouter.Methods("GET").Path("/feed").HandlerFunc(transaction.GetFeed)
transactionRouter.Methods("GET").Path("/count").HandlerFunc(transaction.GetCount)
// transactionRouter.Methods("GET").Path("/{transaction_id}/").HandlerFunc(transaction.Get)
transactionRouter.Methods("PUT").Path("/update").HandlerFunc(transaction.Update)
transactionRouter.Methods("POST").Path("/create").HandlerFunc(transaction.Create)
Expand Down
29 changes: 29 additions & 0 deletions internal/microservices/transaction/delivery/http/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,35 @@ func NewHandler(uu transaction.Usecase, l logger.Logger) *Handler {
}
}

// @Summary Get count transaction
// @Tags Transaction
// @Description Get User count transaction
// @Produce json
// @Success 200 {object} Response[TransactionCount] "Show transaction count"
// @Failure 400 {object} ResponseError "Client error"
// @Failure 401 {object} ResponseError "Unauthorized user"
// @Failure 403 {object} ResponseError "Forbidden user"
// @Failure 500 {object} ResponseError "Server error"
// @Router /api/transaction/count [get]
func (h *Handler) GetCount(w http.ResponseWriter, r *http.Request) {
user, err := commonHttp.GetUserFromRequest(r)
if err != nil && errors.Is(err, commonHttp.ErrUnauthorized) {
commonHttp.ErrorResponse(w, http.StatusUnauthorized, err, commonHttp.ErrUnauthorized.Error(), h.logger)
return
}

transactionCount, err := h.transactionService.GetCount(r.Context(), user.ID)

if err != nil {
commonHttp.ErrorResponse(w, http.StatusBadRequest, err, "can't get count transaction info", h.logger)
return
}

response := TransactionCount{Count: transactionCount}
commonHttp.SuccessResponse(w, http.StatusOK, response)

}

// @Summary Get all transaction
// @Tags Transaction
// @Description Get User all transaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ type TransactionCreateResponse struct {
TransactionID uuid.UUID `json:"transaction_id"`
}

type TransactionCount struct {
Count int `json:"count"`
}

type MasTransaction struct {
Transactions []models.TransactionTransfer `json:"transactions"`
IsAll bool `json:"is_all"`
}

type CreateTransaction struct {
Expand Down
Loading

0 comments on commit 0ee98e7

Please sign in to comment.