Skip to content
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

Align with 1.0.11.0 image DB #3

Merged
merged 3 commits into from
Feb 19, 2025
Merged
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using StreamMaster.Application.SMChannels.Commands;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;

namespace StreamMaster.Application.M3UFiles.Commands;

Expand Down Expand Up @@ -37,7 +39,9 @@ public async Task<APIResponse> Handle(SyncChannelsRequest request, CancellationT
}

IQueryable<SMStream> streams = Repository.SMStream.GetQuery().Where(a => a.M3UFileId == request.M3UFileId);
IQueryable<SMChannel> existingSMChannels = Repository.SMChannel.GetQuery().Where(a => a.M3UFileId == request.M3UFileId);
List<string> ids = await streams.Select(a => a.Id).ToListAsync(cancellationToken);

IQueryable<SMChannel> existingSMChannels = Repository.SMChannel.GetQuery().Where(a => ids.Contains(a.BaseStreamID));

// Get the stream IDs as strings
List<string> streamIds = await streams.Select(s => s.Id).ToListAsync(cancellationToken).ConfigureAwait(false);
Expand All @@ -64,7 +68,10 @@ public async Task<APIResponse> Handle(SyncChannelsRequest request, CancellationT

if (streamsToBeDeleted.Count != 0)
{
List<int> smChannelIds = await Repository.SMChannel.GetQuery().Where(a => a.M3UFileId == request.M3UFileId && a.BaseStreamID != null && streamsToBeDeleted.Contains(a.BaseStreamID)).Select(a => a.Id).ToListAsync(cancellationToken: cancellationToken);
List<int> smChannelIds = await Repository.SMChannel.GetQuery()
.Where(channel => channel.BaseStreamID != default && streamsToBeDeleted.Contains(channel.BaseStreamID))
.Select(channel => channel.Id)
.ToListAsync(cancellationToken: cancellationToken);

_ = await sender.Send(new DeleteSMChannelsRequest(smChannelIds), cancellationToken).ConfigureAwait(false);
}
Expand All @@ -85,4 +92,4 @@ public async Task<APIResponse> Handle(SyncChannelsRequest request, CancellationT
return APIResponse.NotFound;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using StreamMaster.Application.Services;
using System.Linq.Expressions;

namespace StreamMaster.Application.StreamGroupSMChannelLinks.Commands;

Expand All @@ -24,7 +25,8 @@ public async Task<APIResponse> Handle(MoveSMChannelsToStreamGroupByM3UFileIdRequ
return APIResponse.ErrorWithMessage("SG not found");
}

List<int> channelsIds = await Repository.SMChannel.GetQuery().Where(a => a.M3UFileId == request.M3UFile.Id).Select(a => a.Id).ToListAsync(cancellationToken: cancellationToken);
List<string> streamIds = await Repository.SMStream.GetQuery().Where(stream => stream.M3UFileId == request.M3UFile.Id).Select(stream => stream.Id).ToListAsync(cancellationToken);
List<int> channelsIds = await Repository.SMChannel.GetQuery().Where(channel => streamIds.Contains(channel.BaseStreamID)).Select(channel => channel.Id).ToListAsync(cancellationToken: cancellationToken);
if (channelsIds.Count == 0)
{
return APIResponse.Success;
Expand All @@ -43,4 +45,4 @@ public async Task<APIResponse> Handle(MoveSMChannelsToStreamGroupByM3UFileIdRequ
await taskQueue.CreateSTRMFiles(cancellationToken);
return APIResponse.Success;
}
}
}
25 changes: 0 additions & 25 deletions src/StreamMaster.Domain/Models/ISMChannel.cs

This file was deleted.

9 changes: 2 additions & 7 deletions src/StreamMaster.Domain/Models/SMChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace StreamMaster.Domain.Models
/// <summary>
/// Represents a channel in the system.
/// </summary>
public class SMChannel : ISMChannel
public class SMChannel
{
/// <summary>
/// Gets or sets the unique identifier for the SMChannel.
Expand Down Expand Up @@ -44,11 +44,6 @@ public class SMChannel : ISMChannel
/// </summary>
public string BaseStreamID { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the ID of the M3U file associated with this channel.
/// </summary>
public int M3UFileId { get; set; }

/// <summary>
/// Gets or sets the channel number.
/// </summary>
Expand Down Expand Up @@ -132,4 +127,4 @@ public class SMChannel : ISMChannel
[Ignore, JsonIgnore, IgnoreMember, IgnoreMap, XmlIgnore, TsIgnore]
public ICollection<StreamGroupSMChannelLink> StreamGroups { get; set; } = [];
}
}
}
12 changes: 8 additions & 4 deletions src/StreamMaster.Domain/Models/SMChannelStreamLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

