Merge pull request #2 from StewKI/feature-whiteboard
Feature whiteboard
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
using System.Windows.Input;
|
||||||
|
using AipsCore.Application.Abstract.Command;
|
||||||
|
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||||
|
|
||||||
|
namespace AipsCore.Application.Models.Whiteboard.Command.CreateWhiteboard;
|
||||||
|
|
||||||
|
public record CreateWhiteboardCommand(string OwnerId, string Title) : ICommand<WhiteboardId>;
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
using AipsCore.Application.Abstract.Command;
|
||||||
|
using AipsCore.Domain.Abstract;
|
||||||
|
using AipsCore.Domain.Models.Whiteboard.External;
|
||||||
|
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||||
|
|
||||||
|
namespace AipsCore.Application.Models.Whiteboard.Command.CreateWhiteboard;
|
||||||
|
|
||||||
|
public class CreateWhiteboardCommandHandler : ICommandHandler<CreateWhiteboardCommand, WhiteboardId>
|
||||||
|
{
|
||||||
|
private readonly IWhiteboardRepository _whiteboardRepository;
|
||||||
|
private readonly IUnitOfWork _unitOfWork;
|
||||||
|
|
||||||
|
public CreateWhiteboardCommandHandler(IWhiteboardRepository whiteboardRepository, IUnitOfWork unitOfWork)
|
||||||
|
{
|
||||||
|
_whiteboardRepository = whiteboardRepository;
|
||||||
|
_unitOfWork = unitOfWork;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<WhiteboardId> Handle(CreateWhiteboardCommand command, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
WhiteboardCode whiteboardCode;
|
||||||
|
bool codeExists;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
whiteboardCode = GenerateUniqueWhiteboardCode();
|
||||||
|
|
||||||
|
codeExists = await _whiteboardRepository.WhiteboardCodeExists(whiteboardCode);
|
||||||
|
} while (codeExists);
|
||||||
|
|
||||||
|
var whiteboard = Domain.Models.Whiteboard.Whiteboard.Create(command.OwnerId, whiteboardCode.CodeValue, command.Title);
|
||||||
|
|
||||||
|
await _whiteboardRepository.Save(whiteboard, cancellationToken);
|
||||||
|
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
|
return whiteboard.Id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TRENUTNO SAMO, CE SE NAPRAVI KO SERVIS IL KAKO VEC KASNIJE
|
||||||
|
private static WhiteboardCode GenerateUniqueWhiteboardCode()
|
||||||
|
{
|
||||||
|
var rng = new Random();
|
||||||
|
char[] result = new char[8];
|
||||||
|
|
||||||
|
for (int i = 0; i < result.Length; i++)
|
||||||
|
{
|
||||||
|
result[i] = (char)('0' + rng.Next(0, 10));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new WhiteboardCode(new string(result));
|
||||||
|
}
|
||||||
|
}
|
||||||
11
dotnet/AipsCore/Domain/Models/Whiteboard/External/IWhiteboardRepository.cs
vendored
Normal file
11
dotnet/AipsCore/Domain/Models/Whiteboard/External/IWhiteboardRepository.cs
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||||
|
|
||||||
|
namespace AipsCore.Domain.Models.Whiteboard.External;
|
||||||
|
|
||||||
|
public interface IWhiteboardRepository
|
||||||
|
{
|
||||||
|
Task<Whiteboard?> Get(WhiteboardId whiteboardId, CancellationToken cancellationToken = default);
|
||||||
|
Task Save(Whiteboard whiteboard, CancellationToken cancellationToken = default);
|
||||||
|
Task<bool> WhiteboardCodeExists(WhiteboardCode whiteboardCode);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,9 +3,9 @@ using AipsCore.Utility.Text;
|
|||||||
|
|
||||||
namespace AipsCore.Domain.Models.Whiteboard.Validation;
|
namespace AipsCore.Domain.Models.Whiteboard.Validation;
|
||||||
|
|
||||||
public class WhitebordCodeCharsetRule : CharsetRule
|
public class WhiteboardCodeCharsetRule : CharsetRule
|
||||||
{
|
{
|
||||||
public WhitebordCodeCharsetRule(string stringValue)
|
public WhiteboardCodeCharsetRule(string stringValue)
|
||||||
: base(stringValue, GetWhiteboardCodeCharset())
|
: base(stringValue, GetWhiteboardCodeCharset())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using AipsCore.Domain.Common.Validation.Rules;
|
||||||
|
using AipsCore.Utility.Text;
|
||||||
|
|
||||||
|
namespace AipsCore.Domain.Models.Whiteboard.Validation;
|
||||||
|
|
||||||
|
public class WhiteboardTitleCharsetRule : CharsetRule
|
||||||
|
{
|
||||||
|
public WhiteboardTitleCharsetRule(string stringValue)
|
||||||
|
: base(stringValue, GetWhiteboardTitleCharset())
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static char[] GetWhiteboardTitleCharset()
|
||||||
|
{
|
||||||
|
var alphanumericCharset = Charset.GetAlphanumericCharset();
|
||||||
|
return [..alphanumericCharset, '_', ' ', '/'];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string ErrorCode => "whiteboard_title_charset";
|
||||||
|
|
||||||
|
protected override string ErrorMessage =>
|
||||||
|
"Whiteboard title contains invalid characters, only alphanumeric characters, '_', ' ', '/' are allowed";
|
||||||
|
}
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
using AipsCore.Domain.Abstract;
|
using AipsCore.Domain.Abstract.Rule;
|
||||||
using AipsCore.Domain.Abstract.Rule;
|
|
||||||
using AipsCore.Domain.Abstract.ValueObject;
|
using AipsCore.Domain.Abstract.ValueObject;
|
||||||
using AipsCore.Domain.Common.Validation;
|
|
||||||
using AipsCore.Domain.Common.Validation.Rules;
|
using AipsCore.Domain.Common.Validation.Rules;
|
||||||
using AipsCore.Domain.Common.ValueObjects;
|
|
||||||
using AipsCore.Domain.Models.Whiteboard.Validation;
|
using AipsCore.Domain.Models.Whiteboard.Validation;
|
||||||
|
|
||||||
namespace AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
namespace AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||||
@@ -25,7 +22,7 @@ public record WhiteboardCode : AbstractValueObject
|
|||||||
return
|
return
|
||||||
[
|
[
|
||||||
new ExactLength(CodeValue, CodeLength),
|
new ExactLength(CodeValue, CodeLength),
|
||||||
new WhitebordCodeCharsetRule(CodeValue)
|
new WhiteboardCodeCharsetRule(CodeValue)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,4 +2,7 @@
|
|||||||
|
|
||||||
namespace AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
namespace AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||||
|
|
||||||
public record WhiteboardId(string IdValue) : DomainId(IdValue);
|
public record WhiteboardId(string IdValue) : DomainId(IdValue)
|
||||||
|
{
|
||||||
|
public static WhiteboardId Any() => new(Guid.NewGuid().ToString());
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using AipsCore.Domain.Abstract.Rule;
|
||||||
|
using AipsCore.Domain.Abstract.ValueObject;
|
||||||
|
using AipsCore.Domain.Common.Validation.Rules;
|
||||||
|
using AipsCore.Domain.Models.Whiteboard.Validation;
|
||||||
|
|
||||||
|
namespace AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||||
|
|
||||||
|
public record WhiteboardTitle : AbstractValueObject
|
||||||
|
{
|
||||||
|
private const int MaxWhiteboardTitleLength = 32;
|
||||||
|
private const int MinWhiteboardTitleLength = 3;
|
||||||
|
|
||||||
|
public string TitleValue { get; init; }
|
||||||
|
|
||||||
|
public WhiteboardTitle(string TitleValue)
|
||||||
|
{
|
||||||
|
this.TitleValue = TitleValue;
|
||||||
|
Validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override ICollection<IRule> GetValidationRules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
new MaxLengthRule(TitleValue, MaxWhiteboardTitleLength),
|
||||||
|
new MinLengthRule(TitleValue, MinWhiteboardTitleLength),
|
||||||
|
new WhiteboardTitleCharsetRule(TitleValue)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,11 +8,41 @@ public class Whiteboard
|
|||||||
public WhiteboardId Id { get; private set; }
|
public WhiteboardId Id { get; private set; }
|
||||||
public UserId WhiteboardOwnerId { get; private set; }
|
public UserId WhiteboardOwnerId { get; private set; }
|
||||||
public WhiteboardCode Code { get; private set; }
|
public WhiteboardCode Code { get; private set; }
|
||||||
|
public WhiteboardTitle Title { get; private set; }
|
||||||
|
|
||||||
public Whiteboard(WhiteboardId id, User.User whiteboardOwner, WhiteboardCode code)
|
public Whiteboard(WhiteboardId id, User.User whiteboardOwner, WhiteboardCode code, WhiteboardTitle title)
|
||||||
{
|
{
|
||||||
Id = id;
|
Id = id;
|
||||||
WhiteboardOwnerId = whiteboardOwner.Id;
|
WhiteboardOwnerId = whiteboardOwner.Id;
|
||||||
Code = code;
|
Code = code;
|
||||||
|
Title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Whiteboard(WhiteboardId id, UserId whiteboardOwnerId, WhiteboardCode code, WhiteboardTitle title)
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
WhiteboardOwnerId = whiteboardOwnerId;
|
||||||
|
Code = code;
|
||||||
|
Title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Whiteboard Create(string id, string ownerId, string code, string title)
|
||||||
|
{
|
||||||
|
var whiteboardId = new WhiteboardId(id);
|
||||||
|
var whiteboardOwnerId = new UserId(ownerId);
|
||||||
|
var whiteboardCode = new WhiteboardCode(code);
|
||||||
|
var whiteboardTitle = new WhiteboardTitle(title);
|
||||||
|
|
||||||
|
return new Whiteboard(whiteboardId, whiteboardOwnerId, whiteboardCode, whiteboardTitle);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Whiteboard Create(string ownerId, string code, string title)
|
||||||
|
{
|
||||||
|
var whiteboardId = WhiteboardId.Any();
|
||||||
|
var whiteboardOwnerId = new UserId(ownerId);
|
||||||
|
var whiteboardCode = new WhiteboardCode(code);
|
||||||
|
var whiteboardTitle = new WhiteboardTitle(title);
|
||||||
|
|
||||||
|
return new Whiteboard(whiteboardId, whiteboardOwnerId, whiteboardCode, whiteboardTitle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
using AipsCore.Domain.Abstract;
|
using AipsCore.Domain.Abstract;
|
||||||
using AipsCore.Domain.Models.User.External;
|
using AipsCore.Domain.Models.User.External;
|
||||||
|
using AipsCore.Domain.Models.Whiteboard.External;
|
||||||
using AipsCore.Infrastructure.DI.Configuration;
|
using AipsCore.Infrastructure.DI.Configuration;
|
||||||
using AipsCore.Infrastructure.Persistence.Db;
|
using AipsCore.Infrastructure.Persistence.Db;
|
||||||
using AipsCore.Infrastructure.Persistence.User;
|
using AipsCore.Infrastructure.Persistence.User;
|
||||||
|
using AipsCore.Infrastructure.Persistence.Whiteboard;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
@@ -23,6 +25,7 @@ public static class PersistenceRegistrationExtensions
|
|||||||
|
|
||||||
services.AddTransient<IUnitOfWork, EfUnitOfWork>();
|
services.AddTransient<IUnitOfWork, EfUnitOfWork>();
|
||||||
services.AddTransient<IUserRepository, UserRepository>();
|
services.AddTransient<IUserRepository, UserRepository>();
|
||||||
|
services.AddTransient<IWhiteboardRepository, WhiteboardRepository>();
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ namespace AipsCore.Infrastructure.Persistence.Db;
|
|||||||
public class AipsDbContext : DbContext
|
public class AipsDbContext : DbContext
|
||||||
{
|
{
|
||||||
public DbSet<User.User> Users { get; set; }
|
public DbSet<User.User> Users { get; set; }
|
||||||
|
public DbSet<Whiteboard.Whiteboard> Whiteboards { get; set; }
|
||||||
|
|
||||||
public AipsDbContext(DbContextOptions options)
|
public AipsDbContext(DbContextOptions<AipsDbContext> options)
|
||||||
: base(options)
|
: base(options)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using AipsCore.Infrastructure.Persistence.Db;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace AipsCore.Infrastructure.Persistence.Db.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(AipsDbContext))]
|
||||||
|
[Migration("20260208220239_AddedBasicWhiteboard")]
|
||||||
|
partial class AddedBasicWhiteboard
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "10.0.2")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("AipsCore.Infrastructure.Persistence.User.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("character varying(255)");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("character varying(255)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("AipsCore.Infrastructure.Persistence.Whiteboard.Whiteboard", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("Code")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(8)
|
||||||
|
.HasColumnType("character varying(8)");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(32)
|
||||||
|
.HasColumnType("character varying(32)");
|
||||||
|
|
||||||
|
b.Property<Guid>("WhiteboardOwnerId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Whiteboards");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace AipsCore.Infrastructure.Persistence.Db.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddedBasicWhiteboard : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Whiteboards",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
WhiteboardOwnerId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
Code = table.Column<string>(type: "character varying(8)", maxLength: 8, nullable: false),
|
||||||
|
Title = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Whiteboards", x => x.Id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Whiteboards");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,6 +42,30 @@ namespace AipsCore.Infrastructure.Persistence.Db.Migrations
|
|||||||
|
|
||||||
b.ToTable("Users");
|
b.ToTable("Users");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("AipsCore.Infrastructure.Persistence.Whiteboard.Whiteboard", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("Code")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(8)
|
||||||
|
.HasColumnType("character varying(8)");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(32)
|
||||||
|
.HasColumnType("character varying(32)");
|
||||||
|
|
||||||
|
b.Property<Guid>("WhiteboardOwnerId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Whiteboards");
|
||||||
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace AipsCore.Infrastructure.Persistence.Whiteboard;
|
||||||
|
|
||||||
|
public class Whiteboard
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public Guid WhiteboardOwnerId { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[MaxLength(8)]
|
||||||
|
[MinLength(8)]
|
||||||
|
public string Code { get; set; } = null!;
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[MaxLength(32)]
|
||||||
|
[MinLength(3)]
|
||||||
|
public string Title { get; set; } = null!;
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
using AipsCore.Domain.Models.Whiteboard.External;
|
||||||
|
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||||
|
using AipsCore.Infrastructure.Persistence.Db;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace AipsCore.Infrastructure.Persistence.Whiteboard;
|
||||||
|
|
||||||
|
public class WhiteboardRepository : IWhiteboardRepository
|
||||||
|
{
|
||||||
|
private readonly AipsDbContext _context;
|
||||||
|
|
||||||
|
public WhiteboardRepository(AipsDbContext context)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Domain.Models.Whiteboard.Whiteboard?> Get(WhiteboardId whiteboardId, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var whiteboardEntity = await _context.Whiteboards.FindAsync([new Guid(whiteboardId.IdValue), cancellationToken], cancellationToken: cancellationToken);
|
||||||
|
|
||||||
|
if (whiteboardEntity is null) return null;
|
||||||
|
|
||||||
|
return Domain.Models.Whiteboard.Whiteboard.Create(
|
||||||
|
whiteboardEntity.Id.ToString(),
|
||||||
|
whiteboardEntity.WhiteboardOwnerId.ToString(),
|
||||||
|
whiteboardEntity.Code,
|
||||||
|
whiteboardEntity.Title);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task Save(Domain.Models.Whiteboard.Whiteboard whiteboard, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var whiteboardEntity = await _context.Whiteboards.FindAsync(new Guid(whiteboard.Id.IdValue));
|
||||||
|
|
||||||
|
if (whiteboardEntity is not null)
|
||||||
|
{
|
||||||
|
whiteboardEntity.WhiteboardOwnerId = new Guid(whiteboard.WhiteboardOwnerId.IdValue);
|
||||||
|
whiteboardEntity.Code = whiteboard.Code.CodeValue;
|
||||||
|
whiteboardEntity.Title = whiteboard.Title.TitleValue;
|
||||||
|
|
||||||
|
_context.Whiteboards.Update(whiteboardEntity);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
whiteboardEntity = new Whiteboard()
|
||||||
|
{
|
||||||
|
Id = new Guid(whiteboard.Id.IdValue),
|
||||||
|
WhiteboardOwnerId = new Guid(whiteboard.WhiteboardOwnerId.IdValue),
|
||||||
|
Code = whiteboard.Code.CodeValue,
|
||||||
|
Title = whiteboard.Title.TitleValue,
|
||||||
|
};
|
||||||
|
|
||||||
|
_context.Whiteboards.Add(whiteboardEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> WhiteboardCodeExists(WhiteboardCode whiteboardCode)
|
||||||
|
{
|
||||||
|
var codeExists = await _context.Whiteboards.AnyAsync(w => w.Code == whiteboardCode.CodeValue);
|
||||||
|
return codeExists;
|
||||||
|
}
|
||||||
|
}
|
||||||
17
dotnet/AipsWebApi/Controllers/WhiteboardController.cs
Normal file
17
dotnet/AipsWebApi/Controllers/WhiteboardController.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using AipsCore.Application.Abstract;
|
||||||
|
using AipsCore.Application.Models.Whiteboard.Command.CreateWhiteboard;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace AipsWebApi.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("[controller]")]
|
||||||
|
public class WhiteboardController : ControllerBase
|
||||||
|
{
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<ActionResult<int>> CreateWhiteboard(CreateWhiteboardCommand command, IDispatcher dispatcher, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var whiteboardId = await dispatcher.Execute(command, cancellationToken);
|
||||||
|
return Ok(whiteboardId.IdValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user