Skip to content

Commit 39d4d38

Browse files
committed
contest Frontend Routes
2 parents ee92242 + b669c69 commit 39d4d38

25 files changed

Lines changed: 333 additions & 283 deletions

codecamp-front/src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import { ContestComponent } from './components/contest/contest.component';
1717
import { AboutComponent } from './components/about/about.component';
1818

1919
import { AuthService } from './services/auth.service';
20+
import { ContestService } from './services/contest.service';
21+
2022
import { HttpModule } from '@angular/http';
2123
import { IdeComponent } from './components/ide/ide.component';
2224
import { ProblemsComponent } from './components/problems/problems.component';
@@ -53,7 +55,7 @@ import { SolutionComponent } from './components/solution/solution.component';
5355
ReactiveFormsModule,
5456
AppRoutingModule
5557
],
56-
providers: [ AuthService],
58+
providers: [ AuthService, ContestService],
5759
bootstrap: [AppComponent]
5860
})
5961
export class AppModule { }

codecamp-front/src/app/components/add-contest/add-contest.component.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<form [formGroup]="form" (submit)="onAddContestSubmit()">
66
<div class="form-group">
77
<label for="name">Contest Name</label>
8-
<input type="text"
8+
<input type="text"
99
name="name"
1010
formControlName="name"
1111
class="form-control"
@@ -28,25 +28,25 @@
2828
<div class="col-md-6">
2929
<div class="form-group">
3030
<label for="startDate">Start Time</label>
31-
<input type="datetime-local"
32-
name="startdate"
33-
formControlName="startdate"
31+
<input type="date"
32+
name="startTime"
33+
formControlName="startTime"
3434
class="form-control"
3535
placeholder="Start Time"
3636
autocomplete="off"
37-
[ngClass]="{'is-invalid': (form.controls.startdate.errors && form.controls.startdate.dirty) , 'is-valid': !form.controls.startdate.errors}">
37+
[ngClass]="{'is-invalid': (form.controls.startTime.errors && form.controls.startTime.dirty) , 'is-valid': !form.controls.startTime.errors}">
3838
</div>
3939
</div>
4040
<div class="col-md-6">
4141
<div class="form-group">
4242
<label for="EndDate">End Time</label>
43-
<input type="datetime-local"
44-
name="enddate"
45-
formControlName="enddate"
43+
<input type="date"
44+
name="endTime"
45+
formControlName="endTime"
4646
class="form-control"
4747
placeholder="End Time"
4848
autocomplete="off"
49-
[ngClass]="{'is-invalid': (form.controls.enddate.errors && form.controls.enddate.dirty) , 'is-valid': !form.controls.enddate.errors}">
49+
[ngClass]="{'is-invalid': (form.controls.endTime.errors && form.controls.endTime.dirty) , 'is-valid': !form.controls.endTime.errors}">
5050
</div>
5151
</div>
5252
</div>

codecamp-front/src/app/components/add-contest/add-contest.component.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
22
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
33
import { AuthService } from '../../services/auth.service';
44
import { Router } from '@angular/router';
5+
import { ContestService } from '../../services/contest.service';
56

