-
Notifications
You must be signed in to change notification settings - Fork 2
/
delete_account_balance.go
72 lines (61 loc) · 1.67 KB
/
delete_account_balance.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package action
import (
"fmt"
"net/http"
"github.com/felixa1996/go-plate/adapter/api/logging"
"github.com/felixa1996/go-plate/adapter/api/response"
"github.com/felixa1996/go-plate/adapter/logger"
"github.com/felixa1996/go-plate/domain"
"github.com/felixa1996/go-plate/usecase"
)
type DeleteAccountBalanceAction struct {
uc usecase.DeleteAccountBalanceUseCase
log logger.Logger
}
func NewDeleteAccountBalanceAction(uc usecase.DeleteAccountBalanceUseCase, log logger.Logger) DeleteAccountBalanceAction {
return DeleteAccountBalanceAction{
uc: uc,
log: log,
}
}
func (a DeleteAccountBalanceAction) Execute(w http.ResponseWriter, r *http.Request) {
const logKey = "delete_balance_account"
var id = r.URL.Query().Get("id")
fmt.Print("Text " + id)
if !domain.IsValidUUID(id) {
var err = response.ErrParameterInvalid
logging.NewError(
a.log,
err,
logKey,
http.StatusBadRequest,
).Log("invalid parameter")
response.NewError(err, http.StatusBadRequest).Send(w)
return
}
output, err := a.uc.Execute(r.Context(), domain.AccountID(id))
if err != nil {
switch err {
case domain.ErrAccountNotFound:
logging.NewError(
a.log,
err,
logKey,
http.StatusBadRequest,
).Log("error fetching account balance")
response.NewError(err, http.StatusBadRequest).Send(w)
return
default:
logging.NewError(
a.log,
err,
logKey,
http.StatusInternalServerError,
).Log("error when returning account balance")
response.NewError(err, http.StatusInternalServerError).Send(w)
return
}
}
logging.NewInfo(a.log, logKey, http.StatusOK).Log("success when returning account balance")
response.NewSuccess(output, http.StatusOK).Send(w)
}