Skip to content

Commit 2ccbe9d

Browse files
authored
Added filesize column (#45)
1 parent 759d4d7 commit 2ccbe9d

File tree

21 files changed

+839
-48
lines changed

21 files changed

+839
-48
lines changed

src/DfE.ExternalApplications.Api/DfE.ExternalApplications.Api.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<ItemGroup>
1111
<PackageReference Include="Asp.Versioning.Mvc" Version="8.1.0" />
1212
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
13-
<PackageReference Include="DfE.CoreLibs.Contracts" Version="1.0.42" />
13+
<PackageReference Include="DfE.CoreLibs.Contracts" Version="1.0.43" />
1414
<PackageReference Include="DfE.CoreLibs.Http" Version="1.0.9" />
1515
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.23.0" />
1616
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.18" />

src/DfE.ExternalApplications.Application/Applications/Commands/UploadFileCommandHandler.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ public async Task<Result<UploadDto>> Handle(UploadFileCommand request, Cancellat
9595
// Upload file to the storage
9696
await fileStorageService.UploadAsync(storagePath, request.FileContent, cancellationToken);
9797

98+
var fileSize = request.FileContent.Length;
99+
98100
// Create File entity using factory
99101
var upload = fileFactory.CreateUpload(
100102
new FileId(Guid.NewGuid()),
@@ -105,7 +107,8 @@ public async Task<Result<UploadDto>> Handle(UploadFileCommand request, Cancellat
105107
hashedFileName,
106108
application.ApplicationReference,
107109
DateTime.UtcNow,
108-
dbUser.Id!
110+
dbUser.Id!,
111+
fileSize
109112
);
110113

111114
await uploadRepository.AddAsync(upload, cancellationToken);
@@ -121,7 +124,8 @@ public async Task<Result<UploadDto>> Handle(UploadFileCommand request, Cancellat
121124
Description = upload.Description,
122125
OriginalFileName = upload.OriginalFileName,
123126
FileName = upload.FileName,
124-
UploadedOn = upload.UploadedOn
127+
UploadedOn = upload.UploadedOn,
128+
FileSize = fileSize
125129
};
126130

127131
return Result<UploadDto>.Success(dto);

src/DfE.ExternalApplications.Application/Applications/Queries/GetFilesForApplicationQueryHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public async Task<Result<IReadOnlyCollection<UploadDto>>> Handle(GetFilesForAppl
7474
Description = u.Description,
7575
OriginalFileName = u.OriginalFileName,
7676
FileName = u.FileName,
77-
UploadedOn = u.UploadedOn
77+
UploadedOn = u.UploadedOn,
78+
FileSize = u.FileSize
7879
})
7980
.ToListAsync(cancellationToken)).AsReadOnly();
8081

src/DfE.ExternalApplications.Application/DfE.ExternalApplications.Application.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<PackageReference Include="AutoMapper" Version="14.0.0" />
1818
<PackageReference Include="DfE.CoreLibs.AsyncProcessing" Version="1.0.12" />
1919
<PackageReference Include="DfE.CoreLibs.Caching" Version="1.0.10" />
20-
<PackageReference Include="DfE.CoreLibs.Contracts" Version="1.0.42" />
20+
<PackageReference Include="DfE.CoreLibs.Contracts" Version="1.0.43" />
2121
<PackageReference Include="DfE.CoreLibs.FileStorage" Version="0.1.0" />
2222
<PackageReference Include="DfE.CoreLibs.Security" Version="1.1.14-prerelease-23" />
2323
<PackageReference Include="DfE.CoreLibs.Utilities" Version="1.0.15" />

src/DfE.ExternalApplications.Domain/DfE.ExternalApplications.Domain.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<ItemGroup>
88
<PackageReference Include="DfE.CoreLibs.Caching" Version="1.0.10" />
9-
<PackageReference Include="DfE.CoreLibs.Contracts" Version="1.0.42" />
9+
<PackageReference Include="DfE.CoreLibs.Contracts" Version="1.0.43" />
1010
<PackageReference Include="FluentValidation" Version="12.0.0" />
1111
<PackageReference Include="MediatR" Version="12.5.0" />
1212
</ItemGroup>

src/DfE.ExternalApplications.Domain/Entities/File.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public sealed class File : BaseAggregateRoot, IEntity<FileId>
1414
public string? Description { get; private set; }
1515
public string OriginalFileName { get; private set; } = null!;
1616
public string FileName { get; private set; } = null!;
17+
public long FileSize { get; private set; }
1718
public string Path { get; private set; }
1819
public DateTime UploadedOn { get; private set; }
1920
public UserId UploadedBy { get; private set; }
@@ -31,7 +32,8 @@ public File(
3132
string fileName,
3233
string path,
3334
DateTime uploadedOn,
34-
UserId uploadedBy)
35+
UserId uploadedBy,
36+
long fileSize)
3537
{
3638
Id = id ?? throw new ArgumentNullException(nameof(id));
3739
ApplicationId = applicationId ?? throw new ArgumentNullException(nameof(applicationId));
@@ -42,6 +44,7 @@ public File(
4244
Path = path;
4345
UploadedOn = uploadedOn;
4446
UploadedBy = uploadedBy ?? throw new ArgumentNullException(nameof(uploadedBy));
47+
FileSize = fileSize;
4548
}
4649

4750
public void Delete()

src/DfE.ExternalApplications.Domain/Factories/FileFactory.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public File CreateUpload(
1717
string fileName,
1818
string path,
1919
DateTime uploadedOn,
20-
UserId uploadedBy)
20+
UserId uploadedBy,
21+
long fileSize)
2122
{
2223
return new File(
2324
id,
@@ -28,7 +29,8 @@ public File CreateUpload(
2829
fileName,
2930
path,
3031
uploadedOn,
31-
uploadedBy
32+
uploadedBy,
33+
fileSize
3234
);
3335
}
3436

src/DfE.ExternalApplications.Domain/Factories/IFileFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ File CreateUpload(
1515
string fileName,
1616
string path,
1717
DateTime uploadedOn,
18-
UserId uploadedBy);
18+
UserId uploadedBy,
19+
long fileSize);
1920
void DeleteFile(File file);
2021
}

src/DfE.ExternalApplications.Infrastructure/Database/ExternalApplicationsContext.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,9 @@ private static void ConfigureFile(EntityTypeBuilder<File> b)
483483
.HasColumnName("FileName")
484484
.HasMaxLength(255)
485485
.IsRequired();
486+
b.Property(e => e.FileSize)
487+
.HasColumnName("FileSize")
488+
.IsRequired();
486489
b.Property(e => e.Path)
487490
.HasColumnName("Path")
488491
.HasMaxLength(255);

0 commit comments

Comments
 (0)