Revize af485ed9
Přidáno uživatelem Milan Hotovec před téměř 4 roky(ů)
src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/Goals/Commands/CreateGoal.cs | ||
---|---|---|
1 |
using Leuze.Core.Application.CQRS; |
|
2 |
using Leuze.Core.Domain.Domains.Users.Services.Abstractions; |
|
3 |
using Leuze.Modules.Goal.Domain.Domains; |
|
4 |
using Leuze.Modules.Goal.Domain.Repositories; |
|
5 |
using System; |
|
6 |
using System.Collections.Generic; |
|
7 |
using System.Linq; |
|
8 |
using System.Text; |
|
9 |
using System.Threading; |
|
10 |
using System.Threading.Tasks; |
|
11 |
|
|
12 |
namespace Leuze.Modules.Goal.Application.CQRS.Goals.Commands |
|
13 |
{ |
|
14 |
public static class CreateGoal |
|
15 |
{ |
|
16 |
public record Command(Guid GoalDefinitionId, string Name, string Description) : IBaseRequest<Response>; |
|
17 |
|
|
18 |
public record Response(GoalItem item); |
|
19 |
|
|
20 |
|
|
21 |
public class Handler : IBaseRequestHandler<Command, Response> |
|
22 |
{ |
|
23 |
private readonly IGoalItemRepository _goalItemRepo; |
|
24 |
private readonly IGoalDefinitionRepository _goalDefinitionRepo; |
|
25 |
private readonly IDomainUserProvider _domainUserProvider; |
|
26 |
|
|
27 |
public Handler(IGoalItemRepository goalItemRepo, IGoalDefinitionRepository goalDefinitionRepo, IDomainUserProvider domainuserProvider) |
|
28 |
{ |
|
29 |
_goalItemRepo = goalItemRepo; |
|
30 |
_goalDefinitionRepo = goalDefinitionRepo; |
|
31 |
_domainUserProvider = domainuserProvider; |
|
32 |
} |
|
33 |
|
|
34 |
public async Task<RequestResponse<Response>> Handle(Command request, CancellationToken cancellationToken) |
|
35 |
{ |
|
36 |
//TODO: user muze byt null, ale to my nechceme!!! |
|
37 |
var user = await _domainUserProvider.GetCurrentUserAsync(); |
|
38 |
var goalDef = await _goalDefinitionRepo.GetByIdAsync(request.GoalDefinitionId); |
|
39 |
|
|
40 |
if(goalDef == null) |
|
41 |
{ |
|
42 |
return RequestResponse<Response>.CreateErrorResponse($"Goal definition with id: {request.GoalDefinitionId} not found!"); |
|
43 |
} |
|
44 |
|
|
45 |
GoalItem item = new(goalDef, user, request.Name, request.Description); |
|
46 |
|
|
47 |
await _goalItemRepo.AddAsync(item); |
|
48 |
|
|
49 |
return RequestResponse<Response>.CreateSuccessResponse(new(item)); |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
} |
|
54 |
} |
src/Modules/Goal/Application/Leuze.Modules.Goal.Application/Class1.cs | ||
---|---|---|
1 |
using System; |
|
2 |
|
|
3 |
namespace Leuze.Modules.Goal.Application |
|
4 |
{ |
|
5 |
public class Class1 |
|
6 |
{ |
|
7 |
} |
|
8 |
} |
src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Repositories/ICommentRepository.cs | ||
---|---|---|
1 |
using ExtCore.Data.Abstractions; |
|
2 |
using System; |
|
3 |
using System.Collections.Generic; |
|
4 |
using System.Linq; |
|
5 |
using System.Text; |
|
6 |
using System.Threading.Tasks; |
|
7 |
|
|
8 |
namespace Leuze.Modules.Goal.Domain.Repositories |
|
9 |
{ |
|
10 |
public interface ICommentRepository : IRepository |
|
11 |
{ |
|
12 |
} |
|
13 |
} |
src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Repositories/IGoalDefinitionRepository.cs | ||
---|---|---|
1 |
using ExtCore.Data.Abstractions; |
|
2 |
using Leuze.Modules.Goal.Domain.Domains; |
|
3 |
using System; |
|
4 |
using System.Collections.Generic; |
|
5 |
using System.Linq; |
|
6 |
using System.Text; |
|
7 |
using System.Threading.Tasks; |
|
8 |
|
|
9 |
namespace Leuze.Modules.Goal.Domain.Repositories |
|
10 |
{ |
|
11 |
public interface IGoalDefinitionRepository : IRepository |
|
12 |
{ |
|
13 |
Task<GoalDefinition> GetByIdAsync(Guid id); |
|
14 |
} |
|
15 |
} |
src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Repositories/IGoalItemRepository.cs | ||
---|---|---|
1 |
using ExtCore.Data.Abstractions; |
|
2 |
using Leuze.Modules.Goal.Domain.Domains; |
|
3 |
using System; |
|
4 |
using System.Collections.Generic; |
|
5 |
using System.Linq; |
|
6 |
using System.Text; |
|
7 |
using System.Threading.Tasks; |
|
8 |
|
|
9 |
namespace Leuze.Modules.Goal.Domain.Repositories |
|
10 |
{ |
|
11 |
public interface IGoalItemRepository : IRepository |
|
12 |
{ |
|
13 |
|
|
14 |
Task AddAsync(GoalItem item); |
|
15 |
} |
|
16 |
} |
src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Repositories/IGoalUpdateRepository.cs | ||
---|---|---|
1 |
using ExtCore.Data.Abstractions; |
|
2 |
using System; |
|
3 |
using System.Collections.Generic; |
|
4 |
using System.Linq; |
|
5 |
using System.Text; |
|
6 |
using System.Threading.Tasks; |
|
7 |
|
|
8 |
namespace Leuze.Modules.Goal.Domain.Repositories |
|
9 |
{ |
|
10 |
public interface IGoalUpdateRepository : IRepository |
|
11 |
{ |
|
12 |
} |
|
13 |
} |
src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Repositories/IReviewRepository.cs | ||
---|---|---|
1 |
using ExtCore.Data.Abstractions; |
|
2 |
using System; |
|
3 |
using System.Collections.Generic; |
|
4 |
using System.Linq; |
|
5 |
using System.Text; |
|
6 |
using System.Threading.Tasks; |
|
7 |
|
|
8 |
namespace Leuze.Modules.Goal.Domain.Repositories |
|
9 |
{ |
|
10 |
public interface IReviewRepository : IRepository |
|
11 |
{ |
|
12 |
} |
|
13 |
} |
src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Extensions/RepositoriesExtension.cs | ||
---|---|---|
1 |
using Microsoft.Extensions.DependencyInjection; |
|
1 |
using Leuze.Modules.Goal.Domain.Repositories; |
|
2 |
using Leuze.Modules.Goal.Infrastructure.Persistence.Repositories; |
|
3 |
using Microsoft.Extensions.DependencyInjection; |
|
2 | 4 |
|
3 | 5 |
namespace Leuze.Modules.Goal.Infrastructure.Persistence.Extensions |
4 | 6 |
{ |
... | ... | |
13 | 15 |
/// <param name="services"></param> |
14 | 16 |
public static void AddRepositories(this IServiceCollection services) |
15 | 17 |
{ |
16 |
//TODO: Insert needed |
|
18 |
services.AddTransient<ICommentRepository,CommentRepository>(); |
|
19 |
services.AddTransient<IGoalDefinitionRepository,GoalDefinitionRepository>(); |
|
20 |
services.AddTransient<IGoalItemRepository,GoalItemRepository>(); |
|
21 |
services.AddTransient<IGoalUpdateRepository,GoalUpdateRepository>(); |
|
22 |
services.AddTransient<IReviewRepository,ReviewRepository>(); |
|
17 | 23 |
} |
18 | 24 |
|
19 | 25 |
} |
src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Repositories/CommentRepository.cs | ||
---|---|---|
1 |
using AutoMapper; |
|
2 |
using ExtCore.Data.Abstractions; |
|
3 |
using Leuze.Core.Infrastructure.Persistence; |
|
4 |
using Leuze.Modules.Goal.Domain.Domains; |
|
5 |
using Leuze.Modules.Goal.Domain.Repositories; |
|
6 |
using System; |
|
7 |
using System.Collections.Generic; |
|
8 |
using System.Linq; |
|
9 |
using System.Text; |
|
10 |
using System.Threading.Tasks; |
|
11 |
|
|
12 |
namespace Leuze.Modules.Goal.Infrastructure.Persistence.Repositories |
|
13 |
{ |
|
14 |
public class CommentRepository : RepositoryBase<Comment>, ICommentRepository |
|
15 |
{ |
|
16 |
public CommentRepository(IStorageContext context, IMapper mapper) : base(context, mapper) |
|
17 |
{ |
|
18 |
} |
|
19 |
} |
|
20 |
} |
src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Repositories/GoalDefinitionRepository.cs | ||
---|---|---|
1 |
using AutoMapper; |
|
2 |
using ExtCore.Data.Abstractions; |
|
3 |
using Leuze.Core.Infrastructure.Persistence; |
|
4 |
using Leuze.Modules.Goal.Domain.Domains; |
|
5 |
using Leuze.Modules.Goal.Domain.Repositories; |
|
6 |
using Microsoft.EntityFrameworkCore; |
|
7 |
using System; |
|
8 |
using System.Collections.Generic; |
|
9 |
using System.Linq; |
|
10 |
using System.Text; |
|
11 |
using System.Threading.Tasks; |
|
12 |
|
|
13 |
namespace Leuze.Modules.Goal.Infrastructure.Persistence.Repositories |
|
14 |
{ |
|
15 |
public class GoalDefinitionRepository : RepositoryBase<GoalDefinition>, IGoalDefinitionRepository |
|
16 |
{ |
|
17 |
|
|
18 |
public GoalDefinitionRepository(IStorageContext context, IMapper mapper) : base(context, mapper) |
|
19 |
{ |
|
20 |
} |
|
21 |
|
|
22 |
public async Task<GoalDefinition> GetByIdAsync(Guid id) |
|
23 |
{ |
|
24 |
return await dbSet.Where(item => item.Id == id).SingleOrDefaultAsync(); |
|
25 |
} |
|
26 |
} |
|
27 |
} |
src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Repositories/GoalItemRepository.cs | ||
---|---|---|
1 |
using AutoMapper; |
|
2 |
using ExtCore.Data.Abstractions; |
|
3 |
using Leuze.Core.Infrastructure.Persistence; |
|
4 |
using Leuze.Modules.Goal.Domain.Domains; |
|
5 |
using Leuze.Modules.Goal.Domain.Repositories; |
|
6 |
using System; |
|
7 |
using System.Collections.Generic; |
|
8 |
using System.Linq; |
|
9 |
using System.Text; |
|
10 |
using System.Threading.Tasks; |
|
11 |
|
|
12 |
namespace Leuze.Modules.Goal.Infrastructure.Persistence.Repositories |
|
13 |
{ |
|
14 |
public class GoalItemRepository : RepositoryBase<GoalItem>, IGoalItemRepository |
|
15 |
{ |
|
16 |
public GoalItemRepository(IStorageContext context, IMapper mapper) : base(context, mapper) |
|
17 |
{ |
|
18 |
} |
|
19 |
|
|
20 |
public async Task AddAsync(GoalItem item) |
|
21 |
{ |
|
22 |
await dbSet.AddAsync(item); |
|
23 |
await storageContext.SaveChangesAsync(); |
|
24 |
} |
|
25 |
} |
|
26 |
} |
src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Repositories/GoalUpdateRepository.cs | ||
---|---|---|
1 |
using AutoMapper; |
|
2 |
using ExtCore.Data.Abstractions; |
|
3 |
using Leuze.Core.Infrastructure.Persistence; |
|
4 |
using Leuze.Modules.Goal.Domain.Domains; |
|
5 |
using Leuze.Modules.Goal.Domain.Repositories; |
|
6 |
using System; |
|
7 |
using System.Collections.Generic; |
|
8 |
using System.Linq; |
|
9 |
using System.Text; |
|
10 |
using System.Threading.Tasks; |
|
11 |
|
|
12 |
namespace Leuze.Modules.Goal.Infrastructure.Persistence.Repositories |
|
13 |
{ |
|
14 |
public class GoalUpdateRepository : RepositoryBase<GoalUpdate>, IGoalUpdateRepository |
|
15 |
{ |
|
16 |
public GoalUpdateRepository(IStorageContext context, IMapper mapper) : base(context, mapper) |
|
17 |
{ |
|
18 |
} |
|
19 |
} |
|
20 |
} |
src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Repositories/ReviewRepository.cs | ||
---|---|---|
1 |
using AutoMapper; |
|
2 |
using ExtCore.Data.Abstractions; |
|
3 |
using Leuze.Core.Infrastructure.Persistence; |
|
4 |
using Leuze.Modules.Goal.Domain.Domains; |
|
5 |
using Leuze.Modules.Goal.Domain.Repositories; |
|
6 |
using System; |
|
7 |
using System.Collections.Generic; |
|
8 |
using System.Linq; |
|
9 |
using System.Text; |
|
10 |
using System.Threading.Tasks; |
|
11 |
|
|
12 |
namespace Leuze.Modules.Goal.Infrastructure.Persistence.Repositories |
|
13 |
{ |
|
14 |
public class ReviewRepository : RepositoryBase<Review>, IReviewRepository |
|
15 |
{ |
|
16 |
public ReviewRepository(IStorageContext context, IMapper mapper) : base(context, mapper) |
|
17 |
{ |
|
18 |
} |
|
19 |
} |
|
20 |
} |
Také k dispozici: Unified diff
Added GoalCreation