Skip to content
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

Feature/implement update delete service request #47

Merged
merged 12 commits into from
Feb 3, 2024

Conversation

Zheng-Zhi-Qiang
Copy link
Collaborator

@Zheng-Zhi-Qiang Zheng-Zhi-Qiang commented Jan 31, 2024

Description
In this PR, I implemented delete and updating of service requests using their ids.

Assumptions

For update, I am assuming that only the three of the service request fields will be modified by user: pipeline_id, pipeline_version, and remarks.

Minor Changes

Added logging to all service request handler methods

Post Review Fixes:

  • Added two SR status: Not Started and Cancelled
  • Changed delete SR to cancel SR -> delete function remains in case
  • Added status check to update function

*Note: cancellation function to be implemented separately

@Zheng-Zhi-Qiang Zheng-Zhi-Qiang self-assigned this Jan 31, 2024
@Zheng-Zhi-Qiang Zheng-Zhi-Qiang added backend Backend related feature A new feature refactor Code refactor or updates labels Jan 31, 2024
@Zheng-Zhi-Qiang Zheng-Zhi-Qiang added this to the M1: Basic setup milestone Jan 31, 2024
This was linked to issues Jan 31, 2024
Copy link
Collaborator

@Ziyang-98 Ziyang-98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice LGTM. I skim through the code so do have josh proof read them. Also not sure if we allow service requests to be deleted via API (i.e. to keep for logs and auditing purpose) so do check with josh on that. If its not allowed might be dangerous to expose that API, esp if want to use in DSTA

Copy link
Owner

@joshtyf joshtyf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove deletion code as it won't be supported. Apart from that, the rest are fine 👍🏼

event.FireAsync(events.NewNewServiceRequestEvent(srm))
w.WriteHeader(http.StatusCreated)
}

func DeleteServiceRequest(w http.ResponseWriter, r *http.Request) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we won't allow for deletion. this is for logging purposes. but we can have a cancel. however, the cancellation logic will be much more involved and implemented at a later date.

Copy link
Owner

@joshtyf joshtyf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments. Most important change required is the updating of service request. User should only be able to update the data in the form, not pipeline ids and version.

return
}
srm := &dbmodels.ServiceRequestModel{
CreatedOn: time.Now(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should not update created_on field

Comment on lines 48 to 52
update := bson.M{"$set": bson.M{
"pipeline_id": srm.PipelineId,
"pipeline_version": srm.PipelineVersion,
"last_updated": srm.LastUpdated,
"remarks": srm.Remarks}}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is flawed actually.

pipeline_id and version should never be updated. It's a fixed 1-to-1 mapping.

The stuff that can be updated are the user parameters to the form input. None of these parameters you use are updatable.

Status: dbmodels.Pending,
}
err = json.NewDecoder(r.Body).Decode(srm)
w.Header().Set("Content-Type", "application/json")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually why do we still set this here when you already set it inside the JSONError method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I specify in case we need to return a response that is not an error.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay. then maybe we need a new method for returning data

Comment on lines +124 to +128
if status != models.Pending && status != models.Running {
logger.Error("[CancelStartedServiceRequest] Unable to cancel service request as execution has been completed", nil)
JSONError(w, handlermodels.NewHttpError(errors.New("service request execution has been completed")), http.StatusBadRequest)
return
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just check for status == models.Completed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the cancellation can happen in the middle of the execution, where maybe the execution is at a pending approval step, and if the status is already completed, means the sr execution completed already what so what is there to cancel

@@ -33,6 +33,31 @@ func (sr *ServiceRequest) GetById(id string) (*models.ServiceRequestModel, error
return srm, nil
}

func (sr *ServiceRequest) DeleteById(id string) (*mongo.DeleteResult, error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should remove this method

Comment on lines 85 to 91
func (sr *ServiceRequest) GetStatus(id string) (status models.ServiceRequestStatus, err error) {
srm, err := sr.GetById(id)
if err != nil {
return "", err
}
return srm.Status, nil
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method shouldn't exist for a few reasons:

  1. It provides an unnecessary wrapper around the GetById method.
  2. In the event of error, it returns an empty string which is not helpful

You should just call the GetById method directly

@Zheng-Zhi-Qiang Zheng-Zhi-Qiang merged commit e29e673 into main Feb 3, 2024
2 checks passed
@Zheng-Zhi-Qiang Zheng-Zhi-Qiang deleted the feature/implement-update-delete-service-request branch February 3, 2024 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Backend related feature A new feature refactor Code refactor or updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Delete Service Request Update Service Request
3 participants