Skip to content

Commit

Permalink
Merge pull request #31 from BellumGens/weekly-checkins
Browse files Browse the repository at this point in the history
feat(*): adding checkin endpoint
  • Loading branch information
kdinev authored Nov 30, 2024
2 parents 4cb6d00 + f80e280 commit 289f615
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions BellumGens.Api.Core/Controllers/TournamentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,57 @@ public async Task<IActionResult> GetAllApplications()
return Ok(await _dbContext.TournamentApplications.Include(a => a.Tournament).ToListAsync());
}

[Route("SendCheckinEmails")]
[Authorize(Roles = "admin")]
public async Task<IActionResult> SendCheckinEmails(Guid tournamentId)
{
List<TournamentApplication> applications = await _dbContext.TournamentApplications.Include(a => a.Tournament).Where(a => a.TournamentId == tournamentId).ToListAsync();
foreach (TournamentApplication app in applications)
{
try
{
// var callbackUrl = Url.ActionLink("Checkin", "Tournament", new { id = tournamentId });
string message = $@"Greetings, {app.FirstName},
<p>The weekly checkin for {app.Tournament.Name} is live. Go to <a href='https://bellumgens.com' target='_blank'>your profile settings</a> and check in from there.</p>
<p>Thank you from the Bellum Gens team and GL HF in this week's matches!</p>
<a href='https://bellumgens.com' target='_blank'>https://bellumgens.com</a>";
await _sender.SendEmailAsync(app.Email, "BGE Balkan: Time to check in", message).ConfigureAwait(false);
}
catch (Exception e)
{
System.Diagnostics.Trace.TraceError("Tournament registration error: " + e.Message);
}
}
return Ok(new { message = $"{applications.Count} emails sent" });
}

[HttpPut]
[Route("Checkin")]
public async Task<IActionResult> WeeklyCheckin(Guid id)
{
ApplicationUser user = await GetAuthUser();
TournamentApplication entity = await _dbContext.TournamentApplications.FindAsync(id);
if (entity.UserId == user.Id || await UserIsInRole("admin"))
{
if (entity != null)
{
entity.State = TournamentApplicationState.Confirmed;

try
{
await _dbContext.SaveChangesAsync();
}
catch (DbUpdateException e)
{
System.Diagnostics.Trace.TraceError("Tournament registration update error: " + e.Message);
return BadRequest("Something went wrong!");
}
return Ok(entity);
}
}
return NotFound();
}

[HttpPut]
[Route("Confirm")]
[Authorize(Roles = "admin")]
Expand Down

0 comments on commit 289f615

Please sign in to comment.