Skip to content

Commit 638ec73

Browse files
committed
fix: Rename to response_delay_in_milliseconds
1 parent 429807a commit 638ec73

File tree

11 files changed

+128
-117
lines changed

11 files changed

+128
-117
lines changed

api/docs/docs.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,6 @@ const docTemplate = `{
676676
"type": "object",
677677
"required": [
678678
"created_at",
679-
"delay_in_milliseconds",
680679
"description",
681680
"id",
682681
"project_id",
@@ -685,6 +684,7 @@ const docTemplate = `{
685684
"request_path",
686685
"response_body",
687686
"response_code",
687+
"response_delay_in_milliseconds",
688688
"response_headers",
689689
"subdomain",
690690
"updated_at",
@@ -695,10 +695,6 @@ const docTemplate = `{
695695
"type": "string",
696696
"example": "2022-06-05T14:26:02.302718+03:00"
697697
},
698-
"delay_in_milliseconds": {
699-
"type": "integer",
700-
"example": 1000
701-
},
702698
"description": {
703699
"type": "string",
704700
"example": "Mock API for an online store for the /v1/products endpoint"
@@ -731,6 +727,10 @@ const docTemplate = `{
731727
"type": "integer",
732728
"example": 200
733729
},
730+
"response_delay_in_milliseconds": {
731+
"type": "integer",
732+
"example": 100
733+
},
734734
"response_headers": {
735735
"type": "string",
736736
"example": "[{\"Content-Type\":\"application/json\"}]"
@@ -806,18 +806,15 @@ const docTemplate = `{
806806
"requests.ProjectEndpointUpdateRequest": {
807807
"type": "object",
808808
"required": [
809-
"delay_in_milliseconds",
810809
"description",
811810
"request_method",
812811
"request_path",
813812
"response_body",
814813
"response_code",
814+
"response_delay_in_milliseconds",
815815
"response_headers"
816816
],
817817
"properties": {
818-
"delay_in_milliseconds": {
819-
"type": "integer"
820-
},
821818
"description": {
822819
"type": "string"
823820
},
@@ -833,6 +830,9 @@ const docTemplate = `{
833830
"response_code": {
834831
"type": "integer"
835832
},
833+
"response_delay_in_milliseconds": {
834+
"type": "integer"
835+
},
836836
"response_headers": {
837837
"type": "string"
838838
}

api/docs/swagger.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,6 @@
629629
"type": "object",
630630
"required": [
631631
"created_at",
632-
"delay_in_milliseconds",
633632
"description",
634633
"id",
635634
"project_id",
@@ -638,6 +637,7 @@
638637
"request_path",
639638
"response_body",
640639
"response_code",
640+
"response_delay_in_milliseconds",
641641
"response_headers",
642642
"subdomain",
643643
"updated_at",
@@ -648,10 +648,6 @@
648648
"type": "string",
649649
"example": "2022-06-05T14:26:02.302718+03:00"
650650
},
651-
"delay_in_milliseconds": {
652-
"type": "integer",
653-
"example": 1000
654-
},
655651
"description": {
656652
"type": "string",
657653
"example": "Mock API for an online store for the /v1/products endpoint"
@@ -684,6 +680,10 @@
684680
"type": "integer",
685681
"example": 200
686682
},
683+
"response_delay_in_milliseconds": {
684+
"type": "integer",
685+
"example": 100
686+
},
687687
"response_headers": {
688688
"type": "string",
689689
"example": "[{\"Content-Type\":\"application/json\"}]"
@@ -755,18 +755,15 @@
755755
"requests.ProjectEndpointUpdateRequest": {
756756
"type": "object",
757757
"required": [
758-
"delay_in_milliseconds",
759758
"description",
760759
"request_method",
761760
"request_path",
762761
"response_body",
763762
"response_code",
763+
"response_delay_in_milliseconds",
764764
"response_headers"
765765
],
766766
"properties": {
767-
"delay_in_milliseconds": {
768-
"type": "integer"
769-
},
770767
"description": {
771768
"type": "string"
772769
},
@@ -782,6 +779,9 @@
782779
"response_code": {
783780
"type": "integer"
784781
},
782+
"response_delay_in_milliseconds": {
783+
"type": "integer"
784+
},
785785
"response_headers": {
786786
"type": "string"
787787
}

api/docs/swagger.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ definitions:
3636
created_at:
3737
example: "2022-06-05T14:26:02.302718+03:00"
3838
type: string
39-
delay_in_milliseconds:
40-
example: 1000
41-
type: integer
4239
description:
4340
example: Mock API for an online store for the /v1/products endpoint
4441
type: string
@@ -63,6 +60,9 @@ definitions:
6360
response_code:
6461
example: 200
6562
type: integer
63+
response_delay_in_milliseconds:
64+
example: 100
65+
type: integer
6666
response_headers:
6767
example: '[{"Content-Type":"application/json"}]'
6868
type: string
@@ -77,7 +77,6 @@ definitions:
7777
type: string
7878
required:
7979
- created_at
80-
- delay_in_milliseconds
8180
- description
8281
- id
8382
- project_id
@@ -86,6 +85,7 @@ definitions:
8685
- request_path
8786
- response_body
8887
- response_code
88+
- response_delay_in_milliseconds
8989
- response_headers
9090
- subdomain
9191
- updated_at
@@ -131,8 +131,6 @@ definitions:
131131
type: object
132132
requests.ProjectEndpointUpdateRequest:
133133
properties:
134-
delay_in_milliseconds:
135-
type: integer
136134
description:
137135
type: string
138136
request_method:
@@ -143,15 +141,17 @@ definitions:
143141
type: string
144142
response_code:
145143
type: integer
144+
response_delay_in_milliseconds:
145+
type: integer
146146
response_headers:
147147
type: string
148148
required:
149-
- delay_in_milliseconds
150149
- description
151150
- request_method
152151
- request_path
153152
- response_body
154153
- response_code
154+
- response_delay_in_milliseconds
155155
- response_headers
156156
type: object
157157
requests.ProjectUpdateRequest:

api/pkg/entities/project_endpoint.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ import (
88

99
// ProjectEndpoint is an endpoint belonging to a project
1010
type ProjectEndpoint struct {
11-
ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;" example:"8f9c71b8-b84e-4417-8408-a62274f65a08"`
12-
ProjectID uuid.UUID `json:"project_id" example:"8f9c71b8-b84e-4417-8408-a62274f65a08"`
13-
Subdomain string `json:"subdomain" example:"stripe-mock-api"`
14-
UserID UserID `json:"user_id" example:"user_2oeyIzOf9xxxxxxxxxxxxxx"`
15-
RequestMethod string `json:"request_method" example:"GET" gorm:"type:varchar(7)"`
16-
RequestPath string `json:"request_path" example:"/v1/products" gorm:"type:varchar(255)"`
17-
ResponseCode uint `json:"response_code" example:"200"`
18-
ResponseBody *string `json:"response_body" example:"{\"message\": \"Hello World\",\"status\": 200}"`
19-
ResponseHeaders *string `json:"response_headers" example:"[{\"Content-Type\":\"application/json\"}]"`
20-
DelayInMilliseconds uint `json:"delay_in_milliseconds" example:"1000"`
21-
Description *string `json:"description" example:"Mock API for an online store for the /v1/products endpoint"`
22-
RequestCount uint `json:"request_count" example:"100"`
23-
CreatedAt time.Time `json:"created_at" example:"2022-06-05T14:26:02.302718+03:00"`
24-
UpdatedAt time.Time `json:"updated_at" example:"2022-06-05T14:26:10.303278+03:00"`
11+
ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;" example:"8f9c71b8-b84e-4417-8408-a62274f65a08"`
12+
ProjectID uuid.UUID `json:"project_id" example:"8f9c71b8-b84e-4417-8408-a62274f65a08"`
13+
Subdomain string `json:"subdomain" example:"stripe-mock-api"`
14+
UserID UserID `json:"user_id" example:"user_2oeyIzOf9xxxxxxxxxxxxxx"`
15+
RequestMethod string `json:"request_method" example:"GET" gorm:"type:varchar(7)"`
16+
RequestPath string `json:"request_path" example:"/v1/products" gorm:"type:varchar(255)"`
17+
ResponseCode uint `json:"response_code" example:"200"`
18+
ResponseBody *string `json:"response_body" example:"{\"message\": \"Hello World\",\"status\": 200}"`
19+
ResponseHeaders *string `json:"response_headers" example:"[{\"Content-Type\":\"application/json\"}]"`
20+
ResponseDelayInMilliseconds uint `json:"response_delay_in_milliseconds" example:"100"`
21+
Description *string `json:"description" example:"Mock API for an online store for the /v1/products endpoint"`
22+
RequestCount uint `json:"request_count" example:"100"`
23+
CreatedAt time.Time `json:"created_at" example:"2022-06-05T14:26:02.302718+03:00"`
24+
UpdatedAt time.Time `json:"updated_at" example:"2022-06-05T14:26:10.303278+03:00"`
2525
}

api/pkg/requests/project_endpoint_create_request.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ type ProjectEndpointStoreRequest struct {
1313
request
1414
ProjectID string `json:"projectId" swaggerignore:"true"`
1515

16-
RequestMethod string `json:"request_method"`
17-
RequestPath string `json:"request_path"`
18-
ResponseCode uint `json:"response_code"`
19-
ResponseBody string `json:"response_body"`
20-
ResponseHeaders string `json:"response_headers"`
21-
DelayInMilliseconds uint `json:"delay_in_milliseconds"`
22-
Description string `json:"description"`
16+
RequestMethod string `json:"request_method"`
17+
RequestPath string `json:"request_path"`
18+
ResponseCode uint `json:"response_code"`
19+
ResponseBody string `json:"response_body"`
20+
ResponseHeaders string `json:"response_headers"`
21+
ResponseDelayInMilliseconds uint `json:"response_delay_in_milliseconds"`
22+
Description string `json:"description"`
2323
}
2424

2525
// Sanitize the request by stripping whitespaces
@@ -36,14 +36,14 @@ func (request *ProjectEndpointStoreRequest) Sanitize() *ProjectEndpointStoreRequ
3636
// ToProjectEndpointStorePrams creates services.ProjectEndpointStoreParams from ProjectEndpointStoreRequest
3737
func (request *ProjectEndpointStoreRequest) ToProjectEndpointStorePrams(userID entities.UserID) *services.ProjectEndpointStoreParams {
3838
return &services.ProjectEndpointStoreParams{
39-
RequestMethod: request.RequestMethod,
40-
RequestPath: request.RequestPath,
41-
ResponseCode: request.ResponseCode,
42-
ResponseBody: &request.ResponseBody,
43-
ResponseHeaders: &request.ResponseHeaders,
44-
DelayInMilliseconds: request.DelayInMilliseconds,
45-
Description: &request.Description,
46-
ProjectID: uuid.MustParse(request.ProjectID),
47-
UserID: userID,
39+
RequestMethod: request.RequestMethod,
40+
RequestPath: request.RequestPath,
41+
ResponseCode: request.ResponseCode,
42+
ResponseBody: &request.ResponseBody,
43+
ResponseHeaders: &request.ResponseHeaders,
44+
ResponseDelayInMilliseconds: request.ResponseDelayInMilliseconds,
45+
Description: &request.Description,
46+
ProjectID: uuid.MustParse(request.ProjectID),
47+
UserID: userID,
4848
}
4949
}

api/pkg/requests/project_endpoint_update_request.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ type ProjectEndpointUpdateRequest struct {
1414
ProjectID string `json:"projectId" swaggerignore:"true"`
1515
ProjectEndpointID string `json:"projectEndpointId" swaggerignore:"true"`
1616

17-
RequestMethod string `json:"request_method"`
18-
RequestPath string `json:"request_path"`
19-
ResponseCode uint `json:"response_code"`
20-
ResponseBody string `json:"response_body"`
21-
ResponseHeaders string `json:"response_headers"`
22-
DelayInMilliseconds uint `json:"delay_in_milliseconds"`
23-
Description string `json:"description"`
17+
RequestMethod string `json:"request_method"`
18+
RequestPath string `json:"request_path"`
19+
ResponseCode uint `json:"response_code"`
20+
ResponseBody string `json:"response_body"`
21+
ResponseHeaders string `json:"response_headers"`
22+
ResponseDelayInMilliseconds uint `json:"response_delay_in_milliseconds"`
23+
Description string `json:"description"`
2424
}
2525

2626
// Sanitize the request by stripping whitespaces
@@ -37,15 +37,15 @@ func (request *ProjectEndpointUpdateRequest) Sanitize() *ProjectEndpointUpdateRe
3737
// ToProjectEndpointUpdatePrams creates services.ProjectEndpointUpdateParams from ProjectEndpointUpdateRequest
3838
func (request *ProjectEndpointUpdateRequest) ToProjectEndpointUpdatePrams(userID entities.UserID) *services.ProjectEndpointUpdateParams {
3939
return &services.ProjectEndpointUpdateParams{
40-
RequestMethod: request.RequestMethod,
41-
RequestPath: request.RequestPath,
42-
ResponseCode: request.ResponseCode,
43-
ResponseBody: &request.ResponseBody,
44-
ResponseHeaders: &request.ResponseHeaders,
45-
DelayInMilliseconds: request.DelayInMilliseconds,
46-
Description: &request.Description,
47-
ProjectEndpointID: uuid.MustParse(request.ProjectEndpointID),
48-
ProjectID: uuid.MustParse(request.ProjectID),
49-
UserID: userID,
40+
RequestMethod: request.RequestMethod,
41+
RequestPath: request.RequestPath,
42+
ResponseCode: request.ResponseCode,
43+
ResponseBody: &request.ResponseBody,
44+
ResponseHeaders: &request.ResponseHeaders,
45+
ResponseDelayInMilliseconds: request.ResponseDelayInMilliseconds,
46+
Description: &request.Description,
47+
ProjectEndpointID: uuid.MustParse(request.ProjectEndpointID),
48+
ProjectID: uuid.MustParse(request.ProjectID),
49+
UserID: userID,
5050
}
5151
}

api/pkg/services/project_endpoint_request_service.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ func (service *ProjectEndpointRequestService) HandleHTTPRequest(ctx context.Cont
5252
service.storeProjectEndpointRequestEvent(ctx, requestID, stopwatch, c, endpoint)
5353
headers := service.getHTTPHeaders(ctxLogger, c, endpoint)
5454

55-
delay := endpoint.DelayInMilliseconds - uint(time.Since(stopwatch).Milliseconds())
56-
if endpoint.DelayInMilliseconds > 0 && delay > 0 {
55+
delay := endpoint.ResponseDelayInMilliseconds - uint(time.Since(stopwatch).Milliseconds())
56+
if endpoint.ResponseDelayInMilliseconds > 0 && delay > 0 {
5757
time.Sleep(time.Duration(delay) * time.Millisecond)
5858
}
5959

@@ -140,7 +140,7 @@ func (service *ProjectEndpointRequestService) storeProjectEndpointRequestEvent(
140140
ResponseCode: endpoint.ResponseCode,
141141
ResponseBody: endpoint.ResponseBody,
142142
ResponseHeaders: endpoint.ResponseHeaders,
143-
ResponseDelayInMilliseconds: endpoint.DelayInMilliseconds,
143+
ResponseDelayInMilliseconds: endpoint.ResponseDelayInMilliseconds,
144144
IPAddress: c.IP(),
145145
Timestamp: stopwatch,
146146
})

0 commit comments

Comments
 (0)