action.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "time"
  7. )
  8. // Operation types of user action.
  9. const (
  10. OP_CREATE_REPO = iota + 1
  11. OP_DELETE_REPO
  12. OP_STAR_REPO
  13. OP_FOLLOW_REPO
  14. OP_COMMIT_REPO
  15. OP_PULL_REQUEST
  16. )
  17. // An Action represents
  18. type Action struct {
  19. Id int64
  20. UserId int64
  21. UserName string
  22. OpType int
  23. RepoId int64
  24. RepoName string
  25. Content string
  26. Created time.Time `xorm:"created"`
  27. }
  28. // NewRepoAction inserts action for create repository.
  29. func NewRepoAction(user *User, repo *Repository) error {
  30. _, err := orm.InsertOne(&Action{
  31. UserId: user.Id,
  32. UserName: user.Name,
  33. OpType: OP_CREATE_REPO,
  34. RepoId: repo.Id,
  35. RepoName: repo.Name,
  36. })
  37. return err
  38. }
  39. func GetFeeds(userid, offset int64) ([]Action, error) {
  40. actions := make([]Action, 0, 20)
  41. err := orm.Limit(20, int(offset)).Desc("id").Where("user_id=?", userid).Find(&actions)
  42. return actions, err
  43. }