Skip to content

Commit d68f911

Browse files
authored
Merge pull request #1 from jmayer913/v1.0.0/VersionBranch
V1.0.0/version branch
2 parents 87e0b29 + 847d90d commit d68f911

File tree

68 files changed

+6210
-125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+6210
-125
lines changed

.github/workflows/mainworkflow.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This workflow will build a .NET project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3+
4+
name: MainWorkflow
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: windows-latest
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
- name: Setup .NET
21+
uses: actions/setup-dotnet@v4
22+
with:
23+
dotnet-version: 8.0.x
24+
- name: Restore dependencies
25+
run: dotnet restore
26+
- name: Build
27+
run: dotnet build --configuration Release --no-restore
28+
- name: Test
29+
run: dotnet test --verbosity normal
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using JMayer.Data.Data;
2+
using System.ComponentModel.DataAnnotations;
3+
4+
namespace JMayer.Example.ASPReact.Server.Airlines;
5+
6+
/// <summary>
7+
/// The class represents an airline and its codes.
8+
/// </summary>
9+
public class Airline : UserEditableDataObject
10+
{
11+
/// <summary>
12+
/// The property gets/sets the IATA code assigned by the IATA organization.
13+
/// </summary>
14+
[Required]
15+
[RegularExpression("^[A-Z0-9]{2}$", ErrorMessage = "The IATA must be 2 alphanumeric characters; letters must be capitalized.")]
16+
public string IATA { get;set; } = string.Empty;
17+
18+
/// <summary>
19+
/// The property gets/sets the ICAO code assigned by the International Aviation Organization.
20+
/// </summary>
21+
[RegularExpression("^[A-Z]{3}$", ErrorMessage = "The ICAO must be 3 capital letters.")]
22+
public string ICAO { get; set; } = string.Empty;
23+
24+
/// <summary>
25+
/// The property gets/sets the number code assigned by the IATA organization.
26+
/// </summary>
27+
[Required]
28+
[RegularExpression("^\\d{3}$", ErrorMessage = "The number code must be 3 digits.")]
29+
public string NumberCode { get; set; } = ZeroNumberCode;
30+
31+
/// <summary>
32+
/// The constant for the zero number code.
33+
/// </summary>
34+
public const string ZeroNumberCode = "000";
35+
36+
/// <summary>
37+
/// The default constructor.
38+
/// </summary>
39+
public Airline() { }
40+
41+
/// <summary>
42+
/// The copy constructor.
43+
/// </summary>
44+
/// <param name="copy">The copy.</param>
45+
public Airline(Airline copy) => MapProperties(copy);
46+
47+
/// <inheritdoc/>
48+
public override void MapProperties(DataObject dataObject)
49+
{
50+
base.MapProperties(dataObject);
51+
52+
if (dataObject is Airline airline)
53+
{
54+
IATA = airline.IATA;
55+
ICAO = airline.ICAO;
56+
NumberCode = airline.NumberCode;
57+
}
58+
}
59+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using JMayer.Web.Mvc.Controller;
2+
using Microsoft.AspNetCore.Mvc;
3+
4+
namespace JMayer.Example.ASPReact.Server.Airlines;
5+
6+
/// <summary>
7+
/// The class manages HTTP requests for CRUD operations associated with an airline in a database.
8+
/// </summary>
9+
[Route("api/[controller]")]
10+
[ApiController]
11+
public class AirlineController : UserEditableController<Airline, IAirlineDataLayer>
12+
{
13+
/// <inheritdoc/>
14+
public AirlineController(IAirlineDataLayer dataLayer, ILogger<AirlineController> logger) : base(dataLayer, logger) { }
15+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using JMayer.Data.Database.DataLayer.MemoryStorage;
2+
using System.ComponentModel.DataAnnotations;
3+
4+
namespace JMayer.Example.ASPReact.Server.Airlines;
5+
6+
/// <summary>
7+
/// The class manages CRUD interactions with the database for an airline.
8+
/// </summary>
9+
public class AirlineDataLayer : UserEditableDataLayer<Airline>, IAirlineDataLayer
10+
{
11+
/// <inheritdoc/>
12+
/// <remarks>
13+
/// Overriden to check the ICAO is unique and the number code is unique (expect for 000).
14+
/// </remarks>
15+
public override async Task<List<ValidationResult>> ValidateAsync(Airline dataObject, CancellationToken cancellationToken = default)
16+
{
17+
List<ValidationResult> validationResults = await base.ValidateAsync(dataObject, cancellationToken);
18+
19+
if (dataObject.ICAO != null && await ExistAsync(obj => obj.Integer64ID != dataObject.Integer64ID && obj.ICAO == dataObject.ICAO, cancellationToken) == true)
20+
{
21+
validationResults.Add(new ValidationResult("The ICAO must be unique.", [nameof(Airline.ICAO)]));
22+
}
23+
24+
if (dataObject.NumberCode != Airline.ZeroNumberCode && await ExistAsync(obj => obj.Integer64ID != dataObject.Integer64ID && obj.NumberCode == dataObject.NumberCode, cancellationToken) == true)
25+
{
26+
validationResults.Add(new ValidationResult("The number code must be unique unless the code is 000.", [nameof(Airline.NumberCode)]));
27+
}
28+
29+
return validationResults;
30+
}
31+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
3+
namespace JMayer.Example.ASPReact.Server.Airlines;
4+
5+
/// <summary>
6+
/// The class manages comparing two Airline objects.
7+
/// </summary>
8+
public class AirlineEqualityComparer : IEqualityComparer<Airline>
9+
{
10+
/// <summary>
11+
/// Excludes the CreatedOn property from the equals check.
12+
/// </summary>
13+
private readonly bool _excludeCreatedOn;
14+
15+
/// <summary>
16+
/// Excludes the ID property from the equals check.
17+
/// </summary>
18+
private readonly bool _excludeID;
19+
20+
/// <summary>
21+
/// Excludes the LastEditedOn property from the equals check.
22+
/// </summary>
23+
private readonly bool _excludeLastEditedOn;
24+
25+
/// <summary>
26+
/// The default constructor.
27+
/// </summary>
28+
public AirlineEqualityComparer() { }
29+
30+
/// <summary>
31+
/// The property constructor.
32+
/// </summary>
33+
/// <param name="excludeCreatedOn">Excludes the CreatedOn property from the equals check.</param>
34+
/// <param name="excludeID">Excludes the ID property from the equals check.</param>
35+
/// <param name="excludeLastEditedOn">Excludes the LastEditedOn property from the equals check.</param>
36+
public AirlineEqualityComparer(bool excludeCreatedOn, bool excludeID, bool excludeLastEditedOn)
37+
{
38+
_excludeCreatedOn = excludeCreatedOn;
39+
_excludeID = excludeID;
40+
_excludeLastEditedOn = excludeLastEditedOn;
41+
}
42+
43+
/// <inheritdoc/>
44+
public bool Equals(Airline? x, Airline? y)
45+
{
46+
if (x == null || y == null)
47+
{
48+
return false;
49+
}
50+
51+
return (_excludeCreatedOn || x.CreatedOn == y.CreatedOn)
52+
&& x.Description == y.Description
53+
&& x.IATA == y.IATA
54+
&& x.ICAO == y.ICAO
55+
&& (_excludeID || x.Integer64ID == y.Integer64ID)
56+
&& (_excludeLastEditedOn || x.LastEditedBy == y.LastEditedBy)
57+
&& x.Name == y.Name
58+
&& x.NumberCode == y.NumberCode;
59+
}
60+
61+
/// <inheritdoc/>
62+
public int GetHashCode([DisallowNull] Airline obj) => obj.GetHashCode();
63+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using JMayer.Data.Database.DataLayer;
2+
3+
namespace JMayer.Example.ASPReact.Server.Airlines;
4+
5+
/// <summary>
6+
/// The interface for interacting with an airline collection in a database using CRUD operations.
7+
/// </summary>
8+
public interface IAirlineDataLayer : IUserEditableDataLayer<Airline>
9+
{
10+
}

JMayer.Example.ASPReact.Server/Controllers/WeatherForecastController.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)