Skip to content

Mark #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed

Mark #70

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 102 additions & 101 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,32 @@ jobs:
ASPNETCORE_ENVIRONMENT: Development

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0'

- name: Install EF Core tools globally
run: |
dotnet tool install --global dotnet-ef

- name: Install dependencies
run: dotnet restore CargoHub

- name: Build API
run: dotnet build CargoHub --no-restore

- name: Add and apply EF migrations
run: |
cd CargoHub # Navigate to the project folder (if not in root)
dotnet ef migrations add setup
dotnet ef database update
- name: Checkout code
uses: actions/checkout@v2

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: "8.0"

- name: Install EF Core tools globally
run: |
dotnet tool install --global dotnet-ef

- name: Install dependencies
run: dotnet restore CargoHub

- name: Build API
run: dotnet build CargoHub --no-restore

- name: Add and apply EF migrations
run: |
cd CargoHub # Navigate to the project folder (if not in root)
dotnet ef migrations add setup
dotnet ef database update

unit-tests:
needs: build
runs-on: ubuntu-latest

services:
Expand All @@ -51,39 +52,40 @@ jobs:
ASPNETCORE_ENVIRONMENT: Development

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0'

- name: Install EF Core tools globally
run: |
dotnet tool install --global dotnet-ef

- name: Install dependencies
run: dotnet restore CargoHub

- name: Build API
run: dotnet build CargoHub --no-restore

- name: Add and apply EF migrations
run: |
cd CargoHub # Navigate to the project folder (if not in root)
dotnet ef migrations add setup
dotnet ef database update
- name: Install test dependencies
run: dotnet restore UnitTest

- name: Start testing
run: |
cd UnitTest
dotnet test
- name: Checkout code
uses: actions/checkout@v2

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: "8.0"

- name: Install EF Core tools globally
run: |
dotnet tool install --global dotnet-ef

- name: Install dependencies
run: dotnet restore CargoHub

- name: Build API
run: dotnet build CargoHub --no-restore

- name: Add and apply EF migrations
run: |
cd CargoHub # Navigate to the project folder (if not in root)
dotnet ef migrations add setup
dotnet ef database update

- name: Install test dependencies
run: dotnet restore UnitTest

- name: Start testing
run: |
cd UnitTest
dotnet test

integration-tests:
needs: build
runs-on: ubuntu-latest

services:
Expand All @@ -95,48 +97,47 @@ jobs:
ASPNETCORE_ENVIRONMENT: Development

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0'

- name: Install EF Core tools globally
run: |
dotnet tool install --global dotnet-ef

- name: Install dependencies
run: dotnet restore CargoHub

- name: Build API
run: dotnet build CargoHub --no-restore

- name: Add and apply EF migrations
run: |
cd CargoHub # Navigate to the project folder (if not in root)
dotnet ef migrations add setup
dotnet ef database update

- name: Start API
run: |
cd CargoHub # Navigate to the project folder (if not in root)
dotnet run &
sleep 15 # wait for API to start

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.12.6'

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install requests pytest

- name: Run integration tests
env:
API_URL: http://localhost:3000
run: pytest Tests

- name: Checkout code
uses: actions/checkout@v2

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: "8.0"

- name: Install EF Core tools globally
run: |
dotnet tool install --global dotnet-ef

- name: Install dependencies
run: dotnet restore CargoHub

- name: Build API
run: dotnet build CargoHub --no-restore

- name: Add and apply EF migrations
run: |
cd CargoHub # Navigate to the project folder (if not in root)
dotnet ef migrations add setup
dotnet ef database update

- name: Start API
run: |
cd CargoHub # Navigate to the project folder (if not in root)
dotnet run &
sleep 15 # wait for API to start

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.12.6"

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install requests pytest

- name: Run integration tests
env:
API_URL: http://localhost:3000
run: pytest Tests
29 changes: 18 additions & 11 deletions CargoHub/Controllers/MigrationsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,39 @@

namespace CargoHub.Controllers
{
[AuthorizationFilter]

[Route("api/v2/[Controller]")]
public class MigrationsController : ControllerBase
{
private readonly MigrationsService MigrationService;
private readonly MigrationsService _migrationService;

public MigrationsController(MigrationsService Migrate)
public MigrationsController(MigrationsService migrationsService)
{
MigrationService = Migrate;
_migrationService = migrationsService;
}

[HttpPost()]
public async Task<IActionResult> Migrate([FromQuery] string FolderName)
{
// Get the absolute path using a known directory (e.g., Logs)
var logFilePath = Path.Combine(Directory.GetCurrentDirectory(), "Logs", MigrationService.ReadDataFolder(FolderName));
try
{
// Construct the local file path
var localFilePath = Path.Combine(Directory.GetCurrentDirectory(), "Logs", _migrationService.ReadDataFolder(FolderName));

if (string.IsNullOrEmpty(localFilePath) || !System.IO.File.Exists(localFilePath))
{
return NotFound("File not found");
}
byte[] fileBytes = await System.IO.File.ReadAllBytesAsync(localFilePath);

if (string.IsNullOrEmpty(logFilePath) || !System.IO.File.Exists(logFilePath))
return File(fileBytes, "application/octet-stream", Path.GetFileName(localFilePath));
}
catch (Exception)
{
return NotFound("File not found");
return NotFound();
}
byte[] fileBytes = await System.IO.File.ReadAllBytesAsync(logFilePath);

return File(fileBytes, "application/octet-stream", Path.GetFileName(logFilePath));
}

}

}
13 changes: 0 additions & 13 deletions CargoHub/LogTransferData.csv

This file was deleted.

1 change: 0 additions & 1 deletion CargoHub/Rest/Migrate.rest
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@baseUrl = http://localhost:3000/api/v2/Migrations

POST {{baseUrl}}?FolderName=data

2 changes: 1 addition & 1 deletion Tests/test_item_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_put():
def test_put_Item_line_that_does_not_exist():
put_response = requests.put(
BASE_URL + "999999999999", json=VALID_ITEM_LINE)
assert put_response.status_code == 404
assert put_response.status_code ==


def test_delete():
Expand Down
Loading