diff --git a/scripts/run-migrations-and-copy-database.sh b/scripts/run-migrations-and-copy-database.sh index 83631d1..b9da3a9 100644 --- a/scripts/run-migrations-and-copy-database.sh +++ b/scripts/run-migrations-and-copy-database.sh @@ -17,6 +17,7 @@ log() { local timestamp timestamp=$(date +"%Y-%m-%d %H:%M:%S") echo "$emoji [$timestamp] [$level] $message" + return 0 } # Check if the EF Core CLI tool is installed @@ -33,18 +34,18 @@ touch "$TARGET_FILE_PATH" # Run the database migration log "✅" "INFO" "Running EF Core database migration for project at '$PROJECT_ROOT_PATH'..." dotnet ef database update --project "$PROJECT_ROOT_PATH" -if [ $? -ne 0 ]; then +if [[ $? -ne 0 ]]; then log "❌" "ERROR" "Migration failed. See error above." exit 1 fi # Check and copy database -if [ -f "$SOURCE_FILE_PATH" ]; then +if [[ -f "$SOURCE_FILE_PATH" ]]; then log "✅" "INFO" "Found database at '$SOURCE_FILE_PATH'" log "✅" "INFO" "Copying to '$TARGET_FILE_PATH'..." cp -f "$SOURCE_FILE_PATH" "$TARGET_FILE_PATH" - if [ $? -eq 0 ]; then + if [[ $? -eq 0 ]]; then log "✅" "INFO" "Database successfully copied to '$TARGET_FILE_PATH'" else log "❌" "ERROR" "Failed to copy the database file." @@ -57,9 +58,9 @@ else fi # Confirm destination file exists -if [ -f "$TARGET_FILE_PATH" ]; then +if [[ -f "$TARGET_FILE_PATH" ]]; then log "✅" "INFO" "Done. The database is now available at '$TARGET_FILE_PATH'" else log "⚠️" "WARNING" "Something went wrong. The destination file was not found." exit 1 -fi \ No newline at end of file +fi diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Controllers/PlayerController.cs b/src/Dotnet.Samples.AspNetCore.WebApi/Controllers/PlayerController.cs index 42f25ee..3a566c9 100644 --- a/src/Dotnet.Samples.AspNetCore.WebApi/Controllers/PlayerController.cs +++ b/src/Dotnet.Samples.AspNetCore.WebApi/Controllers/PlayerController.cs @@ -177,7 +177,7 @@ [FromBody] PlayerRequestModel player .ToArray(); logger.LogWarning( - "PUT /players/{squadNumber} validation failed: {@Errors}", + "PUT /players/{SquadNumber} validation failed: {@Errors}", squadNumber, errors ); diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Models/PlayerRequestModel.cs b/src/Dotnet.Samples.AspNetCore.WebApi/Models/PlayerRequestModel.cs index 3735482..cdc6928 100644 --- a/src/Dotnet.Samples.AspNetCore.WebApi/Models/PlayerRequestModel.cs +++ b/src/Dotnet.Samples.AspNetCore.WebApi/Models/PlayerRequestModel.cs @@ -20,7 +20,7 @@ public class PlayerRequestModel public DateTime? DateOfBirth { get; set; } - public int SquadNumber { get; set; } + public required int SquadNumber { get; set; } public string? AbbrPosition { get; set; } diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Validators/PlayerRequestModelValidator.cs b/src/Dotnet.Samples.AspNetCore.WebApi/Validators/PlayerRequestModelValidator.cs index 46949cd..bd17682 100644 --- a/src/Dotnet.Samples.AspNetCore.WebApi/Validators/PlayerRequestModelValidator.cs +++ b/src/Dotnet.Samples.AspNetCore.WebApi/Validators/PlayerRequestModelValidator.cs @@ -33,7 +33,6 @@ public PlayerRequestModelValidator(IPlayerRepository playerRepository) .WithMessage("SquadNumber must be greater than 0.") .MustAsync(BeUniqueSquadNumber) .WithMessage("SquadNumber must be unique."); - ; RuleFor(player => player.AbbrPosition) .NotEmpty()