Skip to content

Commit

Permalink
videos database project extracted
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-zhur committed Sep 7, 2024
1 parent daf270e commit 795bc92
Show file tree
Hide file tree
Showing 57 changed files with 188 additions and 146 deletions.
21 changes: 14 additions & 7 deletions HarmonyDB and OneShelf.sln
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,25 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneShelf.Telegram", "OneShe
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OneShelf.OneDragon", "OneShelf.OneDragon", "{950D96F8-860E-4EE6-A8EC-8ECCC6BE480F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneShelf.OneDragon.Runner.Functions", "OneShelf.OneDragon\OneShelf.OneDragon.Runner.Functions\OneShelf.OneDragon.Runner.Functions.csproj", "{4A7E75E5-B345-4BF8-BFCC-788ADC1FA218}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneShelf.OneDragon.Runner.Functions", "OneShelf.OneDragon\OneShelf.OneDragon.Runner.Functions\OneShelf.OneDragon.Runner.Functions.csproj", "{4A7E75E5-B345-4BF8-BFCC-788ADC1FA218}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneShelf.OneDragon.Processor", "OneShelf.OneDragon\OneShelf.OneDragon.Processor\OneShelf.OneDragon.Processor.csproj", "{DF960A56-A097-4220-A8FE-B9714680F87D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneShelf.OneDragon.Processor", "OneShelf.OneDragon\OneShelf.OneDragon.Processor\OneShelf.OneDragon.Processor.csproj", "{DF960A56-A097-4220-A8FE-B9714680F87D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneShelf.OneDragon.Database", "OneShelf.OneDragon\OneShelf.OneDragon.Database\OneShelf.OneDragon.Database.csproj", "{8DB5C0DC-C738-4CC4-A281-392A65ED4743}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneShelf.OneDragon.Database", "OneShelf.OneDragon\OneShelf.OneDragon.Database\OneShelf.OneDragon.Database.csproj", "{8DB5C0DC-C738-4CC4-A281-392A65ED4743}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneShelf.Telegram.Polling", "OneShelf.Telegram\OneShelf.Telegram.Polling\OneShelf.Telegram.Polling.csproj", "{76C5E207-6028-4083-84C5-DAC7839D1F85}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneShelf.Telegram.Polling", "OneShelf.Telegram\OneShelf.Telegram.Polling\OneShelf.Telegram.Polling.csproj", "{76C5E207-6028-4083-84C5-DAC7839D1F85}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OneShelf.TelegramLibrary", "OneShelf.TelegramLibrary", "{FE163498-92F2-4216-B757-BFA3C3C6C0D8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneShelf.Telegram.Ai", "OneShelf.Telegram\OneShelf.Telegram.Ai\OneShelf.Telegram.Ai.csproj", "{DAFCA5B8-2C80-4519-8E4A-3E5958E2A37E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneShelf.Telegram.Ai", "OneShelf.Telegram\OneShelf.Telegram.Ai\OneShelf.Telegram.Ai.csproj", "{DAFCA5B8-2C80-4519-8E4A-3E5958E2A37E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneShelf.Telegram.Ai.Model", "OneShelf.Telegram\OneShelf.Telegram.Ai.Model\OneShelf.Telegram.Ai.Model.csproj", "{DC7B80CC-E597-4E67-9FFB-33DB252EC321}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneShelf.Telegram.Ai.Model", "OneShelf.Telegram\OneShelf.Telegram.Ai.Model\OneShelf.Telegram.Ai.Model.csproj", "{DC7B80CC-E597-4E67-9FFB-33DB252EC321}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OneShelf.Videos", "OneShelf.Videos", "{5F839A7C-B540-4475-9FFE-9E5E4FC10D78}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneShelf.Videos.App", "OneShelf.Videos\OneShelf.Videos.App\OneShelf.Videos.App.csproj", "{99134E7C-CE2F-4641-A9E3-B961F76307F0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneShelf.Videos.App", "OneShelf.Videos\OneShelf.Videos.App\OneShelf.Videos.App.csproj", "{99134E7C-CE2F-4641-A9E3-B961F76307F0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneShelf.Videos.Database", "OneShelf.Videos\OneShelf.Videos.Database\OneShelf.Videos.Database.csproj", "{D702C117-2C9A-44E0-B428-30371616FBAE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -515,6 +517,10 @@ Global
{99134E7C-CE2F-4641-A9E3-B961F76307F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{99134E7C-CE2F-4641-A9E3-B961F76307F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{99134E7C-CE2F-4641-A9E3-B961F76307F0}.Release|Any CPU.Build.0 = Release|Any CPU
{D702C117-2C9A-44E0-B428-30371616FBAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D702C117-2C9A-44E0-B428-30371616FBAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D702C117-2C9A-44E0-B428-30371616FBAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D702C117-2C9A-44E0-B428-30371616FBAE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -596,6 +602,7 @@ Global
{DAFCA5B8-2C80-4519-8E4A-3E5958E2A37E} = {95E2976B-C1F3-47B9-98F5-741E9D21CC68}
{DC7B80CC-E597-4E67-9FFB-33DB252EC321} = {95E2976B-C1F3-47B9-98F5-741E9D21CC68}
{99134E7C-CE2F-4641-A9E3-B961F76307F0} = {5F839A7C-B540-4475-9FFE-9E5E4FC10D78}
{D702C117-2C9A-44E0-B428-30371616FBAE} = {5F839A7C-B540-4475-9FFE-9E5E4FC10D78}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {59093261-FDDA-411A-852D-EA21AEF83E07}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@
<PackageReference Include="CasCap.Apis.GooglePhotos" Version="3.0.1" />
<PackageReference Include="CsvHelper" Version="33.0.1" />
<PackageReference Include="ExifLibNet" Version="2.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\OneShelf.Common\OneShelf.Common\OneShelf.Common.csproj" />
<ProjectReference Include="..\OneShelf.Videos.Database\OneShelf.Videos.Database.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
7 changes: 4 additions & 3 deletions OneShelf.Videos/OneShelf.Videos.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using OneShelf.Videos.App.Database;
using OneShelf.Videos.App.Models;
using OneShelf.Videos.App.Services;
using OneShelf.Videos.App.UpdatedGooglePhotosService;
using OneShelf.Videos.Database;

var builder = Host.CreateApplicationBuilder();
builder.Configuration.AddJsonFile("appsettings.Secrets.json");
Expand All @@ -14,7 +14,8 @@
.AddScoped<Service1>()
.AddScoped<Service2>()
.AddScoped<Service3>()
.AddDbContext<VideosDatabase>(o => o.UseSqlServer(builder.Configuration.GetConnectionString(nameof(VideosDatabase))))
.AddScoped<VideosDatabaseOperations>()
.AddVideosDatabase(builder.Configuration)
.AddMyGooglePhotos();
var host = builder.Build();

Expand Down Expand Up @@ -46,4 +47,4 @@

//await service2.UploadPhotos((await service1.GetExport1()).OrderBy(_ => Random.Shared.NextDouble()).ToList());
//await service2.UploadVideos((await service1.GetExport2()).OrderBy(_ => Random.Shared.NextDouble()).ToList());
//await service2.CreateAlbums(await service1.GetAlbums());
await service2.CreateAlbums(await service1.GetAlbums());
7 changes: 3 additions & 4 deletions OneShelf.Videos/OneShelf.Videos.App/Services/Service1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using OneShelf.Common;
using OneShelf.Videos.App.Database;
using OneShelf.Videos.App.Database.Models;
using OneShelf.Videos.App.Database.Models.Enums;
using OneShelf.Videos.App.Database.Models.Json;
using OneShelf.Videos.App.Models;
using OneShelf.Videos.Database;
using OneShelf.Videos.Database.Models.Enums;
using OneShelf.Videos.Database.Models.Json;

namespace OneShelf.Videos.App.Services;

Expand Down
10 changes: 6 additions & 4 deletions OneShelf.Videos/OneShelf.Videos.App/Services/Service2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using OneShelf.Common;
using OneShelf.Videos.App.Database;
using OneShelf.Videos.App.Database.Models;
using OneShelf.Videos.Database;
using OneShelf.Videos.Database.Models;

namespace OneShelf.Videos.App.Services;

Expand All @@ -12,14 +12,16 @@ public class Service2
private readonly UpdatedGooglePhotosService.UpdatedGooglePhotosService _googlePhotosService;
private readonly ILogger<Service2> _logger;
private readonly VideosDatabase _videosDatabase;
private readonly VideosDatabaseOperations _videosDatabaseOperations;
private readonly Service3 _service3;

public Service2(UpdatedGooglePhotosService.UpdatedGooglePhotosService googlePhotosService, ILogger<Service2> logger, VideosDatabase videosDatabase, Service3 service3)
public Service2(UpdatedGooglePhotosService.UpdatedGooglePhotosService googlePhotosService, ILogger<Service2> logger, VideosDatabase videosDatabase, Service3 service3, VideosDatabaseOperations videosDatabaseOperations)
{
_googlePhotosService = googlePhotosService;
_logger = logger;
_videosDatabase = videosDatabase;
_service3 = service3;
_videosDatabaseOperations = videosDatabaseOperations;
}

public async Task SaveInventory()
Expand Down Expand Up @@ -121,7 +123,7 @@ private async Task AddToDatabase(
Dictionary<(long chatId, int messageId), NewMediaItemResult> newItems,
Dictionary<(long chatId, int messageId), DateTime>? fileNameTimestamps = null)
{
_videosDatabase.AddItems(newItems.Select(i => items[i.Key].SelectSingle(x => (x.chatId, x.messageId, x.path, x.publishedOn, result: i.Value, fileNameTimestamp: fileNameTimestamps?[i.Key]))));
_videosDatabaseOperations.AddItems(newItems.Select(i => items[i.Key].SelectSingle(x => (x.chatId, x.messageId, x.path, x.publishedOn, result: i.Value, fileNameTimestamp: fileNameTimestamps?[i.Key]))));
await _videosDatabase.SaveChangesAsync();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Text.Json;
using CasCap.Models;
using OneShelf.Videos.Database;
using OneShelf.Videos.Database.Models;

namespace OneShelf.Videos.App.Services;

public class VideosDatabaseOperations(VideosDatabase videosDatabase)
{
public void AddItems(IEnumerable<(long chatId, int messageId, string path, DateTime publishedOn, NewMediaItemResult result, DateTime? fileNameTimestamp)> items)
{
videosDatabase.UploadedItems.AddRange(items.Select(i => new UploadedItem
{
CreatedOn = DateTime.Now,
ChatId = i.chatId,
MessageId = i.messageId,
TelegramPublishedOn = i.publishedOn,
Status = i.result.status.status,
StatusCode = i.result.status.code,
StatusMessage = i.result.status.message,
MediaItemId = i.result.mediaItem?.id,
MediaItemIsPhoto = i.result.mediaItem?.isPhoto,
MediaItemIsVideo = i.result.mediaItem?.isVideo,
MediaItemMimeType = i.result.mediaItem?.mimeType,
MediaItemSyncDate = i.result.mediaItem?.syncDate,
MediaItemMetadataCreationTime = i.result.mediaItem?.mediaMetadata?.creationTime,
Json = JsonSerializer.Serialize(i.result.mediaItem),
FileNameTimestamp = i.fileNameTimestamp,
}));
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#nullable disable

namespace OneShelf.Videos.App.Migrations.VideosDatabaseMigrations
namespace OneShelf.Videos.Database.Migrations.VideosDatabaseMigrations
{
/// <inheritdoc />
public partial class Initial : Migration
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#nullable disable

namespace OneShelf.Videos.App.Migrations.VideosDatabaseMigrations
namespace OneShelf.Videos.Database.Migrations.VideosDatabaseMigrations
{
/// <inheritdoc />
public partial class ChatFoldersAdded : Migration
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#nullable disable

namespace OneShelf.Videos.App.Migrations.VideosDatabaseMigrations
namespace OneShelf.Videos.Database.Migrations.VideosDatabaseMigrations
{
/// <inheritdoc />
public partial class ChatsAdded : Migration
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#nullable disable

namespace OneShelf.Videos.App.Migrations.VideosDatabaseMigrations
namespace OneShelf.Videos.Database.Migrations.VideosDatabaseMigrations
{
/// <inheritdoc />
public partial class MessagesAdded : Migration
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#nullable disable

namespace OneShelf.Videos.App.Migrations.VideosDatabaseMigrations
namespace OneShelf.Videos.Database.Migrations.VideosDatabaseMigrations
{
/// <inheritdoc />
public partial class JsonConversion3 : Migration
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#nullable disable

namespace OneShelf.Videos.App.Migrations.VideosDatabaseMigrations
namespace OneShelf.Videos.Database.Migrations.VideosDatabaseMigrations
{
/// <inheritdoc />
public partial class MessagesIndexAdded : Migration
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#nullable disable

namespace OneShelf.Videos.App.Migrations.VideosDatabaseMigrations
namespace OneShelf.Videos.Database.Migrations.VideosDatabaseMigrations
{
/// <inheritdoc />
public partial class InventoryItems : Migration
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#nullable disable

namespace OneShelf.Videos.App.Migrations.VideosDatabaseMigrations
namespace OneShelf.Videos.Database.Migrations.VideosDatabaseMigrations
{
/// <inheritdoc />
public partial class InventoryItemsNullableColumns : Migration
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#nullable disable

namespace OneShelf.Videos.App.Migrations.VideosDatabaseMigrations
namespace OneShelf.Videos.Database.Migrations.VideosDatabaseMigrations
{
/// <inheritdoc />
public partial class Sources : Migration
Expand Down
Loading

0 comments on commit 795bc92

Please sign in to comment.