Skip to content
This repository was archived by the owner on Nov 18, 2025. It is now read-only.
Open

Dev #23

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
62bf453
Created Review entity and CRUD apis
nicksoftware Nov 19, 2020
e6c61ef
Changed Review to Comment
nicksoftware Nov 19, 2020
1a176ff
Renamed file names from review to Comment
nicksoftware Nov 19, 2020
e09c416
Delete BuildAndTestMain.yml
nicksoftware Nov 19, 2020
fb7fb21
Merge pull request #15 from hnicolus/CommentFeature
nicksoftware Nov 19, 2020
38f122a
Framewrk updated to dotnet 5.0
nicksoftware Nov 19, 2020
b073f4d
Merge pull request #18 from hnicolus/FrameworkUpgrade
nicksoftware Nov 19, 2020
1810a81
framework patches and initial presentation design
nicksoftware Nov 20, 2020
8fdc62e
fixed upgrade Identity conflicts by applying identiy update migration
nicksoftware Nov 20, 2020
e6e690d
Introduced base Entity aside for the auditary entity and added Like a…
nicksoftware Nov 21, 2020
455d4cc
Created Like Feature
nicksoftware Nov 28, 2020
141cc87
Added First Name ,LastName, AvatarImage, CoverImage Fields
nicksoftware Nov 28, 2020
fbce61d
fixed nswag
nicksoftware Nov 29, 2020
ee0cb81
Merge branch 'hnicolus-patch-5' into dev
nicksoftware Nov 29, 2020
b7827f9
Merge branch 'FrameworkUpgrade' into dev
nicksoftware Nov 29, 2020
b26fa36
Merge branch 'CommentFeature' into dev
nicksoftware Nov 29, 2020
6387dfc
Merge branch 'LikeFeature' into dev
nicksoftware Nov 29, 2020
7c06a4b
Merge branch 'appUserFeature' into dev
nicksoftware Nov 29, 2020
5cf5a5e
Merge pull request #21 from hnicolus/FrameworkUpgrade
nicksoftware Nov 29, 2020
e2ba7e1
Merge branch 'dev' of https://github.com/hnicolus/CodeClinic into dev
nicksoftware Nov 29, 2020
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
25 changes: 0 additions & 25 deletions .github/workflows/BuildAndTestMain.yml

This file was deleted.

4 changes: 2 additions & 2 deletions src/Application/Application.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>CodeClinic.Application</RootNamespace>
<AssemblyName>CodeClinic.Application</AssemblyName>
</PropertyGroup>
Expand All @@ -12,7 +12,7 @@
<PackageReference Include="FluentValidation" Version="8.6.0" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="8.6.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using MediatR;
using System;
using System.Collections.Generic;
using System.Text;

