// RequestUploadURL is a handler for the /assets POST API endpoint. It uses dependency injection to allow for more robust testing.
RequestUploadURL is a handler for the /assets POST API endpoint. It uses dependency injection to allow for more robust testing.
// RequestUploadURL is a handler for the / assets POST API endpoint . It uses dependency injection to allow for more robust testing .
func RequestUploadURL(env *config.Env) http.HandlerFunc {
	return func(wr http.ResponseWriter, r *http.Request) {
		wr.Header().Set(constants.HeaderContentType, constants.ApplicationJSON)
		timeout := r.URL.Query().Get("timeout")
		awsName, url, err := env.AssetUploader.GetSignedUploadURL(timeout)
		if err != nil {
			responses.WriteInternalServerErrorResponse(wr, constants.InternalServerErrorMessage)
			return
		}
		id, err := env.Store.AddNewAsset(awsName, url)
		if err != nil {
			responses.WriteInternalServerErrorResponse(wr, constants.InternalServerErrorMessage)
			return
		}
		resp := &responses.UploadURLResponse{
			ID:  id,
			URL: url,
		}
		responses.WriteOkResponse(wr, resp)
	}
}
func RequestUploadURL ( env * config . Env ) http . HandlerFunc { return func ( wr http . ResponseWriter , r * http . Request ) { wr . Header ( ) . Set ( constants . HeaderContentType , constants . ApplicationJSON ) timeout := r . URL . Query ( ) . Get ( " " ) awsName , url , err := env . AssetUploader . GetSignedUploadURL ( timeout ) if err != nil { responses . WriteInternalServerErrorResponse ( wr , constants . InternalServerErrorMessage ) return } id , err := env . Store . AddNewAsset ( awsName , url ) if err != nil { responses . WriteInternalServerErrorResponse ( wr , constants . InternalServerErrorMessage ) return } resp := & responses . UploadURLResponse { ID : id , URL : url , } responses . WriteOkResponse ( wr , resp ) } }
RequestUploadURL is a handler for the /assets POST API endpoint.
RequestUploadURL is a handler for the / assets POST API endpoint .