Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apiserver/controllers/domains/domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func Index(c *gin.Context) {
return
}

domainsAsJSON := []interface{}{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah PR is half done because of this: #72 (comment)

I wanted to return domains as "objects" but the CLI depends on them being just strings.


c.JSON(http.StatusOK, gin.H{
"domains": domNames,
})
Expand Down Expand Up @@ -110,6 +112,12 @@ func Create(c *gin.Context) {
return
}

// Re-fetch from db to get correct timestamps.
if err := db.First(dom, dom.ID).Error; err != nil {
controllers.InternalServerError(c, err)
return
}

if proj.ActiveDeploymentID != nil {
j, err := job.NewWithJSON(queues.Deploy, &messages.DeployJobData{
DeploymentID: *proj.ActiveDeploymentID,
Expand Down
52 changes: 40 additions & 12 deletions apiserver/controllers/domains/domains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,20 @@ var _ = Describe("Domains", func() {
_, err := b.ReadFrom(res.Body)
Expect(err).To(BeNil())

dom := &domain.Domain{}
err = db.Last(dom).Error
Expect(err).To(BeNil())

createdAtJSON, err := dom.CreatedAt.MarshalJSON()
Expect(err).To(BeNil())

Expect(res.StatusCode).To(Equal(http.StatusCreated))
Expect(b.String()).To(MatchJSON(`{
Expect(b.String()).To(MatchJSON(fmt.Sprintf(`{
"domain": {
"name": "www.foo-bar-express.com"
"name": "www.foo-bar-express.com",
"created_at": %s
}
}`))
}`, createdAtJSON)))
})
})

Expand Down Expand Up @@ -369,12 +377,20 @@ var _ = Describe("Domains", func() {
_, err := b.ReadFrom(res.Body)
Expect(err).To(BeNil())

dom := &domain.Domain{}
err = db.Last(dom).Error
Expect(err).To(BeNil())

createdAtJSON, err := dom.CreatedAt.MarshalJSON()
Expect(err).To(BeNil())

Expect(res.StatusCode).To(Equal(http.StatusCreated))
Expect(b.String()).To(MatchJSON(`{
Expect(b.String()).To(MatchJSON(fmt.Sprintf(`{
"domain": {
"name": "www.foo-bar-express.com"
"name": "www.foo-bar-express.com",
"created_at": %s
}
}`))
}`, createdAtJSON)))
})

It("creates a domain record in the DB", func() {
Expand All @@ -400,12 +416,20 @@ var _ = Describe("Domains", func() {
_, err := b.ReadFrom(res.Body)
Expect(err).To(BeNil())

dom := &domain.Domain{}
err = db.Last(dom).Error
Expect(err).To(BeNil())

createdAtJSON, err := dom.CreatedAt.MarshalJSON()
Expect(err).To(BeNil())

Expect(res.StatusCode).To(Equal(http.StatusCreated))
Expect(b.String()).To(MatchJSON(`{
Expect(b.String()).To(MatchJSON(fmt.Sprintf(`{
"domain": {
"name": "www.foo-bar-express.com"
"name": "www.foo-bar-express.com",
"created_at": %s
}
}`))
}`, createdAtJSON)))
})

It("creates a domain record in the DB", func() {
Expand All @@ -429,12 +453,16 @@ var _ = Describe("Domains", func() {
_, err := b.ReadFrom(res.Body)
Expect(err).To(BeNil())

createdAtJSON, err := dom.CreatedAt.MarshalJSON()
Expect(err).To(BeNil())

Expect(res.StatusCode).To(Equal(http.StatusCreated))
Expect(b.String()).To(MatchJSON(`{
Expect(b.String()).To(MatchJSON(fmt.Sprintf(`{
"domain": {
"name": "www.foo-bar-express.com"
"name": "www.foo-bar-express.com",
"created_at": %s
}
}`))
}`, createdAtJSON)))

Expect(dom.Name).To(Equal("www.foo-bar-express.com"))
Expect(dom.ProjectID).To(Equal(proj.ID))
Expand Down
5 changes: 4 additions & 1 deletion apiserver/models/domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package domain
import (
"regexp"
"strings"
"time"

"github.com/jinzhu/gorm"
"github.com/nitrous-io/rise-server/shared"
Expand Down Expand Up @@ -69,8 +70,10 @@ func (d *Domain) Validate() map[string]string {
// Returns a struct that can be converted to JSON
func (d *Domain) AsJSON() interface{} {
return struct {
Name string `json:"name"`
Name string `json:"name"`
CreatedAt time.Time `json:"created_at"`
}{
d.Name,
d.CreatedAt,
}
}