Skip to content

Commit 0bc0b6a

Browse files
uzabanovgeorgethebeatle
authored andcommitted
Change CreatedAt and UpdatedAt in API responses to valid timestamps
Closes #4259
1 parent 87e6edc commit 0bc0b6a

19 files changed

+106
-89
lines changed

api/presenter/app.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package presenter
22

33
import (
44
"net/url"
5+
"time"
56

67
"code.cloudfoundry.org/korifi/api/repositories"
78
"code.cloudfoundry.org/korifi/api/repositories/include"
@@ -17,8 +18,8 @@ type AppResponse struct {
1718
GUID string `json:"guid"`
1819
State string `json:"state"`
1920

20-
CreatedAt string `json:"created_at"`
21-
UpdatedAt string `json:"updated_at"`
21+
CreatedAt time.Time `json:"created_at"`
22+
UpdatedAt time.Time `json:"updated_at"`
2223
Relationships map[string]ToOneRelationship `json:"relationships"`
2324
Lifecycle Lifecycle `json:"lifecycle"`
2425
Metadata Metadata `json:"metadata"`
@@ -46,8 +47,8 @@ func ForApp(responseApp repositories.AppRecord, baseURL url.URL, includes ...inc
4647
Name: responseApp.Name,
4748
GUID: responseApp.GUID,
4849
State: string(responseApp.State),
49-
CreatedAt: tools.ZeroIfNil(formatTimestamp(&responseApp.CreatedAt)),
50-
UpdatedAt: tools.ZeroIfNil(formatTimestamp(responseApp.UpdatedAt)),
50+
CreatedAt: tools.ZeroIfNil(toUTC(&responseApp.CreatedAt)),
51+
UpdatedAt: tools.ZeroIfNil(toUTC(responseApp.UpdatedAt)),
5152
Relationships: ForRelationships(responseApp.Relationships()),
5253
Lifecycle: Lifecycle{
5354
Type: responseApp.Lifecycle.Type,

api/presenter/build.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package presenter
22

33
import (
44
"net/url"
5+
"time"
56

67
"code.cloudfoundry.org/korifi/api/repositories"
78
"code.cloudfoundry.org/korifi/api/repositories/include"
@@ -15,8 +16,8 @@ const (
1516

1617
type BuildResponse struct {
1718
GUID string `json:"guid"`
18-
CreatedAt string `json:"created_at"`
19-
UpdatedAt string `json:"updated_at"`
19+
CreatedAt time.Time `json:"created_at"`
20+
UpdatedAt time.Time `json:"updated_at"`
2021
CreatedBy map[string]interface{} `json:"created_by"`
2122
State string `json:"state"`
2223
StagingMemoryMB int `json:"staging_memory_in_mb"`
@@ -33,8 +34,8 @@ type BuildResponse struct {
3334
func ForBuild(buildRecord repositories.BuildRecord, baseURL url.URL, includes ...include.Resource) BuildResponse {
3435
toReturn := BuildResponse{
3536
GUID: buildRecord.GUID,
36-
CreatedAt: tools.ZeroIfNil(formatTimestamp(&buildRecord.CreatedAt)),
37-
UpdatedAt: tools.ZeroIfNil(formatTimestamp(buildRecord.UpdatedAt)),
37+
CreatedAt: tools.ZeroIfNil(toUTC(&buildRecord.CreatedAt)),
38+
UpdatedAt: tools.ZeroIfNil(toUTC(buildRecord.UpdatedAt)),
3839
CreatedBy: make(map[string]interface{}),
3940
State: buildRecord.State,
4041
StagingMemoryMB: buildRecord.StagingMemoryMB,

api/presenter/buildpack.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package presenter
22

33
import (
44
"net/url"
5+
"time"
56

67
"code.cloudfoundry.org/korifi/api/repositories"
78
"code.cloudfoundry.org/korifi/api/repositories/include"
@@ -10,8 +11,8 @@ import (
1011

1112
type BuildpackResponse struct {
1213
GUID string `json:"guid"`
13-
CreatedAt string `json:"created_at"`
14-
UpdatedAt string `json:"updated_at"`
14+
CreatedAt time.Time `json:"created_at"`
15+
UpdatedAt time.Time `json:"updated_at"`
1516
Name string `json:"name"`
1617
Filename string `json:"filename"`
1718
Stack string `json:"stack"`
@@ -25,8 +26,8 @@ type BuildpackResponse struct {
2526
func ForBuildpack(buildpackRecord repositories.BuildpackRecord, _ url.URL, includes ...include.Resource) BuildpackResponse {
2627
toReturn := BuildpackResponse{
2728
GUID: "",
28-
CreatedAt: tools.ZeroIfNil(formatTimestamp(&buildpackRecord.CreatedAt)),
29-
UpdatedAt: tools.ZeroIfNil(formatTimestamp(buildpackRecord.UpdatedAt)),
29+
CreatedAt: tools.ZeroIfNil(toUTC(&buildpackRecord.CreatedAt)),
30+
UpdatedAt: tools.ZeroIfNil(toUTC(buildpackRecord.UpdatedAt)),
3031
Name: buildpackRecord.Name,
3132
Filename: buildpackRecord.Name + "@" + buildpackRecord.Version,
3233
Stack: buildpackRecord.Stack,

api/presenter/deployment.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package presenter
22

33
import (
44
"net/url"
5+
"time"
56

67
"code.cloudfoundry.org/korifi/api/repositories"
78
"code.cloudfoundry.org/korifi/api/repositories/include"
@@ -26,8 +27,8 @@ type DeploymentResponse struct {
2627
Droplet DropletGUID `json:"droplet"`
2728
Relationships map[string]ToOneRelationship `json:"relationships"`
2829
Links DeploymentLinks `json:"links"`
29-
CreatedAt string `json:"created_at"`
30-
UpdatedAt string `json:"updated_at"`
30+
CreatedAt time.Time `json:"created_at"`
31+
UpdatedAt time.Time `json:"updated_at"`
3132
}
3233

3334
type DeploymentLinks struct {
@@ -46,8 +47,8 @@ func ForDeployment(responseDeployment repositories.DeploymentRecord, baseURL url
4647
Guid: responseDeployment.DropletGUID,
4748
},
4849
Relationships: ForRelationships(responseDeployment.Relationships()),
49-
CreatedAt: tools.ZeroIfNil(formatTimestamp(&responseDeployment.CreatedAt)),
50-
UpdatedAt: tools.ZeroIfNil(formatTimestamp(responseDeployment.UpdatedAt)),
50+
CreatedAt: tools.ZeroIfNil(toUTC(&responseDeployment.CreatedAt)),
51+
UpdatedAt: tools.ZeroIfNil(toUTC(responseDeployment.UpdatedAt)),
5152
Links: DeploymentLinks{
5253
Self: Link{
5354
HRef: buildURL(baseURL).appendPath(deploymentsBase, responseDeployment.GUID).build(),

api/presenter/domain.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package presenter
22

33
import (
44
"net/url"
5+
"time"
56

67
"code.cloudfoundry.org/korifi/api/repositories"
78
"code.cloudfoundry.org/korifi/api/repositories/include"
@@ -19,8 +20,8 @@ type DomainResponse struct {
1920
RouterGroup *string `json:"router_group"`
2021
SupportedProtocols []string `json:"supported_protocols"`
2122

22-
CreatedAt string `json:"created_at"`
23-
UpdatedAt string `json:"updated_at"`
23+
CreatedAt time.Time `json:"created_at"`
24+
UpdatedAt time.Time `json:"updated_at"`
2425
Metadata Metadata `json:"metadata"`
2526
Relationships DomainRelationships `json:"relationships"`
2627
Links DomainLinks `json:"links"`
@@ -52,8 +53,8 @@ func ForDomain(responseDomain repositories.DomainRecord, baseURL url.URL, includ
5253
Internal: false,
5354
RouterGroup: nil,
5455
SupportedProtocols: []string{"http"},
55-
CreatedAt: tools.ZeroIfNil(formatTimestamp(&responseDomain.CreatedAt)),
56-
UpdatedAt: tools.ZeroIfNil(formatTimestamp(responseDomain.UpdatedAt)),
56+
CreatedAt: tools.ZeroIfNil(toUTC(&responseDomain.CreatedAt)),
57+
UpdatedAt: tools.ZeroIfNil(toUTC(responseDomain.UpdatedAt)),
5758

5859
Metadata: Metadata{
5960
Labels: emptyMapIfNil(responseDomain.Labels),

api/presenter/droplet.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package presenter
22

33
import (
44
"net/url"
5+
"time"
56

67
"code.cloudfoundry.org/korifi/api/repositories"
78
"code.cloudfoundry.org/korifi/api/repositories/include"
@@ -10,8 +11,8 @@ import (
1011

1112
type DropletResponse struct {
1213
GUID string `json:"guid"`
13-
CreatedAt string `json:"created_at"`
14-
UpdatedAt string `json:"updated_at"`
14+
CreatedAt time.Time `json:"created_at"`
15+
UpdatedAt time.Time `json:"updated_at"`
1516
State string `json:"state"`
1617
Error *string `json:"error"`
1718
Lifecycle Lifecycle `json:"lifecycle"`
@@ -41,8 +42,8 @@ type BuildpackData struct {
4142
func ForDroplet(dropletRecord repositories.DropletRecord, baseURL url.URL, includes ...include.Resource) DropletResponse {
4243
toReturn := DropletResponse{
4344
GUID: dropletRecord.GUID,
44-
CreatedAt: tools.ZeroIfNil(formatTimestamp(&dropletRecord.CreatedAt)),
45-
UpdatedAt: tools.ZeroIfNil(formatTimestamp(dropletRecord.UpdatedAt)),
45+
CreatedAt: tools.ZeroIfNil(toUTC(&dropletRecord.CreatedAt)),
46+
UpdatedAt: tools.ZeroIfNil(toUTC(dropletRecord.UpdatedAt)),
4647
State: dropletRecord.State,
4748
Lifecycle: Lifecycle{
4849
Type: dropletRecord.Lifecycle.Type,

api/presenter/org.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package presenter
22

33
import (
44
"net/url"
5+
"time"
56

67
"code.cloudfoundry.org/korifi/api/repositories"
78
"code.cloudfoundry.org/korifi/api/repositories/include"
@@ -17,8 +18,8 @@ type OrgResponse struct {
1718
Name string `json:"name"`
1819
GUID string `json:"guid"`
1920

20-
CreatedAt string `json:"created_at"`
21-
UpdatedAt string `json:"updated_at"`
21+
CreatedAt time.Time `json:"created_at"`
22+
UpdatedAt time.Time `json:"updated_at"`
2223
Suspended bool `json:"suspended"`
2324
Relationships map[string]ToOneRelationship `json:"relationships,omitempty"`
2425
Metadata Metadata `json:"metadata"`
@@ -36,8 +37,8 @@ func ForOrg(org repositories.OrgRecord, apiBaseURL url.URL, includes ...include.
3637
return OrgResponse{
3738
Name: org.Name,
3839
GUID: org.GUID,
39-
CreatedAt: tools.ZeroIfNil(formatTimestamp(&org.CreatedAt)),
40-
UpdatedAt: tools.ZeroIfNil(formatTimestamp(org.UpdatedAt)),
40+
CreatedAt: tools.ZeroIfNil(toUTC(&org.CreatedAt)),
41+
UpdatedAt: tools.ZeroIfNil(toUTC(org.UpdatedAt)),
4142
Suspended: org.Suspended,
4243
Metadata: Metadata{
4344
Labels: emptyMapIfNil(org.Labels),

api/presenter/package.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package presenter
22

33
import (
44
"net/url"
5+
"time"
56

67
"code.cloudfoundry.org/korifi/api/repositories"
78
"code.cloudfoundry.org/korifi/api/repositories/include"
@@ -20,8 +21,8 @@ type PackageResponse struct {
2021
Relationships map[string]ToOneRelationship `json:"relationships"`
2122
Links PackageLinks `json:"links"`
2223
Metadata Metadata `json:"metadata"`
23-
CreatedAt string `json:"created_at"`
24-
UpdatedAt string `json:"updated_at"`
24+
CreatedAt time.Time `json:"created_at"`
25+
UpdatedAt time.Time `json:"updated_at"`
2526
}
2627

2728
type PackageData struct {
@@ -40,8 +41,8 @@ func ForPackage(record repositories.PackageRecord, baseURL url.URL, includes ...
4041
GUID: record.GUID,
4142
Type: record.Type,
4243
State: record.State,
43-
CreatedAt: tools.ZeroIfNil(formatTimestamp(&record.CreatedAt)),
44-
UpdatedAt: tools.ZeroIfNil(formatTimestamp(record.UpdatedAt)),
44+
CreatedAt: tools.ZeroIfNil(toUTC(&record.CreatedAt)),
45+
UpdatedAt: tools.ZeroIfNil(toUTC(record.UpdatedAt)),
4546
Relationships: ForRelationships(record.Relationships()),
4647
Links: PackageLinks{
4748
Self: Link{

api/presenter/process.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"net/http"
66
"net/url"
7+
"time"
78

89
"code.cloudfoundry.org/korifi/api/repositories"
910
"code.cloudfoundry.org/korifi/api/repositories/include"
@@ -24,8 +25,8 @@ type ProcessResponse struct {
2425
HealthCheck ProcessResponseHealthCheck `json:"health_check"`
2526
Relationships map[string]ToOneRelationship `json:"relationships"`
2627
Metadata Metadata `json:"metadata"`
27-
CreatedAt string `json:"created_at"`
28-
UpdatedAt string `json:"updated_at"`
28+
CreatedAt time.Time `json:"created_at"`
29+
UpdatedAt time.Time `json:"updated_at"`
2930
Links ProcessLinks `json:"links"`
3031
}
3132

@@ -120,8 +121,8 @@ func ForProcess(responseProcess repositories.ProcessRecord, baseURL url.URL, _ .
120121
Labels: responseProcess.Labels,
121122
Annotations: responseProcess.Annotations,
122123
},
123-
CreatedAt: tools.ZeroIfNil(formatTimestamp(&responseProcess.CreatedAt)),
124-
UpdatedAt: tools.ZeroIfNil(formatTimestamp(responseProcess.UpdatedAt)),
124+
CreatedAt: tools.ZeroIfNil(toUTC(&responseProcess.CreatedAt)),
125+
UpdatedAt: tools.ZeroIfNil(toUTC(responseProcess.UpdatedAt)),
125126
Links: ProcessLinks{
126127
Self: Link{
127128
HRef: buildURL(baseURL).appendPath(processesBase, responseProcess.GUID).build(),

api/presenter/process_stats.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ type ProcessStatsResource struct {
2525
}
2626

2727
type ProcessUsage struct {
28-
Time *string `json:"time,omitempty"`
29-
CPU *float64 `json:"cpu,omitempty"`
30-
Mem *int64 `json:"mem,omitempty"`
31-
Disk *int64 `json:"disk,omitempty"`
28+
Time *time.Time `json:"time,omitempty"`
29+
CPU *float64 `json:"cpu,omitempty"`
30+
Mem *int64 `json:"mem,omitempty"`
31+
Disk *int64 `json:"disk,omitempty"`
3232
}
3333

3434
func ForProcessStats(gauges []stats.ProcessGauges, instancesState []stats.ProcessInstanceState, now time.Time) ProcessStatsResponse {
@@ -48,7 +48,7 @@ func ForProcessStats(gauges []stats.ProcessGauges, instancesState []stats.Proces
4848

4949
if gauge, hasGauge := gaugesMap[instanceState.ID]; hasGauge {
5050
statsResource.Usage = tools.PtrTo(ProcessUsage{
51-
Time: formatTimestamp(tools.PtrTo(now)),
51+
Time: toUTC(tools.PtrTo(now)),
5252
CPU: gauge.CPU,
5353
Mem: gauge.Mem,
5454
Disk: gauge.Disk,

0 commit comments

Comments
 (0)