-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectionsController.kt
More file actions
84 lines (78 loc) · 3.67 KB
/
Copy pathCollectionsController.kt
File metadata and controls
84 lines (78 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package org.genspectrum.dashboardsbackend.controller
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
import org.genspectrum.dashboardsbackend.api.Collection
import org.genspectrum.dashboardsbackend.api.CollectionRequest
import org.genspectrum.dashboardsbackend.api.CollectionUpdate
import org.genspectrum.dashboardsbackend.model.collection.CollectionModel
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController
@RestController
class CollectionsController(private val collectionModel: CollectionModel) {
@GetMapping("/collections", produces = [MediaType.APPLICATION_JSON_VALUE])
@Operation(
summary = "Get collections",
description = "Returns collections filtered by optional userId and/or organism parameters. " +
"Set includeVariants=true to include the full variant list; by default only variantCount is returned.",
)
fun getCollections(
@RequestParam(required = false) userId: Long?,
@RequestParam(required = false) organism: String?,
@RequestParam(required = false, defaultValue = "false") includeVariants: Boolean,
): List<Collection> = collectionModel.getCollections(
userId = userId,
organism = organism,
includeVariants = includeVariants,
)
@GetMapping("/collections/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
@Operation(
summary = "Get a collection by ID",
description = "Returns a single collection with all its variants.",
)
fun getCollection(
@Parameter(description = "The ID of the collection", example = "1") @PathVariable id: Long,
): Collection = collectionModel.getCollection(id)
@PostMapping("/collections")
@ResponseStatus(HttpStatus.CREATED)
@Operation(
summary = "Create a new collection",
description = "Creates a new collection with variants for a user.",
)
fun postCollection(
@RequestBody collection: CollectionRequest,
@UserIdParameter @RequestParam userId: Long,
): Collection = collectionModel.createCollection(
request = collection,
userId = userId,
)
@PutMapping("/collections/{id}")
@Operation(
summary = "Update a collection",
description = "Updates a collection. Only the owner can update their collection. " +
"Provide only the fields you want to update.",
)
fun putCollection(
@RequestBody collection: CollectionUpdate,
@Parameter(description = "The ID of the collection", example = "1") @PathVariable id: Long,
@UserIdParameter @RequestParam userId: Long,
): Collection = collectionModel.putCollection(id, collection, userId)
@DeleteMapping("/collections/{id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
@Operation(
summary = "Delete a collection",
description = "Deletes a collection. Only the owner can delete their collection.",
)
fun deleteCollection(
@Parameter(description = "The ID of the collection", example = "1") @PathVariable id: Long,
@UserIdParameter @RequestParam userId: Long,
) = collectionModel.deleteCollection(id, userId)
}