|
| 1 | +using Common.Shared; |
| 2 | +using Oak.Api.VItem; |
| 3 | +using IApi = Oak.Api.IApi; |
| 4 | + |
| 5 | +namespace Oak.Cli; |
| 6 | + |
| 7 | +public class VItem |
| 8 | +{ |
| 9 | + private readonly IApi _api; |
| 10 | + private readonly State _state; |
| 11 | + |
| 12 | + public VItem(IApi api, State state) |
| 13 | + { |
| 14 | + _api = api; |
| 15 | + _state = state; |
| 16 | + } |
| 17 | + |
| 18 | + /// <summary> |
| 19 | + /// Create a new VItem |
| 20 | + /// </summary> |
| 21 | + /// <param name="type">-ty, type of vitem</param> |
| 22 | + /// <param name="est">-e, estimated remaining value, mins for time or cents for cost</param> |
| 23 | + /// <param name="inc">-i, incurred value, mins for time or cents for cost</param> |
| 24 | + /// <param name="note">-n, note</param> |
| 25 | + /// <param name="org">-o, org id</param> |
| 26 | + /// <param name="project">-p, project id</param> |
| 27 | + /// <param name="task">-t, task id</param> |
| 28 | + /// <param name="ctkn"></param> |
| 29 | + public async Task Create( |
| 30 | + VItemType type, |
| 31 | + ulong? est, |
| 32 | + ulong inc, |
| 33 | + string note, |
| 34 | + string? org = null, |
| 35 | + string? project = null, |
| 36 | + string? task = null, |
| 37 | + CancellationToken ctkn = default |
| 38 | + ) |
| 39 | + { |
| 40 | + org = _state.GetOrg(org); |
| 41 | + project = _state.GetProject(project); |
| 42 | + task = _state.GetTask(task); |
| 43 | + var res = await _api.VItem.Create( |
| 44 | + new Create(org, project, task, type, est, inc, note), |
| 45 | + ctkn |
| 46 | + ); |
| 47 | + Io.WriteYml(res); |
| 48 | + } |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// Update a new VItem |
| 52 | + /// </summary> |
| 53 | + /// <param name="type">-ty, type of vitem</param> |
| 54 | + /// <param name="id">-i, vitem id</param> |
| 55 | + /// <param name="inc">-in, incurred value, mins for time or cents for cost</param> |
| 56 | + /// <param name="note">-n, note</param> |
| 57 | + /// <param name="org">-o, org id</param> |
| 58 | + /// <param name="project">-p, project id</param> |
| 59 | + /// <param name="task">-t, task id</param> |
| 60 | + /// <param name="ctkn"></param> |
| 61 | + public async Task Update( |
| 62 | + VItemType type, |
| 63 | + string id, |
| 64 | + ulong inc, |
| 65 | + string note, |
| 66 | + string? org = null, |
| 67 | + string? project = null, |
| 68 | + string? task = null, |
| 69 | + CancellationToken ctkn = default |
| 70 | + ) |
| 71 | + { |
| 72 | + org = _state.GetOrg(org); |
| 73 | + project = _state.GetProject(project); |
| 74 | + task = _state.GetTask(task); |
| 75 | + var res = await _api.VItem.Update( |
| 76 | + new Update(org, project, task, type, id, inc, note), |
| 77 | + ctkn |
| 78 | + ); |
| 79 | + Io.WriteYml(res); |
| 80 | + } |
| 81 | + |
| 82 | + /// <summary> |
| 83 | + /// Delete a new VItem |
| 84 | + /// </summary> |
| 85 | + /// <param name="type">-ty, type of vitem</param> |
| 86 | + /// <param name="id">-i, vitem id</param> |
| 87 | + /// <param name="org">-o, org id</param> |
| 88 | + /// <param name="project">-p, project id</param> |
| 89 | + /// <param name="task">-t, task id</param> |
| 90 | + /// <param name="ctkn"></param> |
| 91 | + public async Task Delete( |
| 92 | + VItemType type, |
| 93 | + string id, |
| 94 | + string? org = null, |
| 95 | + string? project = null, |
| 96 | + string? task = null, |
| 97 | + CancellationToken ctkn = default |
| 98 | + ) |
| 99 | + { |
| 100 | + org = _state.GetOrg(org); |
| 101 | + project = _state.GetProject(project); |
| 102 | + task = _state.GetTask(task); |
| 103 | + var res = await _api.VItem.Delete(new Exact(org, project, task, type, id), ctkn); |
| 104 | + Io.WriteYml(res); |
| 105 | + } |
| 106 | + |
| 107 | + /// <summary> |
| 108 | + /// Get VItems |
| 109 | + /// </summary> |
| 110 | + /// <param name="type">-ty, type of vitem</param> |
| 111 | + /// <param name="minCreatedOn">-mco, min created on</param> |
| 112 | + /// <param name="maxCreatedOn">-xco, max created on</param> |
| 113 | + /// <param name="createdBy">-cb, created by</param> |
| 114 | + /// <param name="after">-a, after vitem id</param> |
| 115 | + /// <param name="asc">-asc, ascending order</param> |
| 116 | + /// <param name="org">-o, org id</param> |
| 117 | + /// <param name="project">-p, project id</param> |
| 118 | + /// <param name="task">-t, task id</param> |
| 119 | + /// <param name="ctkn"></param> |
| 120 | + public async Task Get( |
| 121 | + VItemType type, |
| 122 | + DateTime? minCreatedOn = null, |
| 123 | + DateTime? maxCreatedOn = null, |
| 124 | + string? createdBy = null, |
| 125 | + string? after = null, |
| 126 | + bool asc = false, |
| 127 | + string? org = null, |
| 128 | + string? project = null, |
| 129 | + string? task = null, |
| 130 | + CancellationToken ctkn = default |
| 131 | + ) |
| 132 | + { |
| 133 | + org = _state.GetOrg(org); |
| 134 | + project = _state.GetProject(project); |
| 135 | + task = _state.GetTask(task); |
| 136 | + var res = await _api.VItem.Get( |
| 137 | + new Get( |
| 138 | + org, |
| 139 | + project, |
| 140 | + type, |
| 141 | + task, |
| 142 | + MinMax<DateTime>.Create(minCreatedOn, maxCreatedOn), |
| 143 | + createdBy, |
| 144 | + after, |
| 145 | + asc |
| 146 | + ), |
| 147 | + ctkn |
| 148 | + ); |
| 149 | + Io.WriteYml(res); |
| 150 | + } |
| 151 | +} |
0 commit comments