Skip to content

Commit

Permalink
less async and hidden Objectives
Browse files Browse the repository at this point in the history
  • Loading branch information
MMunier committed Apr 17, 2020
1 parent 2a991e8 commit dfa8b36
Show file tree
Hide file tree
Showing 10 changed files with 306 additions and 66 deletions.
9 changes: 9 additions & 0 deletions ChallengePad/ChallengePad.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Migrations\20200417164314_app2.cs" />
<Compile Remove="Migrations\20200417164314_app2.Designer.cs" />
</ItemGroup>

<ItemGroup>
<_ContentIncludedByDefault Remove="appsettings.Development.json" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
13 changes: 12 additions & 1 deletion ChallengePad/Database/ChallengePadDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,23 @@ public async Task CreateObjective(string name, string category, long points, lon
Name = name,
Category = category,
Points = points,
OperationId = operationId
OperationId = operationId,
Visible = true
});
await Context.SaveChangesAsync(token);
await OperationsChannel.Publish(operationId, Settings.Value.RedisConfiguration);
}

public async Task UpdateObjectiveVisiblity(long objectiveId, long operationId, bool visible, CancellationToken token)
{
var obj = await Context.Objectives
.Where(obj => obj.Id == objectiveId)
.SingleAsync(token);
obj.Visible = visible;
await Context.SaveChangesAsync(token);
await OperationsChannel.Publish(operationId, Settings.Value.RedisConfiguration);
}

public async Task UpdateObjective(long objectiveId, long operationId, bool solved, CancellationToken token)
{
var obj = await Context.Objectives
Expand Down
1 change: 1 addition & 0 deletions ChallengePad/Database/IChallengePadDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public interface IChallengePadDb
Task<Operation> GetOperation(long id, CancellationToken token);
Task CreateObjective(string name, string category, long points, long operationId, CancellationToken token);
Task UpdateObjective(long objectiveId, long operationId, bool solved, CancellationToken token);
Task UpdateObjectiveVisiblity(long objectiveId, long operationId, bool visible, CancellationToken token);
Task AddFiles(ICollection<IFormFile> files, long id, bool isObjectiveFile, string username, CancellationToken token);
Task<string> GetFileName(long id, CancellationToken token);
}
Expand Down
132 changes: 132 additions & 0 deletions ChallengePad/Migrations/20200417164541_m2.Designer.cs

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

33 changes: 33 additions & 0 deletions ChallengePad/Migrations/20200417164541_m2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore.Migrations;

namespace ChallengePad.Migrations
{
public partial class m2 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "Visible",
table: "Operations",
nullable: false,
defaultValue: true);

migrationBuilder.AddColumn<bool>(
name: "Visible",
table: "Objectives",
nullable: false,
defaultValue: true);
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Visible",
table: "Operations");

migrationBuilder.DropColumn(
name: "Visible",
table: "Objectives");
}
}
}
6 changes: 6 additions & 0 deletions ChallengePad/Migrations/ChallengePadDbContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<bool>("Solved")
.HasColumnType("boolean");
b.Property<bool>("Visible")
.HasColumnType("boolean");
b.HasKey("Id");
b.HasIndex("OperationId");
Expand All @@ -61,6 +64,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.IsRequired()
.HasColumnType("text");
b.Property<bool>("Visible")
.HasColumnType("boolean");
b.HasKey("Id");
b.ToTable("Operations");
Expand Down
3 changes: 3 additions & 0 deletions ChallengePad/Models/Objective.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Text.Json.Serialization;

Expand All @@ -14,6 +15,8 @@ public class Objective
public long Points { get; set; }
public bool Solved { get; set; }
public long OperationId { get; set; }
[DefaultValue(true)]
public bool Visible { get; set; }
public List<UploadedFile> Files { get; set; } = new List<UploadedFile>();
#pragma warning restore CS8618 // Das Feld lässt keine NULL-Werte zu und ist nicht initialisiert. Deklarieren Sie das Feld ggf. als "Nullable".
}
Expand Down
15 changes: 9 additions & 6 deletions ChallengePad/Models/Operation.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text.Json.Serialization;
Expand All @@ -12,6 +13,8 @@ public class Operation
#pragma warning disable CS8618
public long Id { get; set; }
public string Name { get; set; }
[DefaultValue(true)]
public bool Visible { get; set; }
public List<Objective> Objectives { get; set; } = new List<Objective>();
public List<UploadedFile> Files { get; set; } = new List<UploadedFile>();
#pragma warning restore CS8618
Expand All @@ -30,19 +33,19 @@ public class Operation
return category;
}));

[NotMapped] public long SolvedObjectives => Objectives.Sum(o => o.Solved ? 1 : 0);
[NotMapped] public long SolvedPoints => Objectives.Sum(o => o.Solved ? o.Points : 0);
[NotMapped] public long TotalPoints => Objectives.Sum(o => o.Points);
[NotMapped] public long TotalObjectives => Objectives.Count;
public long SolvedObjectives(bool countHidden) => Objectives.Where(o => o.Visible || countHidden).Sum(o => o.Solved ? 1 : 0);
public long SolvedPoints(bool countHidden) => Objectives.Where(o => o.Visible || countHidden).Sum(o => o.Solved ? o.Points : 0);
public long TotalPoints(bool countHidden) => Objectives.Where(o => o.Visible || countHidden).Sum(o => o.Points);
public long TotalObjectives(bool countHidden) => Objectives.Where(o => o.Visible || countHidden).Count();
}

public class Category
{
#pragma warning disable CS8618
public string Name { get; set; }
public List<Objective> Objectives { get; set; } = new List<Objective>();
public long SolvedObjectives => Objectives.Sum(o => o.Solved ? 1 : 0);
public long TotalObjectives => Objectives.Count;
public long SolvedObjectives(bool countHidden) => Objectives.Where(o => o.Visible || countHidden).Sum(o => o.Solved ? 1 : 0);
public long TotalObjectives(bool countHidden) => Objectives.Where(o => o.Visible || countHidden).Count();
#pragma warning restore CS8618
}
}
Loading

0 comments on commit dfa8b36

Please sign in to comment.