2fas-server/internal/api/browser_extension/app/command/update_browser_extension.go

42 lines
1.0 KiB
Go
Raw Normal View History

2022-12-31 10:22:38 +01:00
package command
import (
"github.com/google/uuid"
2023-01-30 19:59:42 +01:00
"github.com/twofas/2fas-server/internal/api/browser_extension/domain"
2022-12-31 10:22:38 +01:00
)
type UpdateBrowserExtension struct {
BrowserExtensionId string `uri:"extension_id" validate:"required,uuid4"`
Name string `json:"name" validate:"not_blank,lte=64"`
2022-12-31 10:22:38 +01:00
BrowserName string `json:"browser_name" validate:"lte=255"`
BrowserVersion string `json:"browser_version" validate:"lte=32"`
}
type UpdateBrowserExtensionHandler struct {
Repository domain.BrowserExtensionRepository
}
func (h *UpdateBrowserExtensionHandler) Handle(cmd *UpdateBrowserExtension) error {
id, _ := uuid.Parse(cmd.BrowserExtensionId)
browserExtension, err := h.Repository.FindById(id)
if err != nil {
return err
}
if cmd.Name != "" {
browserExtension.Name = cmd.Name
}
if cmd.BrowserVersion != "" {
browserExtension.BrowserName = cmd.BrowserName
}
if cmd.BrowserVersion != "" {
browserExtension.BrowserVersion = cmd.BrowserVersion
}
return h.Repository.Update(browserExtension)
}