-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f65a00e
commit 38ae9b3
Showing
9 changed files
with
92 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,27 @@ | ||
package handlers | ||
|
||
import ( | ||
"gitlab.com/distributed_lab/ape" | ||
"gitlab.com/distributed_lab/ape/problems" | ||
"gitlab.com/tokend/course-certificates/ccp/internal/service/api/requests" | ||
"net/http" | ||
) | ||
|
||
func RemoveTemplateByID(w http.ResponseWriter, r *http.Request) { | ||
templateID, err := requests.NewRemoveTemplateByIDRequest(r) | ||
if err != nil { | ||
Log(r).WithError(err).Error("failed to parse request ") | ||
ape.Render(w, problems.BadRequest(err)) | ||
return | ||
} | ||
|
||
templateID64 := int64(*templateID) | ||
err = MasterQ(r).TemplateQ().FilterByID(templateID64).Delete() | ||
if err != nil { | ||
Log(r).WithError(err).Error("failed to remove template") | ||
ape.Render(w, problems.InternalError()) | ||
return | ||
} | ||
|
||
w.WriteHeader(http.StatusOK) | ||
} |
This file contains 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,32 @@ | ||
package requests | ||
|
||
import ( | ||
"github.com/go-chi/chi" | ||
"gitlab.com/distributed_lab/logan/v3/errors" | ||
"gitlab.com/distributed_lab/urlval" | ||
"net/http" | ||
"strconv" | ||
) | ||
|
||
const ( | ||
TemplateIDPathParam = "template_id" | ||
) | ||
|
||
type RemoveTemplateByIDRequest struct { | ||
TemplateID string `url:"-"` | ||
} | ||
|
||
func NewRemoveTemplateByIDRequest(r *http.Request) (*int, error) { | ||
request := RemoveTemplateByIDRequest{} | ||
if err := urlval.Decode(r.URL.Query(), &request); err != nil { | ||
return nil, errors.Wrap(err, "failed to decode data") | ||
} | ||
request.TemplateID = chi.URLParam(r, TemplateIDPathParam) | ||
|
||
id, err := strconv.Atoi(request.TemplateID) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to convert template id to int") | ||
} | ||
|
||
return &id, nil | ||
} |
This file contains 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
This file contains 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