Skip to content

Commit

Permalink
Add Admin Teams table
Browse files Browse the repository at this point in the history
  • Loading branch information
GODrums committed Oct 23, 2024
1 parent 2b07310 commit fab7203
Show file tree
Hide file tree
Showing 25 changed files with 736 additions and 63 deletions.
86 changes: 62 additions & 24 deletions server/application-server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,29 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/UserDTO"
/admin/teams:
put:
tags:
- admin
operationId: createTeam
requestBody:
content:
application/json:
schema:
type: object
properties:
name:
type: string
color:
type: string
required: true
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/TeamDTO"
/admin/config/repositories:
post:
tags:
Expand Down Expand Up @@ -286,6 +309,25 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/UserDTO"
/admin/teams/{teamId}:
delete:
tags:
- admin
operationId: deleteTeam
parameters:
- name: teamId
in: path
required: true
schema:
type: integer
format: int64
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/TeamDTO"
components:
schemas:
IssueCommentDTO:
Expand Down Expand Up @@ -407,6 +449,20 @@ components:
type: array
items:
$ref: "#/components/schemas/IssueCommentDTO"
TeamDTO:
required:
- color
- id
- name
type: object
properties:
id:
type: integer
format: int64
name:
type: string
color:
type: string
PullRequestReviewDTO:
required:
- createdAt
Expand Down Expand Up @@ -516,9 +572,8 @@ components:
type: string
state:
type: string
description: |-
State of the PullRequest.
Does not include the state of the merge.
description: "State of the PullRequest.\r\n Does not include the state of\
\ the merge."
enum:
- CLOSED
- OPEN
Expand Down Expand Up @@ -696,15 +751,12 @@ components:
description: Display name of the user.
url:
type: string
description: |-
Unique URL to the user's profile.
Not the website a user can set in their profile.
description: "Unique URL to the user's profile.\r\n Not the website a user\
\ can set in their profile."
avatarUrl:
type: string
description: |-
URL to the user's avatar.
If unavailable, a fallback can be generated from the login, e.g. on Github:
https://github.com/{login}.png
description: "URL to the user's avatar.\r\n If unavailable, a fallback can\
\ be generated from the login, e.g. on Github:\r\n https://github.com/{login}.png"
type:
type: string
description: Type of the user. Used to distinguish between users and bots.
Expand Down Expand Up @@ -736,20 +788,6 @@ components:
type: array
items:
$ref: "#/components/schemas/PullRequestReview"
TeamDTO:
required:
- color
- id
- name
type: object
properties:
id:
type: integer
format: int64
name:
type: string
color:
type: string
MetaDataDTO:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import de.tum.in.www1.hephaestus.codereview.team.TeamDTO;
import de.tum.in.www1.hephaestus.codereview.user.UserDTO;
import de.tum.in.www1.hephaestus.codereview.user.UserTeamsDTO;

Expand Down Expand Up @@ -76,4 +77,16 @@ public ResponseEntity<UserDTO> removeTeamFromUser(@PathVariable String login, @P
.map(ResponseEntity::ok)
.orElseGet(() -> ResponseEntity.notFound().build());
}

@PutMapping("/teams")
public ResponseEntity<TeamDTO> createTeam(@RequestBody String name, @RequestBody String color) {
return ResponseEntity.ok(adminService.createTeam(name, color));
}

