Skip to content

Commit 6ad59b2

Browse files
committed
API(App, User, Reversion): Add PATCH endpoints
- Suppress unused warning for more controllers - Update SPEC - Update SPEC JSON - Add default content type (json) for Spectrum - Add XmlTransient for User private fields Signed-off-by: duangsuse <fedora-opensuse@outlook.com>
1 parent c606cf1 commit 6ad59b2

File tree

8 files changed

+125
-23
lines changed

8 files changed

+125
-23
lines changed

.idea/misc.xml

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

geekapk_v1b_api.geekspec

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,43 +70,43 @@ DELETE@removeComment(cid-path:CommentId) -> [$cid:number, $deletedSubComments:nu
7070
## GeekApk Categories section
7171

7272
categoryList() -> array:Category
73-
= category/all
73+
= /category/all
7474

7575
categoryName(id-path:CategoryId) -> plain
76-
= category/{id}
76+
= /category/{id}
7777

7878

7979

8080
## GeekApk Users section
8181

8282
readUser(id-path:UserId) -> object:GeekUser
83-
= user/{id}
83+
= /user/{id}
8484

8585

8686
### Requires user permission
8787
PUT@updateUser(id-path:UserId, prop:String{username, nickname, avatar, bio, metaApp}, value-body:String)
8888
-> [$user:number, $prop:string, $old:string, $new:string]
89-
= user/{id}
89+
= /user/{id}
9090

9191
PUT@resetHash(id-path:UserId, shash:String, hash:String)
9292
-> [$id:number, $newShash:string, $newHash:string]
93-
= user/{id}/hash
93+
= /user/{id}/hash
9494

9595
checkHash(id-path:UserId, hash:String)
9696
-> [$valid:boolean, $message:string]
97-
= user/{id}/checkHash
97+
= /user/{id}/checkHash
9898

9999
listUser(sort:String?{created, followers}, sliceFrom:UserSize?, sliceTo:UserSize?) -> array:GeekUser
100-
= user/all
100+
= /user/all
101101

102102
listMetaUser(sort:String?{created, followers}, sliceFrom:UserSize?, sliceTo:UserSize?) -> array:GeekUser
103-
= user/allHasMetaApp
103+
= /user/allHasMetaApp
104104

105105
searchUser(type:String?{username, nickname, bio}, kw-path:String, sort:String?{created, followers}) -> array:GeekUser
106-
= user/search/{kw}
106+
= /user/search/{kw}
107107

108108
PUT@updateOnlineTime(id-path:UserId)
109-
= user/{id}/online
109+
= /user/{id}/online
110110

111111
## GeekApk Timeline section
112112

@@ -254,3 +254,13 @@ stargazers(aid-path:AppId) -> array:App
254254

255255
stars(uid-path:UserId) -> array:App
256256
= /star/user/{uid}
257+
258+
## PATCH APIs
259+
PATCH@patchUser(uid-path:UserId, obj-body:GeekUser) -> object:GeekUser
260+
= /user/{uid}
261+
262+
PATCH@patchApp(aid-path:AppId, obj-body:App) -> object:App
263+
= /app/{aid}
264+
265+
PATCH@patchReversion(aid-path:AppId, rev-path:Int, obj-body:AppUpdate) -> object:AppUpdate
266+
= /appUpdate/{aid}/{rev}

spectrum.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ def initialize(interfaces)
271271
@conn = Faraday.new(url: 'http://127.0.0.1:8080')
272272
@apis = if interfaces.is_a? Array then interfaces else [interfaces] end
273273
@auth = GeekAuth.new(-1, '')
274+
@conn.headers['Content-Type'] = 'application/json;charset=UTF-8'
274275
end
275276

276277
def instance_api_methods

spectrum_geekapk_v1b_api.json

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@
293293
"of": "Category"
294294
},
295295
"method": "GET",
296-
"url": "category/all"
296+
"url": "/category/all"
297297
},
298298
{
299299
"name": "categoryName",
@@ -306,7 +306,7 @@
306306
],
307307
"return": "plain",
308308
"method": "GET",
309-
"url": "category/{id}"
309+
"url": "/category/{id}"
310310
},
311311
{
312312
"name": "readUser",
@@ -322,7 +322,7 @@
322322
"of": "GeekUser"
323323
},
324324
"method": "GET",
325-
"url": "user/{id}"
325+
"url": "/user/{id}"
326326
},
327327
{
328328
"name": "updateUser",
@@ -368,7 +368,7 @@
368368
}
369369
],
370370
"method": "PUT",
371-
"url": "user/{id}"
371+
"url": "/user/{id}"
372372
},
373373
{
374374
"name": "resetHash",
@@ -404,7 +404,7 @@
404404
}
405405
],
406406
"method": "PUT",
407-
"url": "user/{id}/hash"
407+
"url": "/user/{id}/hash"
408408
},
409409
{
410410
"name": "checkHash",
@@ -431,7 +431,7 @@
431431
}
432432
],
433433
"method": "GET",
434-
"url": "user/{id}/checkHash"
434+
"url": "/user/{id}/checkHash"
435435
},
436436
{
437437
"name": "listUser",
@@ -460,7 +460,7 @@
460460
"of": "GeekUser"
461461
},
462462
"method": "GET",
463-
"url": "user/all"
463+
"url": "/user/all"
464464
},
465465
{
466466
"name": "listMetaUser",
@@ -489,7 +489,7 @@
489489
"of": "GeekUser"
490490
},
491491
"method": "GET",
492-
"url": "user/allHasMetaApp"
492+
"url": "/user/allHasMetaApp"
493493
},
494494
{
495495
"name": "searchUser",
@@ -522,7 +522,7 @@
522522
"of": "GeekUser"
523523
},
524524
"method": "GET",
525-
"url": "user/search/{kw}"
525+
"url": "/user/search/{kw}"
526526
},
527527
{
528528
"name": "updateOnlineTime",
@@ -535,7 +535,7 @@
535535
],
536536
"return": null,
537537
"method": "PUT",
538-
"url": "user/{id}/online"
538+
"url": "/user/{id}/online"
539539
},
540540
{
541541
"name": "readUserTimeline",
@@ -1425,5 +1425,73 @@
14251425
},
14261426
"method": "GET",
14271427
"url": "/star/user/{uid}"
1428+
},
1429+
{
1430+
"name": "patchUser",
1431+
"args": [
1432+
{
1433+
"name": "uid-path:UserId",
1434+
"required": true,
1435+
"options": null
1436+
},
1437+
{
1438+
"name": "obj-body:GeekUser",
1439+
"required": true,
1440+
"options": null
1441+
}
1442+
],
1443+
"return": {
1444+
"type": "object",
1445+
"of": "GeekUser"
1446+
},
1447+
"method": "PATCH",
1448+
"url": "/user/{uid}"
1449+
},
1450+
{
1451+
"name": "patchApp",
1452+
"args": [
1453+
{
1454+
"name": "aid-path:AppId",
1455+
"required": true,
1456+
"options": null
1457+
},
1458+
{
1459+
"name": "obj-body:App",
1460+
"required": true,
1461+
"options": null
1462+
}
1463+
],
1464+
"return": {
1465+
"type": "object",
1466+
"of": "App"
1467+
},
1468+
"method": "PATCH",
1469+
"url": "/app/{aid}"
1470+
},
1471+
{
1472+
"name": "patchReversion",
1473+
"args": [
1474+
{
1475+
"name": "aid-path:AppId",
1476+
"required": true,
1477+
"options": null
1478+
},
1479+
{
1480+
"name": "rev-path:Int",
1481+
"required": true,
1482+
"options": null
1483+
},
1484+
{
1485+
"name": "obj-body:AppUpdate",
1486+
"required": true,
1487+
"options": null
1488+
}
1489+
],
1490+
"return": {
1491+
"type": "object",
1492+
"of": "AppUpdate"
1493+
},
1494+
"method": "PATCH",
1495+
"url": "/appUpdate/{aid}/{rev}"
14281496
}
14291497
]

