예제 #1
0
파일: page.go 프로젝트: hxdyxd/pugo
func (ps *PageService) msgDelete(id int64) {
	page := new(model.Page)
	if _, err := core.Db.Where("id = ?", id).Get(page); err != nil {
		return
	}
	if page == nil || page.Id != id {
		return
	}
	data := map[string]string{
		"type":   fmt.Sprint(model.MESSAGE_TYPE_PAGE_REMOVE),
		"author": page.User().Name,
		"title":  page.Title,
		"time":   utils.TimeUnixFormat(page.CreateTime, "01/02 15:04:05"),
	}
	body := com.Expand(MessagePageRemoveTemplate, data)
	message := &model.Message{
		UserId:     page.UserId,
		From:       model.MESSAGE_FROM_PAGE,
		FromId:     page.Id,
		Type:       model.MESSAGE_TYPE_PAGE_REMOVE,
		Body:       body,
		CreateTime: page.CreateTime,
	}
	Message.Save(message)
}
예제 #2
0
파일: page.go 프로젝트: hxdyxd/pugo
func (ps *PageService) msgWrite(isUpdate bool, page *model.Page) {
	data := map[string]string{
		"type":   fmt.Sprint(model.MESSAGE_TYPE_PAGE_CREATE),
		"author": page.User().Name,
		"link":   page.Href(),
		"title":  page.Title,
		"time":   utils.TimeUnixFormat(page.CreateTime, "01/02 15:04:05"),
	}
	var body string
	if isUpdate {
		data["type"] = fmt.Sprint(model.MESSAGE_TYPE_PAGE_UPDATE)
		body = com.Expand(MessagePageUpdateTemplate, data)
	} else {
		body = com.Expand(MessagePageCreateTemplate, data)
	}
	message := &model.Message{
		UserId:     page.UserId,
		From:       model.MESSAGE_FROM_PAGE,
		FromId:     page.Id,
		Type:       model.MESSAGE_TYPE_PAGE_CREATE,
		Body:       body,
		CreateTime: page.CreateTime,
	}
	if isUpdate {
		message.Type = model.MESSAGE_TYPE_PAGE_UPDATE
	}
	Message.Save(message)
}
예제 #3
0
파일: page.go 프로젝트: hxdyxd/pugo
func (as *PageService) Read(v interface{}) (*Result, error) {
	opt, ok := v.(PageReadOption)
	if !ok {
		return nil, ErrServiceFuncNeedType(as.Read, opt)
	}
	whereStr, whereArgs := opt.toWhereString()
	a := new(model.Page)
	if _, err := core.Db.Where(whereStr, whereArgs...).Get(a); err != nil {
		return nil, err
	}
	if a.Id == 0 {
		return nil, ErrPageNotFound
	}
	if opt.IsPublish && !a.IsPublish() {
		return nil, ErrPageNotFound
	}
	if opt.IsHit {
		if _, err := core.Db.Exec("UPDATE page SET hits = hits + 1 WHERE id = ?", a.Id); err != nil {
			return nil, err
		}
	}
	return newResult(as.Read, a), nil
}