Skip to content

Commit

Permalink
add debug-logs in "send-notification"
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mattia-m committed Nov 24, 2023
1 parent 33aed59 commit 7842917
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
15 changes: 15 additions & 0 deletions internal/model/host.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package model

import (
"fmt"
"go.mongodb.org/mongo-driver/bson/primitive"
"time"
)
Expand All @@ -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),
)
}
12 changes: 12 additions & 0 deletions internal/service/domain_notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit 7842917

Please sign in to comment.