namespace CodeClinic.Application.Categories.Commands.CreateCategory
{
public class CreateCategoryCommand : IRequest<int>
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using CodeClinic.Application.Common.Interfaces;
using CodeClinic.Domain.Entities;
using MediatR;
using System.Threading;
using System.Threading.Tasks;

namespace CodeClinic.Application.Categories.Commands.CreateCategory
{
public class CreateCategoryCommandHandler : IRequestHandler<CreateCategoryCommand, int>
{
private readonly IApplicationDbContext _context;

public CreateCategoryCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<int> Handle(CreateCategoryCommand request, CancellationToken cancellationToken)
{
var category = new Category
{
Name = request.Name,
Description = request.Description,

};

_context.Categories.Add(category);

await _context.SaveChangesAsync(cancellationToken);

return category.Id;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using CodeClinic.Application.Common.Interfaces;
using FluentValidation;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace CodeClinic.Application.Categories.Commands.CreateCategory
{
public class CreateCategoryCommandValidator : AbstractValidator<CreateCategoryCommand>
{
private readonly IApplicationDbContext _context;

public CreateCategoryCommandValidator(IApplicationDbContext context)
{
RuleFor(n => n.Name)
.MaximumLength(50)
.WithMessage("Name should not be greater than 50 characters")
.NotNull().NotEmpty().WithMessage("Name is required")
.MustAsync(BeUnique).WithMessage("Category must be Unique");

RuleFor(d => d.Description)
.MaximumLength(500).WithMessage("Description should be short") ;
_context = context;
}

public async Task<bool> BeUnique(CreateCategoryCommand request,string name,CancellationToken cancellationToken)
{
return await _context
.Categories
.Where(n => n.Id != request.Id)
.AllAsync(n => n.Name != request.Name);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
using System.Text;

namespace CodeClinic.Application.Categories.Commands.DeleteCategory
{
public class DeleteCategoryCommand :IRequest
{
public int Id { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using CodeClinic.Application.Common.Exceptions;
using CodeClinic.Application.Common.Interfaces;
using CodeClinic.Domain.Entities;
using MediatR;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace CodeClinic.Application.Categories.Commands.DeleteCategory
{
public class DeleteCategoryCommandHandler : IRequestHandler<DeleteCategoryCommand>
{
private readonly IApplicationDbContext _context;

public DeleteCategoryCommandHandler(IApplicationDbContext context)
{
_context = context;

}

public async Task<Unit> Handle(DeleteCategoryCommand request, CancellationToken cancellationToken)
{

var entity = await _context.Categories.FindAsync(request.Id);

if (entity == null) throw new NotFoundException(nameof(Category), request.Id);

_context.Categories.Remove(entity);

await _context.SaveChangesAsync(cancellationToken);

return Unit.Value;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using FluentValidation;

namespace CodeClinic.Application.Categories.Commands.DeleteCategory
{
public class DeleteCategoryCommandValidator : AbstractValidator<DeleteCategoryCommand>
{
public DeleteCategoryCommandValidator()
{


RuleFor(c => c.Id).NotNull()
.NotEmpty().WithMessage("Id Cannot be null");
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using MediatR;
using System;
using System.Collections.Generic;
using System.Text;

namespace CodeClinic.Application.Categories.Commands.UpdateCategory
{
public class UpdateCategoryCommand : IRequest
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using CodeClinic.Application.Common.Exceptions;
using CodeClinic.Application.Common.Interfaces;
using CodeClinic.Domain.Entities;
using MediatR;
using System.Threading;
using System.Threading.Tasks;

namespace CodeClinic.Application.Categories.Commands.UpdateCategory
{
public partial class UpdateCategoryCommandHandler : IRequestHandler<UpdateCategoryCommand>
{
private readonly IApplicationDbContext _context;

public UpdateCategoryCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(UpdateCategoryCommand request, CancellationToken cancellationToken)
{
var categoryUpdate = await _context.Categories.FindAsync(request.Id);
if (categoryUpdate == null)
throw new NotFoundException(nameof(Category), request.Id);


categoryUpdate.Name = request.Name;
categoryUpdate.Description = request.Description;

_context.Categories.Update(categoryUpdate);

await _context.SaveChangesAsync(cancellationToken);

return Unit.Value;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using CodeClinic.Application.Common.Interfaces;
using FluentValidation;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace CodeClinic.Application.Categories.Commands.UpdateCategory
{

public partial class UpdateCategoryCommandHandler
{
public class UpdateCategoryCommandValidator : AbstractValidator<UpdateCategoryCommand>
{
private readonly IApplicationDbContext _context;

public UpdateCategoryCommandValidator(IApplicationDbContext context)
{
RuleFor(n => n.Name)
.MaximumLength(50)
.WithMessage("Name should not be greater than 50 characters")
.NotNull().NotEmpty().WithMessage("Name is required")
.MustAsync(BeUniqueName).WithMessage("Category must be Unique");

_context = context;
}
public async Task<bool> BeUniqueName(UpdateCategoryCommand model, string name, CancellationToken cancellationToken)
{
return await _context.Categories
.Where(l => l.Id != model.Id)
.AllAsync(l => l.Name != name);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using AutoMapper;
using CodeClinic.Application.Categories.Queries.GetCategoryList;
using CodeClinic.Application.Common.Mappings;
using CodeClinic.Application.Issues.Queries.GetIssueList;
using CodeClinic.Domain.Entities;
using System;
using System.Collections.Generic;

namespace CodeClinic.Application.Categories.Queries.GetCategory
{
public class CategoryDetailVm : IMapFrom<Category>
{
public int CategoryId { get; set; }
public string CategoryName { get; set; }
public string CategoryDescription { get; set; }

public DateTime DateCreated { get; set; }

public string LastModifiedBy { get; set; }

public DateTime? LastModified { get; set; }
public IList<IssueTicketDto> IssuesTickets { get; set; } = new List<IssueTicketDto>();



public void Mapping(Profile profile)
{
profile.CreateMap<Category, CategoryDetailVm>()
.ForMember(d => d.CategoryId, opt => opt.MapFrom(s => s.Id))
.ForMember(c=> c.CategoryName , cd=> cd.MapFrom(c=> c.Name))
.ForMember(c=> c.CategoryDescription,op=> op.MapFrom(d=> d.Description));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using AutoMapper;
using AutoMapper.QueryableExtensions;
using CodeClinic.Application.Common.Exceptions;
using CodeClinic.Application.Common.Interfaces;
using CodeClinic.Application.Issues.Queries.GetIssueList;
using CodeClinic.Domain.Entities;
using MediatR;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace CodeClinic.Application.Categories.Queries.GetCategory
{
public class GetCategoryDetailQuery:IRequest<CategoryDetailVm>
{
public int Id { get; set; }
}

public class GetCategoryDetailQueryHandler : IRequestHandler<GetCategoryDetailQuery, CategoryDetailVm>
{
private readonly IApplicationDbContext _context;
private readonly IMapper _mapper;

public GetCategoryDetailQueryHandler(IApplicationDbContext context,IMapper mapper)
{
_context = context;
_mapper = mapper;
}
public async Task<CategoryDetailVm> Handle(GetCategoryDetailQuery request, CancellationToken cancellationToken)
{
var viewModel = await _context.Categories
.ProjectTo<CategoryDetailVm>(_mapper.ConfigurationProvider)
.FirstOrDefaultAsync(p => p.CategoryId == request.Id, cancellationToken);

if (viewModel == null) throw new NotFoundException(nameof(Category), request.Id);

var issueTicketList = await _context.IssueTickets.ProjectTo<IssueTicketDto>(_mapper.ConfigurationProvider)
.Where(c => c.CategoryId == request.Id).ToListAsync();


viewModel.IssuesTickets = issueTicketList;
return viewModel;
}
}

}
21 changes: 21 additions & 0 deletions src/Application/Categories/Queries/GetCategoryList/CategoryDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using AutoMapper;
using CodeClinic.Application.Common.Mappings;
using CodeClinic.Application.Issues.Queries.GetIssueList;
using CodeClinic.Domain.Entities;
using System.Collections.Generic;

namespace CodeClinic.Application.Categories.Queries.GetCategoryList
{
public class CategoryDto : IMapFrom<Category>
{
public int CategoryId { get; set; }
public string Name { get; set; }
public string Description { get; set; }

public void Mapping(Profile profile)
{
profile.CreateMap<Category, CategoryDto>()
.ForMember(i => i.CategoryId, op => op.MapFrom(s => s.Id));
}
}
}
Loading