diff --git a/server/application-server/openapi.yaml b/server/application-server/openapi.yaml index ab068833..2920a715 100644 --- a/server/application-server/openapi.yaml +++ b/server/application-server/openapi.yaml @@ -84,6 +84,34 @@ paths: application/json: schema: $ref: "#/components/schemas/TeamInfo" + delete: + tags: + - admin + operationId: removeRepositoryFromTeam + parameters: + - name: teamId + in: path + required: true + schema: + type: integer + format: int64 + - name: repositoryOwner + in: path + required: true + schema: + type: string + - name: repositoryName + in: path + required: true + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/TeamInfo" /admin/teams/{teamId}/label/{label}: post: tags: @@ -108,6 +136,29 @@ paths: application/json: schema: $ref: "#/components/schemas/TeamInfo" + delete: + tags: + - admin + operationId: removeLabelFromTeam + parameters: + - name: teamId + in: path + required: true + schema: + type: integer + format: int64 + - name: label + in: path + required: true + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/TeamInfo" /admin/config/repositories: post: tags: diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/admin/AdminController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/admin/AdminController.java index 77e771de..37b4e65e 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/admin/AdminController.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/admin/AdminController.java @@ -88,6 +88,13 @@ public ResponseEntity addRepositoryToTeam(@PathVariable Long teamId .orElseGet(() -> ResponseEntity.notFound().build()); } + @DeleteMapping("/teams/{teamId}/repository/{repositoryOwner}/{repositoryName}") + public ResponseEntity removeRepositoryFromTeam(@PathVariable Long teamId, @PathVariable String repositoryOwner, @PathVariable String repositoryName) { + return adminService.removeRepositoryFromTeam(teamId, repositoryOwner + '/' + repositoryName) + .map(ResponseEntity::ok) + .orElseGet(() -> ResponseEntity.notFound().build()); + } + @PostMapping("/teams/{teamId}/label/{label}") public ResponseEntity addLabelToTeam(@PathVariable Long teamId, @PathVariable String label) { return adminService.addLabelToTeam(teamId, label) @@ -95,6 +102,13 @@ public ResponseEntity addLabelToTeam(@PathVariable Long teamId, @Pa .orElseGet(() -> ResponseEntity.notFound().build()); } + @DeleteMapping("/teams/{teamId}/label/{label}") + public ResponseEntity removeLabelFromTeam(@PathVariable Long teamId, @PathVariable String label) { + return adminService.removeLabelFromTeam(teamId, label) + .map(ResponseEntity::ok) + .orElseGet(() -> ResponseEntity.notFound().build()); + } + @DeleteMapping("/teams/{teamId}") public ResponseEntity deleteTeam(@PathVariable Long teamId) { return adminService.deleteTeam(teamId) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/admin/AdminService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/admin/AdminService.java index 3d36bb5d..49048420 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/admin/AdminService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/admin/AdminService.java @@ -149,6 +149,22 @@ public Optional addRepositoryToTeam(Long teamId, String repositoryN return Optional.of(TeamInfoDTO.fromTeam(team)); } + public Optional removeRepositoryFromTeam(Long teamId, String repositoryName) { + logger.info("Removing repository with name: " + repositoryName + " from team with ID: " + teamId); + Optional optionalTeam = teamService.getTeam(teamId); + if (optionalTeam.isEmpty()) { + return Optional.empty(); + } + Team team = optionalTeam.get(); + Repository repository = repositoryRepository.findByNameWithOwner(repositoryName); + if (repository == null) { + return Optional.empty(); + } + team.removeRepository(repository); + teamService.saveTeam(team); + return Optional.of(TeamInfoDTO.fromTeam(team)); + } + public Optional addLabelToTeam(Long teamId, String label) { logger.info("Adding label '" + label + "' to team with ID: " + teamId); Optional optionalTeam = teamService.getTeam(teamId); @@ -165,6 +181,22 @@ public Optional addLabelToTeam(Long teamId, String label) { return Optional.of(TeamInfoDTO.fromTeam(team)); } + public Optional removeLabelFromTeam(Long teamId, String label) { + logger.info("Removing label '" + label + "' from team with ID: " + teamId); + Optional optionalTeam = teamService.getTeam(teamId); + if (optionalTeam.isEmpty()) { + return Optional.empty(); + } + Team team = optionalTeam.get(); + Optional