Skip to content

Commit

Permalink
Merge pull request #11 from DoodleyJC/dev
Browse files Browse the repository at this point in the history
added separate object for post requests, added index to get request o…
  • Loading branch information
DoodleyJC authored Apr 4, 2024
2 parents e99a84c + 002c53b commit 75fe480
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
11 changes: 9 additions & 2 deletions bluenps/src/app/backend.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import { HttpClient, HttpHeaders} from '@angular/common/http';
import { environment } from 'src/environments/environment';

export type signup = {
index: number;
name: string;
time: string;
court: string;
}

export type signupPost = {
name: string;
time: string;
court: string;
Expand All @@ -24,10 +31,10 @@ export class BackendService {

}

postSignup(newPlayer:signup){
postSignup(newPlayer:signupPost){
console.log(newPlayer);
var headers = new HttpHeaders().set("Content-Type", "application/json; charset=utf-8");
return this.http.post<signup>(this.url, newPlayer, {headers: headers});
return this.http.post<signupPost>(this.url, newPlayer, {headers: headers});
}


Expand Down
30 changes: 24 additions & 6 deletions bluenps/src/app/home-page/home-page.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,32 @@
<button type="button" class="btn btn-success" (click)="submitCourtName()">submit</button>
</div>
</div>



<div class="container">
<li class="border" *ngFor="let player of data">
<div class="row">
<div class="col">{{player.name}}</div>
<div class="col">{{player.time}}</div>
<div class="col">{{player.court}}</div>
<div class="col"> <button type="button" class="btn btn-danger" (click) = "deletePlayer(player)">remove</button> </div>
<div class="row">
<div class="col">
<div class="border border-success" *ngFor="let player of npsdata">
<div class="row">
<div class="col">{{player.name}}</div>
<div class="col">{{player.time}}</div>
<div class="col">{{player.court}}</div>
<div class="col"> <button type="button" class="btn btn-danger" (click) = "deletePlayer(player)">remove</button></div>
</div>
</div>
</div>
<div class="col">
<div class="border border-primary" *ngFor="let player of bluedata">
<div class="row">
<div class="col">{{player.name}}</div>
<div class="col">{{player.time}}</div>
<div class="col">{{player.court}}</div>
<div class="col"> <button type="button" class="btn btn-danger" (click) = "deletePlayer(player)">remove</button> </div>
</div>
</div>
</div>
</div>
</div>

</html>
18 changes: 14 additions & 4 deletions bluenps/src/app/home-page/home-page.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import {formatDate} from '@angular/common';
import { HttpClient, HttpResponse } from '@angular/common/http';
import {signup, BackendService } from '../backend.service';
import {signup, BackendService, signupPost } from '../backend.service';
import { RouterModule } from '@angular/router';
@Component({
selector: 'app-home-page',
Expand All @@ -11,7 +11,10 @@ import { RouterModule } from '@angular/router';
export class HomePageComponent implements OnInit {
title = 'bluenps';
test: any;
data: signup[]= [{name: "uninitialized", court: "uninitialized", time: "please wait"}];
data: signup[]= [{index: 0, name: "uninitialized", court: "uninitialized", time: "please wait"}];
npsdata: signup[]= [{index: 0,name: "nps", court: "uninitialized", time: "please wait"}];
bluedata: signup[] = [{index: 0,name: "blue", court: "uninitialized", time: "please wait"}];

constructor(private http: HttpClient, private backendService: BackendService){}

ngOnInit(){
Expand All @@ -21,7 +24,14 @@ export class HomePageComponent implements OnInit {
refreshData(){
console.log("refreshing data");
this.backendService.getAllData()
.subscribe( data => this.data = data);
.subscribe( data => this.setData(data));
}


setData(data:signup[]){
this.data = data;
this.npsdata = data.filter((activity) => activity.court === "nps");
this.bluedata = data.filter((activity) => activity.court === "blue");
}
submitCourtName(): void{
var e = (document.getElementById("courtSelection") as HTMLInputElement);
Expand All @@ -34,7 +44,7 @@ export class HomePageComponent implements OnInit {
}
var dateString = formatDate(date, "yyyy-MM-dd", 'en')

var newSignup:signup = {
var newSignup:signupPost = {
"name" : name,
"time" : dateString,
"court" : court
Expand Down
Binary file modified bluenpsbackend/db.sqlite3
Binary file not shown.

0 comments on commit 75fe480

Please sign in to comment.