Skip to content

Commit

Permalink
Manage challenge - Add Challenge Support (Azure-Samples#211)
Browse files Browse the repository at this point in the history
* Add Challenge Definition API to leaderboard
* Initial Implementation of Add a challenge
* Linting fixes
  • Loading branch information
rguthriemsft authored and dtzar committed Sep 17, 2018
1 parent 884d871 commit c724e2a
Show file tree
Hide file tree
Showing 23 changed files with 1,226 additions and 87 deletions.
64 changes: 56 additions & 8 deletions leaderboard/api/web/Controllers/LeaderboardController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ public LeaderboardController(LeaderboardContext context)
// Challenges
// * GET /api/leaderboard/challenges/ - get challenges for all teams
// * GET /api/leaderboard/challenges/{teamName} - get challenges for a team
// * GET /api/leaderboard/challenges/id/{challengeId} - get challenge by id
// * POST /api/leaderboard/challenges/ - create a challenge for a team
// * PATCH /api/leaderboard/challenges/{challengeId} - update a challenge. Update start/end times for a challenge

//Challenge Definitions
// * GET /api/leaderboard/challengedefinitions - Get list of challenge definitions.

//Service Health
// * GET /api/leaderboard/servicehealth/ - get health for all teams services
// * GET /api/leaderboard/servicehealth/{teamName} - get health for a team`

//Challenge Definitions
// * GET /api/leaderboard/challengedefinitions/id/{challengeId}

// Sentinel Controller
// * GET /api/sentinel/logs/{teamId} - gets all logs for a team
// * POST /api/sentinel/logs/{teamId} - posts logs for a team
Expand Down Expand Up @@ -176,11 +177,31 @@ public List<Challenge> GetChallenges()
[HttpGet("challenges/{teamName}",Name = "GetChallengesForTeam")]
public List<Challenge> GetChallengesForTeam(string teamName){

var query = from c in _context.Challenges join t in _context.Teams on c.TeamId equals t.Id where t.TeamName == teamName select c;
Team team = _context.Teams.Where(t => t.TeamName == teamName).Single<Team>();

//var query = from c in _context.Challenges join t in _context.Teams on c.TeamId equals t.Id where t.TeamName == teamName select c;
var query = _context.Challenges.Where(c => c.TeamId == team.Id)
.Include(tm => tm.Team)
.Include(cd => cd.ChallengeDefinition);
return query.ToList<Challenge>();
}

/// <summary>
/// GET /api/leaderboard/challenges/id/{challengeId} - get challenge by id
/// </summary>
/// <param name="challengeId"></param>
/// <returns>List of challenges</returns>
[HttpGet("challenges/id/{challengeId}",Name = "GetChallengeById")]
public Challenge GetChallengeById(string challengeId){

var query = _context.Challenges.Where(c => c.Id == challengeId)
.Include(tm => tm.Team)
.Include(cd => cd.ChallengeDefinition);
return query.Single<Challenge>();
}



/// <summary>
/// POST /api/leaderboard/challenges/ - create a challenge for a team
/// </summary>
Expand Down Expand Up @@ -225,20 +246,47 @@ public IActionResult UpdateChallenge([FromBody] Challenge c)
return NoContent();
}

//Service Health
// * GET /api/leaderboard/servicehealth/ - get health for all teams services

// * GET /api/leaderboard/servicehealth/{teamName} - get health for a team`
//Challenge Definitions
// * GET /api/leaderboard/challengedefinitions - Get list of challenge definitions.

/// <summary>
///
/// </summary>
/// <returns></returns>
[HttpGet("challengedefinitions", Name = "GetAllChallengeDefinitions")]
public List<ChallengeDefinition> GetAllChallengeDefinitions()
{
var query = from cd in _context.ChallengeDefinitions orderby cd.MaxPoints ascending, cd.Name ascending select cd;

return query.ToList<ChallengeDefinition>();
}

//Service Health APIS

/// <summary>
/// GET /api/leaderboard/servicehealth/ - get health for all teams services
/// </summary>
/// <returns>ListOfServiceHealth Records</returns>
[HttpGet("servicehealth", Name = "GetAllServiceHealth")]
public List<Team> GetAllServiceHealth()
{
var query = _context.Teams.Include(tm => tm.ServiceStatus);
return query.ToList();
}

/// <summary>
/// GET /api/leaderboard/servicehealth/{teamName} - get health for a team
/// </summary>
/// <param name="teamName"></param>
/// <returns>ListOfServiceHealth Records</returns>

[HttpGet("servicehealth/{teamName}", Name = "GetServiceHealthForTeam")]
[Produces("application/json", Type = typeof(Team))]
public List<Team> GetServiceHealthForTeam(string teamName)
{
var query = _context.Teams.Where(tm => tm.TeamName == teamName)
.Include(tm => tm.ServiceStatus);
return query.ToList();
}
}
}
1 change: 1 addition & 0 deletions leaderboard/web/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"node_modules/socicon/css/socicon.css",
"node_modules/nebular-icons/scss/nebular-icons.scss",
"node_modules/pace-js/templates/pace-theme-flash.tmpl.css",
"node_modules/@angular/material/prebuilt-themes/purple-green.css",
"src/app/@theme/styles/styles.scss"
],
"scripts": [
Expand Down
43 changes: 43 additions & 0 deletions leaderboard/web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion leaderboard/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
"prepush": "npm run lint:ci"
},
"dependencies": {
"@angular/animations": "~6.1.2",
"@angular/animations": "^6.1.7",
"@angular/cdk": "^6.4.7",
"@angular/common": "~6.1.2",
"@angular/compiler": "~6.1.2",
"@angular/core": "~6.1.2",
"@angular/forms": "~6.1.2",
"@angular/http": "~6.1.2",
"@angular/material": "^6.4.7",
"@angular/platform-browser": "~6.1.2",
"@angular/platform-browser-dynamic": "~6.1.2",
"@angular/router": "~6.1.2",
Expand All @@ -42,16 +44,19 @@
"@nebular/theme": "~2.0.0-rc.10",
"@ng-bootstrap/ng-bootstrap": "~2.2.2",
"add": "^2.0.6",
"angular-bootstrap-datetimepicker": "^2.2.1",
"angular-font-awesome": "^3.1.2",
"bootstrap": "^4.1.3",
"classlist.js": "1.1.20150312",
"core-js": "~2.5.7",
"echarts": "~4.1.0",
"intl": "1.2.5",
"ionicons": "2.0.1",
"moment": "^2.22.2",
"nebular-icons": "1.0.9",
"ngx-echarts": "^2.3.1",
"normalize.css": "6.0.0",
"open-iconic": "^1.1.1",
"pace-js": "1.0.2",
"roboto-fontface": "0.10.0",
"rxjs": "^6.3.2",
Expand Down
2 changes: 0 additions & 2 deletions leaderboard/web/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
HttpClientModule,
AppRoutingModule,
FormsModule,


NgbModule.forRoot(),
ThemeModule.forRoot(),
CoreModule.forRoot(),
Expand Down
52 changes: 52 additions & 0 deletions leaderboard/web/src/app/pages/challenges/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# TODO

## Add

### Fields
• Team: required
• Challenge: required
• StartDateTime: set using custom control
• EndDateTime: disabled
• Score: read only
• MaxScore: read only

### Init
• Create dummy challenge

### Validations
• Team: required
• Challenge: required
• Team/ChallengeCombo: Not already completed, prompt user if not completed.
• StartDateTime: greater than enddate < end time of last completed challenge
• EndDateTime: greater than start time

### Guards
• Can Deactivate: ask if want to lose changes

## Edit

### Fields
• Team: required
• Challenge: required
• StartDateTime: set using custom control
• EndDateTime: disabled
• Score: read only
• MaxScore: read only

### Init
• Look up challenge to edit
• Enable startDateTime, enddatetime
• Disable team, challenge, score

### Validations
• Team: required
• Challenge: required
• Team/ChallengeCombo: Not already completed, prompt user if not completed. Should not fire though
• StartDateTime: greater than enddate < end time of last completed challenge
• EndDateTime: greater than start time and < end Event Time

### Guards
• Can Deactivate: ask if want to lose changes


## Add unsubscribe to list views
Loading

0 comments on commit c724e2a

Please sign in to comment.