Skip to content

Commit

Permalink
fix: team create endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
GODrums committed Oct 23, 2024
1 parent fab7203 commit 69205e0
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 68 deletions.
7 changes: 1 addition & 6 deletions server/application-server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ paths:
content:
application/json:
schema:
type: object
properties:
name:
type: string
color:
type: string
$ref: "#/components/schemas/TeamDTO"
required: true
responses:
"200":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public ResponseEntity<UserDTO> removeTeamFromUser(@PathVariable String login, @P
}

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

@DeleteMapping("/teams/{teamId}")
Expand Down
19 changes: 11 additions & 8 deletions webapp/src/app/admin/teams/table/teams-table.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@
<brn-column-def name="color" class="w-20 flex-1">
<hlm-th *brnHeaderDef>Color</hlm-th>
<hlm-td class="font-medium tabular-nums flex gap-4" *brnCellDef="let element">
<div class="w-4 h-4 rounded-full" [style.backgroundColor]="element.color"></div>
<span>{{ element.color }}</span>
@if (this.isLoading()) {
<hlm-skeleton class="w-4 h-4 rounded-full" [style.backgroundColor]="'#69feff'" />
<hlm-skeleton class="h-6 w-12" />
} @else {
<div class="w-4 h-4 rounded-full" [style.backgroundColor]="element.color"></div>
<span>{{ element.color }}</span>
}
</hlm-td>
</brn-column-def>
<brn-column-def name="actions" class="w-16">
Expand Down Expand Up @@ -122,15 +127,13 @@
</div>
</div>
<!-- Card to add new team -->
<div hlmCard class="size-fit">
<div hlmCard class="size-fit mt-4">
<div hlmCardHeader class="pb-0">
<h3 hlmCardTitle>Create new team</h3>
</div>
<div hlmCardContent class="flex gap-4">
<div hlmCardContent class="flex items-center gap-4">
<input hlmInput placeholder="Team name" [formControl]="_newTeamName" />
<input hlmInput placeholder="Team color" [formControl]="_newTeamColor" />
</div>
<div hlmCardFooter class="justify-end">
<button hlmBtn>Create</button>
<input hlmInput placeholder="Team color" type="color" [formControl]="_newTeamColor" />
<button hlmBtn class="ml-4" (click)="createTeam()">Create</button>
</div>
</div>
37 changes: 18 additions & 19 deletions webapp/src/app/admin/teams/table/teams-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,32 +169,31 @@ export class AdminTeamsTableComponent {
navigator.clipboard.writeText(element.name!);
}

protected invalidateTeams() {
if (this.isLoading()) {
return;
}
for (const team of this._selected()) {
this._selectionModel.deselect(team);
}
this.queryClient.invalidateQueries({ queryKey: ['admin', 'teams'] });
}

_newTeamName = new FormControl('');
_newTeamColor = new FormControl('');

protected createTeam() {
if (this.isLoading() || !this._newTeamName.value || !this._newTeamColor.value) {
return;
}
this.adminService
.createTeam({
name: this._newTeamName.value,
color: this._newTeamColor.value
})
.subscribe({
next: () => console.log('Team created'),
error: (err) => console.error('Error creating team', err)
});
const newTeam = {
name: this._newTeamName.value,
color: this._newTeamColor.value
} as TeamDTO;
this.adminService.createTeam(newTeam).subscribe({
next: () => console.log('Team created'),
error: (err) => console.error('Error creating team', err)
});
this.invalidateTeams();
}

protected invalidateTeams() {
if (this.isLoading()) {
return;
}
for (const team of this._selected()) {
this._selectionModel.deselect(team);
}
this.queryClient.invalidateQueries({ queryKey: ['admin', 'teams'] });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ encoder.ts
git_push.sh
index.ts
model/admin-config.ts
model/create-team-request.ts
model/issue-comment-dto.ts
model/issue-comment.ts
model/leaderboard-entry.ts
Expand Down
18 changes: 8 additions & 10 deletions webapp/src/app/core/modules/openapi/api/admin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import { Observable } from 'rxjs';
// @ts-ignore
import { AdminConfig } from '../model/admin-config';
// @ts-ignore
import { CreateTeamRequest } from '../model/create-team-request';
// @ts-ignore
import { TeamDTO } from '../model/team-dto';
// @ts-ignore
import { UserDTO } from '../model/user-dto';
Expand Down Expand Up @@ -232,16 +230,16 @@ export class AdminService implements AdminServiceInterface {
}

/**
* @param createTeamRequest
* @param teamDTO
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param reportProgress flag to report request and response progress.
*/
public createTeam(createTeamRequest: CreateTeamRequest, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<TeamDTO>;
public createTeam(createTeamRequest: CreateTeamRequest, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpResponse<TeamDTO>>;
public createTeam(createTeamRequest: CreateTeamRequest, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpEvent<TeamDTO>>;
public createTeam(createTeamRequest: CreateTeamRequest, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<any> {
if (createTeamRequest === null || createTeamRequest === undefined) {
throw new Error('Required parameter createTeamRequest was null or undefined when calling createTeam.');
public createTeam(teamDTO: TeamDTO, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<TeamDTO>;
public createTeam(teamDTO: TeamDTO, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpResponse<TeamDTO>>;
public createTeam(teamDTO: TeamDTO, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpEvent<TeamDTO>>;
public createTeam(teamDTO: TeamDTO, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<any> {
if (teamDTO === null || teamDTO === undefined) {
throw new Error('Required parameter teamDTO was null or undefined when calling createTeam.');
}

let localVarHeaders = this.defaultHeaders;
Expand Down Expand Up @@ -293,7 +291,7 @@ export class AdminService implements AdminServiceInterface {
return this.httpClient.request<TeamDTO>('put', `${this.configuration.basePath}${localVarPath}`,
{
context: localVarHttpContext,
body: createTeamRequest,
body: teamDTO,
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
headers: localVarHeaders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { HttpHeaders } from '@angular/comm
import { Observable } from 'rxjs';

import { AdminConfig } from '../model/models';
import { CreateTeamRequest } from '../model/models';
import { TeamDTO } from '../model/models';
import { UserDTO } from '../model/models';
import { UserInfoDto } from '../model/models';
Expand Down Expand Up @@ -46,9 +45,9 @@ export interface AdminServiceInterface {
/**
*
*
* @param createTeamRequest
* @param teamDTO
*/
createTeam(createTeamRequest: CreateTeamRequest, extraHttpRequestParams?: any): Observable<TeamDTO>;
createTeam(teamDTO: TeamDTO, extraHttpRequestParams?: any): Observable<TeamDTO>;

/**
*
Expand Down
18 changes: 0 additions & 18 deletions webapp/src/app/core/modules/openapi/model/create-team-request.ts

This file was deleted.

1 change: 0 additions & 1 deletion webapp/src/app/core/modules/openapi/model/models.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './admin-config';
export * from './create-team-request';
export * from './issue-comment';
export * from './issue-comment-dto';
export * from './leaderboard-entry';
Expand Down

0 comments on commit 69205e0

Please sign in to comment.