unit TimeEntry.Service;

interface

uses
  System.Generics.Collections,
  XData.Service.Common,
  Bcl.Types.Nullable,
  Aurelius.Mapping.Attributes;

const
  API_MODEL = 'Api';

type
  TTimeEntry = class
  public
    entryId: Integer;
    taskDate: string;
    taskId: string;
    taskDisplay: string;
    hours: Nullable<Double>;
    taskTime: string;
    category: string;
    categoryDesc: string;
    summary: string;
  end;

  TTimeEntryTaskOption = class
  public
    taskId: string;
    taskDisplay: string;
  end;

  TTimeEntryCategoryOption = class
  public
    code: string;
    codeDesc: string;
  end;

  TTimeEntriesResponse = class
  public
    userName: string;
    count: Integer;
    items: TList<TTimeEntry>;
    taskOptions: TList<TTimeEntryTaskOption>;
    categoryOptions: TList<TTimeEntryCategoryOption>;
    constructor Create;
    destructor Destroy; override;
  end;

  TTimeEntrySave = class
  public
    entryId: string;
    userId: string;
    taskDate: string;
    taskId: string;
    hours: Double;
    taskTime: string;
    category: string;
    summary: string;
  end;

  [ServiceContract, Model(API_MODEL)]
  ITimeEntryService = interface(IInvokable)
    ['{B18BCD1E-B19A-4D25-BBA9-50A24FC4C690}']
    [HttpGet] function GetTimeEntries(userId, startDate, endDate: string): TTimeEntriesResponse;
    [HttpPost] function AddTimeEntry(userId, taskDate: string): string;
    [HttpPost] function SaveTimeEntry(Item: TTimeEntrySave): Boolean;
  end;

implementation

constructor TTimeEntriesResponse.Create;
begin
  inherited;
  items := TList<TTimeEntry>.Create;
  taskOptions := TList<TTimeEntryTaskOption>.Create;
  categoryOptions := TList<TTimeEntryCategoryOption>.Create;
end;

destructor TTimeEntriesResponse.Destroy;
begin
  items.Free;
  taskOptions.Free;
  categoryOptions.Free;
  inherited;
end;

initialization
  RegisterServiceType(TypeInfo(ITimeEntryService));

end.
