Skip to content

Commit

Permalink
Added task API to get ApplicationTask by UID
Browse files Browse the repository at this point in the history
  • Loading branch information
sparshev committed Aug 2, 2024
1 parent 56dba83 commit 4bc686d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
29 changes: 29 additions & 0 deletions docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,35 @@ paths:
security:
- basic_auth: []

/api/v1/task/{task_uid}:
get:
summary: Get ApplicationTask data
description: Returns the Application Task
operationId: ApplicationTaskGet
tags:
- Application
parameters:
- name: task_uid
in: path
description: UID of the Task
required: true
schema:
type: string
format: uuid
responses:
'200':
description: Successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/ApplicationTask'
'401':
$ref: '#/components/responses/UnauthorizedError'
'404':
description: ApplicationTask not found
security:
- basic_auth: []

/api/v1/application/{uid}/deallocate:
get:
summary: Triggers Application deallocate
Expand Down
23 changes: 23 additions & 0 deletions lib/openapi/api/api_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,29 @@ func (e *Processor) ApplicationTaskCreatePost(c echo.Context, app_uid types.Appl
return c.JSON(http.StatusOK, data)
}

func (e *Processor) ApplicationTaskGet(c echo.Context, task_uid types.ApplicationTaskUID) error {
task, err := e.fish.ApplicationTaskGet(task_uid)
if err != nil {
c.JSON(http.StatusBadRequest, H{"message": fmt.Sprintf("Unable to find the Application: %s", task_uid)})
return fmt.Errorf("Unable to find the ApplicationTask: %s, %w", task_uid, err)
}

app, err := e.fish.ApplicationGet(task.ApplicationUID)
if err != nil {
c.JSON(http.StatusBadRequest, H{"message": fmt.Sprintf("Unable to find the Application: %s", task.ApplicationUID)})
return fmt.Errorf("Unable to find the Application: %s, %w", task.ApplicationUID, err)
}

// Only the owner of the application (or admin) could get the attached task
user := c.Get("user")
if app.OwnerName != user.(*types.User).Name && user.(*types.User).Name != "admin" {
c.JSON(http.StatusBadRequest, H{"message": fmt.Sprintf("Only the owner of Application & admin can get the ApplicationTask")})
return fmt.Errorf("Only the owner of Application & admin can get the ApplicationTask")
}

return c.JSON(http.StatusOK, task)
}

func (e *Processor) ApplicationDeallocateGet(c echo.Context, uid types.ApplicationUID) error {
app, err := e.fish.ApplicationGet(uid)
if err != nil {
Expand Down

0 comments on commit 4bc686d

Please sign in to comment.