// SetUploadStatus is a handler for the /status PUT API endpoint. It uses dependency injection to allow for more robust testing.
SetUploadStatus is a handler for the /status PUT API endpoint. It uses dependency injection to allow for more robust testing.
// SetUploadStatus is a handler for the / status PUT API endpoint . It uses dependency injection to allow for more robust testing .
func SetUploadStatus(env *config.Env) http.HandlerFunc {
	return func(wr http.ResponseWriter, r *http.Request) {
		wr.Header().Set(constants.HeaderContentType, constants.ApplicationJSON)
		assetID := r.URL.Query().Get("id")
		status := r.URL.Query().Get("status")
		asset, err := env.Store.SetAssetStatus(assetID, status)
		if err != nil {
			switch err.(type) {
			case *data.ErrorNoAssetFound:
				responses.WriteResourceNotFoundResponse(wr, err.Error())
			case *data.ErrorInvalidStatus:
				responses.WriteBadRequest(wr, err.Error())
			default:
				responses.WriteInternalServerErrorResponse(wr, constants.InternalServerErrorMessage)
			}
			return
		}
		resp := responses.StatusUpdateResponse{
			ID:     asset.Name,
			Status: asset.UploadStatus,
		}
		responses.WriteOkResponse(wr, resp)
	}
}
func SetUploadStatus ( env * config . Env ) http . HandlerFunc { return func ( wr http . ResponseWriter , r * http . Request ) { wr . Header ( ) . Set ( constants . HeaderContentType , constants . ApplicationJSON ) assetID := r . URL . Query ( ) . Get ( " " ) status := r . URL . Query ( ) . Get ( " " ) asset , err := env . Store . SetAssetStatus ( assetID , status ) if err != nil { switch err . ( type ) { case * data . ErrorNoAssetFound : responses . WriteResourceNotFoundResponse ( wr , err . Error ( ) ) case * data . ErrorInvalidStatus : responses . WriteBadRequest ( wr , err . Error ( ) ) default : responses . WriteInternalServerErrorResponse ( wr , constants . InternalServerErrorMessage ) } return } resp := responses . StatusUpdateResponse { ID : asset . Name , Status : asset . UploadStatus , } responses . WriteOkResponse ( wr , resp ) } }
SetUploadStatus is a handler for the /status PUT API endpoint.
SetUploadStatus is a handler for the / status PUT API endpoint .