-
-
Save vitiko/2db8e9086f94fe7b5f860149eb461ee8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (cc *CPaperImpl) List(ctx router.Context, in *empty.Empty) (*schema.CommercialPaperList, error) { | |
if res, err := cc.state(ctx).List(&schema.CommercialPaper{}); err != nil { | |
return nil, err | |
} else { | |
return res.(*schema.CommercialPaperList), nil | |
} | |
} | |
func (cc *CPaperImpl) Get(ctx router.Context, id *schema.CommercialPaperId) (*schema.CommercialPaper, error) { | |
if res, err := cc.state(ctx).Get(id, &schema.CommercialPaper{}); err != nil { | |
return nil, err | |
} else { | |
return res.(*schema.CommercialPaper), nil | |
} | |
} | |
func (cc *CPaperImpl) Issue(ctx router.Context, issue *schema.IssueCommercialPaper) (*schema.CommercialPaper, error) { | |
// Validate input message using the rules defined in schema | |
if err := issue.Validate(); err != nil { | |
return nil, errors.Wrap(err, "payload validation") | |
} | |
// Create state entry | |
cpaper := &schema.CommercialPaper{ | |
Issuer: issue.Issuer, | |
PaperNumber: issue.PaperNumber, | |
Owner: issue.Issuer, | |
IssueDate: issue.IssueDate, | |
MaturityDate: issue.MaturityDate, | |
FaceValue: issue.FaceValue, | |
State: schema.CommercialPaper_ISSUED, // Initial state | |
ExternalId: issue.ExternalId, | |
} | |
if err := cc.event(ctx).Set(issue); err != nil { | |
return nil, err | |
} | |
if err := cc.state(ctx).Insert(cpaper); err != nil { | |
return nil, err | |
} | |
return cpaper, nil | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment