Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions Backend/Backend/Controllers/IssuesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,39 +108,39 @@ public async Task<IActionResult> SubmitQuest(long id)
quest.CompletedAt = DateTime.UtcNow;

var user = await _context.Users.FindAsync(userId);
if (user != null)
{
user.ExperiencePoints += issue.XPReward;
if (user == null)
return NotFound("User account not found.");

user.ExperiencePoints += issue.XPReward;

// Update streak based on contribution dates (once per day)
var today = DateTime.UtcNow.Date;
if (user.LastContributionDate.HasValue)
// Update streak based on contribution dates (once per day)
var today = DateTime.UtcNow.Date;
if (user.LastContributionDate.HasValue)
{
var lastDate = user.LastContributionDate.Value.Date;
if (lastDate == today)
{
// Already contributed today – do not increment streak
}
else if (lastDate == today.AddDays(-1))
{
var lastDate = user.LastContributionDate.Value.Date;
if (lastDate == today)
{
// Already contributed today – do not increment streak
}
else if (lastDate == today.AddDays(-1))
{
// Contributed yesterday – extend streak
user.CurrentStreak += 1;
}
else
{
// Gap in contributions – reset streak
user.CurrentStreak = 1;
}
// Contributed yesterday – extend streak
user.CurrentStreak += 1;
}
else
{
// Gap in contributions – reset streak
user.CurrentStreak = 1;
}

user.LastContributionDate = DateTime.UtcNow;
}
else
{
user.CurrentStreak = 1;
}

user.LastContributionDate = DateTime.UtcNow;

await _context.SaveChangesAsync();
return Ok(new { message = $"{issue.XPReward} XP Awarded!", totalXp = user?.ExperiencePoints });
return Ok(new { message = $"{issue.XPReward} XP Awarded!", totalXp = user.ExperiencePoints });
}
}

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

8 changes: 7 additions & 1 deletion Backend/Backend/Migrations/20260315082912_InitialCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
GitHubId = table.Column<string>(type: "nvarchar(max)", nullable: false),
GitHubId = table.Column<string>(type: "nvarchar(450)", nullable: false),
GitHubUsername = table.Column<string>(type: "nvarchar(450)", nullable: false),
Email = table.Column<string>(type: "nvarchar(max)", nullable: true),
AvatarUrl = table.Column<string>(type: "nvarchar(max)", nullable: true),
Expand Down Expand Up @@ -111,6 +111,12 @@ protected override void Up(MigrationBuilder migrationBuilder)
column: "GitHubIssueId",
unique: true);

migrationBuilder.CreateIndex(
name: "IX_Users_GitHubId",
table: "Users",
column: "GitHubId",
unique: true);

migrationBuilder.CreateIndex(
name: "IX_Users_GitHubUsername",
table: "Users",
Expand Down
26 changes: 0 additions & 26 deletions Backend/Backend/Migrations/20260315125659_AddUniqueConstraints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ protected override void Up(MigrationBuilder migrationBuilder)
name: "IX_Quests_UserId",
table: "Quests");

migrationBuilder.AlterColumn<string>(
name: "GitHubId",
table: "Users",
type: "nvarchar(450)",
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(max)");

migrationBuilder.AlterColumn<string>(
name: "Status",
table: "Quests",
Expand All @@ -30,12 +22,6 @@ protected override void Up(MigrationBuilder migrationBuilder)
oldClrType: typeof(string),
oldType: "nvarchar(max)");

migrationBuilder.CreateIndex(
name: "IX_Users_GitHubId",
table: "Users",
column: "GitHubId",
unique: true);

migrationBuilder.CreateIndex(
name: "IX_Quests_UserId_GitHubIssueId_ActiveStatus",
table: "Quests",
Expand All @@ -47,22 +33,10 @@ protected override void Up(MigrationBuilder migrationBuilder)
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_Users_GitHubId",
table: "Users");

migrationBuilder.DropIndex(
name: "IX_Quests_UserId_GitHubIssueId_ActiveStatus",
table: "Quests");

migrationBuilder.AlterColumn<string>(
name: "GitHubId",
table: "Users",
type: "nvarchar(max)",
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(450)");

migrationBuilder.AlterColumn<string>(
name: "Status",
table: "Quests",
Expand Down
2 changes: 1 addition & 1 deletion Backend/Backend/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
var secretKey = jwtSettings["Key"];
if (string.IsNullOrEmpty(secretKey))
throw new InvalidOperationException("JwtSettings:Key is not configured. Set it via environment variable or user secrets.");
var key = Encoding.ASCII.GetBytes(secretKey);
var key = Encoding.UTF8.GetBytes(secretKey);

builder.Services.AddAuthentication(options =>
{
Expand Down
Loading