feat: delete all releases from settings (#170)

This commit is contained in:
Ludvig Lundgren 2022-03-06 18:08:32 +01:00 committed by GitHub
parent c28c6186d9
commit 3b43ccba8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 148 additions and 14 deletions

View file

@ -21,6 +21,14 @@ func (e encoder) StatusResponse(ctx context.Context, w http.ResponseWriter, resp
}
}
func (e encoder) StatusNoContent(w http.ResponseWriter) {
w.WriteHeader(http.StatusNoContent)
}
func (e encoder) StatusNotFound(ctx context.Context, w http.ResponseWriter) {
w.WriteHeader(http.StatusNotFound)
}
func (e encoder) StatusInternalError(w http.ResponseWriter) {
w.WriteHeader(http.StatusInternalServerError)
}

View file

@ -14,6 +14,7 @@ type releaseService interface {
Find(ctx context.Context, query domain.ReleaseQueryParams) (res []domain.Release, nextCursor int64, count int64, err error)
GetIndexerOptions(ctx context.Context) ([]string, error)
Stats(ctx context.Context) (*domain.ReleaseStats, error)
Delete(ctx context.Context) error
}
type releaseHandler struct {
@ -32,6 +33,7 @@ func (h releaseHandler) Routes(r chi.Router) {
r.Get("/", h.findReleases)
r.Get("/stats", h.getStats)
r.Get("/indexers", h.getIndexerOptions)
r.Delete("/all", h.deleteReleases)
}
func (h releaseHandler) findReleases(w http.ResponseWriter, r *http.Request) {
@ -135,3 +137,13 @@ func (h releaseHandler) getStats(w http.ResponseWriter, r *http.Request) {
h.encoder.StatusResponse(r.Context(), w, stats, http.StatusOK)
}
func (h releaseHandler) deleteReleases(w http.ResponseWriter, r *http.Request) {
err := h.service.Delete(r.Context())
if err != nil {
h.encoder.StatusInternalError(w)
return
}
h.encoder.StatusNoContent(w)
}