feat , fix : activity part

fix done and undone activity methods , feat page controller
master
Amir Hossein Khademi 2023-12-09 09:54:34 +03:30
parent 101728aad4
commit 7fd9ce03ca
20 changed files with 1676 additions and 30 deletions

View File

@ -21,6 +21,10 @@ public class ActivityController : ICarterModule
.WithDisplayName("DoneActivity")
.HasApiVersion(1.0);
group.MapPost("undone/{id:guid}", UnDoneActivityAsync)
.WithDisplayName("UnDoneActivity")
.HasApiVersion(1.0);
//group.MapPost("", Post)
// .AllowAnonymous()
// .HasApiVersion(1.0);
@ -42,8 +46,11 @@ public class ActivityController : ICarterModule
public async Task<IResult> GetAsync(Guid id, IActivityService activityService, CancellationToken cancellationToken)
=> TypedResults.Ok(await activityService.DoneActivityAsync(id,cancellationToken));
public async Task<IResult> DoneActivityAsync(Guid id, ISender sender, CancellationToken cancellationToken)
=> TypedResults.Ok(await sender.Send(new GetActivityQuery(id), cancellationToken));
public async Task<IResult> DoneActivityAsync(Guid id, [FromServices] IActivityService activityService, CancellationToken cancellationToken)
=> TypedResults.Ok(await activityService.DoneActivityAsync(id, cancellationToken));
public async Task<IResult> UnDoneActivityAsync(Guid id,[FromQuery]string undoneReason, [FromServices]IActivityService activityService, CancellationToken cancellationToken)
=> TypedResults.Ok(await activityService.UnDoneActivityAsync(id,undoneReason, cancellationToken));
//// POST:Create Entity
//public async Task<IResult> Post([FromQuery]Guid shiftPlanId,IActivityService activityService, CancellationToken cancellationToken)

View File

@ -0,0 +1,21 @@
namespace Brizco.Api.Controllers;
public class PageController : ICarterModule
{
public void AddRoutes(IEndpointRouteBuilder app)
{
var group = app.NewVersionedApi("Page")
.MapGroup($"api/page")
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser());
group.MapGet("/dashboard/app", GetAppDashboardAsync)
.WithDisplayName("GetAppDashboard")
.HasApiVersion(1.0);
}
public async Task<IResult> GetAppDashboardAsync([FromServices] IPageService pageService, CancellationToken cancellationToken)
=> TypedResults.Ok(await pageService.GetAppDashboardAsync(cancellationToken));
}

View File

@ -1,25 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!--<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MD.PersianDateTime.Standard" Version="2.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.0.3" />
</ItemGroup>
<!--<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MD.PersianDateTime.Standard" Version="2.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
@ -27,6 +14,20 @@
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.0.3" />
</ItemGroup>-->
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MD.PersianDateTime.Standard" Version="2.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.0.3" />
</ItemGroup>
<ItemGroup>
<Using Include="MD.PersianDateTime.Standard" />
<Using Include="System.ComponentModel.DataAnnotations" />

View File

@ -34,6 +34,7 @@
<Using Include="Brizco.Core.CoreServices.Abstracts" />
<Using Include="Brizco.Core.EntityServices.Abstracts" />
<Using Include="Brizco.Domain.CommandQueries.Commands" />
<Using Include="Brizco.Domain.Dtos.PageDto" />
<Using Include="Brizco.Domain.Dtos.RequestDtos" />
<Using Include="Brizco.Domain.Dtos.ResponseDto" />
<Using Include="Brizco.Domain.Dtos.SmallDtos" />

View File

@ -1,6 +1,6 @@
namespace Brizco.Core.CoreServices.Abstracts;
public interface IPageService
public interface IPageService : IScopedDependency
{
Task<AppDashboardPageDto> GetAppDashboardAsync(CancellationToken cancellationToken);
}

View File

