31 lines
670 B
Go
31 lines
670 B
Go
package datasets
|
|
|
|
import (
|
|
"gis/app"
|
|
"gis/server/httputil"
|
|
"net/http"
|
|
)
|
|
|
|
type CreateDatasetRequest struct {
|
|
Name string `json:"name" validate:"required,max=255"`
|
|
Description string `json:"description" validate:"required"`
|
|
}
|
|
|
|
func createDatasetRoute(application *app.App) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
req, err := httputil.DecodeJSON[CreateDatasetRequest](w, r)
|
|
|
|
if err != nil {
|
|
http.Error(w, "Invalid request", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
if err := application.Validator.Struct(req); err != nil {
|
|
httputil.WriteValidationErrors(w, err)
|
|
return
|
|
}
|
|
|
|
w.WriteHeader(http.StatusCreated)
|
|
}
|
|
}
|