Skip to content

Commit 7b629d3

Browse files
committed
feat(coderd/database): add GetTaskByOwnerIDAndName
1 parent 11f2411 commit 7b629d3

File tree

7 files changed

+79
-0
lines changed

7 files changed

+79
-0
lines changed

coderd/database/dbauthz/dbauthz.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2989,6 +2989,10 @@ func (q *querier) GetTaskByID(ctx context.Context, id uuid.UUID) (database.Task,
29892989
return fetch(q.log, q.auth, q.db.GetTaskByID)(ctx, id)
29902990
}
29912991

2992+
func (q *querier) GetTaskByOwnerIDAndName(ctx context.Context, arg database.GetTaskByOwnerIDAndNameParams) (database.Task, error) {
2993+
return fetch(q.log, q.auth, q.db.GetTaskByOwnerIDAndName)(ctx, arg)
2994+
}
2995+
29922996
func (q *querier) GetTaskByWorkspaceID(ctx context.Context, workspaceID uuid.UUID) (database.Task, error) {
29932997
return fetch(q.log, q.auth, q.db.GetTaskByWorkspaceID)(ctx, workspaceID)
29942998
}

coderd/database/dbauthz/dbauthz_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,6 +2375,17 @@ func (s *MethodTestSuite) TestTasks() {
23752375
dbm.EXPECT().GetTaskByID(gomock.Any(), task.ID).Return(task, nil).AnyTimes()
23762376
check.Args(task.ID).Asserts(task, policy.ActionRead).Returns(task)
23772377
}))
2378+
s.Run("GetTaskByOwnerIDAndName", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) {
2379+
task := testutil.Fake(s.T(), faker, database.Task{})
2380+
dbm.EXPECT().GetTaskByOwnerIDAndName(gomock.Any(), database.GetTaskByOwnerIDAndNameParams{
2381+
OwnerID: task.OwnerID,
2382+
Name: task.Name,
2383+
}).Return(task, nil).AnyTimes()
2384+
check.Args(database.GetTaskByOwnerIDAndNameParams{
2385+
OwnerID: task.OwnerID,
2386+
Name: task.Name,
2387+
}).Asserts(task, policy.ActionRead).Returns(task)
2388+
}))
23782389
s.Run("DeleteTask", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) {
23792390
task := testutil.Fake(s.T(), faker, database.Task{})
23802391
arg := database.DeleteTaskParams{

coderd/database/dbmetrics/querymetrics.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbmock/dbmock.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/querier.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/tasks.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ SELECT * FROM tasks_with_status WHERE id = @id::uuid;
4141
-- name: GetTaskByWorkspaceID :one
4242
SELECT * FROM tasks_with_status WHERE workspace_id = @workspace_id::uuid;
4343

44+
-- name: GetTaskByOwnerIDAndName :one
45+
SELECT * FROM tasks_with_status
46+
WHERE owner_id = @owner_id::uuid
47+
AND LOWER(name) = LOWER(@name::text);
48+
4449
-- name: ListTasks :many
4550
SELECT * FROM tasks_with_status tws
4651
WHERE tws.deleted_at IS NULL

0 commit comments

Comments
 (0)