From 30635edd4471b857feeda4545897f5372e584ad5 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Fri, 22 Sep 2023 21:41:11 +0300 Subject: feat: improve map and user searches (#77) Former-commit-id: 77019e11d0d0ee29061b603eaf6a79f42d68058f --- backend/handlers/home.go | 247 ++++++++++++++++++++++++----------------------- 1 file changed, 127 insertions(+), 120 deletions(-) (limited to 'backend') diff --git a/backend/handlers/home.go b/backend/handlers/home.go index a2b7113..42e27be 100644 --- a/backend/handlers/home.go +++ b/backend/handlers/home.go @@ -12,8 +12,8 @@ import ( ) type SearchResponse struct { - Players []models.UserShort `json:"players"` - Maps []models.MapShort `json:"maps"` + Players []models.UserShortWithAvatar `json:"players"` + Maps []MapShortWithGame `json:"maps"` } type RankingsResponse struct { @@ -22,6 +22,13 @@ type RankingsResponse struct { Multiplayer []models.UserRanking `json:"rankings_multiplayer"` } +type MapShortWithGame struct { + ID int `json:"id"` + Game string `json:"game"` + Chapter string `json:"chapter"` + Map string `json:"map"` +} + // GET Rankings // // @Description Get rankings of every player. @@ -143,143 +150,143 @@ func SearchWithQuery(c *gin.Context) { log.Println(query) var response SearchResponse // Cache all maps for faster response - var maps = []models.MapShort{ - {ID: 1, Name: "Container Ride"}, - {ID: 2, Name: "Portal Carousel"}, - {ID: 3, Name: "Portal Gun"}, - {ID: 4, Name: "Smooth Jazz"}, - {ID: 5, Name: "Cube Momentum"}, - {ID: 6, Name: "Future Starter"}, - {ID: 7, Name: "Secret Panel"}, - {ID: 8, Name: "Wakeup"}, - {ID: 9, Name: "Incinerator"}, - {ID: 10, Name: "Laser Intro"}, - {ID: 11, Name: "Laser Stairs"}, - {ID: 12, Name: "Dual Lasers"}, - {ID: 13, Name: "Laser Over Goo"}, - {ID: 14, Name: "Catapult Intro"}, - {ID: 15, Name: "Trust Fling"}, - {ID: 16, Name: "Pit Flings"}, - {ID: 17, Name: "Fizzler Intro"}, - {ID: 18, Name: "Ceiling Catapult"}, - {ID: 19, Name: "Ricochet"}, - {ID: 20, Name: "Bridge Intro"}, - {ID: 21, Name: "Bridge The Gap"}, - {ID: 22, Name: "Turret Intro"}, - {ID: 23, Name: "Laser Relays"}, - {ID: 24, Name: "Turret Blocker"}, - {ID: 25, Name: "Laser vs Turret"}, - {ID: 26, Name: "Pull The Rug"}, - {ID: 27, Name: "Column Blocker"}, - {ID: 28, Name: "Laser Chaining"}, - {ID: 29, Name: "Triple Laser"}, - {ID: 30, Name: "Jail Break"}, - {ID: 31, Name: "Escape"}, - {ID: 32, Name: "Turret Factory"}, - {ID: 33, Name: "Turret Sabotage"}, - {ID: 34, Name: "Neurotoxin Sabotage"}, - {ID: 35, Name: "Core"}, - {ID: 36, Name: "Underground"}, - {ID: 37, Name: "Cave Johnson"}, - {ID: 38, Name: "Repulsion Intro"}, - {ID: 39, Name: "Bomb Flings"}, - {ID: 40, Name: "Crazy Box"}, - {ID: 41, Name: "PotatOS"}, - {ID: 42, Name: "Propulsion Intro"}, - {ID: 43, Name: "Propulsion Flings"}, - {ID: 44, Name: "Conversion Intro"}, - {ID: 45, Name: "Three Gels"}, - {ID: 46, Name: "Test"}, - {ID: 47, Name: "Funnel Intro"}, - {ID: 48, Name: "Ceiling Button"}, - {ID: 49, Name: "Wall Button"}, - {ID: 50, Name: "Polarity"}, - {ID: 51, Name: "Funnel Catch"}, - {ID: 52, Name: "Stop The Box"}, - {ID: 53, Name: "Laser Catapult"}, - {ID: 54, Name: "Laser Platform"}, - {ID: 55, Name: "Propulsion Catch"}, - {ID: 56, Name: "Repulsion Polarity"}, - {ID: 57, Name: "Finale 1"}, - {ID: 58, Name: "Finale 2"}, - {ID: 59, Name: "Finale 3"}, - {ID: 60, Name: "Finale 4"}, - {ID: 61, Name: "Calibration"}, - {ID: 62, Name: "Hub"}, - {ID: 63, Name: "Doors"}, - {ID: 64, Name: "Buttons"}, - {ID: 65, Name: "Lasers"}, - {ID: 66, Name: "Rat Maze"}, - {ID: 67, Name: "Laser Crusher"}, - {ID: 68, Name: "Behind The Scenes"}, - {ID: 69, Name: "Flings"}, - {ID: 70, Name: "Infinifling"}, - {ID: 71, Name: "Team Retrieval"}, - {ID: 72, Name: "Vertical Flings"}, - {ID: 73, Name: "Catapults"}, - {ID: 74, Name: "Multifling"}, - {ID: 75, Name: "Fling Crushers"}, - {ID: 76, Name: "Industrial Fan"}, - {ID: 77, Name: "Cooperative Bridges"}, - {ID: 78, Name: "Bridge Swap"}, - {ID: 79, Name: "Fling Block"}, - {ID: 80, Name: "Catapult Block"}, - {ID: 81, Name: "Bridge Fling"}, - {ID: 82, Name: "Turret Walls"}, - {ID: 83, Name: "Turret Assasin"}, - {ID: 84, Name: "Bridge Testing"}, - {ID: 85, Name: "Cooperative Funnels"}, - {ID: 86, Name: "Funnel Drill"}, - {ID: 87, Name: "Funnel Catch"}, - {ID: 88, Name: "Funnel Laser"}, - {ID: 89, Name: "Cooperative Polarity"}, - {ID: 90, Name: "Funnel Hop"}, - {ID: 91, Name: "Advanced Polarity"}, - {ID: 92, Name: "Funnel Maze"}, - {ID: 93, Name: "Turret Warehouse"}, - {ID: 94, Name: "Repulsion Jumps"}, - {ID: 95, Name: "Double Bounce"}, - {ID: 96, Name: "Bridge Repulsion"}, - {ID: 97, Name: "Wall Repulsion"}, - {ID: 98, Name: "Propulsion Crushers"}, - {ID: 99, Name: "Turret Ninja"}, - {ID: 100, Name: "Propulsion Retrieval"}, - {ID: 101, Name: "Vault Entrance"}, - {ID: 102, Name: "Seperation"}, - {ID: 103, Name: "Triple Axis"}, - {ID: 104, Name: "Catapult Catch"}, - {ID: 105, Name: "Bridge Gels"}, - {ID: 106, Name: "Maintenance"}, - {ID: 107, Name: "Bridge Catch"}, - {ID: 108, Name: "Double Lift"}, - {ID: 109, Name: "Gel Maze"}, - {ID: 110, Name: "Crazier Box"}, + var maps = []MapShortWithGame{ + {ID: 1, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 1 - The Courtesy Call", Map: "Container Ride"}, + {ID: 2, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 1 - The Courtesy Call", Map: "Portal Carousel"}, + {ID: 3, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 1 - The Courtesy Call", Map: "Portal Gun"}, + {ID: 4, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 1 - The Courtesy Call", Map: "Smooth Jazz"}, + {ID: 5, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 1 - The Courtesy Call", Map: "Cube Momentum"}, + {ID: 6, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 1 - The Courtesy Call", Map: "Future Starter"}, + {ID: 7, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 1 - The Courtesy Call", Map: "Secret Panel"}, + {ID: 8, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 1 - The Courtesy Call", Map: "Wakeup"}, + {ID: 9, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 1 - The Courtesy Call", Map: "Incinerator"}, + {ID: 10, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 2 - The Cold Boot", Map: "Laser Intro"}, + {ID: 11, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 2 - The Cold Boot", Map: "Laser Stairs"}, + {ID: 12, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 2 - The Cold Boot", Map: "Dual Lasers"}, + {ID: 13, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 2 - The Cold Boot", Map: "Laser Over Goo"}, + {ID: 14, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 2 - The Cold Boot", Map: "Catapult Intro"}, + {ID: 15, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 2 - The Cold Boot", Map: "Trust Fling"}, + {ID: 16, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 2 - The Cold Boot", Map: "Pit Flings"}, + {ID: 17, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 2 - The Cold Boot", Map: "Fizzler Intro"}, + {ID: 18, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 3 - The Return", Map: "Ceiling Catapult"}, + {ID: 19, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 3 - The Return", Map: "Ricochet"}, + {ID: 20, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 3 - The Return", Map: "Bridge Intro"}, + {ID: 21, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 3 - The Return", Map: "Bridge The Gap"}, + {ID: 22, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 3 - The Return", Map: "Turret Intro"}, + {ID: 23, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 3 - The Return", Map: "Laser Relays"}, + {ID: 24, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 3 - The Return", Map: "Turret Blocker"}, + {ID: 25, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 3 - The Return", Map: "Laser vs Turret"}, + {ID: 26, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 3 - The Return", Map: "Pull The Rug"}, + {ID: 27, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 4 - The Surprise", Map: "Column Blocker"}, + {ID: 28, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 4 - The Surprise", Map: "Laser Chaining"}, + {ID: 29, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 4 - The Surprise", Map: "Triple Laser"}, + {ID: 30, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 4 - The Surprise", Map: "Jail Break"}, + {ID: 31, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 4 - The Surprise", Map: "Escape"}, + {ID: 32, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 5 - The Escape", Map: "Turret Factory"}, + {ID: 33, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 5 - The Escape", Map: "Turret Sabotage"}, + {ID: 34, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 5 - The Escape", Map: "Neurotoxin Sabotage"}, + {ID: 35, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 5 - The Escape", Map: "Core"}, + {ID: 36, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 6 - The Fall", Map: "Underground"}, + {ID: 37, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 6 - The Fall", Map: "Cave Johnson"}, + {ID: 38, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 6 - The Fall", Map: "Repulsion Intro"}, + {ID: 39, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 6 - The Fall", Map: "Bomb Flings"}, + {ID: 40, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 6 - The Fall", Map: "Crazy Box"}, + {ID: 41, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 6 - The Fall", Map: "PotatOS"}, + {ID: 42, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 7 - The Reunion", Map: "Propulsion Intro"}, + {ID: 43, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 7 - The Reunion", Map: "Propulsion Flings"}, + {ID: 44, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 7 - The Reunion", Map: "Conversion Intro"}, + {ID: 45, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 7 - The Reunion", Map: "Three Gels"}, + {ID: 46, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 8 - The Itch", Map: "Test"}, + {ID: 47, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 8 - The Itch", Map: "Funnel Intro"}, + {ID: 48, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 8 - The Itch", Map: "Ceiling Button"}, + {ID: 49, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 8 - The Itch", Map: "Wall Button"}, + {ID: 50, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 8 - The Itch", Map: "Polarity"}, + {ID: 51, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 8 - The Itch", Map: "Funnel Catch"}, + {ID: 52, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 8 - The Itch", Map: "Stop The Box"}, + {ID: 53, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 8 - The Itch", Map: "Laser Catapult"}, + {ID: 54, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 8 - The Itch", Map: "Laser Platform"}, + {ID: 55, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 8 - The Itch", Map: "Propulsion Catch"}, + {ID: 56, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 8 - The Itch", Map: "Repulsion Polarity"}, + {ID: 57, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 9 - The Part Where He Kills You", Map: "Finale 1"}, + {ID: 58, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 9 - The Part Where He Kills You", Map: "Finale 2"}, + {ID: 59, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 9 - The Part Where He Kills You", Map: "Finale 3"}, + {ID: 60, Game: "Portal 2 - Singleplayer", Chapter: "Chapter 9 - The Part Where He Kills You", Map: "Finale 4"}, + {ID: 61, Game: "Portal 2 - Cooperative", Chapter: "Course 0 - Introduction", Map: "Calibration"}, + {ID: 62, Game: "Portal 2 - Cooperative", Chapter: "Course 0 - Introduction", Map: "Hub"}, + {ID: 63, Game: "Portal 2 - Cooperative", Chapter: "Course 1 - Team Building", Map: "Doors"}, + {ID: 64, Game: "Portal 2 - Cooperative", Chapter: "Course 1 - Team Building", Map: "Buttons"}, + {ID: 65, Game: "Portal 2 - Cooperative", Chapter: "Course 1 - Team Building", Map: "Lasers"}, + {ID: 66, Game: "Portal 2 - Cooperative", Chapter: "Course 1 - Team Building", Map: "Rat Maze"}, + {ID: 67, Game: "Portal 2 - Cooperative", Chapter: "Course 1 - Team Building", Map: "Laser Crusher"}, + {ID: 68, Game: "Portal 2 - Cooperative", Chapter: "Course 1 - Team Building", Map: "Behind The Scenes"}, + {ID: 69, Game: "Portal 2 - Cooperative", Chapter: "Course 2 - Mass And Velocity", Map: "Flings"}, + {ID: 70, Game: "Portal 2 - Cooperative", Chapter: "Course 2 - Mass And Velocity", Map: "Infinifling"}, + {ID: 71, Game: "Portal 2 - Cooperative", Chapter: "Course 2 - Mass And Velocity", Map: "Team Retrieval"}, + {ID: 72, Game: "Portal 2 - Cooperative", Chapter: "Course 2 - Mass And Velocity", Map: "Vertical Flings"}, + {ID: 73, Game: "Portal 2 - Cooperative", Chapter: "Course 2 - Mass And Velocity", Map: "Catapults"}, + {ID: 74, Game: "Portal 2 - Cooperative", Chapter: "Course 2 - Mass And Velocity", Map: "Multifling"}, + {ID: 75, Game: "Portal 2 - Cooperative", Chapter: "Course 2 - Mass And Velocity", Map: "Fling Crushers"}, + {ID: 76, Game: "Portal 2 - Cooperative", Chapter: "Course 2 - Mass And Velocity", Map: "Industrial Fan"}, + {ID: 77, Game: "Portal 2 - Cooperative", Chapter: "Course 3 - Hard-Light Surfaces", Map: "Cooperative Bridges"}, + {ID: 78, Game: "Portal 2 - Cooperative", Chapter: "Course 3 - Hard-Light Surfaces", Map: "Bridge Swap"}, + {ID: 79, Game: "Portal 2 - Cooperative", Chapter: "Course 3 - Hard-Light Surfaces", Map: "Fling Block"}, + {ID: 80, Game: "Portal 2 - Cooperative", Chapter: "Course 3 - Hard-Light Surfaces", Map: "Catapult Block"}, + {ID: 81, Game: "Portal 2 - Cooperative", Chapter: "Course 3 - Hard-Light Surfaces", Map: "Bridge Fling"}, + {ID: 82, Game: "Portal 2 - Cooperative", Chapter: "Course 3 - Hard-Light Surfaces", Map: "Turret Walls"}, + {ID: 83, Game: "Portal 2 - Cooperative", Chapter: "Course 3 - Hard-Light Surfaces", Map: "Turret Assasin"}, + {ID: 84, Game: "Portal 2 - Cooperative", Chapter: "Course 3 - Hard-Light Surfaces", Map: "Bridge Testing"}, + {ID: 85, Game: "Portal 2 - Cooperative", Chapter: "Course 4 - Excursion Funnels", Map: "Cooperative Funnels"}, + {ID: 86, Game: "Portal 2 - Cooperative", Chapter: "Course 4 - Excursion Funnels", Map: "Funnel Drill"}, + {ID: 87, Game: "Portal 2 - Cooperative", Chapter: "Course 4 - Excursion Funnels", Map: "Funnel Catch"}, + {ID: 88, Game: "Portal 2 - Cooperative", Chapter: "Course 4 - Excursion Funnels", Map: "Funnel Laser"}, + {ID: 89, Game: "Portal 2 - Cooperative", Chapter: "Course 4 - Excursion Funnels", Map: "Cooperative Polarity"}, + {ID: 90, Game: "Portal 2 - Cooperative", Chapter: "Course 4 - Excursion Funnels", Map: "Funnel Hop"}, + {ID: 91, Game: "Portal 2 - Cooperative", Chapter: "Course 4 - Excursion Funnels", Map: "Advanced Polarity"}, + {ID: 92, Game: "Portal 2 - Cooperative", Chapter: "Course 4 - Excursion Funnels", Map: "Funnel Maze"}, + {ID: 93, Game: "Portal 2 - Cooperative", Chapter: "Course 4 - Excursion Funnels", Map: "Turret Warehouse"}, + {ID: 94, Game: "Portal 2 - Cooperative", Chapter: "Course 5 - Mobility Gels", Map: "Repulsion Jumps"}, + {ID: 95, Game: "Portal 2 - Cooperative", Chapter: "Course 5 - Mobility Gels", Map: "Double Bounce"}, + {ID: 96, Game: "Portal 2 - Cooperative", Chapter: "Course 5 - Mobility Gels", Map: "Bridge Repulsion"}, + {ID: 97, Game: "Portal 2 - Cooperative", Chapter: "Course 5 - Mobility Gels", Map: "Wall Repulsion"}, + {ID: 98, Game: "Portal 2 - Cooperative", Chapter: "Course 5 - Mobility Gels", Map: "Propulsion Crushers"}, + {ID: 99, Game: "Portal 2 - Cooperative", Chapter: "Course 5 - Mobility Gels", Map: "Turret Ninja"}, + {ID: 100, Game: "Portal 2 - Cooperative", Chapter: "Course 5 - Mobility Gels", Map: "Propulsion Retrieval"}, + {ID: 101, Game: "Portal 2 - Cooperative", Chapter: "Course 5 - Mobility Gels", Map: "Vault Entrance"}, + {ID: 102, Game: "Portal 2 - Cooperative", Chapter: "Course 6 - Art Therapy", Map: "Seperation"}, + {ID: 103, Game: "Portal 2 - Cooperative", Chapter: "Course 6 - Art Therapy", Map: "Triple Axis"}, + {ID: 104, Game: "Portal 2 - Cooperative", Chapter: "Course 6 - Art Therapy", Map: "Catapult Catch"}, + {ID: 105, Game: "Portal 2 - Cooperative", Chapter: "Course 6 - Art Therapy", Map: "Bridge Gels"}, + {ID: 106, Game: "Portal 2 - Cooperative", Chapter: "Course 6 - Art Therapy", Map: "Maintenance"}, + {ID: 107, Game: "Portal 2 - Cooperative", Chapter: "Course 6 - Art Therapy", Map: "Bridge Catch"}, + {ID: 108, Game: "Portal 2 - Cooperative", Chapter: "Course 6 - Art Therapy", Map: "Double Lift"}, + {ID: 109, Game: "Portal 2 - Cooperative", Chapter: "Course 6 - Art Therapy", Map: "Gel Maze"}, + {ID: 110, Game: "Portal 2 - Cooperative", Chapter: "Course 6 - Art Therapy", Map: "Crazier Box"}, } - var filteredMaps []models.MapShort + var filteredMaps []MapShortWithGame for _, m := range maps { - if strings.Contains(strings.ToLower(m.Name), strings.ToLower(query)) { + if strings.Contains(strings.ToLower(m.Map), strings.ToLower(query)) { filteredMaps = append(filteredMaps, m) } } response.Maps = filteredMaps if len(response.Maps) == 0 { - response.Maps = []models.MapShort{} + response.Maps = []MapShortWithGame{} } - rows, err := database.DB.Query("SELECT steam_id, user_name FROM users WHERE lower(user_name) LIKE $1", "%"+query+"%") + rows, err := database.DB.Query("SELECT steam_id, user_name, avatar_link FROM users WHERE lower(user_name) LIKE $1", "%"+query+"%") if err != nil { log.Fatal(err) } defer rows.Close() for rows.Next() { - var user models.UserShort - if err := rows.Scan(&user.SteamID, &user.UserName); err != nil { + var user models.UserShortWithAvatar + if err := rows.Scan(&user.SteamID, &user.UserName, &user.AvatarLink); err != nil { c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } response.Players = append(response.Players, user) } if len(response.Players) == 0 { - response.Players = []models.UserShort{} + response.Players = []models.UserShortWithAvatar{} } c.JSON(http.StatusOK, models.Response{ Success: true, -- cgit v1.2.3