67
@Component({
78
selector: 'app-add-contest',
@@ -11,27 +12,46 @@ import { Router } from '@angular/router';
1112
export class AddContestComponent implements OnInit {
1213

1314
form: FormGroup;
15+
username: string;
1416

1517
constructor(
1618
private authService: AuthService,
1719
private router: Router,
18-
private formBuilder: FormBuilder
20+
private formBuilder: FormBuilder,
21+
private contestService: ContestService
1922
) { }
2023

2124
ngOnInit() {
2225
this.createForm();
26+
this.authService.getProfile().subscribe(profile => {
27+
this.username = profile.msg.username; // Used when creating new blog posts and comments
28+
});
2329
}
2430
createForm() {
2531
this.form = this.formBuilder.group({
2632
name: ['', Validators.required],
2733
id: ['', Validators.required],
28-
startdate: ['', Validators.required],
29-
enddate: ['', Validators.required],
34+
startTime: ['', Validators.required],
35+
endTime: ['', Validators.required],
3036
description: ['', Validators.required]
3137
});
3238
}
3339

3440
onAddContestSubmit() {
35-
41+
const contest = {
42+
// username: this.username,
43+
name: this.form.get('name').value,
44+
id: this.form.get('id').value,
45+
startTime: this.form.get('startTime').value,
46+
endTime: this.form.get('endTime').value,
47+
description: this.form.get('description').value
48+
};
49+
this.contestService.addContest(contest).subscribe(data => {
50+
if (!data.success) {
51+
console.log(data.msg);
52+
} else {
53+
this.router.navigate(['/contest']);
54+
}
55+
});
3656
}
3757
}

codecamp-front/src/app/components/profile/profile.component.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ <h2 class="page-header">{{user.name}}</h2>
33
<ul class="list-group">
44
<li class="list-group-item">Username: {{user.username}}</li>
55
<li class="list-group-item">Email: {{user.email_id}}</li>
6-
<li class="list-group-item">Name: {{user.name}}</li>
6+
<li class="list-group-item">Name: {{ user.name }}</li>
7+
<li class="list-group-item">College: {{ user.college }}</li>
8+
<li class="list-group-item">Date Of Birth: {{ user.dob }}</li>
9+
<li class="list-group-item">City: {{ user.city }}</li>
10+
<li class="list-group-item">Gender: {{ user.gender }}</li>
11+
<li class="list-group-item">JoinedOn: {{ user.joinedOn }}</li>
712
</ul>
8-
</div>
13+
</div>

codecamp-front/src/app/components/profile/profile.component.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@ import { Router } from '@angular/router';
99
})
1010
export class ProfileComponent implements OnInit {
1111

12-
user: Object;
12+
user;
1313
constructor(
1414
private authService: AuthService,
1515
private router: Router
16-
) { }
16+
) {
17+
this.user = authService.getProfile().subscribe(profile => {
18+
this.user = profile.msg;
19+
console.log(JSON.stringify(this.user));
20+
});
21+
console.log(this.user);
22+
}
1723

1824
ngOnInit() {
19-
}
25+
26+
}
2027

2128
}

codecamp-front/src/app/components/register/register.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export class RegisterComponent implements OnInit {
8484
};
8585
this.authService.registerUser(user).subscribe(data => {
8686
if (!data.success) {
87+
console.log(data.msg);
8788
} else {
8889
this.router.navigate(['/login']);
8990
}

codecamp-front/src/app/services/auth.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { tokenNotExpired } from 'angular2-jwt';
99
export class AuthService {
1010
public authToken: any;
1111
public user: any;
12-
public domain = '';
12+
public domain = 'http://localhost:3000';
1313
public options;
1414

1515
constructor(
@@ -68,4 +68,8 @@ export class AuthService {
6868
this.user = null;
6969
localStorage.clear(); // Clear local storage
7070
}
71+
getProfile() {
72+
this.createAuthenticationHeaders();
73+
return this.http.get(this.domain + '/users/profile', this.options).map(res => res.json());
74+
}
7175
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { TestBed, inject } from '@angular/core/testing';
2+
3+
import { ContestService } from './contest.service';
4+
5+
describe('ContestService', () => {
6+
beforeEach(() => {
7+
TestBed.configureTestingModule({
8+
providers: [ContestService]
9+
});
10+
});
11+
12+
it('should be created', inject([ContestService], (service: ContestService) => {
13+
expect(service).toBeTruthy();
14+
}));
15+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Injectable } from '@angular/core';
2+
import { Http, Headers, RequestOptions } from '@angular/http';
3+
import { HttpModule } from '@angular/http';
4+
5+
import 'rxjs/add/operator/map';
6+
import { tokenNotExpired } from 'angular2-jwt';
7+
8+
@Injectable()
9+
export class ContestService {
10+
11+
public authToken: any;
12+
public user: any;
13+
public contest: any;
14+
public domain = 'http://localhost:3000';
15+
public options;
16+
17+
constructor(
18+
private http: Http
19+
) { }
20+
21+
public createAuthenticationHeaders() {
22+
this.loadToken(); // Get token so it can be attached to headers
23+
// Headers configuration options
24+
this.options = new RequestOptions({
25+
headers: new Headers({
26+
'Content-Type': 'application/json', // Format set to JSON
27+
'authorization': this.authToken // Attach token
28+
})
29+
});
30+
}
31+
32+
public loadToken() {
33+
this.authToken = localStorage.getItem('token'); // Get token and asssign to variable to be used elsewhere
34+
}
35+
36+
public addContest(contest) {
37+
console.log(contest);
38+
return this.http
39+
.post(this.domain + '/contest', contest)
40+
.map(res => res.json());
41+
}
42+
}

contest/models/contest.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ var contestSchema = new mongoose.Schema({
66
type:String,
77
required:true
88
},
9+
'id':{
10+
type:String,
11+
required:true,
12+
unique:true
13+
},
914
'startTime':{
1015
type:Date,
11-
required:true,
16+
required:true
1217
},
1318
'endTime':{
1419
type:Date,

0 commit comments

Comments
 (0)