public class SMChannelStreamLink
{
public required int SMChannelId { get; set; }
public required SMChannel SMChannel { get; set; }
public required string SMStreamId { get; set; }
public int SMChannelId { get; set; }

public virtual int SMStreamM3UFileId { get; set; }

public SMChannel SMChannel { get; set; }

public string SMStreamId { get; set; }

#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
public SMStream SMStream { get; set; }
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.

public required int Rank { get; set; }
public int Rank { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace StreamMaster.Infrastructure.EF.Base.Configurations
{
public class SMChannelStreamLinkConfiguration : IEntityTypeConfiguration<SMChannelStreamLink>
{
public void Configure(EntityTypeBuilder<SMChannelStreamLink> entity)
{
entity.HasKey(channelStreamLink => new
{
channelStreamLink.SMChannelId,
channelStreamLink.SMStreamId,
channelStreamLink.SMStreamM3UFileId
});

entity.HasOne(vsl => vsl.SMChannel)
.WithMany(vs => vs.SMStreams)
.HasForeignKey(vsl => vsl.SMChannelId)
.OnDelete(DeleteBehavior.Cascade);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace StreamMaster.Infrastructure.EF.Base.Configurations
{
public class SMStreamConfiguration : IEntityTypeConfiguration<SMStream>
{
public void Configure(EntityTypeBuilder<SMStream> modelBuilder)
{
modelBuilder.HasKey(stream => stream.Id);
}
}
}

This file was deleted.

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

namespace StreamMaster.Infrastructure.EF.PGSQL.Migrations.Repository
{
/// <inheritdoc />
public partial class AddUserGroups_M3UGroups_APIKeys_Devices_to_PGSQLRepositoryContext_to_PGSQLRepositoryContext : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "APIKeys",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Key = table.Column<string>(type: "text", nullable: false),
UserId = table.Column<string>(type: "text", nullable: false),
DeviceName = table.Column<string>(type: "text", nullable: false),
Scopes = table.Column<List<string>>(type: "text[]", nullable: false),
Expiration = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
LastUsedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
IsActive = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_APIKeys", x => x.Id);
});
// Create APIKeys table if it doesn't exist
migrationBuilder.Sql(@"
DO $$
BEGIN
IF NOT EXISTS (
SELECT FROM information_schema.tables
WHERE table_name = 'APIKeys'
) THEN
CREATE TABLE ""APIKeys"" (
""Id"" uuid NOT NULL,
""Key"" text NOT NULL,
""UserId"" text NOT NULL,
""DeviceName"" text NOT NULL,
""Scopes"" text[] NOT NULL,
""Expiration"" timestamp with time zone,
""CreatedAt"" timestamp with time zone NOT NULL,
""LastUsedAt"" timestamp with time zone,
""IsActive"" boolean NOT NULL,
CONSTRAINT ""PK_APIKeys"" PRIMARY KEY (""Id"")
);
END IF;
END $$;
");

migrationBuilder.CreateTable(
name: "Devices",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
ApiKeyId = table.Column<string>(type: "text", nullable: false),
UserId = table.Column<string>(type: "text", nullable: false),
DeviceType = table.Column<string>(type: "text", nullable: false),
DeviceId = table.Column<string>(type: "text", nullable: false),
UserAgent = table.Column<string>(type: "text", nullable: false),
IPAddress = table.Column<string>(type: "text", nullable: false),
LastActivity = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Devices", x => x.Id);
});
// Create Devices table if it doesn't exist
migrationBuilder.Sql(@"
DO $$
BEGIN
IF NOT EXISTS (
SELECT FROM information_schema.tables
WHERE table_name = 'Devices'
) THEN
CREATE TABLE ""Devices"" (
""Id"" uuid NOT NULL,
""ApiKeyId"" text NOT NULL,
""UserId"" text NOT NULL,
""DeviceType"" text NOT NULL,
""DeviceId"" text NOT NULL,
""UserAgent"" text NOT NULL,
""IPAddress"" text NOT NULL,
""LastActivity"" timestamp with time zone NOT NULL,
CONSTRAINT ""PK_Devices"" PRIMARY KEY (""Id"")
);
END IF;
END $$;
");

migrationBuilder.CreateTable(
name: "M3UGroups",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityAlwaysColumn),
Name = table.Column<string>(type: "citext", nullable: false),
IsIncluded = table.Column<bool>(type: "boolean", nullable: false),
TotalCount = table.Column<int>(type: "integer", nullable: false),
IsUser = table.Column<bool>(type: "boolean", nullable: false),
IsPPV = table.Column<bool>(type: "boolean", nullable: false),
IsVOD = table.Column<bool>(type: "boolean", nullable: false),
M3UFileId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_M3UGroups", x => x.Id);
});
// Create M3UGroups table if it doesn't exist
migrationBuilder.Sql(@"
DO $$
BEGIN
IF NOT EXISTS (
SELECT FROM information_schema.tables
WHERE table_name = 'M3UGroups'
) THEN
CREATE TABLE ""M3UGroups"" (
""Id"" integer NOT NULL GENERATED ALWAYS AS IDENTITY,
""Name"" citext NOT NULL,
""IsIncluded"" boolean NOT NULL,
""TotalCount"" integer NOT NULL,
""IsUser"" boolean NOT NULL,
""IsPPV"" boolean NOT NULL,
""IsVOD"" boolean NOT NULL,
""M3UFileId"" integer NOT NULL,
CONSTRAINT ""PK_M3UGroups"" PRIMARY KEY (""Id"")
);
END IF;
END $$;
");

migrationBuilder.CreateTable(
name: "UserGroups",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityAlwaysColumn),
TotalCount = table.Column<int>(type: "integer", nullable: false),
Name = table.Column<string>(type: "citext", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UserGroups", x => x.Id);
});
// Create UserGroups table if it doesn't exist
migrationBuilder.Sql(@"
DO $$
BEGIN
IF NOT EXISTS (
SELECT FROM information_schema.tables
WHERE table_name = 'UserGroups'
) THEN
CREATE TABLE ""UserGroups"" (
""Id"" integer NOT NULL GENERATED ALWAYS AS IDENTITY,
""TotalCount"" integer NOT NULL,
""Name"" citext NOT NULL,
CONSTRAINT ""PK_UserGroups"" PRIMARY KEY (""Id"")
);
END IF;
END $$;
");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
Expand All @@ -100,4 +115,4 @@ protected override void Down(MigrationBuilder migrationBuilder)
name: "UserGroups");
}
}
}
}
Loading
Loading