diff --git a/internal/model/host.go b/internal/model/host.go index 626f222..27c39fc 100644 --- a/internal/model/host.go +++ b/internal/model/host.go @@ -1,6 +1,7 @@ package model import ( + "fmt" "go.mongodb.org/mongo-driver/bson/primitive" "time" ) @@ -21,3 +22,17 @@ type HostRequest struct { Host string `json:"host"` Stage string `json:"stage"` } + +func (h *Host) String() string { + return fmt.Sprintf( + fmt.Sprintf("Id: %s", h.Id.String()), + fmt.Sprintf("ProjectId: %s", h.ProjectId), + fmt.Sprintf("Host: %s", h.Host), + fmt.Sprintf("Stage: %s", h.Stage), + fmt.Sprintf("Verified: %s", h.VerifyToken), + fmt.Sprintf("VerifyToken: %s", h.VerifyToken), + fmt.Sprintf("UpdatedAt: %s", h.UpdatedAt), + fmt.Sprintf("CreatedAt: %s", h.CreatedAt), + fmt.Sprintf("DeletedAt: %s", h.DeletedAt), + ) +} diff --git a/internal/service/domain_notification.go b/internal/service/domain_notification.go index ff7977e..77e722d 100644 --- a/internal/service/domain_notification.go +++ b/internal/service/domain_notification.go @@ -20,31 +20,43 @@ const ( func (c *Client) SendNotification(host string, notification model.Notification) (*model.SuccessMessage, error) { err := validateNotificationRequest(notification) if err != nil { + log.Debug("notification-request-validation is failed; ", err.Error()) return nil, err } validatedHost, err := url.Parse(host) if err != nil { + log.Debug("parse host is failed; ", err.Error()) return nil, fmt.Errorf("failed to parse host") } hosts, err := c.db.ListHosts(model.Host{ProjectId: notification.ProjectId}) if err != nil { log.Error(err) + log.Debug("failed to list hosts; ", err.Error()) return nil, fmt.Errorf("failed to verify host") } if index := ifHostInHosts(validatedHost.Host, hosts); hosts == nil || index == -1 || !hosts[index].Verified { + log.Debug( + "failed to verify hosts; ", + fmt.Sprintf("host: %s; ", validatedHost.Host), + fmt.Sprintf("index: %d; ", index), + fmt.Sprintf("length: %d; ", len(hosts)), + fmt.Sprintf("hosts: %v", hosts), + ) return nil, fmt.Errorf("failed to verify host") } flows, err := c.db.ListFlows(model.Flow{ProjectId: notification.ProjectId}) if err != nil { log.Error(err) + log.Debug("failed to list flows; ", err.Error()) return nil, fmt.Errorf("failed to list flows") } if flows == nil || len(flows) == 0 { + log.Debug("failed to list flows; ", "there are no flows; ", flows) return nil, fmt.Errorf("failed to list flows") }