src/main/kotlin/org/duangsuse/geekapk/controller/AppController.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ class AppController {
3131
TODO()
3232
}
3333

34+
@PatchMapping("/{aid}")
35+
@ResponseBody
36+
fun patchApp(@PathVariable("aid") aid: AppId, @RequestBody obj: App): App {
37+
TODO()
38+
}
39+
3440

3541
@PostMapping("/")
3642
@ResponseBody

src/main/kotlin/org/duangsuse/geekapk/controller/AppReversionController.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ class AppReversionController {
4949
TODO()
5050
}
5151

52+
@PatchMapping("/{aid}/{rev}")
53+
@ResponseBody
54+
fun patchReversion(@PathVariable("aid") aid: AppId, @PathVariable("rev") rev: Int, @RequestBody obj: AppUpdate): AppUpdate {
55+
TODO()
56+
}
57+
5258

5359
@DeleteMapping("/{aid}/{rev}")
5460
@ResponseBody

src/main/kotlin/org/duangsuse/geekapk/controller/UserController.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ class UserController {
2929
TODO()
3030
}
3131

32+
@PatchMapping("/{uid}")
33+
@ResponseBody
34+
fun patchUser(@PathVariable("uid") uid: UserId, @RequestBody obj: GeekUser): GeekUser {
35+
TODO()
36+
}
37+
3238
@PutMapping("/{id}/hash")
3339
@ResponseBody fun resetHash(@PathVariable("id") id: UserId, @RequestParam("shash") shash: String, @RequestParam("hash") hash: String): Map<String, String> {
3440
TODO()

src/main/kotlin/org/duangsuse/geekapk/entity/GeekUser.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import java.io.Serializable
1313
import java.util.*
1414
import javax.persistence.*
1515
import javax.validation.constraints.Size
16+
import javax.xml.bind.annotation.XmlTransient
1617
import kotlin.math.roundToInt
1718

1819
/**
@@ -79,13 +80,15 @@ data class GeekUser (
7980
*/
8081
@UserPrivate
8182
@JsonIgnore
83+
@XmlTransient
8284
var sharedHash: String = makeSharedHash(20), /* static server-computed size */
8385

8486
/**
8587
* Password for the user
8688
*/
8789
@UserPrivate /* should be set to another value in controller level */
8890
@JsonIgnore
91+
@XmlTransient
8992
@Size(min = 256 / 4, max = 256 / 4) /* SHA-256 hex representation hash */
9093
var hash: String = "68e656b251e67e8358bef8483ab0d51c6619f3e7a1a9f0e75838d41ff368f728",
9194

0 commit comments

Comments
 (0)