func (self *User) SignUp(params *ess.Command) error { err := ess.NewValidationError() if self.signedUp { err.Add("username", "not_unique") } if err.Ok() { self.events.PublishEvent( ess.NewEvent("user.signed-up"). For(self). Add("username", params.Get("username").String()). Add("password", params.Get("password").String()). Add("email", params.Get("email").String()), ) } return err.Return() }
func (self *User) HandleCommand(command *ess.Command) error { switch command.Name { case "sign-up": return self.SignUp(command) case "login": return self.Login(command.Get("session").String(), command.Get("password").(*ess.BcryptedPassword)) case "logout": return self.Logout(command.Get("session").String()) } return nil }
func (self *User) HandleCommand(command *ess.Command) error { switch command.Name { case "sign-up": return self.SignUp( command.Get("name").String(), command.Get("email").String(), command.Get("password").String(), ) } return nil }
func ShowEditPostFormError(w http.ResponseWriter, params *ess.Command, err error) { w.Header().Set("Content-Type", "text/html; charset=utf-8") NewHTMLDocument("Edit Post", EditPostForm. Fill(params, err). Action("/posts/"+params.AggregateId()+"/edit"). Param("id", params.AggregateId()). Param("username", params.Get("username").String()). ToHTML("Edit post"), ).WriteHTML(w, "", " ") }
func NewUserFromCommand(command *ess.Command) ess.Aggregate { return NewUser(command.Get("username").String()) }
func UserFromCommand(params *ess.Command) ess.Aggregate { return NewUser(params.Get("username").String()) }
func PostFromCommand(params *ess.Command) ess.Aggregate { return NewPost(params.AggregateId()) }
func (self *Post) HandleCommand(command *ess.Command) error { switch command.Name { case "write-post": return self.Write( command.Get("title").String(), command.Get("body").String(), command.Get("username").String(), ) case "edit-post": return self.Edit( command.Get("title").String(), command.Get("body").String(), command.Get("reason").String(), command.Get("username").String(), ) } return nil }