Skip to content
This repository was archived by the owner on Sep 2, 2024. It is now read-only.

Commit 39caa4b

Browse files
authored
Merge pull request #69 from VladPetriv/refactor/replace-depracaded-function
refactor: remove deprecated function
2 parents a1a7162 + ec770fc commit 39caa4b

File tree

4 files changed

+14
-56
lines changed

4 files changed

+14
-56
lines changed

db.go

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ func (database *Database) add(w http.ResponseWriter, r *http.Request) {
6161
return
6262
}
6363

64-
_, r.URL.Path = ShiftPath(r.URL.Path)
65-
col, _ := ShiftPath(r.URL.Path)
64+
col := getURLPart(r.URL.Path, 2)
6665

6766
var v interface{}
6867
if err := json.NewDecoder(r.Body).Decode(&v); err != nil {
@@ -92,8 +91,7 @@ func (database *Database) bulkAdd(w http.ResponseWriter, r *http.Request) {
9291
return
9392
}
9493

95-
_, r.URL.Path = ShiftPath(r.URL.Path)
96-
col, _ := ShiftPath(r.URL.Path)
94+
col := getURLPart(r.URL.Path, 2)
9795

9896
var v []interface{}
9997
if err := json.NewDecoder(r.Body).Decode(&v); err != nil {
@@ -124,8 +122,7 @@ func (database *Database) list(w http.ResponseWriter, r *http.Request) {
124122
return
125123
}
126124

127-
_, r.URL.Path = ShiftPath(r.URL.Path)
128-
col, _ := ShiftPath(r.URL.Path)
125+
col := getURLPart(r.URL.Path, 2)
129126

130127
result, err := backend.DB.ListDocuments(auth, conf.Name, col, params)
131128
if err != nil {
@@ -177,11 +174,8 @@ func (database *Database) get(w http.ResponseWriter, r *http.Request) {
177174
return
178175
}
179176

180-
col, id := "", ""
181-
182-
_, r.URL.Path = ShiftPath(r.URL.Path)
183-
col, r.URL.Path = ShiftPath(r.URL.Path)
184-
id, r.URL.Path = ShiftPath(r.URL.Path)
177+
col := getURLPart(r.URL.Path, 2)
178+
id := getURLPart(r.URL.Path, 3)
185179

186180
result, err := backend.DB.GetDocumentByID(auth, conf.Name, col, id)
187181
if err != nil {
@@ -225,10 +219,7 @@ func (database *Database) query(w http.ResponseWriter, r *http.Request) {
225219
return
226220
}
227221

228-
var col string
229-
230-
_, r.URL.Path = ShiftPath(r.URL.Path)
231-
col, r.URL.Path = ShiftPath(r.URL.Path)
222+
col := getURLPart(r.URL.Path, 2)
232223

233224
result, err := backend.DB.QueryDocuments(auth, conf.Name, col, filter, params)
234225
if err != nil {
@@ -246,10 +237,7 @@ func (database *Database) getByIds(w http.ResponseWriter, r *http.Request) {
246237
return
247238
}
248239

249-
col := ""
250-
251-
_, r.URL.Path = ShiftPath(r.URL.Path)
252-
col, r.URL.Path = ShiftPath(r.URL.Path)
240+
col := getURLPart(r.URL.Path, 2)
253241

254242
var ids []string
255243
if err := parseBody(r.Body, &ids); err != nil {
@@ -278,11 +266,8 @@ func (database *Database) update(w http.ResponseWriter, r *http.Request) {
278266
return
279267
}
280268

281-
col, id := "", ""
282-
283-
_, r.URL.Path = ShiftPath(r.URL.Path)
284-
col, r.URL.Path = ShiftPath(r.URL.Path)
285-
id, r.URL.Path = ShiftPath(r.URL.Path)
269+
col := getURLPart(r.URL.Path, 2)
270+
id := getURLPart(r.URL.Path, 3)
286271

287272
var v interface{}
288273
if err := json.NewDecoder(r.Body).Decode(&v); err != nil {
@@ -312,10 +297,7 @@ func (database *Database) bulkUpdate(w http.ResponseWriter, r *http.Request) {
312297
return
313298
}
314299

315-
var col string
316-
317-
_, r.URL.Path = ShiftPath(r.URL.Path)
318-
col, r.URL.Path = ShiftPath(r.URL.Path)
300+
col := getURLPart(r.URL.Path, 2)
319301

320302
var v struct {
321303
UpdateFields map[string]any `json:"update"`
@@ -376,11 +358,8 @@ func (database *Database) del(w http.ResponseWriter, r *http.Request) {
376358
return
377359
}
378360

379-
col, id := "", ""
380-
381-
_, r.URL.Path = ShiftPath(r.URL.Path)
382-
col, r.URL.Path = ShiftPath(r.URL.Path)
383-
id, r.URL.Path = ShiftPath(r.URL.Path)
361+
col := getURLPart(r.URL.Path, 2)
362+
id := getURLPart(r.URL.Path, 3)
384363

385364
count, err := backend.DB.DeleteDocument(auth, conf.Name, col, id)
386365
if err != nil {

form.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ func submitForm(w http.ResponseWriter, r *http.Request) {
1515
return
1616
}
1717

18-
form := ""
19-
20-
_, r.URL.Path = ShiftPath(r.URL.Path)
21-
form, r.URL.Path = ShiftPath(r.URL.Path)
18+
form := getURLPart(r.URL.Path, 2)
2219

2320
doc := make(map[string]interface{})
2421

membership.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,7 @@ func (m *membership) sudoGetTokenFromAccountID(w http.ResponseWriter, r *http.Re
197197
return
198198
}
199199

200-
id := ""
201-
202-
_, r.URL.Path = ShiftPath(r.URL.Path)
203-
id, r.URL.Path = ShiftPath(r.URL.Path)
200+
id := getURLPart(r.URL.Path, 2)
204201

205202
tok, err := backend.DB.GetFirstUserFromAccountID(conf.Name, id)
206203
if err != nil {

url.go

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)