(ctx context.Context, username string, per, page int, onlyPublic bool)
| 49 | } |
| 50 | |
| 51 | func (s *CodeStore) ByUsername(ctx context.Context, username string, per, page int, onlyPublic bool) (codes []Code, total int, err error) { |
| 52 | query := s.db.Operator.Core. |
| 53 | NewSelect(). |
| 54 | Model(&codes). |
| 55 | Relation("Repository.Tags"). |
| 56 | Relation("Repository.User"). |
| 57 | Where("repository.path like ?", fmt.Sprintf("%s/%%", username)) |
| 58 | |
| 59 | if onlyPublic { |
| 60 | query = query.Where("repository.private = ?", false) |
| 61 | } |
| 62 | query = query.Order("code.created_at DESC"). |
| 63 | Limit(per). |
| 64 | Offset((page - 1) * per) |
| 65 | |
| 66 | err = query.Scan(ctx) |
| 67 | if err != nil { |
| 68 | return |
| 69 | } |
| 70 | total, err = query.Count(ctx) |
| 71 | if err != nil { |
| 72 | return |
| 73 | } |
| 74 | return |
| 75 | } |
| 76 | |
| 77 | func (s *CodeStore) UserLikesCodes(ctx context.Context, userID int64, per, page int) (codes []Code, total int, err error) { |
| 78 | query := s.db.Operator.Core. |
no test coverage detected