Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi canvas #273

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions backend/routes/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,14 @@ func getCanvas(w http.ResponseWriter, r *http.Request) {

w.Write([]byte(val))
}

type CanvasMetadata struct {
CanvasId int `json:"canvasId"`
Name string `json:"name"`
Width int `json:"width"`
Height int `json:"height"`
Host string `json:"host"`
StartTime int64 `json:"startTime"`
EndTime int64 `json:"endTime"`
FavoriteCount int `json:"favoriteCount"`
}
55 changes: 55 additions & 0 deletions backend/routes/worlds.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func InitWorldsRoutes() {
http.HandleFunc("/unfavorite-world-devnet", unfavoriteWorldDevnet)
http.HandleFunc("/place-world-pixel-devnet", placeWorldPixelDevnet)
}
http.HandleFunc("/get-all-worlds", getAllWorlds)
}

func InitWorldsStaticRoutes() {
Expand Down Expand Up @@ -690,3 +691,57 @@ func doesWorldNameExist(name string) (bool, error) {
}
return *exists, nil
}

func getAllWorlds(w http.ResponseWriter, r *http.Request) {
// Get query parameters
address := r.URL.Query().Get("address")
if address == "" {
address = "0"
}

// Parse pagination
pageLength, err := strconv.Atoi(r.URL.Query().Get("pageLength"))
if err != nil || pageLength <= 0 {
pageLength = 25
}
if pageLength > 50 {
pageLength = 50
}

page, err := strconv.Atoi(r.URL.Query().Get("page"))
if err != nil || page <= 0 {
page = 1
}
offset := (page - 1) * pageLength

query := `
SELECT
worlds.*,
COALESCE(worldfavorites.favorite_count, 0) AS favorites,
COALESCE((
SELECT true FROM worldfavorites
WHERE user_address = $1
AND worldfavorites.world_id = worlds.world_id
), false) as favorited
FROM
worlds
LEFT JOIN (
SELECT
world_id,
COUNT(*) AS favorite_count
FROM
worldfavorites
GROUP BY
world_id
) worldfavorites ON worlds.world_id = worldfavorites.world_id
ORDER BY worlds.world_id DESC
LIMIT $2 OFFSET $3`

worlds, err := core.PostgresQueryJson[WorldData](query, address, pageLength, offset)
if err != nil {
routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to retrieve Worlds")
return
}

routeutils.WriteDataJson(w, string(worlds))
}
Loading
Loading