Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit 455ee77

Browse files
committed
Client - RESTful api, right HTTP verb and response codes
Brotli Response implementing Problem details as default response - https://tools.ietf.org/html/rfc7807
1 parent 796a1f3 commit 455ee77

36 files changed

Lines changed: 473 additions & 440 deletions

src/Backend/Jp.Application/AutoMapper/ViewModelToDomainMappingProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public ViewModelToDomainMappingProfile()
5555
/*
5656
* Client commands
5757
*/
58-
CreateMap<ClientViewModel, UpdateClientCommand>().ConstructUsing(c => new UpdateClientCommand(c, c.OldClientId));
58+
CreateMap<ClientViewModel, UpdateClientCommand>().ConstructUsing(c => new UpdateClientCommand(c));
5959
CreateMap<RemoveClientSecretViewModel, RemoveClientSecretCommand>().ConstructUsing(c => new RemoveClientSecretCommand(c.Id, c.ClientId));
6060
CreateMap<RemovePropertyViewModel, RemovePropertyCommand>().ConstructUsing(c => new RemovePropertyCommand(c.Id, c.ClientId));
6161
CreateMap<SaveClientSecretViewModel, SaveClientSecretCommand>().ConstructUsing(c => new SaveClientSecretCommand(c.ClientId, c.Description, c.Value, c.Type, c.Expiration, (int)c.Hash.GetValueOrDefault(HashType.Sha256)));

src/Backend/Jp.Application/Interfaces/IClientAppService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Threading.Tasks;
41
using IdentityServer4.Models;
52
using Jp.Application.ViewModels;
63
using Jp.Application.ViewModels.ClientsViewModels;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Threading.Tasks;
77

