// get a page // // in : *PageRouteParam // out : { // "page":*Page // } // func (_ *PageApi) Get(v interface{}) *Res { param, ok := v.(*PageRouteParam) if !ok { return Fail(paramTypeError(param)) } var ( page *model.Page err error ) if param.Id > 0 { page, err = model.GetPageBy("id", param.Id) if err != nil { return Fail(err) } } if param.Link != "" { page, err = model.GetPageBy("link", param.Link) if err != nil { return Fail(err) } } // check value if param.Id > 0 && param.Id != page.Id { return Fail(ERR_PAGE_MISSING) } if param.Link != "" && param.Link != page.Link { return Fail(ERR_PAGE_MISSING) } return Success(map[string]interface{}{ "page": page, }) }
func (w *Write) getPage() { w.Title("Write Page") id := w.FormInt64("id") if id > 0 { page, err := model.GetPageBy("id", id) if err != nil { w.RenderError(500, err) return } w.Title("Write Page - " + page.Title) w.Assign("Page", page) } w.Render("write_page.tmpl") }
// write a page, // if input id, update page by id, // or save new page // // in : *PageForm // out : { // "page":*Page // } // func (_ *PageApi) Write(v interface{}) *Res { form, ok := v.(*PageForm) if !ok { return Fail(paramTypeError(form)) } // check link a, err := model.GetPageBy("link", form.Link) if err != nil { return Fail(err) } if a != nil { if form.Id == 0 || form.Id != a.Id { return Fail(ERR_PAGE_LINK) } } // create page object page := &model.Page{ Id: form.Id, AuthorId: form.AuthorId, Title: form.Title, Link: form.Link, Body: form.Body, Hits: 1, Comments: 0, Status: model.PAGE_STATUS_PUBLISH, CommentStatus: model.PAGE_COMMENT_OPEN, } if form.Draft != "" { page.Status = model.ARTICLE_STATUS_DRAFT } // save page page, err = model.SavePage(page) if err != nil { return Fail(err) } return Success(map[string]interface{}{ "page": page, }) }