44 lines
881 B
Go
44 lines
881 B
Go
|
package command
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
"github.com/pkg/errors"
|
||
|
|
||
|
"forge.cadoles.com/Cadoles/fake-sms/internal/model"
|
||
|
"forge.cadoles.com/Cadoles/fake-sms/internal/storm"
|
||
|
"gitlab.com/wpetit/goweb/cqrs"
|
||
|
"gitlab.com/wpetit/goweb/middleware/container"
|
||
|
)
|
||
|
|
||
|
type DeleteSMSRequest struct {
|
||
|
SMSID int
|
||
|
}
|
||
|
|
||
|
func HandleDeleteSMS(ctx context.Context, cmd cqrs.Command) error {
|
||
|
req, ok := cmd.Request().(*DeleteSMSRequest)
|
||
|
if !ok {
|
||
|
return cqrs.ErrUnexpectedRequest
|
||
|
}
|
||
|
|
||
|
ctn, err := container.From(ctx)
|
||
|
if err != nil {
|
||
|
return errors.Wrap(err, "could not retrieve service container")
|
||
|
}
|
||
|
|
||
|
db, err := storm.From(ctn)
|
||
|
if err != nil {
|
||
|
return errors.Wrap(err, "could not retrieve storm service")
|
||
|
}
|
||
|
|
||
|
if err := db.DeleteStruct(&model.SMS{ID: req.SMSID}); err != nil {
|
||
|
if err == storm.ErrNotFound {
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
return errors.Wrap(err, "could not delete email")
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|