-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUpdateWebhook.go
executable file
·39 lines (32 loc) · 1.09 KB
/
UpdateWebhook.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package logic
import (
"ch/kirari04/videocms/inits"
"ch/kirari04/videocms/models"
"errors"
"log"
"net/http"
"github.com/labstack/echo/v4"
"gorm.io/gorm"
)
func UpdateWebhook(validated *models.WebhookUpdateValidation, userID uint) (status int, response string, err error) {
var webhook models.Webhook
if res := inits.DB.Where(&models.Webhook{
UserID: userID,
}).First(&webhook, validated.WebhookID); res.Error != nil {
if errors.Is(res.Error, gorm.ErrRecordNotFound) {
return http.StatusNotFound, "", echo.ErrNotFound
}
log.Printf("Failed to query webhook %v: %v", validated.WebhookID, res.Error)
return http.StatusInternalServerError, "", echo.ErrInternalServerError
}
webhook.Name = validated.Name
webhook.Url = validated.Url
webhook.Rpm = validated.Rpm
webhook.ReqQuery = validated.ReqQuery
webhook.ResField = validated.ResField
if res := inits.DB.Save(&webhook); res.Error != nil {
log.Printf("Failed to update webhook %v: %v", validated.WebhookID, res.Error)
return http.StatusInternalServerError, "", echo.ErrInternalServerError
}
return http.StatusOK, "ok", nil
}