Skip to content

Commit da94fa0

Browse files
committed
make voucher balance fixed
1 parent dcfeca3 commit da94fa0

7 files changed

Lines changed: 7 additions & 16 deletions

File tree

server/app/setup.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ func SetUp(t testing.TB) *App {
7676
"medium_vm": 20,
7777
"large_vm": 30
7878
},
79-
"stripe_secret": "sk_test"
79+
"stripe_secret": "sk_test",
80+
"voucher_balance": 10
8081
}
8182
`, dbPath)
8283

server/app/user_handler.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ type EmailInput struct {
6565

6666
// ApplyForVoucherInput struct for user to apply for voucher
6767
type ApplyForVoucherInput struct {
68-
Balance uint64 `json:"balance" binding:"required" validate:"min=0"`
69-
Reason string `json:"reason" binding:"required" validate:"nonzero"`
68+
Reason string `json:"reason" binding:"required" validate:"nonzero"`
7069
}
7170

7271
// AddVoucherInput struct for voucher applied by user
@@ -711,7 +710,7 @@ func (a *App) ApplyForVoucherHandler(req *http.Request) (interface{}, Response)
711710
voucher := models.Voucher{
712711
Voucher: v,
713712
UserID: userID,
714-
Balance: input.Balance,
713+
Balance: a.config.VoucherBalance,
715714
Reason: input.Reason,
716715
}
717716

server/app/user_handler_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,6 @@ func TestApplyForVoucherHandler(t *testing.T) {
870870
assert.NoError(t, err)
871871

872872
voucherBody := []byte(`{
873-
"vms":10,
874-
"public_ips":1,
875873
"reason":"strongReason"
876874
}`)
877875

server/docs/docs.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,14 +2712,9 @@ const docTemplate = `{
27122712
"app.ApplyForVoucherInput": {
27132713
"type": "object",
27142714
"required": [
2715-
"balance",
27162715
"reason"
27172716
],
27182717
"properties": {
2719-
"balance": {
2720-
"type": "integer",
2721-
"minimum": 0
2722-
},
27232718
"reason": {
27242719
"type": "string"
27252720
}

server/docs/swagger.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,9 @@ definitions:
3535
type: object
3636
app.ApplyForVoucherInput:
3737
properties:
38-
balance:
39-
minimum: 0
40-
type: integer
4138
reason:
4239
type: string
4340
required:
44-
- balance
4541
- reason
4642
type: object
4743
app.ChangePasswordInput:

server/internal/config_parser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Configuration struct {
2424
PricesPerMonth Prices `json:"prices"`
2525
Currency string `json:"currency" validate:"nonzero"`
2626
StripeSecret string `json:"stripe_secret" validate:"nonzero"`
27+
VoucherBalance uint64 `json:"voucher_balance" validate:"nonzero"`
2728
}
2829

2930
// Server struct to hold server's information

server/internal/config_parser_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ var rightConfig = `
4242
"medium_vm": 20,
4343
"large_vm": 30
4444
},
45-
"stripe_secret": "sk_test"
45+
"stripe_secret": "sk_test",
46+
"voucher_balance": 10
4647
}
4748
`
4849

0 commit comments

Comments
 (0)