Skip to content

Commit

Permalink
frontend error message
Browse files Browse the repository at this point in the history
  • Loading branch information
supreme2580 committed Dec 5, 2024
1 parent c52a834 commit 166bb7a
Show file tree
Hide file tree
Showing 8 changed files with 7,137 additions and 2,476 deletions.
20 changes: 20 additions & 0 deletions backend/routes/worlds.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func InitWorldsRoutes() {
http.HandleFunc("/get-worlds-pixel-count", getWorldsPixelCount)
http.HandleFunc("/get-worlds-pixel-info", getWorldsPixelInfo)
http.HandleFunc("/worlds/", handleWorldRoute)
http.HandleFunc("/check-world-name", checkWorldName)
if !core.ArtPeaceBackend.BackendConfig.Production {
http.HandleFunc("/create-canvas-devnet", createCanvasDevnet)
http.HandleFunc("/favorite-world-devnet", favoriteWorldDevnet)
Expand Down Expand Up @@ -708,3 +709,22 @@ func handleWorldRoute(w http.ResponseWriter, r *http.Request) {
}
routeutils.WriteDataJson(w, string(world))
}

func checkWorldName(w http.ResponseWriter, r *http.Request) {
routeutils.SetupAccessHeaders(w)

name := r.URL.Query().Get("name")
if name == "" {
routeutils.WriteErrorJson(w, http.StatusBadRequest, "Missing name parameter")
return
}

// Check if name exists
exists, err := core.PostgresQueryOne[bool]("SELECT EXISTS(SELECT 1 FROM worlds WHERE name = $1)", name)
if err != nil {
routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to check world name")
return
}

routeutils.WriteDataJson(w, strconv.FormatBool(*exists))
}
Loading

0 comments on commit 166bb7a

Please sign in to comment.