Skip to content

Commit

Permalink
delete code api endpoint
Browse files Browse the repository at this point in the history
added boiler plate code for the delete code in api endpoints
  • Loading branch information
rakhanda authored and rakhanda committed Oct 3, 2022
1 parent 6ea5606 commit 88db735
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
46 changes: 46 additions & 0 deletions api/design_api.partials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,49 @@
summary: Update a design code
tags:
- designCodes
#------------------------------------#
# Delete Code Zip
#------------------------------------#
delete:
operationId: deleteDesignCode
summary: Delete code of a specified version from a given design
tags:
- designCodes
parameters:
- name: user
description: user name
explode: false
in: path
required: true
schema:
type: string
style: simple
- name: designId
description: design id
explode: false
in: path
required: true
schema:
type: string
style: simple
- name: version
description: version string
explode: false
in: path
required: true
schema:
type: string
style: simple
responses:
'200':
description: Deleted
'404':
description: Design id not found
'401':
description: Unauthorized
default:
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
description: unexpected error
2 changes: 2 additions & 0 deletions pkg/openapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type DatasetsApiRouter interface {
// pass the data to a DesignCodesApiServicer to perform the required actions, then write the service results to the http response.
type DesignCodesApiRouter interface {
CreateDesignCode(http.ResponseWriter, *http.Request)
DeleteDesignCode(http.ResponseWriter, *http.Request)
GetDesignCode(http.ResponseWriter, *http.Request)
UpdateDesignCode(http.ResponseWriter, *http.Request)
}
Expand Down Expand Up @@ -136,6 +137,7 @@ type DatasetsApiServicer interface {
// and updated with the logic required for the API.
type DesignCodesApiServicer interface {
CreateDesignCode(context.Context, string, string, string, string, *os.File) (ImplResponse, error)
DeleteDesignCode(context.Context, string, string, string) (ImplResponse, error)
GetDesignCode(context.Context, string, string, string) (ImplResponse, error)
UpdateDesignCode(context.Context, string, string, string, string, string, *os.File) (ImplResponse, error)
}
Expand Down
25 changes: 25 additions & 0 deletions pkg/openapi/api_design_codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ func (c *DesignCodesApiController) Routes() Routes {
"/users/{user}/designs/{designId}/codes",
c.CreateDesignCode,
},
{
"DeleteDesignCode",
strings.ToUpper("Delete"),
"/users/{user}/designs/{designId}/codes/{version}",
c.DeleteDesignCode,
},
{
"GetDesignCode",
strings.ToUpper("Get"),
Expand Down Expand Up @@ -98,6 +104,25 @@ func (c *DesignCodesApiController) CreateDesignCode(w http.ResponseWriter, r *ht
EncodeJSONResponse(result.Body, &result.Code, w)
}

// DeleteDesignCode - Delete code of a specified version from a given design
func (c *DesignCodesApiController) DeleteDesignCode(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
userParam := params["user"]

designIdParam := params["designId"]

versionParam := params["version"]

result, err := c.service.DeleteDesignCode(r.Context(), userParam, designIdParam, versionParam)
// If an error occurred, encode the error with the status code
if err != nil {
EncodeJSONResponse(err.Error(), &result.Code, w)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}

// GetDesignCode - Get a zipped design code file owned by user
func (c *DesignCodesApiController) GetDesignCode(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
Expand Down
22 changes: 22 additions & 0 deletions pkg/openapi/apiserver/api_design_codes_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,28 @@ func (s *DesignCodesApiService) CreateDesignCode(ctx context.Context, user strin
return openapi.Response(http.StatusCreated, nil), nil
}

// DeleteDesignCode - Delete a zipped design code file owned by user
func (s *DesignCodesApiService) DeleteDesignCode(ctx context.Context, user string, designId string,
version string) (openapi.ImplResponse, error) {
// TODO - update DeleteDesignCode with the required logic for this service method.
// Add api_design_codes_service.go to the .openapi-generator-ignore
// to avoid overwriting this service implementation when updating open api generation.

//TODO: Uncomment the next line to return response Response(200, {}) or use other options such as http.Ok ...
//return openapi.Response(200, nil),nil

//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return openapi.Response(404, nil),nil

//TODO: Uncomment the next line to return response Response(401, {}) or use other options such as http.Ok ...
//return openapi.Response(401, nil),nil

//TODO: Uncomment the next line to return response Response(0, Error{}) or use other options such as http.Ok ...
//return openapi.Response(0, Error{}), nil

return openapi.Response(http.StatusNotImplemented, nil), errors.New("DeleteDesignCode method not implemented")
}

// GetDesignCode - Get a zipped design code file owned by user
func (s *DesignCodesApiService) GetDesignCode(ctx context.Context, user string, designId string,
version string) (openapi.ImplResponse, error) {
Expand Down
22 changes: 22 additions & 0 deletions pkg/openapi/controller/api_design_codes_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ func (s *DesignCodesApiService) CreateDesignCode(ctx context.Context, user strin
return openapi.Response(http.StatusCreated, nil), nil
}

// DeleteDesignCode - Delete a zipped design code file owned by user
func (s *DesignCodesApiService) DeleteDesignCode(ctx context.Context, user string, designId string,
version string) (openapi.ImplResponse, error) {
// TODO - update DeleteDesignCode with the required logic for this service method.
// Add api_design_codes_service.go to the .openapi-generator-ignore
// to avoid overwriting this service implementation when updating open api generation.

//TODO: Uncomment the next line to return response Response(200, {}) or use other options such as http.Ok ...
//return openapi.Response(200, nil),nil

//TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ...
//return openapi.Response(404, nil),nil

//TODO: Uncomment the next line to return response Response(401, {}) or use other options such as http.Ok ...
//return openapi.Response(401, nil),nil

//TODO: Uncomment the next line to return response Response(0, Error{}) or use other options such as http.Ok ...
//return openapi.Response(0, Error{}), nil

return openapi.Response(http.StatusNotImplemented, nil), errors.New("DeleteDesignCode method not implemented")
}

// GetDesignCode - Get a zipped design code file owned by user
func (s *DesignCodesApiService) GetDesignCode(ctx context.Context, user string, designId string,
version string) (openapi.ImplResponse, error) {
Expand Down

0 comments on commit 88db735

Please sign in to comment.