Skip to content

Commit

Permalink
Poll service implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Toxantron committed Sep 27, 2020
1 parent 9b577ba commit b86c6d4
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 14 deletions.
24 changes: 12 additions & 12 deletions src/app/master/master.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { IssueSource } from './issue-source';
import { DefaultSourceComponent } from './default-source/default-source.component';
import { Statistic } from '../statistic';
import { Topic } from '../topic';
import { PollService } from '../poll.service';

@Component({
selector: 'app-master',
Expand All @@ -29,22 +30,21 @@ export class MasterComponent implements OnInit, AfterViewInit {
flipped: boolean;

constructor(
private route: ActivatedRoute) {
private route: ActivatedRoute,
private pollService: PollService) {

}

ngOnInit() {
// TODO: Read from service
var session = new Session();
session.id = +this.route.snapshot.paramMap.get('id');
session.name = "Hi";
this.session = session;

this.flipped = true;
this.votes = [
{id: 1, value: '1', active: false,name: 'Thomas',confirmed: true,placed: true, canDelete: true},
{id: 1, value: '3', active: false,name: 'Sandra',confirmed: true,placed: true, canDelete: true},
];
this.session.id = +this.route.snapshot.paramMap.get('id');
this.pollService.currentPoll(this.session).subscribe(pr => {
this.session.name = pr.name;
this.flipped = pr.flipped;
this.votes = pr.votes;
if (pr.topic === '')
return;
this.teamComplete = true;
});
this.statistics = [
{ name: "Test", value: "123", enabled: true}
]
Expand Down
47 changes: 46 additions & 1 deletion src/app/poll.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,54 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Session } from './session';
import { MemberVote } from './card';
import { Observable, of } from 'rxjs';
import { Topic } from './topic';
import { Member } from './member';

export class PollResponse {
name: string;
timestamp: number;

topic: string;
description: string;
url: string;

flipped: boolean;
consensus: boolean;

votes: MemberVote[];
}

@Injectable({
providedIn: 'root'
})
export class PollService {

constructor() { }
constructor(private http: HttpClient) { }

currentPoll(session: Session) : Observable<PollResponse> {
return this.http.get<PollResponse>('/api/poll/current/' + session.id);
}

getTopic(session: Session) : Observable<Topic> {
return this.http.get<Topic>('/api/poll/topic/' + session.id);
}

setTopic(session: Session, topic: Topic) {
this.http.post('/api/poll/topic/' + session.id, topic)
}

placeVote(session: Session, member: Member, vote: string) {
var wrapper = {
vote: vote
};
var url = '/api/poll/vote/' + session.id + '/' + member.id;
this.http.post(url, wrapper);
}

retractVote(session: Session, member: Member, vote: string) {
var url = '/api/poll/vote/' + session.id + '/' + member.id;
this.http.delete(url);
}
}
4 changes: 3 additions & 1 deletion src/app/topic.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
export class Topic {
id: number;

name: string;
topic: string;

description: string;

url: string;

votable: boolean;

constructor() {

}
Expand Down

0 comments on commit b86c6d4

Please sign in to comment.