-
Notifications
You must be signed in to change notification settings - Fork 59
feat(tasks): implement bulk task actions (complete/delete) #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
ShivaGupta-14
wants to merge
1
commit into
CCExtractor:main
from
ShivaGupta-14:feat/178-bulk-task-actions
+1,163
−130
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package controllers | ||
|
|
||
| import ( | ||
| "ccsync_backend/models" | ||
| "ccsync_backend/utils/tw" | ||
| "encoding/json" | ||
| "fmt" | ||
| "io" | ||
| "net/http" | ||
| ) | ||
|
|
||
| // BulkCompleteTaskHandler godoc | ||
| // @Summary Bulk complete tasks | ||
| // @Description Mark multiple tasks as completed in Taskwarrior | ||
| // @Tags Tasks | ||
| // @Accept json | ||
| // @Produce json | ||
| // @Param task body models.BulkCompleteTaskRequestBody true "Bulk task completion details" | ||
| // @Success 202 {string} string "Bulk task completion accepted for processing" | ||
| // @Failure 400 {string} string "Invalid request - missing or empty taskuuids" | ||
| // @Failure 405 {string} string "Method not allowed" | ||
| // @Router /complete-tasks [post] | ||
| func BulkCompleteTaskHandler(w http.ResponseWriter, r *http.Request) { | ||
| if r.Method != http.MethodPost { | ||
| http.Error(w, "Invalid request method", http.StatusMethodNotAllowed) | ||
| return | ||
| } | ||
|
|
||
| body, err := io.ReadAll(r.Body) | ||
| if err != nil { | ||
| http.Error(w, fmt.Sprintf("error reading request body: %v", err), http.StatusBadRequest) | ||
| return | ||
| } | ||
| defer r.Body.Close() | ||
|
|
||
| var requestBody models.BulkCompleteTaskRequestBody | ||
|
|
||
| if err := json.Unmarshal(body, &requestBody); err != nil { | ||
| http.Error(w, fmt.Sprintf("error decoding request body: %v", err), http.StatusBadRequest) | ||
| return | ||
| } | ||
|
|
||
| email := requestBody.Email | ||
| encryptionSecret := requestBody.EncryptionSecret | ||
| uuid := requestBody.UUID | ||
| taskUUIDs := requestBody.TaskUUIDs | ||
|
|
||
| if len(taskUUIDs) == 0 { | ||
| http.Error(w, "taskuuids is required and cannot be empty", http.StatusBadRequest) | ||
| return | ||
| } | ||
|
|
||
| logStore := models.GetLogStore() | ||
|
|
||
| // Create a *single* job for all UUIDs | ||
| job := Job{ | ||
| Name: "Bulk Complete Tasks", | ||
| Execute: func() error { | ||
| for _, tu := range taskUUIDs { | ||
| logStore.AddLog("INFO", fmt.Sprintf("[Bulk Complete] Starting: %s", tu), uuid, "Bulk Complete Task") | ||
|
|
||
| err := tw.CompleteTaskInTaskwarrior(email, encryptionSecret, uuid, tu) | ||
| if err != nil { | ||
| logStore.AddLog("ERROR", fmt.Sprintf("[Bulk Complete] Failed: %s (%v)", tu, err), uuid, "Bulk Complete Task") | ||
| continue | ||
| } | ||
|
|
||
| logStore.AddLog("INFO", fmt.Sprintf("[Bulk Complete] Completed: %s", tu), uuid, "Bulk Complete Task") | ||
| } | ||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| GlobalJobQueue.AddJob(job) | ||
| w.WriteHeader(http.StatusAccepted) | ||
| } |
its-me-abhishek marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package controllers | ||
|
|
||
| import ( | ||
| "ccsync_backend/models" | ||
| "ccsync_backend/utils/tw" | ||
| "encoding/json" | ||
| "fmt" | ||
| "io" | ||
| "net/http" | ||
| ) | ||
|
|
||
| // BulkDeleteTaskHandler godoc | ||
| // @Summary Bulk delete tasks | ||
| // @Description Delete multiple tasks in Taskwarrior | ||
| // @Tags Tasks | ||
| // @Accept json | ||
| // @Produce json | ||
| // @Param task body models.BulkDeleteTaskRequestBody true "Bulk task deletion details" | ||
| // @Success 202 {string} string "Bulk task deletion accepted for processing" | ||
| // @Failure 400 {string} string "Invalid request - missing or empty taskuuids" | ||
| // @Failure 405 {string} string "Method not allowed" | ||
| // @Router /delete-tasks [post] | ||
| func BulkDeleteTaskHandler(w http.ResponseWriter, r *http.Request) { | ||
| if r.Method != http.MethodPost { | ||
| http.Error(w, "Invalid request method", http.StatusMethodNotAllowed) | ||
| return | ||
| } | ||
|
|
||
| body, err := io.ReadAll(r.Body) | ||
| if err != nil { | ||
| http.Error(w, fmt.Sprintf("error reading request body: %v", err), http.StatusBadRequest) | ||
| return | ||
| } | ||
| defer r.Body.Close() | ||
|
|
||
| var requestBody models.BulkDeleteTaskRequestBody | ||
|
|
||
| if err := json.Unmarshal(body, &requestBody); err != nil { | ||
| http.Error(w, fmt.Sprintf("error decoding request body: %v", err), http.StatusBadRequest) | ||
| return | ||
| } | ||
|
|
||
| email := requestBody.Email | ||
| encryptionSecret := requestBody.EncryptionSecret | ||
| uuid := requestBody.UUID | ||
| taskUUIDs := requestBody.TaskUUIDs | ||
|
|
||
| if len(taskUUIDs) == 0 { | ||
| http.Error(w, "taskuuids is required and cannot be empty", http.StatusBadRequest) | ||
| return | ||
| } | ||
|
|
||
| logStore := models.GetLogStore() | ||
|
|
||
| job := Job{ | ||
| Name: "Bulk Delete Tasks", | ||
| Execute: func() error { | ||
| for _, tu := range taskUUIDs { | ||
| logStore.AddLog("INFO", fmt.Sprintf("[Bulk Delete] Starting: %s", tu), uuid, "Bulk Delete Task") | ||
|
|
||
| err := tw.DeleteTaskInTaskwarrior(email, encryptionSecret, uuid, tu) | ||
| if err != nil { | ||
| logStore.AddLog("ERROR", fmt.Sprintf("[Bulk Delete] Failed: %s (%v)", tu, err), uuid, "Bulk Delete Task") | ||
| continue | ||
| } | ||
|
|
||
| logStore.AddLog("INFO", fmt.Sprintf("[Bulk Delete] Deleted: %s", tu), uuid, "Bulk Delete Task") | ||
| } | ||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| GlobalJobQueue.AddJob(job) | ||
| w.WriteHeader(http.StatusAccepted) | ||
| } |
its-me-abhishek marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
its-me-abhishek marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
its-me-abhishek marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created new endpoint for bulk task completion. uses a single job for all UUIDs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a O(n) operation with lots of Config->Operate->Sync tasks, preferably what shall be done could be that- add another CMD operation for this called CompleteTasksInTaskwarrior, and then operate that loop there, instead of this API that initiates the Job. So they would have a single SetConfig->MultipleOperations->SingleSync as the final workflow. Similar shall be done for delete so as to reduce server overheads
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@its-me-abhishek
Thanks for the suggestion! I understand, I'll refactor to move the loop into a single CompleteTasksInTaskwarrior function with the flow: SetConfig -> Loop operations -> SingleSync.
Quick question: for tracking which individual tasks fail within the batch, should I return a map[string]string (uuid -> error) or define a struct like FailedTask{UUID, Error}? Both work, just wondering if you have a preference.