-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Init * Response for GetDataById was fixed * Add view to migration * Fix some code smells * Fix some smells * Code smells * Code smells * Code smells * Smell * Migration was deleted * Add migration after merge * Delete migration * Add new migration
- Loading branch information
Showing
37 changed files
with
3,957 additions
and
10 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
OutOfSchool/OutOfSchool.DataAccess/Contexts/Configuration/GcpStorageFilesSourceConfig.cs
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,8 @@ | ||
namespace OutOfSchool.Services.Contexts.Configuration; | ||
|
||
/// <summary> | ||
/// Contains a configuration that is essential for operations with files in Google Cloud Storage. | ||
/// </summary> | ||
public class GcpStorageFilesSourceConfig : GcpStorageSourceConfig | ||
{ | ||
} |
8 changes: 8 additions & 0 deletions
8
OutOfSchool/OutOfSchool.DataAccess/Enums/StatisticReportDataTypes.cs
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,8 @@ | ||
namespace OutOfSchool.Services.Enums; | ||
|
||
public enum StatisticReportDataTypes | ||
{ | ||
CSV, | ||
XLSX, | ||
HTML, | ||
} |
20 changes: 20 additions & 0 deletions
20
OutOfSchool/OutOfSchool.DataAccess/Enums/StatisticReportTypes.cs
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,20 @@ | ||
namespace OutOfSchool.Services.Enums; | ||
|
||
public enum StatisticReportTypes | ||
{ | ||
WorkshopsYear, | ||
WorkshopsDaily, | ||
} | ||
|
||
public static class StatisticReportTypesExtensions | ||
{ | ||
public static string GetReportTitle(this StatisticReportTypes value) | ||
{ | ||
return value switch | ||
{ | ||
StatisticReportTypes.WorkshopsYear => "Річний звіт по гуртках: {0:dd-MM-yyyy}", | ||
StatisticReportTypes.WorkshopsDaily => "Поточний звіт по гуртках: {0:dd-MM-yyyy}", | ||
_ => string.Empty | ||
}; | ||
} | ||
} |
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,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace OutOfSchool.Services.Models; | ||
public class FileInDb : IKeyedEntity<string> | ||
{ | ||
public string Id { get; set; } | ||
|
||
public string ContentType { get; set; } | ||
|
||
public byte[] Data { get; set; } | ||
} |
26 changes: 26 additions & 0 deletions
26
OutOfSchool/OutOfSchool.DataAccess/Models/StatisticReport.cs
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,26 @@ | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
using OutOfSchool.Services.Enums; | ||
|
||
namespace OutOfSchool.Services.Models; | ||
|
||
public class StatisticReport : IKeyedEntity<Guid> | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
[Required] | ||
public DateTime Date { get; set; } | ||
|
||
[Required] | ||
public StatisticReportTypes ReportType { get; set; } | ||
|
||
[Required] | ||
public StatisticReportDataTypes ReportDataType { get; set; } | ||
|
||
[Required] | ||
[MaxLength(250)] | ||
public string Title { get; set; } | ||
|
||
[Required] | ||
public string ExternalStorageId { get; set; } | ||
} |
112 changes: 112 additions & 0 deletions
112
OutOfSchool/OutOfSchool.DataAccess/Models/StatisticReportCSV.cs
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,112 @@ | ||
using System; | ||
using CsvHelper.Configuration.Attributes; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace OutOfSchool.Services.Models; | ||
|
||
[Keyless] | ||
public class StatisticReportCSV | ||
{ | ||
[Name("Рік звітності")] | ||
public int Year { get; set; } | ||
|
||
[Name("ID закладу позашкільної освіти")] | ||
public Guid ProviderId { get; set; } | ||
|
||
[Name("Повна назва закладу")] | ||
public string ProviderName { get; set; } | ||
|
||
[Name("ЄДРПОУ")] | ||
public string EDRPOU { get; set; } | ||
|
||
[Name("Форма власності")] | ||
public string ProviderType { get; set; } | ||
|
||
[Name("Підпорядкування(Назва міністерства)")] | ||
public string InstitutionTitle { get; set; } | ||
|
||
[Name("КАТОТТГ")] | ||
public string CATOTTGCode { get; set; } | ||
|
||
[Name("Область")] | ||
public string Region { get; set; } | ||
|
||
[Name("Громада")] | ||
public string TerritorialCommunity { get; set; } | ||
|
||
[Name("Населений пункт")] | ||
public string Settlement { get; set; } | ||
|
||
[Name("Тип місцевості")] | ||
public string CATOTTGCategory { get; set; } | ||
|
||
[Name("Комплексний/профільний")] | ||
public string Complex { get; set; } | ||
|
||
[Name("Статус(окрема юридична особа/структурний підрозділ)")] | ||
public string Status { get; set; } | ||
|
||
[Name("Загальна кількість гуртків")] | ||
public int WorkshopsAmount { get; set; } | ||
|
||
[Name("Загальна кількість поданих заяв(всі які є для цього надавача, за звітний період)")] | ||
public int ApplicationsAmount { get; set; } | ||
|
||
[Name("Загальна кількість зарахованих заяв(заразовані/навчаються, за звітній період)")] | ||
public int ApplicationsApproved { get; set; } | ||
|
||
[Name("Загальна кількість здобувачів освіти(загалом, крім тих хто завершив навчання)")] | ||
public int ChildrenStudying { get; set; } | ||
|
||
[Name("Загальна кількість здобувачів освіти жіночої статі(загалом, крім тих хто завершив навчання)")] | ||
public int ChildrenStudyingFemale { get; set; } | ||
|
||
[Name("Загальна кількість здобувачів освіти віком до 18 років(загалом, крім тих хто завершив навчання)")] | ||
public int ChildrenStudyingLess18 { get; set; } | ||
|
||
[Name("Загальна кількість викладачів")] | ||
public int Teachers { get; set; } | ||
|
||
// By InstitutionHierarchy | ||
[Name("Кількість гуртків (в розрізі напрямків)")] | ||
public int WorkshopsAmountInstitutionHierarchy { get; set; } | ||
|
||
[Name("Кількість здобувачів освіти (в розрізі напрямків)")] | ||
public int ChildrenStudyingInstitutionHierarchy { get; set; } | ||
|
||
[Name("Кількість здобувачів освіти жіночої статі (в розрізі напрямків)")] | ||
public int ChildrenStudyingFemaleInstitutionHierarchy { get; set; } | ||
|
||
[Name("Кількість здобувачів освіти із досягненнями (в розрізі напрямків)")] | ||
public int ChildrenStudyingAchievementsInstitutionHierarchy { get; set; } | ||
|
||
[Name("Кількість здобувачів освіти із багатодітних сімей (в розрізі напрямків)")] | ||
public int ChildrenStudyingLargeFamilyInstitutionHierarchy { get; set; } | ||
|
||
[Name("Кількість здобувачів освіти із малозабезпечених сімей (в розрізі напрямків)")] | ||
public int ChildrenStudyingPoorFamilyInstitutionHierarchy { get; set; } | ||
|
||
[Name("Кількість здобувачів освіти з інвалідністю (в розрізі напрямків)")] | ||
public int ChildrenStudyingDisabilityInstitutionHierarchy { get; set; } | ||
|
||
[Name("Кількість здобувачів освіти, що є сиротами або позбавленими батьківського піклування (в розрізі напрямків)")] | ||
public int ChildrenStudyingOrphanInstitutionHierarchy { get; set; } | ||
|
||
[Name("Загальна кількість викладачів (в розрізі напрямків)")] | ||
public int TeachersInstitutionHierarchy { get; set; } | ||
|
||
[Name("Кількість викладачів віком до 30 (в розрізі напрямків)")] | ||
public int TeachersLess30InstitutionHierarchy { get; set; } | ||
|
||
[Name("Кількість викладачів віком 31 - 40 (в розрізі напрямків)")] | ||
public int TeachersFrom31To40InstitutionHierarchy { get; set; } | ||
|
||
[Name("Кількість викладачів віком 41 - 50 (в розрізі напрямків)")] | ||
public int TeachersFrom41To50InstitutionHierarchy { get; set; } | ||
|
||
[Name("Кількість викладачів віком 51 - 55 (в розрізі напрямків)")] | ||
public int TeachersFrom51To55InstitutionHierarchy { get; set; } | ||
|
||
[Name("Кількість викладачів віком 55 + (в розрізі напрямків)")] | ||
public int TeachersFrom55InstitutionHierarchy { get; set; } | ||
} |
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
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
11 changes: 11 additions & 0 deletions
11
OutOfSchool/OutOfSchool.DataAccess/Repository/Files/FileInDbRepository.cs
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,11 @@ | ||
using OutOfSchool.Services.Models; | ||
|
||
namespace OutOfSchool.Services.Repository.Files; | ||
|
||
public class FileInDbRepository : EntityRepositoryBase<string, FileInDb>, IFileInDbRepository | ||
{ | ||
public FileInDbRepository(OutOfSchoolDbContext dbContext) | ||
: base(dbContext) | ||
{ | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
OutOfSchool/OutOfSchool.DataAccess/Repository/Files/FileInDbStorageBase.cs
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,81 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Reflection.Metadata; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Google; | ||
using Google.Apis.Storage.v1.Data; | ||
using Google.Cloud.Storage.V1; | ||
using OutOfSchool.Services.Common.Exceptions; | ||
using OutOfSchool.Services.Enums; | ||
using OutOfSchool.Services.Models; | ||
|
||
namespace OutOfSchool.Services.Repository.Files; | ||
|
||
public abstract class FileInDbStorageBase<TFile> : IFilesStorage<TFile, string> | ||
where TFile : FileModel, new() | ||
{ | ||
private readonly IFileInDbRepository fileInDbRepository; | ||
|
||
protected FileInDbStorageBase( | ||
IFileInDbRepository fileInDbRepository) | ||
{ | ||
this.fileInDbRepository = fileInDbRepository; | ||
} | ||
|
||
public async Task DeleteAsync(string fileId, CancellationToken cancellationToken = default) | ||
{ | ||
var fileInDb = await fileInDbRepository.GetById(fileId).ConfigureAwait(false); | ||
|
||
if (fileInDb != null) | ||
{ | ||
await fileInDbRepository.Delete(fileInDb).ConfigureAwait(false); | ||
} | ||
} | ||
|
||
public IAsyncEnumerable<Objects> GetBulkListsOfObjectsAsync(string prefix = null, ListObjectsOptions options = null) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public async Task<TFile> GetByIdAsync(string fileId, CancellationToken cancellationToken = default) | ||
{ | ||
_ = fileId ?? throw new ArgumentNullException(nameof(fileId)); | ||
|
||
try | ||
{ | ||
var fileInDb = await fileInDbRepository.GetById(fileId).ConfigureAwait(false); | ||
|
||
var memoryStream = new MemoryStream(); | ||
memoryStream.Write(fileInDb.Data, 0, fileInDb.Data.Length); | ||
memoryStream.Position = 0; | ||
return new TFile { ContentStream = memoryStream, ContentType = fileInDb.ContentType }; | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new FileStorageException(ex); | ||
} | ||
} | ||
|
||
public async Task<string> UploadAsync(TFile file, CancellationToken cancellationToken = default) | ||
{ | ||
_ = file ?? throw new ArgumentNullException(nameof(file)); | ||
|
||
var fileInDb = new FileInDb() | ||
{ | ||
Id = GenerateFileId(), | ||
ContentType = file.ContentType, | ||
Data = ((MemoryStream)file.ContentStream).ToArray(), | ||
}; | ||
|
||
await fileInDbRepository.Create(fileInDb).ConfigureAwait(false); | ||
|
||
return fileInDb.Id; | ||
} | ||
|
||
protected virtual string GenerateFileId() | ||
{ | ||
return Guid.NewGuid().ToString(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
OutOfSchool/OutOfSchool.DataAccess/Repository/Files/FileStatisticReportStorage.cs
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,13 @@ | ||
using OutOfSchool.Services.Contexts; | ||
using OutOfSchool.Services.Models; | ||
using OutOfSchool.Services.Models.Images; | ||
|
||
namespace OutOfSchool.Services.Repository.Files; | ||
|
||
public class FileStatisticReportStorage : FileInDbStorageBase<FileModel>, IStatisticReportFileStorage | ||
{ | ||
public FileStatisticReportStorage(IFileInDbRepository fileInDbRepository) | ||
: base(fileInDbRepository) | ||
{ | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
OutOfSchool/OutOfSchool.DataAccess/Repository/Files/IFileInDbRepository.cs
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,7 @@ | ||
using OutOfSchool.Services.Models; | ||
|
||
namespace OutOfSchool.Services.Repository.Files; | ||
|
||
public interface IFileInDbRepository : IEntityRepositoryBase<string, FileInDb> | ||
{ | ||
} |
7 changes: 7 additions & 0 deletions
7
OutOfSchool/OutOfSchool.DataAccess/Repository/Files/IStatisticReportFileStorage.cs
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,7 @@ | ||
using OutOfSchool.Services.Models; | ||
|
||
namespace OutOfSchool.Services.Repository.Files; | ||
|
||
public interface IStatisticReportFileStorage : IFilesStorage<FileModel, string> | ||
{ | ||
} |
10 changes: 10 additions & 0 deletions
10
OutOfSchool/OutOfSchool.DataAccess/Repository/IStatisticReportRepository.cs
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,10 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using OutOfSchool.Services.Models; | ||
|
||
namespace OutOfSchool.Services.Repository; | ||
|
||
public interface IStatisticReportRepository : ISensitiveEntityRepository<StatisticReport> | ||
{ | ||
public Task<List<StatisticReportCSV>> GetDataForReport(); | ||
} |
Oops, something went wrong.