package query import ( "context" "forge.cadoles.com/Cadoles/fake-sms/internal/model" "forge.cadoles.com/Cadoles/fake-sms/internal/storm" "github.com/pkg/errors" "gitlab.com/wpetit/goweb/cqrs" "gitlab.com/wpetit/goweb/middleware/container" ) type OpenSMSRequest struct { SMSID int } type OpenSMSData struct { SMS *model.SMS } func HandleOpenSMS(ctx context.Context, qry cqrs.Query) (interface{}, error) { req, ok := qry.Request().(*OpenSMSRequest) if !ok { return nil, cqrs.ErrUnexpectedRequest } ctn, err := container.From(ctx) if err != nil { return nil, errors.Wrap(err, "could not retrieve service container") } db, err := storm.From(ctn) if err != nil { return nil, errors.Wrap(err, "could not retrieve storm service") } sms := &model.SMS{} if err := db.One("ID", req.SMSID, sms); err != nil { return nil, errors.Wrap(err, "could not find email") } return &OpenSMSData{sms}, nil }