aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2024-07-04 19:02:11 +0300
committerGitHub <noreply@github.com>2024-07-04 19:02:11 +0300
commit368f6dd461d768e835124afdd5aa0228d9e0ba0b (patch)
tree4b78a4571f6cc4b7e0f553d90f52c016c9d2b8e1 /backend
parentfix: fetchmaps image sql (diff)
downloadlphub-368f6dd461d768e835124afdd5aa0228d9e0ba0b.tar.gz
lphub-368f6dd461d768e835124afdd5aa0228d9e0ba0b.tar.bz2
lphub-368f6dd461d768e835124afdd5aa0228d9e0ba0b.zip
feat: update map tables db schema (#157)
Diffstat (limited to 'backend')
-rw-r--r--backend/database/init.sql15
-rw-r--r--backend/database/route.sql283
-rw-r--r--backend/handlers/map.go11
-rw-r--r--backend/handlers/mod.go86
-rw-r--r--backend/handlers/user.go24
5 files changed, 33 insertions, 386 deletions
diff --git a/backend/database/init.sql b/backend/database/init.sql
index 1fda15d..c33821b 100644
--- a/backend/database/init.sql
+++ b/backend/database/init.sql
@@ -48,25 +48,14 @@ CREATE TABLE maps (
48 FOREIGN KEY (chapter_id) REFERENCES chapters(id) 48 FOREIGN KEY (chapter_id) REFERENCES chapters(id)
49); 49);
50 50
51CREATE TABLE map_routes (
52 id SERIAL,
53 map_id SMALLINT NOT NULL,
54 category_id SMALLINT NOT NULL,
55 score_count SMALLINT NOT NULL,
56 description TEXT NOT NULL,
57 showcase TEXT NOT NULL DEFAULT,
58 PRIMARY KEY (id),
59 FOREIGN KEY (map_id) REFERENCES maps(id),
60 FOREIGN KEY (category_id) REFERENCES categories(id),
61 UNIQUE (map_id, category_id, score_count)
62);
63
64CREATE TABLE map_history ( 51CREATE TABLE map_history (
65 id SERIAL, 52 id SERIAL,
66 map_id SMALLINT NOT NULL, 53 map_id SMALLINT NOT NULL,
67 category_id SMALLINT NOT NULL, 54 category_id SMALLINT NOT NULL,
68 user_name TEXT NOT NULL, 55 user_name TEXT NOT NULL,
69 score_count SMALLINT NOT NULL, 56 score_count SMALLINT NOT NULL,
57 description TEXT NOT NULL,
58 showcase TEXT NOT NULL DEFAULT,
70 record_date DATE NOT NULL, 59 record_date DATE NOT NULL,
71 PRIMARY KEY (id), 60 PRIMARY KEY (id),
72 FOREIGN KEY (category_id) REFERENCES categories(id), 61 FOREIGN KEY (category_id) REFERENCES categories(id),
diff --git a/backend/database/route.sql b/backend/database/route.sql
deleted file mode 100644
index 8b23a8c..0000000
--- a/backend/database/route.sql
+++ /dev/null
@@ -1,283 +0,0 @@
1INSERT INTO map_routes(map_id,category_id,score_count,description,showcase) VALUES
2-- Portal 2 Singleplayer
3-- 1
4(3,1,3,'',''),
5(3,1,1,'',''),
6(3,1,0,'',''),
7(4,1,1,'',''),
8(4,1,0,'',''),
9(5,1,2,'',''),
10(5,1,1,'',''),
11(6,1,4,'',''),
12(6,1,3,'',''),
13(6,1,2,'',''),
14(7,1,0,'',''),
15(9,1,4,'',''),
16(9,1,3,'',''),
17(9,1,2,'',''),
18(9,1,0,'',''),
19-- 2
20(10,1,2,'',''),
21(10,1,0,'',''),
22(11,1,2,'',''),
23(11,1,0,'',''),
24(12,1,2,'',''),
25(13,1,3,'',''),
26(13,1,2,'',''),
27(13,1,0,'',''),
28(14,1,0,'',''),
29(15,1,2,'',''),
30(16,1,2,'',''),
31(16,1,0,'',''),
32(17,1,2,'',''),
33(17,1,0,'',''),
34-- 3
35(18,1,5,'',''),
36(18,1,4,'',''),
37(18,1,3,'',''),
38(18,1,2,'',''),
39(18,1,0,'',''),
40(19,1,2,'',''),
41(20,1,5,'',''),
42(20,1,4,'',''),
43(20,1,3,'',''),
44(20,1,2,'',''),
45(21,1,4,'',''),
46(21,1,2,'',''),
47(21,1,0,'',''),
48(22,1,0,'',''),
49(23,1,2,'',''),
50(23,1,0,'',''),
51(24,1,0,'',''),
52(25,1,0,'',''),
53(26,1,3,'',''),
54(26,1,2,'',''),
55(26,1,0,'',''),
56-- 4
57(27,1,2,'',''),
58(27,1,0,'',''),
59(28,1,7,'',''),
60(28,1,2,'',''),
61(28,1,0,'',''),
62(29,1,0,'',''),
63(30,1,2,'',''),
64(31,1,0,'',''),
65-- 5
66(32,1,6,'',''),
67(32,1,5,'',''),
68(33,1,7,'',''),
69(33,1,5,'',''),
70(33,1,4,'',''),
71(34,1,3,'',''),
72(34,1,2,'',''),
73(34,1,0,'',''),
74(35,1,2,'',''),
75-- 6
76(36,1,6,'',''),
77(36,1,5,'',''),
78(36,1,4,'',''),
79(36,1,2,'',''),
80(37,1,7,'',''),
81(37,1,6,'',''),
82(37,1,5,'',''),
83(37,1,4,'',''),
84(38,1,2,'',''),
85(38,1,0,'',''),
86(39,1,6,'',''),
87(39,1,5,'',''),
88(39,1,4,'',''),
89(39,1,3,'',''),
90(40,1,7,'',''),
91(40,1,6,'',''),
92(40,1,4,'',''),
93(40,1,3,'',''),
94(40,1,2,'',''),
95(40,1,0,'',''),
96(41,1,7,'',''),
97(41,1,6,'',''),
98(41,1,5,'',''),
99-- 7
100(42,1,4,'',''),
101(42,1,2,'',''),
102(43,1,5,'',''),
103(43,1,2,'',''),
104(43,1,0,'',''),
105(44,1,18,'',''),
106(44,1,13,'',''),
107(44,1,12,'',''),
108(44,1,11,'',''),
109(44,1,9,'',''),
110(45,1,23,'',''),
111(45,1,22,'',''),
112(45,1,17,'',''),
113(45,1,16,'',''),
114(45,1,15,'',''),
115(45,1,12,'',''),
116(45,1,10,'',''),
117(45,1,7,'',''),
118(45,1,4,'',''),
119-- 8
120(46,1,6,'',''),
121(46,1,2,'',''),
122(47,1,2,'',''),
123(47,1,0,'',''),
124(48,1,5,'',''),
125(48,1,2,'',''),
126(48,1,0,'',''),
127(49,1,4,'',''),
128(49,1,2,'',''),
129(49,1,0,'',''),
130(50,1,4,'',''),
131(50,1,2,'',''),
132(50,1,0,'',''),
133(51,1,3,'',''),
134(51,1,2,'',''),
135(52,1,0,'',''),
136(53,1,9,'',''),
137(53,1,2,'',''),
138(53,1,0,'',''),
139(54,1,7,'',''),
140(54,1,6,'',''),
141(54,1,5,'',''),
142(54,1,4,'',''),
143(54,1,3,'',''),
144(55,1,7,'',''),
145(55,1,3,'',''),
146(55,1,2,'',''),
147(55,1,0,'',''),
148(56,1,9,'',''),
149(56,1,5,'',''),
150(56,1,4,'',''),
151(56,1,2,'',''),
152-- 9
153(57,1,7,'',''),
154(57,1,5,'',''),
155(57,1,0,'',''),
156(58,1,2,'',''),
157(59,1,7,'',''),
158(59,1,6,'',''),
159(60,1,7,'',''),
160(60,1,6,'',''),
161-- Portal 2 Cooperative
162-- 1
163(63,1,0,'',''),
164(64,1,3,'',''),
165(64,1,2,'',''),
166(65,1,4,'',''),
167(65,1,3,'',''),
168(65,1,2,'',''),
169(66,1,3,'',''),
170(66,1,2,'',''),
171(67,1,0,'',''),
172(68,1,0,'',''),
173-- 2
174(69,1,4,'',''),
175(70,1,6,'',''),
176(70,1,4,'',''),
177(70,1,2,'',''),
178(70,1,0,'',''),
179(71,1,3,'',''),
180(71,1,0,'',''),
181(72,1,4,'',''),
182(72,1,2,'',''),
183(73,1,9,'',''),
184(73,1,8,'',''),
185(73,1,7,'',''),
186(73,1,6,'',''),
187(73,1,4,'',''),
188(74,1,5,'',''),
189(74,1,7,'',''),
190(74,1,3,'',''),
191(74,1,2,'',''),
192(75,1,5,'',''),
193(75,1,4,'',''),
194(75,1,2,'',''),
195(75,1,0,'',''),
196(76,1,3,'',''),
197(76,1,0,'',''),
198-- 3
199(77,1,3,'',''),
200(78,1,4,'',''),
201(78,1,3,'',''),
202(78,1,2,'',''),
203(79,1,5,'',''),
204(79,1,4,'',''),
205(79,1,2,'',''),
206(79,1,0,'',''),
207(80,1,5,'',''),
208(80,1,4,'',''),
209(81,1,7,'',''),
210(81,1,6,'',''),
211(81,1,5,'',''),
212(81,1,4,'',''),
213(82,1,4,'',''),
214(83,1,5,'',''),
215(83,1,2,'',''),
216(83,1,0,'',''),
217(84,1,6,'',''),
218(84,1,4,'',''),
219(84,1,2,'',''),
220(84,1,0,'',''),
221-- 4
222(85,1,3,'',''),
223(85,1,0,'',''),
224(86,1,3,'',''),
225(86,1,0,'',''),
226(87,1,3,'',''),
227(87,1,2,'',''),
228(87,1,0,'',''),
229(88,1,4,'',''),
230(88,1,0,'',''),
231(89,1,0,'',''),
232(90,1,4,'',''),
233(90,1,2,'',''),
234(90,1,0,'',''),
235(91,1,2,'',''),
236(91,1,0,'',''),
237(92,1,5,'',''),
238(92,1,4,'',''),
239(92,1,2,'',''),
240(92,1,0,'',''),
241(93,1,2,'',''),
242(93,1,0,'',''),
243-- 5
244(94,1,2,'',''),
245(94,1,0,'',''),
246(95,1,2,'',''),
247(96,1,4,'',''),
248(96,1,2,'',''),
249(97,1,7,'',''),
250(97,1,4,'',''),
251(97,1,2,'',''),
252(98,1,0,'',''),
253(99,1,3,'',''),
254(99,1,2,'',''),
255(99,1,0,'',''),
256(100,1,0,'',''),
257(101,1,2,'',''),
258(101,1,0,'',''),
259-- 6
260(102,1,3,'',''),
261(102,1,2,'',''),
262(102,1,0,'',''),
263(103,1,0,'',''),
264(104,1,0,'',''),
265(105,1,8,'',''),
266(105,1,5,'',''),
267(105,1,4,'',''),
268(105,1,3,'',''),
269(105,1,2,'',''),
270(106,1,4,'',''),
271(106,1,3,'',''),
272(106,1,0,'',''),
273(107,1,2,'',''),
274(107,1,0,'',''),
275(108,1,0,'',''),
276(109,1,5,'',''),
277(109,1,0,'',''),
278(110,1,15,'',''),
279(110,1,6,'',''),
280(110,1,5,'',''),
281(110,1,4,'',''),
282(110,1,2,'',''),
283(110,1,0,'',''); \ No newline at end of file
diff --git a/backend/handlers/map.go b/backend/handlers/map.go
index f2ea8ac..bf7c821 100644
--- a/backend/handlers/map.go
+++ b/backend/handlers/map.go
@@ -87,12 +87,11 @@ func FetchMapSummary(c *gin.Context) {
87 return 87 return
88 } 88 }
89 // Get map routes and histories 89 // Get map routes and histories
90 sql = `SELECT r.id, c.id, c.name, h.user_name, h.score_count, h.record_date, r.description, r.showcase, COALESCE(avg(rating), 0.0) FROM map_routes r 90 sql = `SELECT mh.id, c.id, c.name, mh.user_name, mh.score_count, mh.record_date, mh.description, mh.showcase, COALESCE(avg(rating), 0.0) FROM map_history mh
91 INNER JOIN categories c ON r.category_id = c.id 91 INNER JOIN categories c ON mh.category_id = c.id
92 INNER JOIN map_history h ON r.map_id = h.map_id AND r.category_id = h.category_id 92 LEFT JOIN map_ratings rt ON mh.map_id = rt.map_id AND mh.category_id = rt.category_id
93 LEFT JOIN map_ratings rt ON r.map_id = rt.map_id AND r.category_id = rt.category_id 93 WHERE mh.map_id = $1 AND mh.score_count = mh.score_count GROUP BY mh.id, c.id, mh.user_name, mh.score_count, mh.record_date, mh.description, mh.showcase
94 WHERE r.map_id = $1 AND h.score_count = r.score_count GROUP BY r.id, c.id, h.user_name, h.score_count, h.record_date, r.description, r.showcase 94 ORDER BY mh.record_date ASC;`
95 ORDER BY h.record_date ASC;`
96 rows, err := database.DB.Query(sql, id) 95 rows, err := database.DB.Query(sql, id)
97 if err != nil { 96 if err != nil {
98 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 97 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
diff --git a/backend/handlers/mod.go b/backend/handlers/mod.go
index 3709e1d..72a9fd8 100644
--- a/backend/handlers/mod.go
+++ b/backend/handlers/mod.go
@@ -16,7 +16,7 @@ type CreateMapSummaryRequest struct {
16 Description string `json:"description" binding:"required"` 16 Description string `json:"description" binding:"required"`
17 Showcase string `json:"showcase"` 17 Showcase string `json:"showcase"`
18 UserName string `json:"user_name" binding:"required"` 18 UserName string `json:"user_name" binding:"required"`
19 ScoreCount *int `json:"score_count"` 19 ScoreCount int `json:"score_count" binding:"required"`
20 RecordDate time.Time `json:"record_date" binding:"required"` 20 RecordDate time.Time `json:"record_date" binding:"required"`
21} 21}
22 22
@@ -25,7 +25,7 @@ type EditMapSummaryRequest struct {
25 Description string `json:"description" binding:"required"` 25 Description string `json:"description" binding:"required"`
26 Showcase string `json:"showcase"` 26 Showcase string `json:"showcase"`
27 UserName string `json:"user_name" binding:"required"` 27 UserName string `json:"user_name" binding:"required"`
28 ScoreCount int `json:"score_count"` 28 ScoreCount int `json:"score_count" binding:"required"`
29 RecordDate time.Time `json:"record_date" binding:"required"` 29 RecordDate time.Time `json:"record_date" binding:"required"`
30} 30}
31 31
@@ -93,17 +93,9 @@ func CreateMapSummary(c *gin.Context) {
93 return 93 return
94 } 94 }
95 // Update database with new data 95 // Update database with new data
96 sql = `INSERT INTO map_routes (map_id,category_id,score_count,description,showcase) 96 sql = `INSERT INTO map_history (map_id,category_id,user_name,score_count,description,showcase,record_date)
97 VALUES ($1,$2,$3,$4,$5)` 97 VALUES ($1,$2,$3,$4,$5)`
98 _, err = tx.Exec(sql, mapID, request.CategoryID, request.ScoreCount, request.Description, request.Showcase) 98 _, err = tx.Exec(sql, mapID, request.CategoryID, request.UserName, request.ScoreCount, request.Description, request.Showcase, request.RecordDate)
99 if err != nil {
100 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, fmt.Sprintf("INSERT#map_routes: %s", err.Error()))
101 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
102 return
103 }
104 sql = `INSERT INTO map_history (map_id,category_id,user_name,score_count,record_date)
105 VALUES ($1,$2,$3,$4,$5)`
106 _, err = tx.Exec(sql, mapID, request.CategoryID, request.UserName, request.ScoreCount, request.RecordDate)
107 if err != nil { 99 if err != nil {
108 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, fmt.Sprintf("INSERT#map_history: %s", err.Error())) 100 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, fmt.Sprintf("INSERT#map_history: %s", err.Error()))
109 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 101 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
@@ -113,7 +105,7 @@ func CreateMapSummary(c *gin.Context) {
113 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 105 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
114 return 106 return
115 } 107 }
116 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateSuccess, fmt.Sprintf("MapID: %d | CategoryID: %d | ScoreCount: %d", mapID, request.CategoryID, *request.ScoreCount)) 108 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateSuccess, fmt.Sprintf("MapID: %d | CategoryID: %d | ScoreCount: %d", mapID, request.CategoryID, request.ScoreCount))
117 c.JSON(http.StatusOK, models.Response{ 109 c.JSON(http.StatusOK, models.Response{
118 Success: true, 110 Success: true,
119 Message: "Successfully created map summary.", 111 Message: "Successfully created map summary.",
@@ -145,7 +137,8 @@ func EditMapSummary(c *gin.Context) {
145 } 137 }
146 // Bind parameter and body 138 // Bind parameter and body
147 id := c.Param("mapid") 139 id := c.Param("mapid")
148 mapID, err := strconv.Atoi(id) 140 // we get mapid in path parameters, but it's not really used anywhere here lol.
141 _, err := strconv.Atoi(id)
149 if err != nil { 142 if err != nil {
150 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 143 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
151 return 144 return
@@ -163,34 +156,11 @@ func EditMapSummary(c *gin.Context) {
163 return 156 return
164 } 157 }
165 defer tx.Rollback() 158 defer tx.Rollback()
166 // Fetch route category and score count
167 var categoryID, scoreCount, historyID int
168 sql := `SELECT mr.category_id, mr.score_count FROM map_routes mr INNER JOIN maps m ON m.id = mr.map_id WHERE m.id = $1 AND mr.id = $2`
169 err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&categoryID, &scoreCount)
170 if err != nil {
171 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, fmt.Sprintf("(RouteID: %d) SELECT#map_routes: %s", request.RouteID, err.Error()))
172 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
173 return
174 }
175 sql = `SELECT mh.id FROM map_history mh WHERE mh.score_count = $1 AND mh.category_id = $2 AND mh.map_id = $3`
176 err = database.DB.QueryRow(sql, scoreCount, categoryID, mapID).Scan(&historyID)
177 if err != nil {
178 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, fmt.Sprintf("(RouteID: %d) SELECT#map_history: %s", request.RouteID, err.Error()))
179 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
180 return
181 }
182 // Update database with new data 159 // Update database with new data
183 sql = `UPDATE map_routes SET score_count = $2, description = $3, showcase = $4 WHERE id = $1` 160 sql := `UPDATE map_history SET user_name = $2, score_count = $3, record_date = $4, description = $5, showcase = $6 WHERE id = $1`
184 _, err = tx.Exec(sql, request.RouteID, request.ScoreCount, request.Description, request.Showcase) 161 _, err = tx.Exec(sql, request.RouteID, request.UserName, request.ScoreCount, request.RecordDate, request.Description, request.Showcase)
185 if err != nil {
186 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, fmt.Sprintf("(RouteID: %d) UPDATE#map_routes: %s", request.RouteID, err.Error()))
187 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
188 return
189 }
190 sql = `UPDATE map_history SET user_name = $2, score_count = $3, record_date = $4 WHERE id = $1`
191 _, err = tx.Exec(sql, historyID, request.UserName, request.ScoreCount, request.RecordDate)
192 if err != nil { 162 if err != nil {
193 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, fmt.Sprintf("(HistoryID: %d) UPDATE#map_history: %s", historyID, err.Error())) 163 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, fmt.Sprintf("(HistoryID: %d) UPDATE#map_history: %s", request.RouteID, err.Error()))
194 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 164 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
195 return 165 return
196 } 166 }
@@ -198,7 +168,6 @@ func EditMapSummary(c *gin.Context) {
198 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 168 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
199 return 169 return
200 } 170 }
201 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditSuccess, fmt.Sprintf("MapID: %d | CategoryID: %d | ScoreCount: %d", mapID, categoryID, scoreCount))
202 c.JSON(http.StatusOK, models.Response{ 171 c.JSON(http.StatusOK, models.Response{
203 Success: true, 172 Success: true,
204 Message: "Successfully updated map summary.", 173 Message: "Successfully updated map summary.",
@@ -230,7 +199,8 @@ func DeleteMapSummary(c *gin.Context) {
230 } 199 }
231 // Bind parameter and body 200 // Bind parameter and body
232 id := c.Param("mapid") 201 id := c.Param("mapid")
233 mapID, err := strconv.Atoi(id) 202 // we get mapid in path parameters, but it's not really used anywhere here lol.
203 _, err := strconv.Atoi(id)
234 if err != nil { 204 if err != nil {
235 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 205 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
236 return 206 return
@@ -248,38 +218,11 @@ func DeleteMapSummary(c *gin.Context) {
248 return 218 return
249 } 219 }
250 defer tx.Rollback() 220 defer tx.Rollback()
251 // Fetch route category and score count
252 var checkMapID, scoreCount, categoryID, mapHistoryID int
253 sql := `SELECT m.id, mr.score_count, mr.category_id FROM maps m INNER JOIN map_routes mr ON m.id=mr.map_id WHERE m.id = $1 AND mr.id = $2`
254 err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&checkMapID, &scoreCount, &categoryID)
255 if err != nil {
256 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, fmt.Sprintf("(RouteID: %d) SELECT#map_routes: %s", request.RouteID, err.Error()))
257 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
258 return
259 }
260 if mapID != checkMapID {
261 c.JSON(http.StatusOK, models.ErrorResponse("Map ID does not exist."))
262 return
263 }
264 sql = `SELECT mh.id FROM maps m INNER JOIN map_routes mr ON m.id=mr.map_id INNER JOIN map_history mh ON m.id=mh.map_id WHERE m.id = $1 AND mh.category_id = $2 AND mh.score_count = $3`
265 err = database.DB.QueryRow(sql, mapID, categoryID, scoreCount).Scan(&mapHistoryID)
266 if err != nil {
267 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, fmt.Sprintf("(RouteID: %d) SELECT#map_history: %s", request.RouteID, err.Error()))
268 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
269 return
270 }
271 // Update database with new data 221 // Update database with new data
272 sql = `DELETE FROM map_routes mr WHERE mr.id = $1 ` 222 sql := `DELETE FROM map_history mh WHERE mh.id = $1`
273 _, err = tx.Exec(sql, request.RouteID) 223 _, err = tx.Exec(sql, request.RouteID)
274 if err != nil { 224 if err != nil {
275 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, fmt.Sprintf("(RouteID: %d) DELETE#map_routes: %s", request.RouteID, err.Error())) 225 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, fmt.Sprintf("(HistoryID: %d) DELETE#map_history: %s", request.RouteID, err.Error()))
276 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
277 return
278 }
279 sql = `DELETE FROM map_history mh WHERE mh.id = $1`
280 _, err = tx.Exec(sql, mapHistoryID)
281 if err != nil {
282 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, fmt.Sprintf("(HistoryID: %d) DELETE#map_history: %s", mapHistoryID, err.Error()))
283 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 226 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
284 return 227 return
285 } 228 }
@@ -287,7 +230,6 @@ func DeleteMapSummary(c *gin.Context) {
287 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 230 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
288 return 231 return
289 } 232 }
290 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteSuccess, fmt.Sprintf("MapID: %d | CategoryID: %d | ScoreCount: %d", mapID, categoryID, scoreCount))
291 c.JSON(http.StatusOK, models.Response{ 233 c.JSON(http.StatusOK, models.Response{
292 Success: true, 234 Success: true,
293 Message: "Successfully delete map summary.", 235 Message: "Successfully delete map summary.",
diff --git a/backend/handlers/user.go b/backend/handlers/user.go
index 88bbe45..8febf3a 100644
--- a/backend/handlers/user.go
+++ b/backend/handlers/user.go
@@ -99,15 +99,15 @@ func Profile(c *gin.Context) {
99 // Get user completion count 99 // Get user completion count
100 sql = `SELECT 'records_sp' AS table_name, COUNT(sp.id) 100 sql = `SELECT 'records_sp' AS table_name, COUNT(sp.id)
101 FROM records_sp sp JOIN ( 101 FROM records_sp sp JOIN (
102 SELECT mr.map_id, MIN(mr.score_count) AS min_score_count 102 SELECT mh.map_id, MIN(mh.score_count) AS min_score_count
103 FROM public.map_routes mr WHERE mr.category_id = 1 GROUP BY mr.map_id 103 FROM public.map_history mh WHERE mh.category_id = 1 GROUP BY mh.map_id
104 ) AS subquery_sp ON sp.map_id = subquery_sp.map_id AND sp.score_count = subquery_sp.min_score_count 104 ) AS subquery_sp ON sp.map_id = subquery_sp.map_id AND sp.score_count = subquery_sp.min_score_count
105 WHERE sp.user_id = $1 AND sp.is_deleted = false 105 WHERE sp.user_id = $1 AND sp.is_deleted = false
106 UNION ALL 106 UNION ALL
107 SELECT 'records_mp' AS table_name, COUNT(mp.id) 107 SELECT 'records_mp' AS table_name, COUNT(mp.id)
108 FROM public.records_mp mp JOIN ( 108 FROM public.records_mp mp JOIN (
109 SELECT mr.map_id, MIN(mr.score_count) AS min_score_count 109 SELECT mh.map_id, MIN(mh.score_count) AS min_score_count
110 FROM public.map_routes mr WHERE mr.category_id = 1 GROUP BY mr.map_id 110 FROM public.map_history mh WHERE mh.category_id = 1 GROUP BY mh.map_id
111 ) AS subquery_mp ON mp.map_id = subquery_mp.map_id AND mp.score_count = subquery_mp.min_score_count 111 ) AS subquery_mp ON mp.map_id = subquery_mp.map_id AND mp.score_count = subquery_mp.min_score_count
112 WHERE (mp.host_id = $1 OR mp.partner_id = $1) AND mp.is_deleted = false` 112 WHERE (mp.host_id = $1 OR mp.partner_id = $1) AND mp.is_deleted = false`
113 rows, err := database.DB.Query(sql, user.(models.User).SteamID) 113 rows, err := database.DB.Query(sql, user.(models.User).SteamID)
@@ -293,7 +293,7 @@ func Profile(c *gin.Context) {
293 } 293 }
294 records := []ProfileRecords{} 294 records := []ProfileRecords{}
295 // Get singleplayer records 295 // Get singleplayer records
296 sql = `SELECT sp.id, m.game_id, m.chapter_id, sp.map_id, m."name", (SELECT mr.score_count FROM map_routes mr WHERE mr.map_id = sp.map_id ORDER BY mr.score_count ASC LIMIT 1) AS wr_count, sp.score_count, sp.score_time, sp.demo_id, sp.record_date 296 sql = `SELECT sp.id, m.game_id, m.chapter_id, sp.map_id, m."name", (SELECT mh.score_count FROM map_history mh WHERE mh.map_id = sp.map_id ORDER BY mh.score_count ASC LIMIT 1) AS wr_count, sp.score_count, sp.score_time, sp.demo_id, sp.record_date
297 FROM records_sp sp INNER JOIN maps m ON sp.map_id = m.id WHERE sp.user_id = $1 AND sp.is_deleted = false ORDER BY sp.map_id, sp.score_count, sp.score_time` 297 FROM records_sp sp INNER JOIN maps m ON sp.map_id = m.id WHERE sp.user_id = $1 AND sp.is_deleted = false ORDER BY sp.map_id, sp.score_count, sp.score_time`
298 rows, err = database.DB.Query(sql, user.(models.User).SteamID) 298 rows, err = database.DB.Query(sql, user.(models.User).SteamID)
299 if err != nil { 299 if err != nil {
@@ -347,7 +347,7 @@ func Profile(c *gin.Context) {
347 records[len(records)-1].Scores = append(records[len(records)-1].Scores, score) 347 records[len(records)-1].Scores = append(records[len(records)-1].Scores, score)
348 } 348 }
349 // Get multiplayer records 349 // Get multiplayer records
350 sql = `SELECT mp.id, m.game_id, m.chapter_id, mp.map_id, m."name", (SELECT mr.score_count FROM map_routes mr WHERE mr.map_id = mp.map_id ORDER BY mr.score_count ASC LIMIT 1) AS wr_count, mp.score_count, mp.score_time, CASE WHEN host_id = $1 THEN mp.host_demo_id WHEN partner_id = $1 THEN mp.partner_demo_id END demo_id, mp.record_date 350 sql = `SELECT mp.id, m.game_id, m.chapter_id, mp.map_id, m."name", (SELECT mh.score_count FROM map_history mh WHERE mh.map_id = mp.map_id ORDER BY mh.score_count ASC LIMIT 1) AS wr_count, mp.score_count, mp.score_time, CASE WHEN host_id = $1 THEN mp.host_demo_id WHEN partner_id = $1 THEN mp.partner_demo_id END demo_id, mp.record_date
351 FROM records_mp mp INNER JOIN maps m ON mp.map_id = m.id WHERE (mp.host_id = $1 OR mp.partner_id = $1) AND mp.is_deleted = false ORDER BY mp.map_id, mp.score_count, mp.score_time` 351 FROM records_mp mp INNER JOIN maps m ON mp.map_id = m.id WHERE (mp.host_id = $1 OR mp.partner_id = $1) AND mp.is_deleted = false ORDER BY mp.map_id, mp.score_count, mp.score_time`
352 rows, err = database.DB.Query(sql, user.(models.User).SteamID) 352 rows, err = database.DB.Query(sql, user.(models.User).SteamID)
353 if err != nil { 353 if err != nil {
@@ -473,15 +473,15 @@ func FetchUser(c *gin.Context) {
473 // Get user completion count 473 // Get user completion count
474 sql = `SELECT 'records_sp' AS table_name, COUNT(sp.id) 474 sql = `SELECT 'records_sp' AS table_name, COUNT(sp.id)
475 FROM records_sp sp JOIN ( 475 FROM records_sp sp JOIN (
476 SELECT mr.map_id, MIN(mr.score_count) AS min_score_count 476 SELECT mh.map_id, MIN(mh.score_count) AS min_score_count
477 FROM public.map_routes mr WHERE mr.category_id = 1 GROUP BY mr.map_id 477 FROM public.map_history mh WHERE mh.category_id = 1 GROUP BY mh.map_id
478 ) AS subquery_sp ON sp.map_id = subquery_sp.map_id AND sp.score_count = subquery_sp.min_score_count 478 ) AS subquery_sp ON sp.map_id = subquery_sp.map_id AND sp.score_count = subquery_sp.min_score_count
479 WHERE sp.user_id = $1 AND sp.is_deleted = false 479 WHERE sp.user_id = $1 AND sp.is_deleted = false
480 UNION ALL 480 UNION ALL
481 SELECT 'records_mp' AS table_name, COUNT(mp.id) 481 SELECT 'records_mp' AS table_name, COUNT(mp.id)
482 FROM public.records_mp mp JOIN ( 482 FROM public.records_mp mp JOIN (
483 SELECT mr.map_id, MIN(mr.score_count) AS min_score_count 483 SELECT mh.map_id, MIN(mh.score_count) AS min_score_count
484 FROM public.map_routes mr WHERE mr.category_id = 1 GROUP BY mr.map_id 484 FROM public.map_history mh WHERE mh.category_id = 1 GROUP BY mh.map_id
485 ) AS subquery_mp ON mp.map_id = subquery_mp.map_id AND mp.score_count = subquery_mp.min_score_count 485 ) AS subquery_mp ON mp.map_id = subquery_mp.map_id AND mp.score_count = subquery_mp.min_score_count
486 WHERE (mp.host_id = $1 OR mp.partner_id = $1) AND mp.is_deleted = false` 486 WHERE (mp.host_id = $1 OR mp.partner_id = $1) AND mp.is_deleted = false`
487 rows, err = database.DB.Query(sql, user.SteamID) 487 rows, err = database.DB.Query(sql, user.SteamID)
@@ -667,7 +667,7 @@ func FetchUser(c *gin.Context) {
667 } 667 }
668 records := []ProfileRecords{} 668 records := []ProfileRecords{}
669 // Get singleplayer records 669 // Get singleplayer records
670 sql = `SELECT sp.id, m.game_id, m.chapter_id, sp.map_id, m."name", (SELECT mr.score_count FROM map_routes mr WHERE mr.map_id = sp.map_id ORDER BY mr.score_count ASC LIMIT 1) AS wr_count, sp.score_count, sp.score_time, sp.demo_id, sp.record_date 670 sql = `SELECT sp.id, m.game_id, m.chapter_id, sp.map_id, m."name", (SELECT mh.score_count FROM map_history mh WHERE mh.map_id = sp.map_id ORDER BY mh.score_count ASC LIMIT 1) AS wr_count, sp.score_count, sp.score_time, sp.demo_id, sp.record_date
671 FROM records_sp sp INNER JOIN maps m ON sp.map_id = m.id WHERE sp.user_id = $1 AND sp.is_deleted = false ORDER BY sp.map_id, sp.score_count, sp.score_time` 671 FROM records_sp sp INNER JOIN maps m ON sp.map_id = m.id WHERE sp.user_id = $1 AND sp.is_deleted = false ORDER BY sp.map_id, sp.score_count, sp.score_time`
672 rows, err = database.DB.Query(sql, user.SteamID) 672 rows, err = database.DB.Query(sql, user.SteamID)
673 if err != nil { 673 if err != nil {
@@ -721,7 +721,7 @@ func FetchUser(c *gin.Context) {
721 records[len(records)-1].Scores = append(records[len(records)-1].Scores, score) 721 records[len(records)-1].Scores = append(records[len(records)-1].Scores, score)
722 } 722 }
723 // Get multiplayer records 723 // Get multiplayer records
724 sql = `SELECT mp.id, m.game_id, m.chapter_id, mp.map_id, m."name", (SELECT mr.score_count FROM map_routes mr WHERE mr.map_id = mp.map_id ORDER BY mr.score_count ASC LIMIT 1) AS wr_count, mp.score_count, mp.score_time, CASE WHEN host_id = $1 THEN mp.host_demo_id WHEN partner_id = $1 THEN mp.partner_demo_id END demo_id, mp.record_date 724 sql = `SELECT mp.id, m.game_id, m.chapter_id, mp.map_id, m."name", (SELECT mh.score_count FROM map_history mh WHERE mh.map_id = mp.map_id ORDER BY mh.score_count ASC LIMIT 1) AS wr_count, mp.score_count, mp.score_time, CASE WHEN host_id = $1 THEN mp.host_demo_id WHEN partner_id = $1 THEN mp.partner_demo_id END demo_id, mp.record_date
725 FROM records_mp mp INNER JOIN maps m ON mp.map_id = m.id WHERE (mp.host_id = $1 OR mp.partner_id = $1) AND mp.is_deleted = false ORDER BY mp.map_id, mp.score_count, mp.score_time` 725 FROM records_mp mp INNER JOIN maps m ON mp.map_id = m.id WHERE (mp.host_id = $1 OR mp.partner_id = $1) AND mp.is_deleted = false ORDER BY mp.map_id, mp.score_count, mp.score_time`
726 rows, err = database.DB.Query(sql, user.SteamID) 726 rows, err = database.DB.Query(sql, user.SteamID)
727 if err != nil { 727 if err != nil {