-
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.
- Loading branch information
1 parent
14c3ab0
commit c1b0068
Showing
76 changed files
with
6,902 additions
and
0 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,34 @@ | ||
name: Build & Push Prod | ||
on: | ||
push: | ||
tags: | ||
- "*" | ||
jobs: | ||
DockerBuildPush: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
packages: write | ||
contents: read | ||
steps: | ||
- name: Checkout the repo | ||
uses: actions/checkout@v2 | ||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Get tag | ||
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV | ||
- name: Build api image | ||
run: | | ||
cd api | ||
docker build -t zme-api -f ZME.API/Dockerfile . | ||
- name: Tag images | ||
run: | | ||
docker tag zme-api ghcr.io/memphis-artcc/zme-api:latest | ||
docker tag zme-api ghcr.io/memphis-artcc/zme-api:${{ env.RELEASE_VERSION }} | ||
- name: Push images | ||
run: | | ||
docker push ghcr.io/memphis-artcc/zme-api:latest | ||
docker push ghcr.io/memphis-artcc/zme-api:${{ env.RELEASE_VERSION }} |
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,16 @@ | ||
name: Build | ||
on: | ||
push: | ||
branches: [develop, feature/*] | ||
jobs: | ||
DockerBuildPush: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
steps: | ||
- name: Checkout the repo | ||
uses: actions/checkout@v2 | ||
- name: Build api image | ||
run: | | ||
cd api | ||
docker build -t api -f ZME.API/Dockerfile . |
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,24 @@ | ||
name: Bump version | ||
on: | ||
pull_request: | ||
types: | ||
- closed | ||
branches: | ||
- main | ||
jobs: | ||
CreateTag: | ||
if: github.event.pull_request.merged == true | ||
runs-on: ubuntu-22.04 | ||
permissions: | ||
contents: write | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: '0' | ||
- name: Bump version and push tag | ||
uses: anothrNick/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.TAGGING_PAT }} | ||
WITH_V: true | ||
PRERELEASE: true | ||
DEFAULT_BUMP: patch |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Jacob Boyles | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,31 @@ | ||
CONNECTION_STRING=Host=localhost;Database=memphis;Username=postgres;Password=qwerty123 | ||
REDIS_HOST=localhost:6379 | ||
|
||
VATUSA_API_KEY=wyKPGJCPgzzDXBmm | ||
VATUSA_FACILITY=zme | ||
|
||
CONNECT_CLIENT_ID=1158 | ||
CONNECT_CLIENT_SECRET=lFMwfE6wnkpJT3jaWb17x39GbWJo1OA4U1G6n0Vd | ||
CONNECT_AUTH_URL=https://auth.vatsim.net | ||
CONNECT_REDIRECT_URL=http://localhost:5000/v1/auth/callback | ||
CONNEXT_REDIRECT_URL_UI=http://localhost:3000/auth/process | ||
|
||
JWT_ISSUER=MemphisARTCC | ||
JWT_AUDIENCE=MemphisARTCC | ||
JWT_SECRET=265e8853f0ab1c0471ed3214d24ef4c017b35c6ba3596268d0ca45351208c2c05fea62b0151138f90ab3eddf18189fb68aeaa948672c0a4c24bf82875c7cc161 | ||
JWT_ACCESS_EXPIRATION=7 | ||
JWT_REFRESH_EXPIRATION=30 | ||
|
||
EMAIL_FROM=[email protected] | ||
EMAIL_HOST=email-smtp.us-east-1.amazonaws.com | ||
EMAIL_PORT=587 | ||
EMAIL_USERNAME=AKIAQ42SJQKEB5AFRC52 | ||
EMAIL_PASSWORD=BBvgMhKJIMAgqyarHfV4OC/Hui33TVdbySrId9gm70J0 | ||
|
||
S3_KEY=146e86a593ab43818cc1eaedbd575849 | ||
S3_SECRET=fbebd70c801849848254c317d5281f8c | ||
S3_SERVICE_URL=https://nyc3.digitaloceanspaces.com | ||
S3_BUCKET_NAME=memphis-artcc | ||
S3_URL=https://cdn.memphisartcc.com | ||
|
||
SENTRY_DSN=https://f86076f8779344d0a3a8349a5b2bb7b6@o4504489093758976.ingest.sentry.io/4504489094873088 |
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,259 @@ | ||
using FluentValidation; | ||
using FluentValidation.Results; | ||
using Memphis.API.Data; | ||
using Memphis.API.Extensions; | ||
using Memphis.API.Services; | ||
using Memphis.Shared.Models; | ||
using Memphis.Shared.Utils; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
using Newtonsoft.Json; | ||
using Sentry; | ||
using Constants = Memphis.Shared.Utils.Constants; | ||
|
||
namespace Memphis.API.Controllers; | ||
|
||
[ApiController] | ||
[Route("[controller]")] | ||
[Produces("application/json")] | ||
public class AirportsController : ControllerBase | ||
{ | ||
private readonly DatabaseContext _context; | ||
private readonly RedisService _redisService; | ||
private readonly LoggingService _loggingService; | ||
private readonly IValidator<Airport> _validator; | ||
private readonly IHub _sentryHub; | ||
private readonly ILogger<AirportsController> _logger; | ||
|
||
public AirportsController(DatabaseContext context, RedisService redisService, LoggingService loggingService, | ||
IValidator<Airport> validator, IHub sentryHub, ILogger<AirportsController> logger) | ||
{ | ||
_context = context; | ||
_redisService = redisService; | ||
_loggingService = loggingService; | ||
_validator = validator; | ||
_sentryHub = sentryHub; | ||
_logger = logger; | ||
} | ||
|
||
|
||
[HttpPost] | ||
[Authorize(Roles = Constants.CAN_AIRPORTS)] | ||
[ProducesResponseType(typeof(Response<Airport>), 200)] | ||
[ProducesResponseType(typeof(Response<IList<ValidationFailure>>), 400)] | ||
[ProducesResponseType(401)] | ||
[ProducesResponseType(403)] | ||
[ProducesResponseType(typeof(Response<string?>), 500)] | ||
public async Task<ActionResult<Response<Airport>>> CreateAirport(Airport data) | ||
{ | ||
try | ||
{ | ||
if (!await _redisService.ValidateRoles(Request.HttpContext.User, Constants.CAN_AIRPORTS_LIST)) | ||
return StatusCode(401); | ||
|
||
var validation = await _validator.ValidateAsync(data); | ||
if (!validation.IsValid) | ||
{ | ||
return BadRequest(new Response<IList<ValidationFailure>> | ||
{ | ||
StatusCode = 400, | ||
Message = "Validation failure", | ||
Data = validation.Errors | ||
}); | ||
} | ||
|
||
var result = await _context.Airports.AddAsync(data); | ||
await _context.SaveChangesAsync(); | ||
var newData = JsonConvert.SerializeObject(result.Entity); | ||
await _loggingService.AddWebsiteLog(Request, $"Created airport {result.Entity.Id}", string.Empty, newData); | ||
|
||
await _redisService.RemoveCached("airports"); | ||
return CreatedAtAction(nameof(GetAirport), new { airportId = result.Entity.Id }, new Response<Airport> | ||
{ | ||
StatusCode = 200, | ||
Message = $"Created airport '{result.Entity.Id}'", | ||
Data = result.Entity | ||
}); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.LogError("CreateAirport error '{Message}'\n{StackTrace}", ex.Message, ex.StackTrace); | ||
return _sentryHub.CaptureException(ex).ReturnActionResult(); | ||
} | ||
} | ||
|
||
[HttpGet] | ||
[ProducesResponseType(typeof(Response<IList<Airport>>), 200)] | ||
[ProducesResponseType(typeof(Response<string?>), 500)] | ||
public async Task<ActionResult<Response<IList<Airport>>>> GetAirports() | ||
{ | ||
try | ||
{ | ||
var cached = await _redisService.GetCached("airports"); | ||
_logger.LogDebug("Cached airports: {Airports}", cached); | ||
if (cached != null) | ||
{ | ||
var cachedResult = JsonConvert.DeserializeObject<IList<Airport>>(cached); | ||
return Ok(new Response<IList<Airport>> | ||
{ | ||
StatusCode = 200, | ||
Message = $"Got {cachedResult?.Count} airports", | ||
Data = cachedResult | ||
}); | ||
} | ||
var result = await _context.Airports.ToListAsync(); | ||
await _redisService.SetCached("airports", JsonConvert.SerializeObject(result)); | ||
return Ok(new Response<IList<Airport>> | ||
{ | ||
StatusCode = 200, | ||
Message = $"Got {result.Count} airports", | ||
Data = result | ||
}); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.LogError("GetAirports error '{Message}'\n{StackTrace}", ex.Message, ex.StackTrace); | ||
return _sentryHub.CaptureException(ex).ReturnActionResult(); | ||
} | ||
} | ||
|
||
[HttpGet("{airportId:int}")] | ||
[ProducesResponseType(typeof(Response<Airport>), 200)] | ||
[ProducesResponseType(typeof(Response<int>), 404)] | ||
[ProducesResponseType(typeof(Response<string?>), 500)] | ||
public async Task<ActionResult<Response<IList<Airport>>>> GetAirport(int airportId) | ||
{ | ||
try | ||
{ | ||
var result = await _context.Airports.FindAsync(airportId); | ||
if (result == null) | ||
{ | ||
return NotFound(new Response<int> | ||
{ | ||
StatusCode = 404, | ||
Message = $"Airport '{airportId}' not found", | ||
Data = airportId | ||
}); | ||
} | ||
|
||
return Ok(new Response<Airport> | ||
{ | ||
StatusCode = 200, | ||
Message = $"Got airport '{result.Id}'", | ||
Data = result | ||
}); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.LogError("GetAirport error '{Message}'\n{StackTrace}", ex.Message, ex.StackTrace); | ||
return _sentryHub.CaptureException(ex).ReturnActionResult(); | ||
} | ||
} | ||
|
||
[HttpPut] | ||
[Authorize(Roles = Constants.CAN_AIRPORTS)] | ||
[ProducesResponseType(typeof(Response<Airport>), 200)] | ||
[ProducesResponseType(typeof(Response<IList<ValidationFailure>>), 400)] | ||
[ProducesResponseType(401)] | ||
[ProducesResponseType(403)] | ||
[ProducesResponseType(typeof(Response<int>), 404)] | ||
[ProducesResponseType(typeof(Response<string?>), 500)] | ||
public async Task<ActionResult<Response<Airport>>> UpdateAirport(Airport data) | ||
{ | ||
try | ||
{ | ||
if (!await _redisService.ValidateRoles(Request.HttpContext.User, Constants.CAN_AIRPORTS_LIST)) | ||
return StatusCode(401); | ||
|
||
var validation = await _validator.ValidateAsync(data); | ||
if (!validation.IsValid) | ||
{ | ||
return BadRequest(new Response<IList<ValidationFailure>> | ||
{ | ||
StatusCode = 400, | ||
Message = "Validation failure", | ||
Data = validation.Errors | ||
}); | ||
} | ||
|
||
var airport = await _context.Airports.FindAsync(data.Id); | ||
if (airport == null) | ||
{ | ||
return NotFound(new Response<int> | ||
{ | ||
StatusCode = 404, | ||
Message = $"Airport '{data.Id}' not found", | ||
Data = data.Id | ||
}); | ||
} | ||
|
||
var oldData = JsonConvert.SerializeObject(airport); | ||
airport.Name = data.Name; | ||
airport.Icao = data.Icao; | ||
airport.Updated = DateTimeOffset.UtcNow; | ||
await _context.SaveChangesAsync(); | ||
var newData = JsonConvert.SerializeObject(airport); | ||
|
||
await _loggingService.AddWebsiteLog(Request, $"Updated airport '{airport.Id}'", oldData, newData); | ||
|
||
await _redisService.RemoveCached("airports"); | ||
return Ok(new Response<Airport> | ||
{ | ||
StatusCode = 200, | ||
Message = $"Updated airport '{airport.Id}'", | ||
Data = airport | ||
}); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.LogError("UpdateAirport error '{Message}'\n{StackTrace}", ex.Message, ex.StackTrace); | ||
return _sentryHub.CaptureException(ex).ReturnActionResult(); | ||
} | ||
} | ||
|
||
[HttpDelete("{airportId:int}")] | ||
[Authorize(Roles = Constants.CAN_AIRPORTS)] | ||
[ProducesResponseType(typeof(Response<string?>), 200)] | ||
[ProducesResponseType(401)] | ||
[ProducesResponseType(403)] | ||
[ProducesResponseType(typeof(Response<int>), 404)] | ||
[ProducesResponseType(typeof(Response<string?>), 500)] | ||
public async Task<ActionResult<Response<string>>> DeleteAirport(int airportId) | ||
{ | ||
try | ||
{ | ||
if (!await _redisService.ValidateRoles(Request.HttpContext.User, Constants.CAN_AIRPORTS_LIST)) | ||
return StatusCode(401); | ||
|
||
var airport = await _context.Airports.FindAsync(airportId); | ||
if (airport == null) | ||
{ | ||
return NotFound(new Response<int> | ||
{ | ||
StatusCode = 404, | ||
Message = $"Airport '{airportId}' not found", | ||
Data = airportId | ||
}); | ||
} | ||
|
||
var oldData = JsonConvert.SerializeObject(airport); | ||
_context.Airports.Remove(airport); | ||
await _context.SaveChangesAsync(); | ||
|
||
await _loggingService.AddWebsiteLog(Request, $"Deleted airport '{airportId}'", oldData, string.Empty); | ||
|
||
await _redisService.RemoveCached("airports"); | ||
return Ok(new Response<string?> | ||
{ | ||
StatusCode = 200, | ||
Message = $"Deleted airport '{airportId}'" | ||
}); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.LogError("DeleteAirport error '{Message}'\n{StackTrace}", ex.Message, ex.StackTrace); | ||
return _sentryHub.CaptureException(ex).ReturnActionResult(); | ||
} | ||
} | ||
} |
Oops, something went wrong.