feat: add comments badge to task card
This commit is contained in:
@ -74,6 +74,7 @@ type Querier interface {
|
||||
GetAssignedTasksDueDateForUserID(ctx context.Context, arg GetAssignedTasksDueDateForUserIDParams) ([]Task, error)
|
||||
GetAssignedTasksProjectForUserID(ctx context.Context, arg GetAssignedTasksProjectForUserIDParams) ([]Task, error)
|
||||
GetAuthTokenByID(ctx context.Context, tokenID uuid.UUID) (AuthToken, error)
|
||||
GetCommentCountForTask(ctx context.Context, taskID uuid.UUID) (int64, error)
|
||||
GetCommentsForTaskID(ctx context.Context, taskID uuid.UUID) ([]TaskComment, error)
|
||||
GetConfirmTokenByEmail(ctx context.Context, email string) (UserAccountConfirmToken, error)
|
||||
GetConfirmTokenByID(ctx context.Context, confirmTokenID uuid.UUID) (UserAccountConfirmToken, error)
|
||||
|
@ -95,3 +95,6 @@ SELECT task.* FROM task_assigned
|
||||
)
|
||||
)
|
||||
ORDER BY task.due_date DESC, task_group.project_id DESC;
|
||||
|
||||
-- name: GetCommentCountForTask :one
|
||||
SELECT COUNT(*) FROM task_comment WHERE task_id = $1;
|
||||
|
@ -316,6 +316,17 @@ func (q *Queries) GetAssignedTasksProjectForUserID(ctx context.Context, arg GetA
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getCommentCountForTask = `-- name: GetCommentCountForTask :one
|
||||
SELECT COUNT(*) FROM task_comment WHERE task_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetCommentCountForTask(ctx context.Context, taskID uuid.UUID) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, getCommentCountForTask, taskID)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const getCommentsForTaskID = `-- name: GetCommentsForTaskID :many
|
||||
SELECT task_comment_id, task_id, created_at, updated_at, created_by, pinned, message FROM task_comment WHERE task_id = $1 ORDER BY created_at
|
||||
`
|
||||
|
@ -73,6 +73,11 @@ type ComplexityRoot struct {
|
||||
Total func(childComplexity int) int
|
||||
}
|
||||
|
||||
CommentsBadge struct {
|
||||
Total func(childComplexity int) int
|
||||
Unread func(childComplexity int) int
|
||||
}
|
||||
|
||||
CreateTaskCommentPayload struct {
|
||||
Comment func(childComplexity int) int
|
||||
TaskID func(childComplexity int) int
|
||||
@ -419,6 +424,7 @@ type ComplexityRoot struct {
|
||||
|
||||
TaskBadges struct {
|
||||
Checklist func(childComplexity int) int
|
||||
Comments func(childComplexity int) int
|
||||
}
|
||||
|
||||
TaskChecklist struct {
|
||||
@ -768,6 +774,20 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
||||
|
||||
return e.complexity.ChecklistBadge.Total(childComplexity), true
|
||||
|
||||
case "CommentsBadge.total":
|
||||
if e.complexity.CommentsBadge.Total == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.complexity.CommentsBadge.Total(childComplexity), true
|
||||
|
||||
case "CommentsBadge.unread":
|
||||
if e.complexity.CommentsBadge.Unread == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.complexity.CommentsBadge.Unread(childComplexity), true
|
||||
|
||||
case "CreateTaskCommentPayload.comment":
|
||||
if e.complexity.CreateTaskCommentPayload.Comment == nil {
|
||||
break
|
||||
@ -2553,6 +2573,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
||||
|
||||
return e.complexity.TaskBadges.Checklist(childComplexity), true
|
||||
|
||||
case "TaskBadges.comments":
|
||||
if e.complexity.TaskBadges.Comments == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.complexity.TaskBadges.Comments(childComplexity), true
|
||||
|
||||
case "TaskChecklist.id":
|
||||
if e.complexity.TaskChecklist.ID == nil {
|
||||
break
|
||||
@ -3212,8 +3239,14 @@ type ChecklistBadge {
|
||||
total: Int!
|
||||
}
|
||||
|
||||
type CommentsBadge {
|
||||
total: Int!
|
||||
unread: Boolean!
|
||||
}
|
||||
|
||||
type TaskBadges {
|
||||
checklist: ChecklistBadge
|
||||
comments: CommentsBadge
|
||||
}
|
||||
|
||||
type CausedBy {
|
||||
@ -5280,6 +5313,76 @@ func (ec *executionContext) _ChecklistBadge_total(ctx context.Context, field gra
|
||||
return ec.marshalNInt2int(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _CommentsBadge_total(ctx context.Context, field graphql.CollectedField, obj *CommentsBadge) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
ret = graphql.Null
|
||||
}
|
||||
}()
|
||||
fc := &graphql.FieldContext{
|
||||
Object: "CommentsBadge",
|
||||
Field: field,
|
||||
Args: nil,
|
||||
IsMethod: false,
|
||||
IsResolver: false,
|
||||
}
|
||||
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return obj.Total, nil
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(int)
|
||||
fc.Result = res
|
||||
return ec.marshalNInt2int(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _CommentsBadge_unread(ctx context.Context, field graphql.CollectedField, obj *CommentsBadge) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
ret = graphql.Null
|
||||
}
|
||||
}()
|
||||
fc := &graphql.FieldContext{
|
||||
Object: "CommentsBadge",
|
||||
Field: field,
|
||||
Args: nil,
|
||||
IsMethod: false,
|
||||
IsResolver: false,
|
||||
}
|
||||
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return obj.Unread, nil
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(bool)
|
||||
fc.Result = res
|
||||
return ec.marshalNBoolean2bool(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _CreateTaskCommentPayload_taskID(ctx context.Context, field graphql.CollectedField, obj *CreateTaskCommentPayload) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
@ -14831,6 +14934,38 @@ func (ec *executionContext) _TaskBadges_checklist(ctx context.Context, field gra
|
||||
return ec.marshalOChecklistBadge2ᚖgithubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐChecklistBadge(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _TaskBadges_comments(ctx context.Context, field graphql.CollectedField, obj *TaskBadges) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
ret = graphql.Null
|
||||
}
|
||||
}()
|
||||
fc := &graphql.FieldContext{
|
||||
Object: "TaskBadges",
|
||||
Field: field,
|
||||
Args: nil,
|
||||
IsMethod: false,
|
||||
IsResolver: false,
|
||||
}
|
||||
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return obj.Comments, nil
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(*CommentsBadge)
|
||||
fc.Result = res
|
||||
return ec.marshalOCommentsBadge2ᚖgithubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐCommentsBadge(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _TaskChecklist_id(ctx context.Context, field graphql.CollectedField, obj *db.TaskChecklist) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
@ -20124,6 +20259,38 @@ func (ec *executionContext) _ChecklistBadge(ctx context.Context, sel ast.Selecti
|
||||
return out
|
||||
}
|
||||
|
||||
var commentsBadgeImplementors = []string{"CommentsBadge"}
|
||||
|
||||
func (ec *executionContext) _CommentsBadge(ctx context.Context, sel ast.SelectionSet, obj *CommentsBadge) graphql.Marshaler {
|
||||
fields := graphql.CollectFields(ec.OperationContext, sel, commentsBadgeImplementors)
|
||||
|
||||
out := graphql.NewFieldSet(fields)
|
||||
var invalids uint32
|
||||
for i, field := range fields {
|
||||
switch field.Name {
|
||||
case "__typename":
|
||||
out.Values[i] = graphql.MarshalString("CommentsBadge")
|
||||
case "total":
|
||||
out.Values[i] = ec._CommentsBadge_total(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
case "unread":
|
||||
out.Values[i] = ec._CommentsBadge_unread(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
default:
|
||||
panic("unknown field " + strconv.Quote(field.Name))
|
||||
}
|
||||
}
|
||||
out.Dispatch()
|
||||
if invalids > 0 {
|
||||
return graphql.Null
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
var createTaskCommentPayloadImplementors = []string{"CreateTaskCommentPayload"}
|
||||
|
||||
func (ec *executionContext) _CreateTaskCommentPayload(ctx context.Context, sel ast.SelectionSet, obj *CreateTaskCommentPayload) graphql.Marshaler {
|
||||
@ -22580,6 +22747,8 @@ func (ec *executionContext) _TaskBadges(ctx context.Context, sel ast.SelectionSe
|
||||
out.Values[i] = graphql.MarshalString("TaskBadges")
|
||||
case "checklist":
|
||||
out.Values[i] = ec._TaskBadges_checklist(ctx, field, obj)
|
||||
case "comments":
|
||||
out.Values[i] = ec._TaskBadges_comments(ctx, field, obj)
|
||||
default:
|
||||
panic("unknown field " + strconv.Quote(field.Name))
|
||||
}
|
||||
@ -26306,6 +26475,13 @@ func (ec *executionContext) marshalOChecklistBadge2ᚖgithubᚗcomᚋjordanknott
|
||||
return ec._ChecklistBadge(ctx, sel, v)
|
||||
}
|
||||
|
||||
func (ec *executionContext) marshalOCommentsBadge2ᚖgithubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐCommentsBadge(ctx context.Context, sel ast.SelectionSet, v *CommentsBadge) graphql.Marshaler {
|
||||
if v == nil {
|
||||
return graphql.Null
|
||||
}
|
||||
return ec._CommentsBadge(ctx, sel, v)
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalOCreateTaskComment2ᚖgithubᚗcomᚋjordanknottᚋtaskcafeᚋinternalᚋgraphᚐCreateTaskComment(ctx context.Context, v interface{}) (*CreateTaskComment, error) {
|
||||
if v == nil {
|
||||
return nil, nil
|
||||
|
@ -33,6 +33,11 @@ type ChecklistBadge struct {
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
type CommentsBadge struct {
|
||||
Total int `json:"total"`
|
||||
Unread bool `json:"unread"`
|
||||
}
|
||||
|
||||
type CreateTaskChecklist struct {
|
||||
TaskID uuid.UUID `json:"taskID"`
|
||||
Name string `json:"name"`
|
||||
@ -431,6 +436,7 @@ type TaskActivityData struct {
|
||||
|
||||
type TaskBadges struct {
|
||||
Checklist *ChecklistBadge `json:"checklist"`
|
||||
Comments *CommentsBadge `json:"comments"`
|
||||
}
|
||||
|
||||
type TaskPositionUpdate struct {
|
||||
|
@ -138,8 +138,14 @@ type ChecklistBadge {
|
||||
total: Int!
|
||||
}
|
||||
|
||||
type CommentsBadge {
|
||||
total: Int!
|
||||
unread: Boolean!
|
||||
}
|
||||
|
||||
type TaskBadges {
|
||||
checklist: ChecklistBadge
|
||||
comments: CommentsBadge
|
||||
}
|
||||
|
||||
type CausedBy {
|
||||
@ -994,4 +1000,3 @@ type DeleteUserAccountPayload {
|
||||
ok: Boolean!
|
||||
userAccount: UserAccount!
|
||||
}
|
||||
|
||||
|
@ -1721,8 +1721,9 @@ func (r *taskResolver) Badges(ctx context.Context, obj *db.Task) (*TaskBadges, e
|
||||
if err != nil {
|
||||
return &TaskBadges{}, err
|
||||
}
|
||||
if len(checklists) == 0 {
|
||||
return &TaskBadges{Checklist: nil}, err
|
||||
comments, err := r.Repository.GetCommentCountForTask(ctx, obj.TaskID)
|
||||
if err != nil {
|
||||
return &TaskBadges{}, err
|
||||
}
|
||||
complete := 0
|
||||
total := 0
|
||||
@ -1738,10 +1739,15 @@ func (r *taskResolver) Badges(ctx context.Context, obj *db.Task) (*TaskBadges, e
|
||||
}
|
||||
}
|
||||
}
|
||||
if complete == 0 && total == 0 {
|
||||
return &TaskBadges{Checklist: nil}, nil
|
||||
var taskChecklist *ChecklistBadge
|
||||
if total != 0 {
|
||||
taskChecklist = &ChecklistBadge{Total: total, Complete: complete}
|
||||
}
|
||||
return &TaskBadges{Checklist: &ChecklistBadge{Total: total, Complete: complete}}, nil
|
||||
var taskComments *CommentsBadge
|
||||
if comments != 0 {
|
||||
taskComments = &CommentsBadge{Total: int(comments), Unread: false}
|
||||
}
|
||||
return &TaskBadges{Checklist: taskChecklist, Comments: taskComments}, nil
|
||||
}
|
||||
|
||||
func (r *taskResolver) Activity(ctx context.Context, obj *db.Task) ([]db.TaskActivity, error) {
|
||||
|
@ -138,8 +138,14 @@ type ChecklistBadge {
|
||||
total: Int!
|
||||
}
|
||||
|
||||
type CommentsBadge {
|
||||
total: Int!
|
||||
unread: Boolean!
|
||||
}
|
||||
|
||||
type TaskBadges {
|
||||
checklist: ChecklistBadge
|
||||
comments: CommentsBadge
|
||||
}
|
||||
|
||||
type CausedBy {
|
||||
|
Reference in New Issue
Block a user