2fas-server/internal/api/mobile/app/command/remove_device_extension.go

29 lines
760 B
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/mobile/domain"
2022-12-31 10:22:38 +01:00
)
type RemoveDevicePairedExtension struct {
DeviceId string `uri:"device_id" validate:"required,uuid4"`
ExtensionId string `uri:"extension_id" validate:"required,uuid4"`
}
type RemoveDeviceExtensionHandler struct {
MobileDeviceExtensionsRepository domain.MobileDeviceExtensionsRepository
}
func (h *RemoveDeviceExtensionHandler) Handle(cmd *RemoveDevicePairedExtension) error {
deviceId, _ := uuid.Parse(cmd.DeviceId)
extId, _ := uuid.Parse(cmd.ExtensionId)
extension, err := h.MobileDeviceExtensionsRepository.FindById(deviceId, extId)
if err != nil {
return err
}
return h.MobileDeviceExtensionsRepository.Delete(extension)
}