Skip to content

Commit

Permalink
Merge pull request #9 from benjaminbear/fix_cname_delete
Browse files Browse the repository at this point in the history
fix model validation and preloading
  • Loading branch information
benjaminbear authored Jul 28, 2021
2 parents 79bd7fe + eb947bd commit 56c4693
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
dist: bionic

language: go

env: GO111MODULE=on

go:
- 1.15.x
- 1.16.x
- 1.13.x
- 1.14.x

git:
depth: 1

script:
before_script:
- cd dyndns

script:
- go test -v ./...
- go build ./...

Expand Down
2 changes: 1 addition & 1 deletion dyndns/handler/cname.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (h *Handler) DeleteCName(c echo.Context) (err error) {
}

cname := &model.CName{}
if err = h.DB.First(cname, id).Error; err != nil {
if err = h.DB.Preload("Target").First(cname, id).Error; err != nil {
return c.JSON(http.StatusBadRequest, &Error{err.Error()})
}

Expand Down
1 change: 0 additions & 1 deletion dyndns/handler/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ func (h *Handler) UpdateIP(c echo.Context) (err error) {
}

func (h *Handler) checkUniqueHostname(hostname, domain string) error {
fmt.Println(hostname, domain)
hosts := new([]model.Host)
if err := h.DB.Where(&model.Host{Hostname: hostname, Domain: domain}).Find(hosts).Error; err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion dyndns/model/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type Host struct {
gorm.Model
Hostname string `gorm:"unique_index:idx_host_domain;not null" form:"hostname" validate:"required,hostname"`
Domain string `gorm:"unique_index:idx_host_domain;not null" validate:"required,hostname"`
Domain string `gorm:"unique_index:idx_host_domain;not null" form:"domain" validate:"required,hostname"`
Ip string `form:"ip" validate:"omitempty,ipv4"`
Ttl int `form:"ttl" validate:"required,min=20,max=86400"`
LastUpdate time.Time `form:"lastupdate"`
Expand Down

0 comments on commit 56c4693

Please sign in to comment.