40 lines
952 B
Go
40 lines
952 B
Go
package files
|
|
|
|
import (
|
|
"errors"
|
|
"gis/app"
|
|
"gis/server/httputil"
|
|
"net/http"
|
|
|
|
"github.com/jackc/pgx/v5"
|
|
)
|
|
|
|
func getFileRoute(application *app.App) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
id := r.PathValue("file_id")
|
|
|
|
var gf GeoFile
|
|
err := application.Db.QueryRow(r.Context(),
|
|
`SELECT id, filename, file_type, validation_status,
|
|
validation_error, kato_column, crs, feature_count,
|
|
uploaded_at, updated_at
|
|
FROM files WHERE id=$1`,
|
|
id,
|
|
).Scan(
|
|
&gf.ID, &gf.Filename, &gf.FileType, &gf.ValidationStatus,
|
|
&gf.ValidationError, &gf.KatoColumn, &gf.CRS, &gf.FeatureCount,
|
|
&gf.UploadedAt, &gf.UpdatedAt,
|
|
)
|
|
if errors.Is(err, pgx.ErrNoRows) {
|
|
httputil.WriteJSON(w, http.StatusNotFound, map[string]string{"error": "not found"})
|
|
return
|
|
}
|
|
if err != nil {
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
httputil.WriteJSON(w, http.StatusOK, gf)
|
|
}
|
|
}
|