Skip to content

Commit 628e359

Browse files
committed
added feature for storing last created issue id.
1 parent 5f48026 commit 628e359

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed

RedmineTelegramBot.Core/Commands.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public static class Commands
1414
public const string Unregister = "unregister";
1515
public const string ProjectList = "projectlist";
1616
public const string AddIssue = "addissue";
17+
public const string AssignIssue = "assignissue";
1718

1819
public static List<BotCommand> GetBotCommands()
1920
{
@@ -43,6 +44,11 @@ public static List<BotCommand> GetBotCommands()
4344
Command = AddIssue,
4445
Description = "Add an issue to a project."
4546
},
47+
new BotCommand()
48+
{
49+
Command = AssignIssue,
50+
Description = "Assign last added issue to a user."
51+
}
4652
};
4753
}
4854
}

RedmineTelegramBot.Core/ConversationHandler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,13 @@ private async Task ReplyWithTrackerList(Message message)
236236
private async Task AddIssue(Message message)
237237
{
238238
var response = await _redmineApiClient.AddIssue(_conversationState.CreateIssueModel);
239-
if (response.Errors != null && response.Errors.Count > 0)
239+
if (response.errors != null && response.errors.Count > 0)
240240
{
241-
await ReplyMessage(message, string.Join("\n", response.Errors));
241+
await ReplyMessage(message, string.Join("\n", response.errors));
242242
}
243243
else
244244
{
245+
_conversationState.LastIssueId = response.issue.id;
245246
await ReplyMessage(message, "Issue created.");
246247
}
247248
}

RedmineTelegramBot.Core/IRedmineApiClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public interface IRedmineApiClient
1111
{
1212
Task<IEnumerable<RedmineProjectModel>> GetProjects();
1313

14-
Task<RedmineResponseModel> AddIssue(AddIssueModel issue);
14+
Task<IssueAddedModel> AddIssue(AddIssueModel issue);
1515

1616
Task<IEnumerable<RedmineTrackerModel>> GetTrackers();
1717
}

RedmineTelegramBot.Core/Models/ConversationStateModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class ConversationStateModel
1515
public State State { get; set; } = State.Command;
1616

1717
public AddIssueModel CreateIssueModel { get; set; }
18+
19+
public int LastIssueId { get; set; }
1820
}
1921

2022
public enum State
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace RedmineTelegramBot.Core.Models
8+
{
9+
public class IssueAddedModel
10+
{
11+
public IssueModel issue { get; set; }
12+
13+
public List<string> errors { get; set; }
14+
15+
public class IssueModel
16+
{
17+
public int id { get; set; }
18+
}
19+
}
20+
}

RedmineTelegramBot.Core/RedmineApiClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ public async Task<IEnumerable<RedmineProjectModel>> GetProjects()
3838
return projects;
3939
}
4040

41-
public Task<RedmineResponseModel> AddIssue(AddIssueModel issue)
41+
public Task<IssueAddedModel> AddIssue(AddIssueModel issue)
4242
{
4343
var client = _restClientFactory.CreateRestClient();
4444

4545
var request = new RestRequest("/issues.json", DataFormat.Json);
4646
request.AddJsonBody(issue);
4747

48-
return client.PostAsync<RedmineResponseModel>(request);
48+
return client.PostAsync<IssueAddedModel>(request);
4949
}
5050

5151
public async Task<IEnumerable<RedmineTrackerModel>> GetTrackers()

0 commit comments

Comments
 (0)