Skip to content

Commit

Permalink
feat(backend): adapt validation for other endpoints
Browse files Browse the repository at this point in the history
 * technical endpoints not changed
 * get sequences of user and stream data to edit: needs decision on how it should look like
  • Loading branch information
TobiasKampmann committed Dec 22, 2023
1 parent 4a54882 commit bda0dbf
Show file tree
Hide file tree
Showing 28 changed files with 454 additions and 433 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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.RequestBody
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController

Expand All @@ -23,19 +24,24 @@ class GroupManagementController(

@Operation(description = "Create a new Group. The user creating the group will be added to the group.")
@ResponseStatus(HttpStatus.NO_CONTENT)
@PostMapping("/groups/{newGroupName}", produces = [MediaType.APPLICATION_JSON_VALUE])
@PostMapping("/groups", produces = [MediaType.APPLICATION_JSON_VALUE])
fun createNewGroup(
@UsernameFromJwt username: String,
@Parameter(
description = "The name of the newly created group",
) @PathVariable newGroupName: String,
) = groupManagementDatabaseService.createNewGroup(newGroupName, username)
) @RequestBody group: GroupName,
) = groupManagementDatabaseService.createNewGroup(group.groupName, username)

@Operation(description = "Get details of a group that the user is a member of.")
@ResponseStatus(HttpStatus.OK)
@GetMapping("/groups/{detailsOfGroupName}", produces = [MediaType.APPLICATION_JSON_VALUE])
fun getUsersOfGroup(@UsernameFromJwt username: String, @PathVariable detailsOfGroupName: String): GroupDetails {
return groupManagementDatabaseService.getDetailsOfGroup(detailsOfGroupName, username)
@GetMapping("/groups/{groupName}", produces = [MediaType.APPLICATION_JSON_VALUE])
fun getUsersOfGroup(
@UsernameFromJwt username: String,
@Parameter(
description = "The name of the group to get details of.",
) @PathVariable groupName: String,
): GroupDetails {
return groupManagementDatabaseService.getDetailsOfGroup(groupName, username)
}

@Operation(description = "Get all groups the user is a member of.")
Expand All @@ -54,27 +60,35 @@ class GroupManagementController(

@Operation(description = "Add user to a group.")
@ResponseStatus(HttpStatus.NO_CONTENT)
@PostMapping("/groups/{groupName}/users/{usernameToAdd}", produces = [MediaType.APPLICATION_JSON_VALUE])
@PostMapping("/groups/{groupName}/users", produces = [MediaType.APPLICATION_JSON_VALUE])
fun addUserToGroup(
@UsernameFromJwt groupMember: String,
@Parameter(
description = "The group name the user should be added to.",
) @PathVariable groupName: String,
@Parameter(
description = "The user name that should be added to the group.",
) @PathVariable usernameToAdd: String,
) = groupManagementDatabaseService.addUserToGroup(groupMember, groupName, usernameToAdd)
) @RequestBody usernameToAdd: Username,
) = groupManagementDatabaseService.addUserToGroup(groupMember, groupName, usernameToAdd.username)

@Operation(description = "Remove user from a group.")
@ResponseStatus(HttpStatus.NO_CONTENT)
@DeleteMapping("/groups/{groupName}/users/{usernameToRemove}", produces = [MediaType.APPLICATION_JSON_VALUE])
@DeleteMapping("/groups/{groupName}/users", produces = [MediaType.APPLICATION_JSON_VALUE])
fun removeUserFromGroup(
@UsernameFromJwt groupMember: String,
@Parameter(
description = "The group name the user should be removed from.",
) @PathVariable groupName: String,
@Parameter(
description = "The user name that should be removed from the group.",
) @PathVariable usernameToRemove: String,
) = groupManagementDatabaseService.removeUserFromGroup(groupMember, groupName, usernameToRemove)
) @RequestBody usernameToRemove: Username,
) = groupManagementDatabaseService.removeUserFromGroup(groupMember, groupName, usernameToRemove.username)

data class GroupName(
val groupName: String,
)

