From b3f42af77c711ad3615c461baba47516240bc5f9 Mon Sep 17 00:00:00 2001 From: mahan Date: Sat, 13 Dec 2025 11:19:17 +0330 Subject: [PATCH] Refactor bug report system to use Guid for identifiers instead of long --- .../CameraBugReportAgg/CameraBugReport.cs | 7 ++-- .../ICameraBugReportRepository.cs | 9 +++-- .../CameraBugReportRepository.cs | 6 +-- .../CameraBugReportDetailViewModel.cs | 2 +- .../CameraBugReportViewModel.cs | 2 +- .../EditCameraBugReportCommand.cs | 4 +- .../ICameraBugReportApplication.cs | 12 +++--- .../CameraBugReportApplication.cs | 23 +++++------ .../Mapping/CameraBugReportLogMapping.cs | 18 --------- .../Mapping/CameraBugReportMapping.cs | 38 ------------------- .../CameraBugReportScreenshotMapping.cs | 19 ---------- .../Repository/CameraBugReportRepository.cs | 31 --------------- .../Pages/BugReport/BugReportPageModel.cs | 4 +- .../AdminNew/Pages/BugReport/Delete.cshtml.cs | 4 +- .../Pages/BugReport/Details.cshtml.cs | 2 +- .../AdminNew/Pages/BugReport/Edit.cshtml.cs | 4 +- .../AdminNew/Pages/BugReport/Index.cshtml | 2 +- .../Controllers/BugReportController.cs | 6 +-- 18 files changed, 44 insertions(+), 149 deletions(-) delete mode 100644 CompanyManagment.EFCore/Mapping/CameraBugReportLogMapping.cs delete mode 100644 CompanyManagment.EFCore/Mapping/CameraBugReportMapping.cs delete mode 100644 CompanyManagment.EFCore/Mapping/CameraBugReportScreenshotMapping.cs delete mode 100644 CompanyManagment.EFCore/Repository/CameraBugReportRepository.cs diff --git a/Company.Domain/CameraBugReportAgg/CameraBugReport.cs b/Company.Domain/CameraBugReportAgg/CameraBugReport.cs index 17817cea..1dfefe2a 100644 --- a/Company.Domain/CameraBugReportAgg/CameraBugReport.cs +++ b/Company.Domain/CameraBugReportAgg/CameraBugReport.cs @@ -8,15 +8,15 @@ namespace Company.Domain.CameraBugReportAgg; /// /// مدل دامنه برای گزارش خرابی دوربین /// -public class CameraBugReport : EntityBase +public class CameraBugReport { [BsonId] [BsonRepresentation(MongoDB.Bson.BsonType.String)] - public new string Id { get; set; } + public Guid Id { get; set; } public CameraBugReport() { - Id = Guid.NewGuid().ToString(); + Id = Guid.NewGuid(); CreationDate = DateTime.Now; Status = CameraBugReportStatus.Open; Screenshots = new List(); @@ -163,6 +163,7 @@ public class CameraBugReport : EntityBase [BsonElement("title")] public string Title { get; private set; } + public void ChangeStatus(CameraBugReportStatus newStatus) { UpdateDate = DateTime.Now; diff --git a/Company.Domain/CameraBugReportAgg/ICameraBugReportRepository.cs b/Company.Domain/CameraBugReportAgg/ICameraBugReportRepository.cs index c9544118..b092ff81 100644 --- a/Company.Domain/CameraBugReportAgg/ICameraBugReportRepository.cs +++ b/Company.Domain/CameraBugReportAgg/ICameraBugReportRepository.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -8,16 +9,16 @@ namespace Company.Domain.CameraBugReportAgg; /// /// رابط انبار گزارش خرابی دوربین برای MongoDB /// -public interface ICameraBugReportRepository : IRepository +public interface ICameraBugReportRepository { // Async methods for MongoDB operations Task CreateAsync(CameraBugReport bugReport); Task UpdateAsync(CameraBugReport bugReport); - Task GetByIdAsync(string id); + Task GetByIdAsync(Guid id); Task> GetAllAsync(); Task> GetAllAsync(int skip, int take); - Task DeleteAsync(string id); - Task IsExistAsync(string id); + Task DeleteAsync(Guid id); + Task IsExistAsync(Guid id); Task> FilterAsync( CameraBugReportType? type = null, CameraBugPriority? priority = null, diff --git a/CompanyManagement.Infrastructure.Mongo/CameraBugReportRepo/CameraBugReportRepository.cs b/CompanyManagement.Infrastructure.Mongo/CameraBugReportRepo/CameraBugReportRepository.cs index 31f0d1ca..40d7b406 100644 --- a/CompanyManagement.Infrastructure.Mongo/CameraBugReportRepo/CameraBugReportRepository.cs +++ b/CompanyManagement.Infrastructure.Mongo/CameraBugReportRepo/CameraBugReportRepository.cs @@ -32,7 +32,7 @@ public class CameraBugReportRepository : ICameraBugReportRepository bugReport); } - public async Task GetByIdAsync(string id) + public async Task GetByIdAsync(Guid id) { return await _cameraBugReports .Find(x => x.Id == id) @@ -56,12 +56,12 @@ public class CameraBugReportRepository : ICameraBugReportRepository .ToListAsync(); } - public async Task DeleteAsync(string id) + public async Task DeleteAsync(Guid id) { await _cameraBugReports.DeleteOneAsync(x => x.Id == id); } - public async Task IsExistAsync(string id) + public async Task IsExistAsync(Guid id) { var result = await _cameraBugReports .Find(x => x.Id == id) diff --git a/CompanyManagment.App.Contracts/CameraBugReport/CameraBugReportDetailViewModel.cs b/CompanyManagment.App.Contracts/CameraBugReport/CameraBugReportDetailViewModel.cs index da456d9d..1abb7128 100644 --- a/CompanyManagment.App.Contracts/CameraBugReport/CameraBugReportDetailViewModel.cs +++ b/CompanyManagment.App.Contracts/CameraBugReport/CameraBugReportDetailViewModel.cs @@ -5,7 +5,7 @@ namespace CompanyManagment.App.Contracts.CameraBugReport { public class CameraBugReportDetailViewModel { - public string Id { get; set; } + public Guid Id { get; set; } public string Title { get; set; } public string Description { get; set; } public string UserEmail { get; set; } diff --git a/CompanyManagment.App.Contracts/CameraBugReport/CameraBugReportViewModel.cs b/CompanyManagment.App.Contracts/CameraBugReport/CameraBugReportViewModel.cs index 1114861c..8790b0cb 100644 --- a/CompanyManagment.App.Contracts/CameraBugReport/CameraBugReportViewModel.cs +++ b/CompanyManagment.App.Contracts/CameraBugReport/CameraBugReportViewModel.cs @@ -4,7 +4,7 @@ namespace CompanyManagment.App.Contracts.CameraBugReport { public class CameraBugReportViewModel { - public string Id { get; set; } + public Guid Id { get; set; } public string Title { get; set; } public string Description { get; set; } public string UserEmail { get; set; } diff --git a/CompanyManagment.App.Contracts/CameraBugReport/EditCameraBugReportCommand.cs b/CompanyManagment.App.Contracts/CameraBugReport/EditCameraBugReportCommand.cs index 9809109e..3d9aea5d 100644 --- a/CompanyManagment.App.Contracts/CameraBugReport/EditCameraBugReportCommand.cs +++ b/CompanyManagment.App.Contracts/CameraBugReport/EditCameraBugReportCommand.cs @@ -1,9 +1,11 @@ +using System; + namespace CompanyManagment.App.Contracts.CameraBugReport { public class EditCameraBugReportCommand { - public string Id { get; set; } + public Guid Id { get; set; } public CameraBugPriority Priority { get; set; } public CameraBugReportStatus Status { get; set; } } diff --git a/CompanyManagment.App.Contracts/CameraBugReport/ICameraBugReportApplication.cs b/CompanyManagment.App.Contracts/CameraBugReport/ICameraBugReportApplication.cs index 7f931b85..bbd02a2e 100644 --- a/CompanyManagment.App.Contracts/CameraBugReport/ICameraBugReportApplication.cs +++ b/CompanyManagment.App.Contracts/CameraBugReport/ICameraBugReportApplication.cs @@ -9,18 +9,18 @@ namespace CompanyManagment.App.Contracts.CameraBugReport { Task CreateAsync(CreateCameraBugReportCommand command); Task EditAsync(EditCameraBugReportCommand command); - Task DeleteAsync(string id); + Task DeleteAsync(Guid id); Task> GetAllAsync(CameraBugReportSearchModel searchModel); - Task GetDetailsAsync(string id); - Task IsExistAsync(string id); + Task GetDetailsAsync(Guid id); + Task IsExistAsync(Guid id); // Keep sync methods for backward compatibility but they delegate to async OperationResult Create(CreateCameraBugReportCommand command); OperationResult Edit(EditCameraBugReportCommand command); - OperationResult Delete(long id); + OperationResult Delete(Guid id); List GetAll(CameraBugReportSearchModel searchModel); - CameraBugReportDetailViewModel GetDetails(long id); - bool IsExist(long id); + CameraBugReportDetailViewModel GetDetails(Guid id); + bool IsExist(Guid id); } public class CameraBugReportSearchModel diff --git a/CompanyManagment.Application/CameraBugReportApplication.cs b/CompanyManagment.Application/CameraBugReportApplication.cs index 1ea1ee60..8fab3b81 100644 --- a/CompanyManagment.Application/CameraBugReportApplication.cs +++ b/CompanyManagment.Application/CameraBugReportApplication.cs @@ -69,7 +69,6 @@ namespace CompanyManagment.Application } await _repository.CreateAsync(bugReport); - await _repository.SaveChangesAsync(); return op.Succcedded(); } @@ -84,7 +83,7 @@ namespace CompanyManagment.Application var op = new OperationResult(); try { - var bugReport = await _repository.GetByIdAsync(command.Id.ToString()); + var bugReport = await _repository.GetByIdAsync(command.Id); if (bugReport == null) return op.Failed("گزارش خرابی یافت نشد."); @@ -92,7 +91,6 @@ namespace CompanyManagment.Application bugReport.ChangeStatus(command.Status); await _repository.UpdateAsync(bugReport); - await _repository.SaveChangesAsync(); return op.Succcedded(); } @@ -102,7 +100,7 @@ namespace CompanyManagment.Application } } - public async Task DeleteAsync(string id) + public async Task DeleteAsync(Guid id) { var op = new OperationResult(); try @@ -112,7 +110,6 @@ namespace CompanyManagment.Application return op.Failed("گزارش خرابی یافت نشد."); await _repository.DeleteAsync(id); - await _repository.SaveChangesAsync(); return op.Succcedded(); } @@ -160,7 +157,7 @@ namespace CompanyManagment.Application } } - public async Task GetDetailsAsync(string id) + public async Task GetDetailsAsync(Guid id) { try { @@ -213,7 +210,7 @@ namespace CompanyManagment.Application } } - public async Task IsExistAsync(string id) + public async Task IsExistAsync(Guid id) { return await _repository.IsExistAsync(id); } @@ -243,11 +240,11 @@ namespace CompanyManagment.Application } } - public OperationResult Delete(long id) + public OperationResult Delete(Guid id) { try { - return DeleteAsync(id.ToString()).ConfigureAwait(false).GetAwaiter().GetResult(); + return DeleteAsync(id).ConfigureAwait(false).GetAwaiter().GetResult(); } catch (Exception ex) { @@ -267,11 +264,11 @@ namespace CompanyManagment.Application } } - public CameraBugReportDetailViewModel GetDetails(long id) + public CameraBugReportDetailViewModel GetDetails(Guid id) { try { - return GetDetailsAsync(id.ToString()).ConfigureAwait(false).GetAwaiter().GetResult(); + return GetDetailsAsync(id).ConfigureAwait(false).GetAwaiter().GetResult(); } catch (Exception ex) { @@ -279,11 +276,11 @@ namespace CompanyManagment.Application } } - public bool IsExist(long id) + public bool IsExist(Guid id) { try { - return IsExistAsync(id.ToString()).ConfigureAwait(false).GetAwaiter().GetResult(); + return IsExistAsync(id).ConfigureAwait(false).GetAwaiter().GetResult(); } catch (Exception ex) { diff --git a/CompanyManagment.EFCore/Mapping/CameraBugReportLogMapping.cs b/CompanyManagment.EFCore/Mapping/CameraBugReportLogMapping.cs deleted file mode 100644 index ea6f418b..00000000 --- a/CompanyManagment.EFCore/Mapping/CameraBugReportLogMapping.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Company.Domain.CameraBugReportAgg; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; - -namespace CompanyManagment.EFCore.Mapping -{ - public class CameraBugReportLogMapping : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - builder.HasKey(x => x.id); - builder.ToTable("CameraBugReportLogs"); - - builder.Property(x => x.Message).HasColumnType("ntext").IsRequired(); - } - } -} - diff --git a/CompanyManagment.EFCore/Mapping/CameraBugReportMapping.cs b/CompanyManagment.EFCore/Mapping/CameraBugReportMapping.cs deleted file mode 100644 index 64c26e4f..00000000 --- a/CompanyManagment.EFCore/Mapping/CameraBugReportMapping.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; -using Company.Domain.CameraBugReportAgg; - -namespace CompanyManagment.EFCore.Mapping; - -public class CameraBugReportMapping : IEntityTypeConfiguration -{ - public void Configure(EntityTypeBuilder builder) - { - builder.HasMany(x => x.Screenshots).WithOne(x => x.CameraBugReport).HasForeignKey(x => x.CameraBugReportId) - .OnDelete(DeleteBehavior.Cascade); - builder.HasMany(x => x.Logs).WithOne(x => x.CameraBugReport).HasForeignKey(x => x.CameraBugReportId) - .OnDelete(DeleteBehavior.Cascade); - - builder.Property(x => x.Status).HasConversion(); - builder.Property(x => x.Priority).HasConversion(); - builder.Property(x => x.Type).HasConversion(); - builder.Property(x => x.StackTrace).HasColumnType("ntext"); - builder.Property(x => x.Flavor).HasMaxLength(50); - builder.Property(x => x.PackageName).HasMaxLength(150); - builder.Property(x => x.BuildNumber).HasMaxLength(50); - builder.Property(x => x.AppVersion).HasMaxLength(50); - builder.Property(x => x.NetworkType).HasMaxLength(50); - builder.Property(x => x.ScreenResolution).HasMaxLength(50); - builder.Property(x => x.DeviceId).HasMaxLength(200); - builder.Property(x => x.Manufacturer).HasMaxLength(100); - builder.Property(x => x.Platform).HasMaxLength(50); - builder.Property(x => x.OsVersion).HasMaxLength(50); - builder.Property(x => x.DeviceModel).HasMaxLength(100); - builder.Property(x => x.UserEmail).HasMaxLength(150).IsRequired(); - builder.Property(x => x.Description).HasColumnType("ntext").IsRequired(); - builder.Property(x => x.Title).HasMaxLength(200).IsRequired(); - - builder.ToTable("CameraBugReports"); - builder.HasKey(x => x.id); - } -} \ No newline at end of file diff --git a/CompanyManagment.EFCore/Mapping/CameraBugReportScreenshotMapping.cs b/CompanyManagment.EFCore/Mapping/CameraBugReportScreenshotMapping.cs deleted file mode 100644 index 994b9302..00000000 --- a/CompanyManagment.EFCore/Mapping/CameraBugReportScreenshotMapping.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Company.Domain.CameraBugReportAgg; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; - -namespace CompanyManagment.EFCore.Mapping -{ - public class CameraBugReportScreenshotMapping : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - builder.HasKey(x => x.id); - builder.ToTable("CameraBugReportScreenshots"); - - builder.Property(x => x.FileName).HasMaxLength(255); - builder.Property(x => x.Base64Data).HasColumnType("ntext").IsRequired(); - } - } -} - diff --git a/CompanyManagment.EFCore/Repository/CameraBugReportRepository.cs b/CompanyManagment.EFCore/Repository/CameraBugReportRepository.cs deleted file mode 100644 index 82988a0f..00000000 --- a/CompanyManagment.EFCore/Repository/CameraBugReportRepository.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using _0_Framework.InfraStructure; -using CompanyManagment.App.Contracts.CameraBugReport; -using Company.Domain.CameraBugReportAgg; -using Microsoft.EntityFrameworkCore; - -namespace CompanyManagment.EFCore.Repository -{ - public class CameraBugReportRepository : RepositoryBase, ICameraBugReportRepository - { - private readonly CompanyContext _companyContext; - - public CameraBugReportRepository(CompanyContext companyContext) : base(companyContext) - { - _companyContext = companyContext; - } - - IQueryable ICameraBugReportRepository.GetAllAsNoTracking() - { - return _companyContext.CameraBugReports.AsNoTracking(); - } - - public bool IsExist(long id) - { - return _companyContext.CameraBugReports.Any(x => x.id == id); - } - } -} - diff --git a/ServiceHost/Areas/AdminNew/Pages/BugReport/BugReportPageModel.cs b/ServiceHost/Areas/AdminNew/Pages/BugReport/BugReportPageModel.cs index 9237cb9e..ad034919 100644 --- a/ServiceHost/Areas/AdminNew/Pages/BugReport/BugReportPageModel.cs +++ b/ServiceHost/Areas/AdminNew/Pages/BugReport/BugReportPageModel.cs @@ -20,12 +20,12 @@ namespace ServiceHost.Areas.AdminNew.Pages.BugReport return _bugReportApplication.GetAll(searchModel); } - protected CameraBugReportDetailViewModel GetBugReportDetails(long id) + protected CameraBugReportDetailViewModel GetBugReportDetails(Guid id) { return _bugReportApplication.GetDetails(id); } - protected bool IsExist(long id) + protected bool IsExist(Guid id) { return _bugReportApplication.IsExist(id); } diff --git a/ServiceHost/Areas/AdminNew/Pages/BugReport/Delete.cshtml.cs b/ServiceHost/Areas/AdminNew/Pages/BugReport/Delete.cshtml.cs index 0a63273c..e5636624 100644 --- a/ServiceHost/Areas/AdminNew/Pages/BugReport/Delete.cshtml.cs +++ b/ServiceHost/Areas/AdminNew/Pages/BugReport/Delete.cshtml.cs @@ -8,7 +8,7 @@ public class DeleteModel : BugReportPageModel { } - public void OnGet(long id) + public void OnGet(Guid id) { BugReportDetails = GetBugReportDetails(id); if (BugReportDetails == null) @@ -18,7 +18,7 @@ public class DeleteModel : BugReportPageModel } - public IActionResult OnPost(long id) + public IActionResult OnPost(Guid id) { var result = _bugReportApplication.Delete(id); if (result.IsSuccedded) diff --git a/ServiceHost/Areas/AdminNew/Pages/BugReport/Details.cshtml.cs b/ServiceHost/Areas/AdminNew/Pages/BugReport/Details.cshtml.cs index 70649c88..99774bf7 100644 --- a/ServiceHost/Areas/AdminNew/Pages/BugReport/Details.cshtml.cs +++ b/ServiceHost/Areas/AdminNew/Pages/BugReport/Details.cshtml.cs @@ -8,7 +8,7 @@ public class DetailsModel : BugReportPageModel { } - public void OnGet(long id) + public void OnGet(Guid id) { BugReportDetails = GetBugReportDetails(id); if (BugReportDetails == null) diff --git a/ServiceHost/Areas/AdminNew/Pages/BugReport/Edit.cshtml.cs b/ServiceHost/Areas/AdminNew/Pages/BugReport/Edit.cshtml.cs index 5bbf39f1..9a4ecf2a 100644 --- a/ServiceHost/Areas/AdminNew/Pages/BugReport/Edit.cshtml.cs +++ b/ServiceHost/Areas/AdminNew/Pages/BugReport/Edit.cshtml.cs @@ -10,7 +10,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.BugReport } [BindProperty] - public long Id { get; set; } + public Guid Id { get; set; } [BindProperty] public CameraBugPriority Priority { get; set; } @@ -20,7 +20,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.BugReport public CameraBugReportDetailViewModel BugReportDetail { get; set; } - public void OnGet(long id) + public void OnGet(Guid id) { BugReportDetail = GetBugReportDetails(id); if (BugReportDetail != null) diff --git a/ServiceHost/Areas/AdminNew/Pages/BugReport/Index.cshtml b/ServiceHost/Areas/AdminNew/Pages/BugReport/Index.cshtml index 2943dcf5..022bb790 100644 --- a/ServiceHost/Areas/AdminNew/Pages/BugReport/Index.cshtml +++ b/ServiceHost/Areas/AdminNew/Pages/BugReport/Index.cshtml @@ -141,7 +141,7 @@ @report.CreationDate.ToString("yyyy-MM-dd HH:mm") - مشاهده + مشاهده ویرایش حذف diff --git a/ServiceHost/Controllers/BugReportController.cs b/ServiceHost/Controllers/BugReportController.cs index b6bf82bd..5ccf74e3 100644 --- a/ServiceHost/Controllers/BugReportController.cs +++ b/ServiceHost/Controllers/BugReportController.cs @@ -60,7 +60,7 @@ namespace ServiceHost.Controllers /// دریافت جزئیات یک گزارش خرابی /// [HttpGet("{id}")] - public IActionResult GetBugReportDetails(long id) + public IActionResult GetBugReportDetails(Guid id) { var bugReport = _bugReportApplication.GetDetails(id); if (bugReport == null) @@ -73,7 +73,7 @@ namespace ServiceHost.Controllers /// ویرایش یک گزارش خرابی /// [HttpPut("{id}")] - public IActionResult EditBugReport(long id, [FromBody] EditCameraBugReportCommand command) + public IActionResult EditBugReport(Guid id, [FromBody] EditCameraBugReportCommand command) { if (id != command.Id) return BadRequest(new { success = false, message = "ID مطابقت ندارد." }); @@ -92,7 +92,7 @@ namespace ServiceHost.Controllers /// حذف یک گزارش خرابی /// [HttpDelete("{id}")] - public IActionResult DeleteBugReport(long id) + public IActionResult DeleteBugReport(Guid id) { var result = _bugReportApplication.Delete(id); if (result.IsSuccedded)