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 UpdateMobileDevice struct {
|
|
|
|
Id string `uri:"device_id" validate:"required,uuid4"`
|
2023-03-18 15:31:00 +01:00
|
|
|
Name string `json:"name" validate:"not_blank,max=128"`
|
2022-12-31 10:22:38 +01:00
|
|
|
Platform string `json:"platform" validate:"omitempty,oneof=ios android huawei"`
|
|
|
|
FcmToken string `json:"fcm_token" validate:"max=256"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type UpdateMobileDeviceHandler struct {
|
|
|
|
Repository domain.MobileDeviceRepository
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *UpdateMobileDeviceHandler) Handle(cmd *UpdateMobileDevice) error {
|
|
|
|
deviceId, _ := uuid.Parse(cmd.Id)
|
|
|
|
|
|
|
|
mobileDevice, err := h.Repository.FindById(deviceId)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if cmd.Name != "" {
|
|
|
|
mobileDevice.Name = cmd.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
if cmd.FcmToken != "" {
|
|
|
|
mobileDevice.FcmToken = cmd.FcmToken
|
|
|
|
}
|
|
|
|
|
|
|
|
return h.Repository.Update(mobileDevice)
|
|
|
|
}
|