-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: api endpoint for sector permission
- Loading branch information
Showing
4 changed files
with
105 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Net.Vatprc.Uniapi.Models; | ||
using Net.Vatprc.Uniapi.Services; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.Collections.Immutable; | ||
using System.Security.Claims; | ||
using Net.Vatprc.Uniapi.Utils; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Net.Vatprc.Uniapi.Controllers; | ||
|
||
/// <summary> | ||
/// Sector information. | ||
/// </summary> | ||
[ApiController, Route("api/sectors")] | ||
public class SectorController( | ||
VATPRCContext DbContext, | ||
VatsimService VatsimService) : ControllerBase | ||
{ | ||
public record SectorPermissionResponse | ||
{ | ||
public required bool HasPermission { get; set; } | ||
|
||
[SetsRequiredMembers] | ||
public SectorPermissionResponse(bool hasPermission) | ||
{ | ||
HasPermission = hasPermission; | ||
} | ||
} | ||
|
||
[HttpGet("current/permission")] | ||
public async Task<SectorPermissionResponse> GetPermission() | ||
{ | ||
var user = await DbContext.User.FindAsync(this.GetUserId()) ?? | ||
throw new ApiError.UserNotFound(this.GetUserId()); | ||
var controllers = await VatsimService.GetAtcList(); | ||
var atc = controllers.FirstOrDefault(c => c.Id.ToString() == user.Cid); | ||
if (atc == null) | ||
{ | ||
return new SectorPermissionResponse(false); | ||
} | ||
var hasPermission = atc.Roles.Any(r => r.Name == "Online Permission" || r.Name == "ATC Student"); | ||
return new SectorPermissionResponse(hasPermission); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters