| 53 | } |
| 54 | |
| 55 | func (s *Store) ListIssueComment(ctx context.Context, find *FindIssueCommentMessage) ([]*IssueCommentMessage, error) { |
| 56 | q := qb.Q().Space(` |
| 57 | SELECT |
| 58 | project, |
| 59 | resource_id, |
| 60 | creator, |
| 61 | created_at, |
| 62 | updated_at, |
| 63 | issue_id, |
| 64 | payload |
| 65 | FROM |
| 66 | issue_comment |
| 67 | WHERE project = ? |
| 68 | `, find.ProjectID) |
| 69 | |
| 70 | if v := find.ResourceID; v != nil { |
| 71 | q.And("resource_id = ?", *v) |
| 72 | } |
| 73 | if v := find.IssueUID; v != nil { |
| 74 | q.And("issue_id = ?", *v) |
| 75 | } |
| 76 | |
| 77 | q.Space("ORDER BY created_at ASC") |
| 78 | if v := find.Limit; v != nil { |
| 79 | q.Space("LIMIT ?", *v) |
| 80 | } |
| 81 | if v := find.Offset; v != nil { |
| 82 | q.Space("OFFSET ?", *v) |
| 83 | } |
| 84 | |
| 85 | query, args, err := q.ToSQL() |
| 86 | if err != nil { |
| 87 | return nil, errors.Wrapf(err, "failed to build sql") |
| 88 | } |
| 89 | |
| 90 | rows, err := s.GetDB().QueryContext(ctx, query, args...) |
| 91 | if err != nil { |
| 92 | return nil, errors.Wrapf(err, "failed to query context") |
| 93 | } |
| 94 | defer rows.Close() |
| 95 | |
| 96 | var issueComments []*IssueCommentMessage |
| 97 | for rows.Next() { |
| 98 | ic := IssueCommentMessage{ |
| 99 | Payload: &storepb.IssueCommentPayload{}, |
| 100 | } |
| 101 | var p []byte |
| 102 | if err := rows.Scan( |
| 103 | &ic.ProjectID, |
| 104 | &ic.ResourceID, |
| 105 | &ic.CreatorEmail, |
| 106 | &ic.CreatedAt, |
| 107 | &ic.UpdatedAt, |
| 108 | &ic.IssueUID, |
| 109 | &p, |
| 110 | ); err != nil { |
| 111 | return nil, errors.Wrapf(err, "failed to scan") |
| 112 | } |