@ -0,0 +1,34 @@
using Brizco.Domain.Entities.Task;
namespace Brizco.Core.CoreServices;
public class PageService : IPageService
{
private readonly ICurrentUserService _currentUserService;
private readonly IRepositoryWrapper _repositoryWrapper;
public PageService(ICurrentUserService currentUserService,IRepositoryWrapper repositoryWrapper)
{
_currentUserService = currentUserService;
_repositoryWrapper = repositoryWrapper;
}
public async Task<AppDashboardPageDto> GetAppDashboardAsync(CancellationToken cancellationToken)
{
if (_currentUserService.UserId == null)
throw new AppException("User id is null ");
if (Guid.TryParse(_currentUserService.UserId, out Guid userId)!)
throw new AppException("User id is wrong");
var todayTasks = await _repositoryWrapper.SetRepository<Activity>()
.TableNoTracking
.Where(a => a.UserId == userId)
.ToListAsync(cancellationToken);
return new AppDashboardPageDto
{
DoneActivitiesToday = todayTasks.Count(t => t.IsDone),
TotalActivitiesToday = todayTasks.Count,
UnDoneActivitiesToday = todayTasks.Count(t => t.IsDone!)
};
}
}

View File

@ -4,4 +4,5 @@ public interface IActivityService : IScopedDependency
{
Task<bool> CreateActivitiesByShiftPlan(Guid shiftPlanId, CancellationToken cancellationToken);
Task<bool> DoneActivityAsync(Guid activityId, CancellationToken cancellationToken);
Task<bool> UnDoneActivityAsync(Guid activityId, string undoneReason, CancellationToken cancellationToken);
}

View File

@ -31,6 +31,21 @@ public class ActivityService : IActivityService
return true;
}
public async Task<bool> UnDoneActivityAsync(Guid activityId,string undoneReason, CancellationToken cancellationToken)
{
var activity = await _repositoryWrapper.SetRepository<Activity>()
.TableNoTracking
.FirstOrDefaultAsync(a => a.Id == activityId, cancellationToken);
if (activity == null)
throw new AppException("Activity not found ", ApiResultStatusCode.NotFound);
activity.UnDoneActivity(undoneReason);
_repositoryWrapper.SetRepository<Activity>()
.Update(activity);
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
return true;
}
public async Task<bool> CreateActivitiesByShiftPlan(Guid shiftPlanId,CancellationToken cancellationToken)
{
var shiftPlan = await _mediator.Send(new GetShiftPlanQuery(shiftPlanId), cancellationToken);
@ -42,7 +57,7 @@ public class ActivityService : IActivityService
$@"SELECT t.""Id"", t.""Amount"", t.""AmountType"", t.""ComplexId"",
t.""CreatedAt"", t.""CreatedBy"", t.""Description"", t.""Discriminator"", t.""HasDisposed"", t.""IsDisposable"", t.""IsRemoved"", t.""ModifiedAt"",
t.""ModifiedBy"", t.""RemovedAt"", t.""RemovedBy"", t.""ScheduleType"", t.""SetFor"", t.""Title"", t.""Type"", t.""DoneAt"", t.""IsDone"",
t.""PerformanceDescription"", t.""ShiftId"", t.""Status"", t.""UserId""
t.""PerformanceDescription"", t.""ShiftId"", t.""Status"", t.""UserId"" , t.""IsActivity"" , t.""UnDoneReason""
FROM public.""Tasks"" t
INNER JOIN public.""TaskShifts"" t1 ON t.""Id"" = t1.""TaskId""
INNER JOIN public.""TaskDays"" t2 ON t.""Id"" = t1.""TaskId""

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!--<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
@ -12,10 +12,10 @@
<PackageReference Include="MediatR" Version="12.2.0" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="8.0.0" />
<PackageReference Include="PropertyChanged.Fody" Version="4.1.0" />
</ItemGroup>
</ItemGroup>-->
<!--<PropertyGroup>
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
@ -31,7 +31,7 @@
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0" />
<PackageReference Include="PropertyChanged.Fody" Version="4.1.0" />
</ItemGroup>-->
</ItemGroup>
<Target Name="Mapster">
@ -71,6 +71,7 @@
<ItemGroup>
<Folder Include="Dtos\PageDto\" />
<Folder Include="Dtos\RequestDtos\" />
<Folder Include="Models\Settings\" />
</ItemGroup>

View File

@ -0,0 +1,8 @@
namespace Brizco.Domain.Dtos.PageDto;
public class AppDashboardPageDto
{
public int UnDoneActivitiesToday { get; set; }
public int DoneActivitiesToday { get; set; }
public int TotalActivitiesToday { get; set; }
}

View File

@ -10,6 +10,8 @@ public class ActivitySDto : BaseDto<ActivitySDto , Activity>
public bool IsDisposable { get; internal set; }
public DateTime SetFor { get; internal set; }
public bool HasDisposed { get; internal set; }
public TaskScheduleType ScheduleType { get; set; }
public string UnDoneReason { get; set; } = string.Empty;
public ActivityStatus Status { get; internal set; }
public DateTime DoneAt { get; internal set; }
public bool IsDone { get; set; }

View File

@ -7,7 +7,6 @@ public partial class Activity : Task
public Activity()
{
}
public Activity(
@ -23,8 +22,7 @@ public partial class Activity : Task
string title,
string description,
Guid complexId,
TaskScheduleType scheduleType) : base(
type, isDisposable, setFor, hasDisposed, amount, amountType, title, description, complexId, scheduleType)
TaskScheduleType scheduleType) : base(type, isDisposable, setFor, hasDisposed, amount, amountType, title, description, complexId, scheduleType)
{
Status = status;
DoneAt = doneAt;
@ -34,6 +32,7 @@ public partial class Activity : Task
public ActivityStatus Status { get; internal set; }
public DateTime DoneAt { get; internal set; }
public bool IsDone { get; internal set; }
public string UnDoneReason { get; internal set; } = string.Empty;
public string PerformanceDescription { get; internal set; } = string.Empty;
public Guid UserId { get; internal set; }
public ApplicationUser? User { get; internal set; }

View File

@ -143,6 +143,13 @@ public partial class Activity
{
DoneAt = DateTime.UtcNow;
IsDone = true;
Status = ActivityStatus.InProgress;
Status = ActivityStatus.Done;
}
public void UnDoneActivity(string undoneReason)
{
IsDone = false;
UnDoneReason = undoneReason;
Status = ActivityStatus.UnDone;
}
}