88
namespace Jp.Application.Interfaces
99
{
10-
public interface IClientAppService: IDisposable
10+
public interface IClientAppService : IDisposable
1111
{
1212
Task<IEnumerable<ClientListViewModel>> GetClients();
1313
Task<Client> GetClientDetails(string clientId);
14-
Task Update(ClientViewModel client);
14+
Task Update(string id, ClientViewModel client);
1515
Task<IEnumerable<SecretViewModel>> GetSecrets(string clientId);
1616
Task RemoveSecret(RemoveClientSecretViewModel model);
1717
Task SaveSecret(SaveClientSecretViewModel model);

src/Backend/Jp.Application/Services/ClientAppService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ public async Task<Client> GetClientDetails(string clientId)
5353
return _mapper.Map<Client>(resultado);
5454
}
5555

56-
public Task Update(ClientViewModel client)
56+
public Task Update(string id, ClientViewModel client)
5757
{
58-
var registerCommand = _mapper.Map<UpdateClientCommand>(client);
59-
return Bus.SendCommand(registerCommand);
58+
var updateClientCommand = _mapper.Map<UpdateClientCommand>(client).SetClientId(id);
59+
return Bus.SendCommand(updateClientCommand);
6060
}
6161

6262
public async Task<IEnumerable<SecretViewModel>> GetSecrets(string clientId)
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
using System.ComponentModel.DataAnnotations;
2-
using IdentityServer4.Models;
1+
using IdentityServer4.Models;
32

43
namespace Jp.Application.ViewModels.ClientsViewModels
54
{
65
public class ClientViewModel : Client
76
{
8-
[Required]
9-
public string OldClientId { get; set; }
107
}
118
}

src/Backend/Jp.Application/ViewModels/ClientsViewModels/CopyClientViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ namespace Jp.Application.ViewModels.ClientsViewModels
44
{
55
public class CopyClientViewModel
66
{
7+
public CopyClientViewModel(string clientId)
8+
{
9+
ClientId = clientId;
10+
}
11+
712
[Required]
813
public string ClientId { get; set; }
914

src/Backend/Jp.Application/ViewModels/ClientsViewModels/RemoveClientClaimViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ namespace Jp.Application.ViewModels.ClientsViewModels
44
{
55
public class RemoveClientClaimViewModel
66
{
7+
public RemoveClientClaimViewModel(string clientId, in int id)
8+
{
9+
ClientId = clientId;
10+
Id = id;
11+
}
12+
713
[Required]
814
public int Id { get; set; }
915
[Required]

src/Backend/Jp.Application/ViewModels/ClientsViewModels/RemoveClientSecretViewModel.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
using System.Collections.Generic;
2-
using System.ComponentModel.DataAnnotations;
3-
using System.Text;
1+
using System.ComponentModel.DataAnnotations;
42

53
namespace Jp.Application.ViewModels.ClientsViewModels
64
{
75
public class RemoveClientSecretViewModel
86
{
7+
8+
public RemoveClientSecretViewModel(string clientId, int id)
9+
{
10+
ClientId = clientId;
11+
Id = id;
12+
}
13+
914
[Required]
1015
public int Id { get; set; }
1116
[Required]

src/Backend/Jp.Application/ViewModels/ClientsViewModels/RemoveClientViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ namespace Jp.Application.ViewModels.ClientsViewModels
44
{
55
public class RemoveClientViewModel
66
{
7+
public RemoveClientViewModel(string clientId)
8+
{
9+
ClientId = clientId;
10+
}
11+
712
[Required]
813
public string ClientId { get; set; }
914

src/Backend/Jp.Application/ViewModels/ClientsViewModels/RemovePropertyViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ namespace Jp.Application.ViewModels.ClientsViewModels
44
{
55
public class RemovePropertyViewModel
66
{
7+
public RemovePropertyViewModel(int id, string clientId)
8+
{
9+
Id = id;
10+
ClientId = clientId;
11+
}
712
[Required]
813
public int Id { get; set; }
914
[Required]

src/Backend/Jp.Domain/CommandHandlers/ClientCommandHandler.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using IdentityServer4.EntityFramework.Mappers;
12
using Jp.Domain.Commands.Clients;
23
using Jp.Domain.Core.Bus;
34
using Jp.Domain.Core.Notifications;
@@ -9,7 +10,6 @@
910
using System.Linq;
1011
using System.Threading;
1112
using System.Threading.Tasks;
12-
using IdentityServer4.EntityFramework.Mappers;
1313

1414
namespace Jp.Domain.CommandHandlers
1515
{
@@ -57,7 +57,7 @@ public async Task<bool> Handle(RemoveClientCommand request, CancellationToken ca
5757
var savedClient = await _clientRepository.GetByClientId(request.Client.ClientId);
5858
if (savedClient == null)
5959
{
60-
await Bus.RaiseEvent(new DomainNotification("1", "Client not found"));
60+
await Bus.RaiseEvent(new DomainNotification("Client", "Client not found"));
6161
return false;
6262
}
6363
_clientRepository.Remove(savedClient.Id);
@@ -80,7 +80,7 @@ public async Task<bool> Handle(UpdateClientCommand request, CancellationToken ca
8080
var savedClient = await _clientRepository.GetClient(request.OldClientId);
8181
if (savedClient == null)
8282
{
83-
await Bus.RaiseEvent(new DomainNotification("1", "Client not found"));
83+
await Bus.RaiseEvent(new DomainNotification("Client", "Client not found"));
8484
return false;
8585
}
8686

@@ -108,13 +108,13 @@ public async Task<bool> Handle(RemoveClientSecretCommand request, CancellationTo
108108
var savedClient = await _clientRepository.GetClient(request.ClientId);
109109
if (savedClient == null)
110110
{
111-
await Bus.RaiseEvent(new DomainNotification("1", "Client not found"));
111+
await Bus.RaiseEvent(new DomainNotification("Client", "Client not found"));
112112
return false;
113113
}
114114

115115
if (savedClient.ClientSecrets.All(f => f.Id != request.Id))
116116
{
117-
await Bus.RaiseEvent(new DomainNotification("2", "Invalid secret"));
117+
await Bus.RaiseEvent(new DomainNotification("Client Secret", "Invalid secret"));
118118
return false;
119119
}
120120

@@ -139,7 +139,7 @@ public async Task<bool> Handle(SaveClientSecretCommand request, CancellationToke
139139
var savedClient = await _clientRepository.GetByClientId(request.ClientId);
140140
if (savedClient == null)
141141
{
142-
await Bus.RaiseEvent(new DomainNotification("1", "Client not found"));
142+
await Bus.RaiseEvent(new DomainNotification("Client", "Client not found"));
143143
return false;
144144
}
145145

@@ -166,13 +166,13 @@ public async Task<bool> Handle(RemovePropertyCommand request, CancellationToken
166166
var savedClient = await _clientRepository.GetClient(request.ClientId);
167167
if (savedClient == null)
168168
{
169-
await Bus.RaiseEvent(new DomainNotification("1", "Client not found"));
169+
await Bus.RaiseEvent(new DomainNotification("Client", "Client not found"));
170170
return false;
171171
}
172172

173173
if (savedClient.Properties.All(f => f.Id != request.Id))
174174
{
175-
await Bus.RaiseEvent(new DomainNotification("2", "Invalid secret"));
175+
await Bus.RaiseEvent(new DomainNotification("Client Properties", "Invalid Property"));
176176
return false;
177177
}
178178

@@ -197,7 +197,7 @@ public async Task<bool> Handle(SaveClientPropertyCommand request, CancellationTo
197197
var savedClient = await _clientRepository.GetByClientId(request.ClientId);
198198
if (savedClient == null)
199199
{
200-
await Bus.RaiseEvent(new DomainNotification("1", "Client not found"));
200+
await Bus.RaiseEvent(new DomainNotification("Client", "Client not found"));
201201
return false;
202202
}
203203
var property = request.ToEntiyTy(savedClient);
@@ -225,13 +225,13 @@ public async Task<bool> Handle(RemoveClientClaimCommand request, CancellationTok
225225
var savedClient = await _clientRepository.GetClient(request.ClientId);
226226
if (savedClient == null)
227227
{
228-
await Bus.RaiseEvent(new DomainNotification("1", "Client not found"));
228+
await Bus.RaiseEvent(new DomainNotification("Client", "Client not found"));
229229
return false;
230230
}
231231

232232
if (savedClient.Claims.All(f => f.Id != request.Id))
233233
{
234-
await Bus.RaiseEvent(new DomainNotification("2", "Invalid secret"));
234+
await Bus.RaiseEvent(new DomainNotification("Client Claims", "Invalid Claim"));
235235
return false;
236236
}
237237

@@ -256,7 +256,7 @@ public async Task<bool> Handle(SaveClientClaimCommand request, CancellationToken
256256
var savedClient = await _clientRepository.GetByClientId(request.ClientId);
257257
if (savedClient == null)
258258
{
259-
await Bus.RaiseEvent(new DomainNotification("1", "Client not found"));
259+
await Bus.RaiseEvent(new DomainNotification("Client", "Client not found"));
260260
return false;
261261
}
262262

@@ -283,7 +283,7 @@ public async Task<bool> Handle(SaveClientCommand request, CancellationToken canc
283283
var savedClient = await _clientRepository.GetByClientId(request.Client.ClientId);
284284
if (savedClient != null)
285285
{
286-
await Bus.RaiseEvent(new DomainNotification("1", "Client already exists"));
286+
await Bus.RaiseEvent(new DomainNotification("Client", "Client already exists"));
287287
return false;
288288
}
289289

@@ -313,7 +313,7 @@ public async Task<bool> Handle(CopyClientCommand request, CancellationToken canc
313313
var savedClient = await _clientRepository.GetByClientId(request.Client.ClientId);
314314
if (savedClient == null)
315315
{
316-
await Bus.RaiseEvent(new DomainNotification("1", "Client not found"));
316+
await Bus.RaiseEvent(new DomainNotification("Client", "Client not found"));
317317
return false;
318318
}
319319

0 commit comments

Comments
 (0)