Skip to content

Commit c75afcd

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

8 files changed

Lines changed: 11 additions & 20 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

server/models/deployments_count.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ func (d *DB) CountAllDeployments() (DeploymentsCount, error) {
2323
dlsCount := k8sCount + vmsCount
2424

2525
var vmIPsCount int64
26-
result = d.db.Table("vms").Where("public_ip = true").Count(&vmIPsCount)
26+
result = d.db.Table("vms").Where("public = true").Count(&vmIPsCount)
2727
if result.Error != nil {
2828
return DeploymentsCount{}, result.Error
2929
}
3030

3131
var k8sIPsCount int64
32-
result = d.db.Table("masters").Where("public_ip = true").Count(&k8sIPsCount)
32+
result = d.db.Table("masters").Where("public = true").Count(&k8sIPsCount)
3333
if result.Error != nil {
3434
return DeploymentsCount{}, result.Error
3535
}
@@ -61,14 +61,14 @@ func (d *DB) CountUserDeployments(userID string) (DeploymentsCount, error) {
6161
dlsCount := k8sCount + vmsCount
6262

6363
var vmIPsCount int64
64-
result = d.db.Table("vms").Where("public_ip = true").Where("user_id = ?", userID).Count(&vmIPsCount)
64+
result = d.db.Table("vms").Where("public = true").Where("user_id = ?", userID).Count(&vmIPsCount)
6565
if result.Error != nil {
6666
return DeploymentsCount{}, result.Error
6767
}
6868

6969
var k8sIPsCount int64
7070
result = d.db.Table("k8s_clusters").Joins("JOIN masters ON k8s_clusters.id = masters.cluster_id").
71-
Where("public_ip = true").Where("user_id = ?", userID).Count(&k8sIPsCount)
71+
Where("public = true").Where("user_id = ?", userID).Count(&k8sIPsCount)
7272
if result.Error != nil {
7373
return DeploymentsCount{}, result.Error
7474
}

0 commit comments

Comments
 (0)