Add base site, needs clean-up

This commit is contained in:
2021-12-26 00:02:51 +01:00
parent ed4475149a
commit ec313045f1
28 changed files with 2806 additions and 18 deletions

View File

@@ -1,6 +1,7 @@
package download
import (
"context"
"downloader/internal/app/api/common/responses"
"downloader/internal/core/entities"
"errors"
@@ -48,6 +49,12 @@ func (a *api) requestDownload(w http.ResponseWriter, r *http.Request) {
func (a *api) getDownloads(writer http.ResponseWriter, request *http.Request) {
ctx := request.Context()
if done := request.URL.Query().Get("done"); done == "true" {
_ = a.getDoneDownloads(writer, request, ctx)
return
}
active := request.URL.Query().Get("active") == "true"
downloads, err := a.drService.GetAll(ctx, active)
if err != nil {
@@ -59,7 +66,20 @@ func (a *api) getDownloads(writer http.ResponseWriter, request *http.Request) {
_ = render.Render(writer, request, responses.ErrInvalidRequest(err))
return
}
}
func (a *api) getDoneDownloads(writer http.ResponseWriter, request *http.Request, ctx context.Context) bool {
downloads, err := a.drService.GetDone(ctx)
if err != nil {
_ = render.Render(writer, request, responses.ErrInvalidRequest(err))
return true
}
if err = render.RenderList(writer, request, newDownloadsResponse(downloads)); err != nil {
_ = render.Render(writer, request, responses.ErrInvalidRequest(err))
return true
}
return false
}
func (a *api) getDownloadById(w http.ResponseWriter, r *http.Request) {