Revize 47db00b8
Přidáno uživatelem Milan Hotovec před téměř 4 roky(ů)
src/Core/Domain/Leuze.Core.Domain/Repositories/IDomainUserRepository.cs | ||
---|---|---|
87 | 87 |
/// <returns></returns> |
88 | 88 |
Task<List<UserShortDto>> GetAllUsersForTL(Guid id); |
89 | 89 |
|
90 |
/// <summary> |
|
91 |
/// |
|
92 |
/// </summary> |
|
93 |
/// <param name="id"></param> |
|
94 |
/// <returns></returns> |
|
95 |
Task<List<UserShortDto>> GetAllTLsForUser(Guid id); |
|
96 |
|
|
90 | 97 |
/// <summary> |
91 | 98 |
/// |
92 | 99 |
/// </summary> |
src/Core/Infrastructure/Leuze.Core.Infrastructure.Persistence/Repository/DomainUserRepository.cs | ||
---|---|---|
33 | 33 |
|
34 | 34 |
/// <inheritdoc/> |
35 | 35 |
public async Task<DomainUser> GetByIdAsync(Guid id) |
36 |
=> await dbSet.SingleOrDefaultAsync(o => o.UserId == id); |
|
36 |
=> await dbSet.Include(o => o.SeniorUser).SingleOrDefaultAsync(o => o.UserId == id);
|
|
37 | 37 |
|
38 | 38 |
/// <inheritdoc/> |
39 | 39 |
public async Task<DomainUser?> GetOptionalByIdAsync(Guid? ownerId) |
... | ... | |
135 | 135 |
return result.ToList(); |
136 | 136 |
} |
137 | 137 |
|
138 |
/// <inheritdoc/> |
|
139 |
public async Task<List<UserShortDto>> GetAllTLsForUser(Guid id) |
|
140 |
{ |
|
141 |
var results = new HashSet<UserShortDto>(); |
|
142 |
var curr = await GetDtoByIdAsync(id); |
|
143 |
|
|
144 |
while (curr.SeniorId != null) |
|
145 |
{ |
|
146 |
curr = await GetDtoByIdAsync(curr.SeniorId.Value); |
|
147 |
if (!results.Contains(curr)) |
|
148 |
{ |
|
149 |
results.Add(curr); |
|
150 |
} |
|
151 |
} |
|
152 |
|
|
153 |
|
|
154 |
return results.ToList(); |
|
155 |
} |
|
156 |
|
|
138 | 157 |
/// <inheritdoc/> |
139 | 158 |
public async Task<UserShortDto> GetDtoByIdAsync(Guid id) |
140 | 159 |
{ |
src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitions/Commands/LockDefinition.cs | ||
---|---|---|
1 |
using Leuze.Core.Application.CQRS; |
|
2 |
using Leuze.Core.Domain.Domains.Users.DTOs; |
|
3 |
using Leuze.Core.Domain.Repositories; |
|
4 |
using Leuze.Modules.Goal.Application.CQRS.GoalDefinitions.Queries; |
|
5 |
using Leuze.Modules.Goal.Domain.Domains; |
|
6 |
using Leuze.Modules.Goal.Domain.Repositories; |
|
7 |
using MediatR; |
|
8 |
using Microsoft.AspNetCore.Components.Authorization; |
|
9 |
using System; |
|
10 |
using System.Collections.Generic; |
|
11 |
using System.Linq; |
|
12 |
using System.Security.Claims; |
|
13 |
using System.Text; |
|
14 |
using System.Threading; |
|
15 |
using System.Threading.Tasks; |
|
16 |
|
|
17 |
namespace Leuze.Modules.Goal.Application.CQRS.GoalDefinitions.Commands |
|
18 |
{ |
|
19 |
public static class LockDefinition |
|
20 |
{ |
|
21 |
public record Command(Guid definitionId) : IBaseRequest<Response>; |
|
22 |
|
|
23 |
public record Response(); |
|
24 |
|
|
25 |
|
|
26 |
public class Handler : IBaseRequestHandler<Command, Response> |
|
27 |
{ |
|
28 |
private readonly IGlobalDefinitionAreaRepository _globalDefinitionAreaRepo; |
|
29 |
private readonly IGoalDefinitionRepository _goalDefinitionRepo; |
|
30 |
private readonly AuthenticationStateProvider _authenticationStateProvider; |
|
31 |
private readonly IDomainUserRepository _domainUserRepo; |
|
32 |
|
|
33 |
public Handler(IGlobalDefinitionAreaRepository globalDefinitionAreaRepo, IGoalDefinitionRepository goalDefinitionRepo, AuthenticationStateProvider authStateProvider, IDomainUserRepository domainUserRepo) |
|
34 |
{ |
|
35 |
_globalDefinitionAreaRepo = globalDefinitionAreaRepo; |
|
36 |
_goalDefinitionRepo = goalDefinitionRepo; |
|
37 |
_authenticationStateProvider = authStateProvider; |
|
38 |
_domainUserRepo = domainUserRepo; |
|
39 |
} |
|
40 |
|
|
41 |
public async Task<RequestResponse<Response>> Handle(Command request, CancellationToken cancellationToken) |
|
42 |
{ |
|
43 |
//TODO: user muze byt null, ale to my nechceme!!! |
|
44 |
var state = await _authenticationStateProvider.GetAuthenticationStateAsync(); |
|
45 |
var id = Guid.Parse(state.User!.FindFirst(ClaimTypes.NameIdentifier)!.Value); |
|
46 |
var editor = await _domainUserRepo.GetByIdAsync(id); |
|
47 |
var definition = await _goalDefinitionRepo.GetByIdAsync(request.definitionId); |
|
48 |
|
|
49 |
if (editor == null) |
|
50 |
{ |
|
51 |
return RequestResponse<Response>.CreateErrorResponse($"Creator user with id: {id} not found!"); |
|
52 |
} |
|
53 |
|
|
54 |
if (definition == null) |
|
55 |
{ |
|
56 |
return RequestResponse<Response>.CreateErrorResponse($"Definition with id: {request.definitionId} not found!"); |
|
57 |
} |
|
58 |
|
|
59 |
|
|
60 |
if (definition.OwnerId == id) |
|
61 |
{ |
|
62 |
definition.LockByOwner(); |
|
63 |
|
|
64 |
await _goalDefinitionRepo.UpdateRepo(); |
|
65 |
return RequestResponse<Response>.CreateSuccessResponse(new()); |
|
66 |
} |
|
67 |
|
|
68 |
var tlList = await _domainUserRepo.GetAllTLsForUser(id); |
|
69 |
|
|
70 |
if (tlList.Where(o => o.Id == id).Any()) |
|
71 |
{ |
|
72 |
definition.LockBySupervisor(); |
|
73 |
|
|
74 |
await _goalDefinitionRepo.UpdateRepo(); |
|
75 |
return RequestResponse<Response>.CreateSuccessResponse(new()); |
|
76 |
} |
|
77 |
|
|
78 |
return RequestResponse<Response>.CreateErrorResponse("Nothing changed!"); |
|
79 |
} |
|
80 |
} |
|
81 |
} |
|
82 |
} |
src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/Goals/Commands/EditGoal.cs | ||
---|---|---|
23 | 23 |
public class Handler : IBaseRequestHandler<Command, Response> |
24 | 24 |
{ |
25 | 25 |
private readonly IGoalItemRepository _goalItemRepo; |
26 |
private readonly IGoalDefinitionRepository _goalDefinitionRepo; |
|
26 | 27 |
private readonly IGoalUpdateRepository _goalUpdateRepo; |
27 | 28 |
private readonly AuthenticationStateProvider _authenticationStateProvider; |
28 | 29 |
private readonly IDomainUserRepository _domainUserRepository; |
29 | 30 |
|
30 |
public Handler(IGoalItemRepository goalItemRepo, IGoalUpdateRepository goalUpdateRepo, |
|
31 |
public Handler(IGoalItemRepository goalItemRepo, IGoalDefinitionRepository goalDefinitioNrepo, IGoalUpdateRepository goalUpdateRepo,
|
|
31 | 32 |
AuthenticationStateProvider authenticationStateProvider, IDomainUserRepository domainUserRepository) |
32 | 33 |
{ |
33 | 34 |
_goalItemRepo = goalItemRepo; |
35 |
_goalDefinitionRepo = goalDefinitioNrepo; |
|
34 | 36 |
_goalUpdateRepo = goalUpdateRepo; |
35 | 37 |
_authenticationStateProvider = authenticationStateProvider; |
36 | 38 |
_domainUserRepository = domainUserRepository; |
... | ... | |
71 | 73 |
GoalUpdate nameUpdate = new(user, goal, UpdateType.Name, goal.Name, request.name); |
72 | 74 |
|
73 | 75 |
await _goalItemRepo.SetNameAsync(request.goalId, request.name); |
76 |
await _goalItemRepo.LocksReset(request.goalId); |
|
77 |
await _goalDefinitionRepo.LocksReset(goal.GoalDefinitionId); |
|
74 | 78 |
await _goalUpdateRepo.AddAsync(nameUpdate); |
75 | 79 |
|
76 | 80 |
sendState = true; |
... | ... | |
81 | 85 |
GoalUpdate descUpdate = new(user, goal, UpdateType.Description, goal.Description, request.description); |
82 | 86 |
|
83 | 87 |
await _goalItemRepo.SetDescriptionAsync(request.goalId, request.description); |
88 |
await _goalItemRepo.LocksReset(request.goalId); |
|
89 |
await _goalDefinitionRepo.LocksReset(goal.GoalDefinitionId); |
|
84 | 90 |
await _goalUpdateRepo.AddAsync(descUpdate); |
85 | 91 |
|
86 | 92 |
sendState = true; |
src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/Goals/Commands/LockGoal.cs | ||
---|---|---|
1 |
using Leuze.Core.Application.CQRS; |
|
2 |
using Leuze.Core.Domain.Repositories; |
|
3 |
using Leuze.Modules.Goal.Domain.Domains; |
|
4 |
using Leuze.Modules.Goal.Domain.Repositories; |
|
5 |
using Microsoft.AspNetCore.Components.Authorization; |
|
6 |
using System; |
|
7 |
using System.Collections.Generic; |
|
8 |
using System.Linq; |
|
9 |
using System.Security.Claims; |
|
10 |
using System.Text; |
|
11 |
using System.Threading; |
|
12 |
using System.Threading.Tasks; |
|
13 |
|
|
14 |
namespace Leuze.Modules.Goal.Application.CQRS.Goals.Commands |
|
15 |
{ |
|
16 |
public static class LockGoal |
|
17 |
{ |
|
18 |
public record Command(Guid goalId) : IBaseRequest<Response>; |
|
19 |
|
|
20 |
public record Response(); |
|
21 |
|
|
22 |
|
|
23 |
public class Handler : IBaseRequestHandler<Command, Response> |
|
24 |
{ |
|
25 |
private readonly IGoalItemRepository _goalItemRepo; |
|
26 |
private readonly IGoalUpdateRepository _goalUpdateRepo; |
|
27 |
private readonly AuthenticationStateProvider _authenticationStateProvider; |
|
28 |
private readonly IDomainUserRepository _domainUserRepository; |
|
29 |
|
|
30 |
public Handler(IGoalItemRepository goalItemRepo, IGoalUpdateRepository goalUpdateRepo, |
|
31 |
AuthenticationStateProvider authenticationStateProvider, IDomainUserRepository domainUserRepository) |
|
32 |
{ |
|
33 |
_goalItemRepo = goalItemRepo; |
|
34 |
_goalUpdateRepo = goalUpdateRepo; |
|
35 |
_authenticationStateProvider = authenticationStateProvider; |
|
36 |
_domainUserRepository = domainUserRepository; |
|
37 |
} |
|
38 |
|
|
39 |
public async Task<RequestResponse<Response>> Handle(Command request, CancellationToken cancellationToken) |
|
40 |
{ |
|
41 |
//TODO: user muze byt null, ale to my nechceme!!! |
|
42 |
var state = await _authenticationStateProvider.GetAuthenticationStateAsync(); |
|
43 |
var id = Guid.Parse(state.User!.FindFirst(ClaimTypes.NameIdentifier)!.Value); |
|
44 |
var user = await _domainUserRepository.GetByIdAsync(id); |
|
45 |
|
|
46 |
var goal = await _goalItemRepo.GetByIdAsync(request.goalId); |
|
47 |
|
|
48 |
if (user == null) |
|
49 |
{ |
|
50 |
return RequestResponse<Response>.CreateErrorResponse($"Uživatel s ID: {id} nebyl nalezen!"); |
|
51 |
} |
|
52 |
|
|
53 |
if (goal == null) |
|
54 |
{ |
|
55 |
return RequestResponse<Response>.CreateErrorResponse($"Cíl s ID: {request.goalId} nebyl nalezen!"); |
|
56 |
} |
|
57 |
|
|
58 |
if (goal.IsLocked()) |
|
59 |
{ |
|
60 |
return RequestResponse<Response>.CreateErrorResponse($"Cíl s ID: {request.goalId} byl uzamčen proti přepsání!"); |
|
61 |
} |
|
62 |
|
|
63 |
if (goal.GoalDefinition.IsLocked()) |
|
64 |
{ |
|
65 |
return RequestResponse<Response>.CreateErrorResponse($"Definice s cílem je uzamčena proti přepsání!"); |
|
66 |
} |
|
67 |
|
|
68 |
if(goal.GoalDefinition.OwnerId == id) |
|
69 |
{ |
|
70 |
GoalUpdate ownerUpdate = new(user, goal, UpdateType.OwnerLock, "true", goal.OwnerLocked.ToString()); |
|
71 |
goal.LockByOwner(); |
|
72 |
|
|
73 |
await _goalItemRepo.UpdateRepo(); |
|
74 |
await _goalUpdateRepo.AddAsync(ownerUpdate); |
|
75 |
return RequestResponse<Response>.CreateSuccessResponse(new()); |
|
76 |
} |
|
77 |
|
|
78 |
var tlList = await _domainUserRepository.GetAllTLsForUser(id); |
|
79 |
|
|
80 |
if (tlList.Where(o => o.Id == id).Any()) |
|
81 |
{ |
|
82 |
GoalUpdate supervisorUpdate = new(user, goal, UpdateType.OwnerLock, "true", goal.SupervisorLocked.ToString()); |
|
83 |
goal.LockBySupervisor(); |
|
84 |
|
|
85 |
await _goalItemRepo.UpdateRepo(); |
|
86 |
await _goalUpdateRepo.AddAsync(supervisorUpdate); |
|
87 |
return RequestResponse<Response>.CreateSuccessResponse(new()); |
|
88 |
} |
|
89 |
|
|
90 |
return RequestResponse<Response>.CreateErrorResponse($"Nic se nezměnilo!"); |
|
91 |
} |
|
92 |
} |
|
93 |
} |
|
94 |
} |
src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Domains/DTOs/CommentGenericConvertor.cs | ||
---|---|---|
20 | 20 |
return "UpdatedPercentileUser"; |
21 | 21 |
case UpdateType.PercentileFinal: |
22 | 22 |
return "UpdatedPercentileFinal"; |
23 |
case UpdateType.OwnerLock: |
|
24 |
return "UpdatedOwnerLock"; |
|
25 |
case UpdateType.SupervisorLock: |
|
26 |
return "UpdatedSupervisorLock"; |
|
23 | 27 |
default: |
24 | 28 |
return "NOT IMPLEMENTED"; |
25 | 29 |
} |
src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Domains/UpdateType.cs | ||
---|---|---|
8 | 8 |
{ |
9 | 9 |
public enum UpdateType |
10 | 10 |
{ |
11 |
Name, Description, PercentileUser, PercentileFinal, None |
|
11 |
Name, Description, PercentileUser, PercentileFinal, OwnerLock, SupervisorLock, None
|
|
12 | 12 |
} |
13 | 13 |
} |
Také k dispozici: Unified diff
Locking update