data class Username(
val username: String,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import org.pathoplexus.backend.api.SubmissionIdMapping
import org.pathoplexus.backend.api.SubmittedProcessedData
import org.pathoplexus.backend.api.UnprocessedData
import org.pathoplexus.backend.model.ReleasedDataModel
import org.pathoplexus.backend.model.SubmissionParams
import org.pathoplexus.backend.model.SubmitModel
import org.pathoplexus.backend.service.submission.DatabaseService
import org.pathoplexus.backend.service.submission.UploadType
import org.pathoplexus.backend.utils.Accession
import org.pathoplexus.backend.utils.IteratorStreamer
import org.springframework.http.HttpHeaders
Expand Down Expand Up @@ -64,15 +64,39 @@ class SubmissionController(
@Parameter(description = GROUP_DESCRIPTION) @RequestParam groupName: String,
@Parameter(description = METADATA_FILE_DESCRIPTION) @RequestParam metadataFile: MultipartFile,
@Parameter(description = SEQUENCE_FILE_DESCRIPTION) @RequestParam sequenceFile: MultipartFile,
): List<SubmissionIdMapping> = submitModel.processSubmissions(
UUID.randomUUID().toString(),
metadataFile,
sequenceFile,
username,
groupName,
organism,
UploadType.ORIGINAL,
)
): List<SubmissionIdMapping> {
val params = SubmissionParams.OriginalSubmissionParams(
organism,
username,
metadataFile,
sequenceFile,
groupName,
)
return submitModel.processSubmissions(UUID.randomUUID().toString(), params)
}

@Operation(description = REVISE_DESCRIPTION)
@ApiResponse(responseCode = "200", description = REVISE_RESPONSE_DESCRIPTION)
@PostMapping("/revise", consumes = ["multipart/form-data"])
fun revise(
@PathVariable @Valid
organism: Organism,
@UsernameFromJwt username: String,
@Parameter(
description = REVISED_METADATA_FILE_DESCRIPTION,
) @RequestParam metadataFile: MultipartFile,
@Parameter(
description = SEQUENCE_FILE_DESCRIPTION,
) @RequestParam sequenceFile: MultipartFile,
): List<SubmissionIdMapping> {
val params = SubmissionParams.RevisionSubmissionParams(
organism,
username,
metadataFile,
sequenceFile,
)
return submitModel.processSubmissions(UUID.randomUUID().toString(), params)
}

@Operation(description = EXTRACT_UNPROCESSED_DATA_DESCRIPTION)
@ApiResponse(
Expand Down Expand Up @@ -158,6 +182,9 @@ class SubmissionController(
@PathVariable @Valid
organism: Organism,
@UsernameFromJwt username: String,
@Parameter(
description = GROUP_DESCRIPTION,
) @RequestParam groupName: String,
@Max(
value = MAX_EXTRACTED_SEQUENCE_ENTRIES,
message = "You can extract at max $MAX_EXTRACTED_SEQUENCE_ENTRIES sequence entries at once.",
Expand All @@ -167,9 +194,7 @@ class SubmissionController(
val headers = HttpHeaders()
headers.contentType = MediaType.parseMediaType(MediaType.APPLICATION_NDJSON_VALUE)

val streamBody = StreamingResponseBody { outputStream ->
databaseService.streamDataToEdit(username, numberOfSequenceEntries, outputStream, organism)
}
val streamBody = databaseService.streamDataToEdit(username, groupName, numberOfSequenceEntries, organism)

return ResponseEntity(streamBody, headers, HttpStatus.OK)
}
Expand All @@ -182,8 +207,11 @@ class SubmissionController(
@PathVariable accession: Accession,
@PathVariable version: Long,
@UsernameFromJwt username: String,
): SequenceEntryVersionToEdit =
databaseService.getSequenceEntryVersionToEdit(username, AccessionVersion(accession, version), organism)
): SequenceEntryVersionToEdit = databaseService.getSequenceEntryVersionToEdit(
username,
AccessionVersion(accession, version),
organism,
)

@Operation(description = SUBMIT_EDITED_DATA_DESCRIPTION)
@ResponseStatus(HttpStatus.NO_CONTENT)
Expand Down Expand Up @@ -217,32 +245,6 @@ class SubmissionController(
databaseService.approveProcessedData(username, body.accessionVersions, organism)
}

@Operation(description = REVISE_DESCRIPTION)
@ApiResponse(responseCode = "200", description = REVISE_RESPONSE_DESCRIPTION)
@PostMapping("/revise", consumes = ["multipart/form-data"])
fun revise(
@PathVariable @Valid
organism: Organism,
@UsernameFromJwt username: String,
@Parameter(
description = GROUP_DESCRIPTION,
) @RequestParam groupName: String,
@Parameter(
description = REVISED_METADATA_FILE_DESCRIPTION,
) @RequestParam metadataFile: MultipartFile,
@Parameter(
description = SEQUENCE_FILE_DESCRIPTION,
) @RequestParam sequenceFile: MultipartFile,
): List<SubmissionIdMapping> = submitModel.processSubmissions(
UUID.randomUUID().toString(),
metadataFile,
sequenceFile,
username,
groupName,
organism,
UploadType.REVISION,
)

@Operation(description = REVOKE_DESCRIPTION)
@PostMapping("/revoke", produces = [MediaType.APPLICATION_JSON_VALUE])
fun revoke(
Expand Down
Loading

0 comments on commit bda0dbf

Please sign in to comment.