Added IRepository comments.

Changed oder of response codes.
changed HoursPerWeek to use float not int.
Changed AssociatedIdentifierCount to use count property on AssociatedIdentifiers instead of needing to populate separately.
Changed UserCount in UserList for the same reason.
Added Users list initialisation to prevent null ref exception.
overrode Equals and GetHashCode to allow use of List.Except method. (tests show without this, Except is useless).
This commit is contained in:
chris.watts90@outlook.com 2017-01-31 21:57:21 +00:00
parent a0d050acd2
commit 440c1f44ce
5 changed files with 100 additions and 11 deletions

View File

@ -1,17 +1,82 @@
using System.Linq; namespace Interfaces
using System.Text;
using System.Threading.Tasks;
namespace Interfaces
{ {
public interface IRepository public interface IRepository
{ {
/// <summary>
/// Get a list of Users
/// </summary>
/// <returns>
/// Returns <see cref="UserList"/> with full list of users,
/// plus a total user count. Pagination options are supported.
/// </returns>
UserList GetUsers(); UserList GetUsers();
/// <summary>
/// Get details about a single user in the system base on their Id
/// </summary>
/// <param name="id">
/// integer data type, the Id of the User to get details about.</param>
/// <returns>
/// <see cref="User"/> object with full details,
/// including full <see cref="Identifier"/>
/// </returns>
User GetUser(int id); User GetUser(int id);
/// <summary>
/// Get a list of the timelogs available for the specified user
/// for the current Calendar Week
/// </summary>
/// <param name="userId">
/// integer data type, the Id of the user to get time logs for
/// </param>
/// <returns>
/// <see cref="TimeLogList"/> with nested <see cref="TimeLog"/> objects
/// for the current calendar week
/// </returns>
TimeLogList GetTimeLogs(int userId); TimeLogList GetTimeLogs(int userId);
/// <summary>
/// Get a list of the timelogs available for the specified user
/// for the specified calendar week
/// </summary>
/// <param name="userId">
/// integer data type, the Id of the user to get time logs for
/// </param>
/// <param name="calendarWeek">
/// integer data type, the calendar week to retrieve logs for.
/// </param>
/// <returns>
/// <see cref="TimeLogList"/> with nested <see cref="TimeLog"/> objects
/// for the current calendar week
/// </returns>
TimeLogList GetTimeLogs(int userId, int calendarWeek); TimeLogList GetTimeLogs(int userId, int calendarWeek);
IdentifierList GetUnassignedList(); /// <summary>
/// Get a full list of Identifiers which are not associated to a user.
/// </summary>
/// <returns>
/// <see cref="IdentifierList"/> with nested <see cref="Identifier"/> list
/// </returns>
IdentifierList GetUnassignedIdentifierList();
/// <summary>
/// Update a user in the system with the new values.
/// </summary>
/// <remarks>
/// If the user object passed does not exist, it will be created.
/// </remarks>
/// <param name="user">
/// <see cref="User"/> object detailing the new properties to assign to the user.
/// The Id Field should not be changed, or should be -1 for new users.
/// </param>
/// <returns>
/// <see cref="OperationResponse"/> to indicate procedure status.
/// </returns>
OperationResponse UpdateUser(User user); OperationResponse UpdateUser(User user);
/// <summary>
/// Create a new TimeLog Event in the repository.
/// </summary>
/// <param name="identifier">
/// <see cref="Identifier"/> object with the Unique Id triggering the event
/// </param>
/// <returns>
/// <see cref="OperationResponse"/> to indicate procedure status.
/// </returns>
OperationResponse LogEventTime(Identifier identifier); OperationResponse LogEventTime(Identifier identifier);
} }
} }

View File

@ -5,5 +5,20 @@
public int Id { get; set; } public int Id { get; set; }
public string UniqueId { get; set; } public string UniqueId { get; set; }
public bool IsAssociatedToUser { get; set; } public bool IsAssociatedToUser { get; set; }
public override bool Equals(object obj)
{
var identObj = obj as Identifier;
if (identObj == null) return false;
return identObj.Id == Id
&& identObj.IsAssociatedToUser == IsAssociatedToUser
&& identObj.UniqueId == UniqueId;
}
public override int GetHashCode()
{
return Id.GetHashCode() ^ UniqueId.GetHashCode() ^ IsAssociatedToUser.GetHashCode();
}
} }
} }

View File

@ -4,8 +4,8 @@
{ {
NONE = 0, NONE = 0,
SUCCESS = 1, SUCCESS = 1,
CREATED = 2, UPDATED = 2,
UPDATED = 3, CREATED = 3,
DELETED = 4, DELETED = 4,
FAILED = 5 FAILED = 5
} }

View File

@ -11,8 +11,13 @@ namespace Interfaces
public int UserId { get; set; } public int UserId { get; set; }
public string FirstName { get; set; } public string FirstName { get; set; }
public string LastName { get; set; } public string LastName { get; set; }
public int HoursPerWeek { get; set; } public float HoursPerWeek { get; set; }
public int AssociatedIdentifierCount { get; set; }
public int AssociatedIdentifierCount
{
get { return AssociatedIdentifiers.Count; }
}
public List<Identifier> AssociatedIdentifiers { get; set; } public List<Identifier> AssociatedIdentifiers { get; set; }
} }
} }

View File

@ -4,7 +4,11 @@ namespace Interfaces
{ {
public class UserList public class UserList
{ {
public int UserCount { get; set; } public UserList()
{
Users = new List<User>();
}
public int UserCount { get { return Users.Count; } }
public List<User> Users { get; set; } public List<User> Users { get; set; }
public int PageSize { get; set; } public int PageSize { get; set; }
public int PageNumber { get; set; } public int PageNumber { get; set; }