Skip to content
Permalink
Browse files

Added more information to application queries

  • Loading branch information...
jgauffin committed Mar 7, 2019
1 parent a45563b commit 2b46cc22caaca368628ea6a1ebb672a955c29447
@@ -0,0 +1,10 @@
using System.Collections.Generic;
using System.Text;
using DotNetCqs;

namespace Coderr.Server.Api.Core.Accounts.Queries
{
public class ListAccounts : Query<ListAccountsResult>
{
}
}
@@ -0,0 +1,7 @@
namespace Coderr.Server.Api.Core.Accounts.Queries
{
public class ListAccountsResult
{
public ListAccountsResultItem[] Accounts { get; set; }
}
}
@@ -0,0 +1,12 @@
using System;

namespace Coderr.Server.Api.Core.Accounts.Queries
{
public class ListAccountsResultItem
{
public int AccountId { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
public DateTime CreatedAtUtc { get; set; }
}
}
@@ -43,5 +43,10 @@ protected ApplicationListItem()
/// User that requested this list is the admin of the specified application.
/// </summary>
public bool IsAdmin { get; set; }

/// <summary>
/// Number of full time developers.
/// </summary>
public decimal NumberOfDevelopers { get; set; }
}
}
@@ -39,5 +39,10 @@ public AssignIncident(int incidentId, int assignedTo, int assignedBy)
/// Incident being assigned.
/// </summary>
public int IncidentId { get; private set; }

/// <summary>
/// Optionally specify when the incident was assigned. Default = now.
/// </summary>
public DateTime? AssignedAtUtc { get; set; }
}
}
@@ -69,5 +69,10 @@ protected CloseIncident()
/// <para>Need to be named "UserId" so that the CQS mapper can add the logged in user id</para>
/// </remarks>
public int UserId { get; set; }

/// <summary>
/// When incident was closed (optional, "now" will be used when not specified)
/// </summary>
public DateTime? ClosedAtUtc { get; set; }
}
}
@@ -60,7 +60,11 @@ public async Task<ApplicationListItem[]> HandleAsync(IMessageContext context, Ge
var apps = await _applicationRepository.GetForUserAsync(query.AccountId);
result = (
from x in apps
select new ApplicationListItem(x.ApplicationId, x.ApplicationName) { IsAdmin = x.IsAdmin }
select new ApplicationListItem(x.ApplicationId, x.ApplicationName)
{
IsAdmin = x.IsAdmin,
NumberOfDevelopers = x.NumberOfDevelopers
}
).ToArray();
}
else
@@ -28,7 +28,7 @@ public async Task HandleAsync(IMessageContext context, AssignIncident message)
assignedBy = context.Principal.GetAccountId();

var incident = await _repository.GetAsync(message.IncidentId);
incident.Assign(message.AssignedTo);
incident.Assign(message.AssignedTo, message.AssignedAtUtc);
await _repository.UpdateAsync(incident);

var evt = new IncidentAssigned(message.IncidentId, assignedBy, message.AssignedTo);
@@ -19,5 +19,10 @@ public class UserApplication
/// If the user that this app is requested for is the admin
/// </summary>
public bool IsAdmin { get; set; }

/// <summary>
/// Number of full time developers.
/// </summary>
public decimal NumberOfDevelopers { get; set; }
}
}
@@ -154,12 +154,12 @@ public string Description
/// Assign this incident to someone.
/// </summary>
/// <param name="userId">User to assign to</param>
public void Assign(int userId)
public void Assign(int userId, DateTime? when = null)
{
if (userId <= 0) throw new ArgumentOutOfRangeException(nameof(userId));
AssignedAtUtc = DateTime.UtcNow;
AssignedToId = userId;
UpdatedAtUtc = DateTime.UtcNow;
UpdatedAtUtc = when ?? DateTime.UtcNow;
State = IncidentState.Active;
}

@@ -168,16 +168,17 @@ public void Assign(int userId)
/// </summary>
/// <param name="solvedBy">AccountId for whoever wrote the solution</param>
/// <param name="solution">Actual solution</param>
/// <param name="when">When was the incident closed by the user?</param>
/// <exception cref="ArgumentNullException">solution</exception>
/// <exception cref="ArgumentOutOfRangeException">solvedBy</exception>
public void Close(int solvedBy, string solution)
public void Close(int solvedBy, string solution, DateTime? when = null)
{
if (solution == null) throw new ArgumentNullException("solution");
if (solvedBy <= 0) throw new ArgumentOutOfRangeException("solvedBy");

Solution = new IncidentSolution(solvedBy, solution);
UpdatedAtUtc = DateTime.UtcNow;
SolvedAtUtc = DateTime.UtcNow;
SolvedAtUtc = when ?? DateTime.UtcNow;
State = IncidentState.Closed;
}

@@ -31,7 +31,7 @@ public async Task<UserApplication[]> GetForUserAsync(int accountId)
if (accountId <= 0) throw new ArgumentOutOfRangeException(nameof(accountId));
using (var cmd = (DbCommand) _uow.CreateCommand())
{
cmd.CommandText = @"SELECT a.Id ApplicationId, a.Name ApplicationName, ApplicationMembers.Roles
cmd.CommandText = @"SELECT a.Id ApplicationId, a.Name ApplicationName, ApplicationMembers.Roles, a.NumberOfDevelopers
FROM Applications a
JOIN ApplicationMembers ON (ApplicationMembers.ApplicationId = a.Id)
WHERE ApplicationMembers.AccountId = @userId
@@ -46,7 +46,8 @@ public async Task<UserApplication[]> GetForUserAsync(int accountId)
{
IsAdmin = reader.GetString(2).Contains("Admin"),
ApplicationName = reader.GetString(1),
ApplicationId = reader.GetInt32(0)
ApplicationId = reader.GetInt32(0),
NumberOfDevelopers = reader.GetDecimal(3)
};
apps.Add(a);
}

0 comments on commit 2b46cc2

Please sign in to comment.
You can’t perform that action at this time.