/
repo_work_item_comment.go
70 lines (54 loc) · 2.2 KB
/
repo_work_item_comment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package postgresql
import (
"context"
"fmt"
"github.com/danicc097/openapi-go-gin-postgres-sqlc/internal/repos"
"github.com/danicc097/openapi-go-gin-postgres-sqlc/internal/repos/postgresql/gen/db"
)
// WorkItemComment represents the repository used for interacting with WorkItemComment records.
type WorkItemComment struct {
q db.Querier
}
// NewWorkItemComment instantiates the WorkItemComment repository.
func NewWorkItemComment() *WorkItemComment {
return &WorkItemComment{
q: NewQuerierWrapper(db.New()),
}
}
var _ repos.WorkItemComment = (*WorkItemComment)(nil)
func (wit *WorkItemComment) Create(ctx context.Context, d db.DBTX, params *db.WorkItemCommentCreateParams) (*db.WorkItemComment, error) {
workItemComment, err := db.CreateWorkItemComment(ctx, d, params)
if err != nil {
return nil, fmt.Errorf("could not create workItemComment: %w", parseDBErrorDetail(err))
}
return workItemComment, nil
}
func (wit *WorkItemComment) Update(ctx context.Context, d db.DBTX, id db.WorkItemCommentID, params *db.WorkItemCommentUpdateParams) (*db.WorkItemComment, error) {
workItemComment, err := wit.ByID(ctx, d, id)
if err != nil {
return nil, fmt.Errorf("could not get workItemComment by id %w", parseDBErrorDetail(err))
}
workItemComment.SetUpdateParams(params)
workItemComment, err = workItemComment.Update(ctx, d)
if err != nil {
return nil, fmt.Errorf("could not update workItemComment: %w", parseDBErrorDetail(err))
}
return workItemComment, err
}
func (wit *WorkItemComment) ByID(ctx context.Context, d db.DBTX, id db.WorkItemCommentID, opts ...db.WorkItemCommentSelectConfigOption) (*db.WorkItemComment, error) {
workItemComment, err := db.WorkItemCommentByWorkItemCommentID(ctx, d, id, opts...)
if err != nil {
return nil, fmt.Errorf("could not get workItemComment: %w", parseDBErrorDetail(err))
}
return workItemComment, nil
}
func (wit *WorkItemComment) Delete(ctx context.Context, d db.DBTX, id db.WorkItemCommentID) (*db.WorkItemComment, error) {
workItemComment := &db.WorkItemComment{
WorkItemCommentID: id,
}
err := workItemComment.Delete(ctx, d)
if err != nil {
return nil, fmt.Errorf("could not delete workItemComment: %w", parseDBErrorDetail(err))
}
return workItemComment, err
}