View File

@ -44,6 +44,7 @@ public partial class Task : ApiEntity
public Guid ComplexId { get; set; }
public Complex.Complex? Complex { get; set; }
public bool IsActivity { get; set; }
public int Amount { get; internal set; }

View File

@ -8,6 +8,8 @@ public enum ActivityStatus
InProgress,
[Display(Name = "انجام شده")]
Done,
[Display(Name = "تمام شده")]
Complete,
[Display(Name = "انجام نشده")]
UnDone
}

View File

@ -15,6 +15,7 @@ namespace Brizco.Domain.Mappers
Status = p1.Status,
DoneAt = p1.DoneAt,
IsDone = p1.IsDone,
UnDoneReason = p1.UnDoneReason,
PerformanceDescription = p1.PerformanceDescription,
Type = p1.Type,
Title = p1.Title,
@ -22,6 +23,7 @@ namespace Brizco.Domain.Mappers
IsDisposable = p1.IsDisposable,
SetFor = p1.SetFor,
HasDisposed = p1.HasDisposed,
ScheduleType = p1.ScheduleType,
Amount = p1.Amount,
AmountType = p1.AmountType,
Id = p1.Id
@ -38,6 +40,7 @@ namespace Brizco.Domain.Mappers
result.Status = p2.Status;
result.DoneAt = p2.DoneAt;
result.IsDone = p2.IsDone;
result.UnDoneReason = p2.UnDoneReason;
result.PerformanceDescription = p2.PerformanceDescription;
result.Type = p2.Type;
result.Title = p2.Title;
@ -45,6 +48,7 @@ namespace Brizco.Domain.Mappers
result.IsDisposable = p2.IsDisposable;
result.SetFor = p2.SetFor;
result.HasDisposed = p2.HasDisposed;
result.ScheduleType = p2.ScheduleType;
result.Amount = p2.Amount;
result.AmountType = p2.AmountType;
result.Id = p2.Id;
@ -56,6 +60,7 @@ namespace Brizco.Domain.Mappers
Status = p4.Status,
DoneAt = p4.DoneAt,
IsDone = p4.IsDone,
UnDoneReason = p4.UnDoneReason,
PerformanceDescription = p4.PerformanceDescription,
Type = p4.Type,
Title = p4.Title,
@ -63,6 +68,7 @@ namespace Brizco.Domain.Mappers
IsDisposable = p4.IsDisposable,
SetFor = p4.SetFor,
HasDisposed = p4.HasDisposed,
ScheduleType = p4.ScheduleType,
Amount = p4.Amount,
AmountType = p4.AmountType,
Id = p4.Id
@ -77,6 +83,8 @@ namespace Brizco.Domain.Mappers
IsDisposable = p5.IsDisposable,
SetFor = p5.SetFor,
HasDisposed = p5.HasDisposed,
ScheduleType = p5.ScheduleType,
UnDoneReason = p5.UnDoneReason,
Status = p5.Status,
DoneAt = p5.DoneAt,
IsDone = p5.IsDone,
@ -100,6 +108,8 @@ namespace Brizco.Domain.Mappers
result.IsDisposable = p6.IsDisposable;
result.SetFor = p6.SetFor;
result.HasDisposed = p6.HasDisposed;
result.ScheduleType = p6.ScheduleType;
result.UnDoneReason = p6.UnDoneReason;
result.Status = p6.Status;
result.DoneAt = p6.DoneAt;
result.IsDone = p6.IsDone;
@ -118,6 +128,8 @@ namespace Brizco.Domain.Mappers
IsDisposable = p8.IsDisposable,
SetFor = p8.SetFor,
HasDisposed = p8.HasDisposed,
ScheduleType = p8.ScheduleType,
UnDoneReason = p8.UnDoneReason,
Status = p8.Status,
DoneAt = p8.DoneAt,
IsDone = p8.IsDone,

