Skip to content

Commit

Permalink
🛠 refactor: IJiraClient.GetUserInfo() method removed in favour of (de…
Browse files Browse the repository at this point in the history
…layed) IJiraClient.UserInfo property
  • Loading branch information
nop77svk committed Jan 31, 2024
1 parent 0a3ce0b commit 6e3140e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 26 deletions.
2 changes: 1 addition & 1 deletion jwl.jira/IJiraClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public interface IJiraClient
{
Task<api.rest.common.JiraUserInfo> GetUserInfo();
api.rest.common.JiraUserInfo UserInfo { get; }

Task<WorkLogType[]> GetAvailableActivities();

Expand Down
9 changes: 2 additions & 7 deletions jwl.jira/JiraWithICTimePluginApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ public class JiraWithICTimePluginApi
: IJiraClient
{
public string UserName { get; }
public api.rest.common.JiraUserInfo UserInfo => _vanillaJiraApi.UserInfo;

private readonly HttpClient _httpClient;
private readonly VanillaJiraClient _vanillaJiraApi;

public JiraWithICTimePluginApi(HttpClient httpClient, string userName)
{
Expand All @@ -24,13 +26,6 @@ public JiraWithICTimePluginApi(HttpClient httpClient, string userName)
_vanillaJiraApi = new VanillaJiraClient(httpClient, userName);
}

private readonly VanillaJiraClient _vanillaJiraApi;

public async Task<JiraUserInfo> GetUserInfo()
{
return await _vanillaJiraApi.GetUserInfo();
}

public async Task<WorkLogType[]> GetAvailableActivities()
{
return await _vanillaJiraApi.GetAvailableActivities();
Expand Down
15 changes: 5 additions & 10 deletions jwl.jira/JiraWithTempoPluginApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,16 @@ public class JiraWithTempoPluginApi
private const string WorklogTypeAttributeKey = @"_WorklogType_";

private readonly HttpClient _httpClient;
private readonly VanillaJiraClient _vanillaJiraServerApi;
private readonly VanillaJiraClient _vanillaJiraApi;

public string UserName { get; }
public api.rest.common.JiraUserInfo UserInfo => _vanillaJiraApi.UserInfo;

public JiraWithTempoPluginApi(HttpClient httpClient, string userName)
{
_httpClient = httpClient;
_vanillaJiraServerApi = new VanillaJiraClient(httpClient, userName);

UserName = userName;
}

public async Task<JiraUserInfo> GetUserInfo()
{
return await _vanillaJiraServerApi.GetUserInfo();
_vanillaJiraApi = new VanillaJiraClient(httpClient, userName);
}

public async Task<api.rest.response.TempoWorklogAttributeDefinition[]> GetWorklogAttributeDefinitions()
Expand Down Expand Up @@ -60,7 +55,7 @@ public async Task<WorkLog[]> GetIssueWorklogs(DateOnly from, DateOnly to, string

public async Task<WorkLog[]> GetIssueWorklogs(DateOnly from, DateOnly to, IEnumerable<string>? issueKeys)
{
string userKey = _vanillaJiraServerApi.UserInfo.Key ?? throw new ArgumentNullException($"{nameof(_vanillaJiraServerApi.UserInfo)}.{nameof(_vanillaJiraServerApi.UserInfo.Key)}");
string userKey = UserInfo.Key ?? throw new ArgumentNullException($"{nameof(UserInfo)}.{nameof(UserInfo.Key)}");

var request = new api.rest.request.TempoFindWorklogs(from, to)
{
Expand Down Expand Up @@ -94,7 +89,7 @@ public async Task AddWorklog(string issueKey, DateOnly day, int timeSpentSeconds

public async Task AddWorklogPeriod(string issueKey, DateOnly dayFrom, DateOnly dayTo, int timeSpentSeconds, string? tempoWorklogType, string? comment, bool includeNonWorkingDays = false)
{
string userKey = _vanillaJiraServerApi.UserInfo.Key ?? throw new ArgumentNullException($"{nameof(_vanillaJiraServerApi.UserInfo)}.{nameof(_vanillaJiraServerApi.UserInfo.Key)}");
string userKey = UserInfo.Key ?? throw new ArgumentNullException($"{nameof(UserInfo)}.{nameof(UserInfo.Key)}");

var request = new api.rest.request.TempoAddWorklogByIssueKey()
{
Expand Down
11 changes: 3 additions & 8 deletions jwl.jira/VanillaJiraClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ public static async Task CheckHttpResponseForErrorMessages(HttpResponseMessage r
}
}

public async Task<api.rest.common.JiraUserInfo> GetUserInfo()
{
return await GetUserInfo(_httpClient, UserName);
}

#pragma warning disable CS1998
public async Task<WorkLogType[]> GetAvailableActivities()
{
Expand Down Expand Up @@ -186,14 +181,14 @@ public async Task UpdateWorklog(string issueKey, long worklogId, DateOnly day, i
await CheckHttpResponseForErrorMessages(response);
}

private static async Task<api.rest.common.JiraUserInfo> GetUserInfo(HttpClient httpClient, string userName)
private async Task<api.rest.common.JiraUserInfo> GetUserInfo()
{
UriBuilder uriBuilder = new UriBuilder()
{
Path = @"rest/api/2/user",
Query = new UriQueryBuilder()
.Add(@"username", userName)
.Add(@"username", UserName)
};
return await httpClient.GetAsJsonAsync<api.rest.common.JiraUserInfo>(uriBuilder.Uri.PathAndQuery);
return await _httpClient.GetAsJsonAsync<api.rest.common.JiraUserInfo>(uriBuilder.Uri.PathAndQuery);
}
}

0 comments on commit 6e3140e

Please sign in to comment.