@DeleteMapping("/teams/{teamId}")
public ResponseEntity<TeamDTO> deleteTeam(@PathVariable Long teamId) {
return adminService.deleteTeam(teamId)
.map(ResponseEntity::ok)
.orElseGet(() -> ResponseEntity.notFound().build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,19 @@ public Optional<UserDTO> removeTeamFromUser(String login, Long teamId) {
teamService.saveTeam(team);
return Optional.of(new UserDTO(user.getId(), user.getLogin(), user.getEmail(), user.getName(), user.getUrl()));
}

public TeamDTO createTeam(String name, String color) {
logger.info("Creating team with name: " + name + " and color: " + color);
return TeamDTO.fromTeam(teamService.createTeam(name, color));
}

public Optional<TeamDTO> deleteTeam(Long teamId) {
logger.info("Deleting team with ID: " + teamId);
Optional<Team> optionalTeam = teamService.getTeam(teamId);
if (optionalTeam.isEmpty()) {
return Optional.empty();
}
teamService.deleteTeam(teamId);
return Optional.of(TeamDTO.fromTeam(optionalTeam.get()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,51 @@ public List<TeamDTO> getAllTeams() {

public Team saveTeam(Team team) {
logger.info("Saving team: " + team);
return teamRepository.saveAndFlush(team);
}

public Team createTeam(String name, String color) {
logger.info("Creating team with name: " + name + " and color: " + color);
Team team = new Team();
team.setName(name);
team.setColor(color);
return teamRepository.save(team);
}

public void deleteTeam(Long id) {
logger.info("Deleting team with id: " + id);
teamRepository.deleteById(id);
}

public Boolean createDefaultTeams() {
logger.info("Creating default teams");
Team iris = teamRepository.save(new Team());
iris.setName("Iris");
iris.setColor("#69feff");
Team athena = teamRepository.save(new Team());
athena.setName("Athena");
athena.setColor("#69feff");
Team atlas = teamRepository.save(new Team());
atlas.setName("Atlas");
atlas.setColor("#69feff");
Team programming = teamRepository.save(new Team());
programming.setName("Programming");
programming.setColor("#69feff");
Team hephaestus = teamRepository.save(new Team());
hephaestus.setName("Hephaestus");
hephaestus.setColor("#69feff");
Team communication = teamRepository.save(new Team());
communication.setName("Communication");
communication.setColor("#69feff");
Team lectures = teamRepository.save(new Team());
lectures.setName("Lectures");
lectures.setColor("#69feff");
Team usability = teamRepository.save(new Team());
usability.setName("Usability");
usability.setColor("#69feff");
Team ares = teamRepository.save(new Team());
ares.setName("Ares");
ares.setColor("#69feff");
teamRepository.saveAll(
List.of(iris, athena, atlas, programming, hephaestus, communication, lectures, usability, ares));
return true;
Expand Down
19 changes: 9 additions & 10 deletions webapp/src/app/admin/admin.component.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<div class="flex flex-col gap-4 indent-3">
<h3 class="text-xl font-bold">User</h3>
<textarea hlmInput class="block size-full" style="field-sizing: content" readonly>{{ user() | json }}</textarea>
<h3 class="text-xl font-bold">Config</h3>
<!-- input for repositories with save button -->
<div class="flex flex-col items-start gap-4">
<div class="w-1/2">
<textarea hlmInput [formControl]="repositoriesForm" class="block size-fit" style="field-sizing: content"></textarea>
</div>
<button hlmBtn (click)="saveRepositories()">Save</button>
<!-- input for repositories with save button -->
<h1 class="text-3xl font-bold mb-4">Environment</h1>
<div class="flex flex-col items-start gap-4">
<div class="w-1/2">
<h2 class="text-lg font-semibold mb-2">Repositories to monitor:</h2>
<textarea hlmInput [formControl]="repositoriesForm" class="block size-fit" style="field-sizing: content"></textarea>
<h2 class="text-lg font-semibold my-2">User:</h2>
<textarea hlmInput [formControl]="userForm" class="block size-fit" style="field-sizing: content"></textarea>
</div>
<button hlmBtn (click)="saveRepositories()">Save</button>
</div>
15 changes: 14 additions & 1 deletion webapp/src/app/admin/admin.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,24 @@ export class AdminComponent {
queryKey: ['admin', 'config'],
queryFn: async () => {
const adminConfig = await lastValueFrom(this.adminService.getConfig());
this.repositoriesForm.setValue(JSON.stringify(adminConfig.repositoriesToMonitor));
this.repositoriesForm.setValue(JSON.stringify(adminConfig.repositoriesToMonitor, null, 4));
return adminConfig;
}
}));

userForm = new FormControl(
JSON.stringify(
{
id: this.user()?.id,
email: this.user()?.email,
name: this.user()?.name,
anonymous: this.user()?.anonymous,
roles: this.user()?.roles
},
null,
4
)
);
repositoriesForm = new FormControl('');

saveRepositories() {
Expand Down
38 changes: 30 additions & 8 deletions webapp/src/app/admin/layout.component.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
<div class="container space-y-4">
<h1 class="text-3xl font-bold mb-4">Admin Page</h1>
<div class="flex justify-between gap-8">
<div class="flex flex-col items-stretch gap-4 rounded-md border border-input p-2 w-24">
<span class="text-lg font-bold">Admin</span>
<ul class="flex flex-col gap-2 w-24">
<li><a hlmBtn variant="ghost" routerLink="config" class="w-24">Config</a></li>
<li><a hlmBtn variant="ghost" routerLink="users" class="w-24">Users</a></li>
<li><a hlmBtn variant="ghost" routerLink="teams" class="w-24">Teams</a></li>
<div class="flex flex-col gap-4 rounded-md border border-input p-2">
<span class="text-lg font-bold indent-2">Admin Area</span>
<ul class="flex flex-col gap-2 w-40">
<li>
<a
hlmBtn
size="sm"
variant="navButton"
routerLink="."
routerLinkActive="text-accent-foreground bg-accent"
[routerLinkActiveOptions]="{ exact: true }"
ariaCurrentWhenActive="page"
>
<hlm-icon size="normal" name="lucideFileCog" />
Environment
</a>
</li>
<li>
<a hlmBtn size="sm" variant="navButton" routerLink="users" routerLinkActive="text-accent-foreground bg-accent" ariaCurrentWhenActive="page">
<hlm-icon size="normal" name="lucideUserCircle" />
Users
</a>
</li>
<li>
<a hlmBtn size="sm" variant="navButton" routerLink="teams" routerLinkActive="text-accent-foreground bg-accent" ariaCurrentWhenActive="page">
<hlm-icon size="normal" name="lucideUsers2" />
Teams
</a>
</li>
</ul>
</div>
<div class="block">
<div class="block w-full">
<router-outlet></router-outlet>
</div>
</div>
Expand Down
7 changes: 5 additions & 2 deletions webapp/src/app/admin/layout.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { HlmButtonModule } from '@spartan-ng/ui-button-helm';
import { RouterModule, RouterOutlet } from '@angular/router';
import { RouterLinkActive, RouterModule, RouterOutlet } from '@angular/router';
import { HlmIconComponent, provideIcons } from '@spartan-ng/ui-icon-helm';
import { lucideUserCircle, lucideFileCog, lucideUsers2 } from '@ng-icons/lucide';

@Component({
selector: 'app-admin-layout',
standalone: true,
imports: [CommonModule, RouterModule, ReactiveFormsModule, HlmButtonModule, RouterOutlet],
imports: [CommonModule, RouterModule, ReactiveFormsModule, HlmButtonModule, RouterOutlet, RouterLinkActive, HlmIconComponent],
providers: [provideIcons({ lucideUserCircle, lucideFileCog, lucideUsers2 })],
templateUrl: './layout.component.html'
})
export class AdminLayoutComponent {}
Loading

0 comments on commit fab7203

Please sign in to comment.