View File

@ -18,7 +18,7 @@ public class GetActivitiesQueryHandler : IRequestHandler<GetTasksQuery, List<Tas
throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound);
var tasks = await _repositoryWrapper.SetRepository<Domain.Entities.Task.Task>().TableNoTracking
.Where(t=>t.ComplexId==complexId)
.Where(t=>t.ComplexId==complexId && t.IsActivity == false)
.OrderByDescending(s => s.CreatedAt)
.Skip(request.Page * 15).Take(15)
.Select(TaskMapper.ProjectToSDto)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,63 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Brizco.Repository.Migrations
{
/// <inheritdoc />
public partial class editTaskAndActivity : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Discriminator",
schema: "public",
table: "Tasks",
type: "character varying(8)",
maxLength: 8,
nullable: false,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AddColumn<bool>(
name: "IsActivity",
schema: "public",
table: "Tasks",
type: "boolean",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<string>(
name: "UnDoneReason",
schema: "public",
table: "Tasks",
type: "text",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsActivity",
schema: "public",
table: "Tasks");
migrationBuilder.DropColumn(
name: "UnDoneReason",
schema: "public",
table: "Tasks");
migrationBuilder.AlterColumn<string>(
name: "Discriminator",
schema: "public",
table: "Tasks",
type: "text",
nullable: false,
oldClrType: typeof(string),
oldType: "character varying(8)",
oldMaxLength: 8);
}
}
}

View File

@ -18,7 +18,7 @@ namespace Brizco.Repository.Migrations
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("public")
.HasAnnotation("ProductVersion", "7.0.11")
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@ -577,11 +577,15 @@ namespace Brizco.Repository.Migrations
b.Property<string>("Discriminator")
.IsRequired()
.HasColumnType("text");
.HasMaxLength(8)
.HasColumnType("character varying(8)");
b.Property<bool>("HasDisposed")
.HasColumnType("boolean");
b.Property<bool>("IsActivity")
.HasColumnType("boolean");
b.Property<bool>("IsDisposable")
.HasColumnType("boolean");
@ -1060,6 +1064,10 @@ namespace Brizco.Repository.Migrations
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<string>("UnDoneReason")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("UserId")
.HasColumnType("uuid");