Skip to content

Commit ea908f3

Browse files
committed
refactor
1 parent 8b3fb02 commit ea908f3

File tree

6 files changed

+14
-66
lines changed

6 files changed

+14
-66
lines changed

api/internal/delivery/rest/v1/invoice_public.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func (h *Handler) invoiceInfo(c *gin.Context) {
184184
CreatedAt: invoice.CreatedAt.Format("2006-01-02 15:04:05"),
185185
}
186186

187-
if time.Now().Unix() > invoice.EndTimestamp && invoice.Status.IsNotPaid() && !invoice.Status.IsCancelled() {
187+
if time.Now().Unix() > invoice.EndTimestamp && invoice.Status.IsNotPaid() && !invoice.Status.IsCanceled() {
188188
response.Status = "end"
189189
}
190190

@@ -279,7 +279,7 @@ func (h *Handler) invoiceCancel(c *gin.Context) {
279279
return
280280
}
281281

282-
c.AbortWithStatusJSON(http.StatusOK, responseInvoiceCancelled{
282+
c.AbortWithStatusJSON(http.StatusOK, responseInvoiceCanceled{
283283
Error: false,
284284
})
285285

api/internal/delivery/rest/v1/response.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ type responseMerchantCreated struct {
7777
MerchantId string `json:"merchant_id"`
7878
}
7979

80-
type responseInvoiceCancelled struct {
80+
type responseInvoiceCanceled struct {
8181
Error bool `json:"error"`
8282
// Message string `json:"message"`
8383
}

api/internal/domain/invoices.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ const (
2828
STATUS_END
2929
STATUS_PAID_LESS
3030
STATUS_IN_PROCESSING
31-
STATUS_CANCELLED
31+
STATUS_CANCELED
3232
)
3333

34-
var Statuses = [...]string{"not_paid", "paid", "paid_over", "end", "paid_less", "processing", "cancelled"}
34+
var Statuses = [...]string{"not_paid", "paid", "paid_over", "end", "paid_less", "processing", "canceled"}
3535

3636
// methods
3737

@@ -49,8 +49,8 @@ func (s Status) ToString() string {
4949
return Statuses[s]
5050
}
5151

52-
func (s Status) IsCancelled() bool {
53-
return s == STATUS_CANCELLED
52+
func (s Status) IsCanceled() bool {
53+
return s == STATUS_CANCELED
5454
}
5555
func (s Status) IsPaid() bool {
5656
return s == STATUS_PAID || s == STATUS_PAID_OVER

api/internal/domain/responses.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var (
5454
ErrInternalServerError ResponseError = fmt.Errorf(ErrMsgInternalServerError)
5555
ErrInvoiceIdNotFound ResponseError = fmt.Errorf("invoice id not found")
5656

57-
ErrInvoiceAlreadyCancelled ResponseError = fmt.Errorf("invoice already cancelled")
57+
ErrInvoiceAlreadyCanceled ResponseError = fmt.Errorf("the invoice is already canceled")
5858
)
5959

6060
const (
@@ -73,7 +73,7 @@ func GetStatusByErr(err ResponseError) (status int) {
7373
status = http.StatusBadRequest
7474
case errors.Is(err, ErrInvoiceIdNotFound):
7575
status = http.StatusBadRequest
76-
case errors.Is(err, ErrInvoiceAlreadyCancelled):
76+
case errors.Is(err, ErrInvoiceAlreadyCanceled):
7777
status = http.StatusBadRequest
7878
default:
7979
status = http.StatusInternalServerError

api/internal/service/invoices.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ func (s *InvoicesService) RunCheck(ctx context.Context, cancel context.CancelFun
158158
continue
159159
}
160160

161-
if invoice.Status.IsCancelled() {
162-
fmt.Println("CANCELLED")
161+
if invoice.Status.IsCanceled() {
162+
fmt.Println("CANCELED")
163163
return
164164
}
165165

@@ -355,12 +355,12 @@ func (s *InvoicesService) Cancel(invoiceId string) domain.ResponseError {
355355
return err
356356
}
357357

358-
if invoice.Status.IsCancelled() {
359-
return domain.ErrInvoiceAlreadyCancelled
358+
if invoice.Status.IsCanceled() {
359+
return domain.ErrInvoiceAlreadyCanceled
360360
}
361361

362362
return s.db.Transaction(func(tx *gorm.DB) error {
363-
invoice.Status = domain.STATUS_CANCELLED
363+
invoice.Status = domain.STATUS_CANCELED
364364

365365
// update invoice table
366366
err := s.repo.Update(tx, invoice)

pkg/nats/natsdomain/helpers.go

-52
Original file line numberDiff line numberDiff line change
@@ -74,58 +74,6 @@ func (ns *Ns) InitBuckets(ctx context.Context) error {
7474
return nil
7575
}
7676

77-
func (ns *Ns) KvWatch(ctx context.Context, bucket BucketType, key string) (jetstream.KeyWatcher, error) {
78-
kv, err := kvGet(ns.Js, bucket.String())
79-
if err != nil {
80-
return nil, err
81-
}
82-
83-
watcher, err := kv.Watch(ctx, key)
84-
if err != nil {
85-
return nil, err
86-
}
87-
return watcher, nil
88-
89-
}
90-
91-
func kvGet(js jetstream.JetStream, bucket string) (jetstream.KeyValue, error) {
92-
return js.KeyValue(context.Background(), bucket)
93-
}
94-
95-
func (ns *Ns) KvPut(bucket BucketType, key string, value []byte) {
96-
fmt.Println("SET KEY VALUE", key)
97-
kv, err := kvGet(ns.Js, bucket.String())
98-
if err != nil {
99-
panic(err)
100-
}
101-
102-
_, err = kv.Put(context.Background(), key, value)
103-
if err != nil {
104-
panic(err)
105-
}
106-
}
107-
108-
func (ns *Ns) KVPutStr(bucket BucketType, key string, value string) {
109-
kv, err := kvGet(ns.Js, bucket.String())
110-
if err != nil {
111-
panic(err)
112-
}
113-
114-
_, err = kv.PutString(context.Background(), key, value)
115-
if err != nil {
116-
panic(err)
117-
}
118-
}
119-
120-
func (ns *Ns) KVGet(bucket BucketType, key string) (jetstream.KeyValueEntry, error) {
121-
kv, err := kvGet(ns.Js, bucket.String())
122-
if err != nil {
123-
panic(err)
124-
}
125-
126-
return kv.Get(context.Background(), key)
127-
}
128-
12977
func sendrecv(nc *nats.Conn, timeout time.Duration, subj SubjType, jsonMsg []byte) (*nats.Msg, error) {
13078
resp, err := nc.Request(subj.String(), jsonMsg, timeout)
13179
if err != nil {

0 commit comments

Comments
 (0)