Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: improve developer experience #12

Merged
merged 39 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9d3363b
docs: add summaries for INavigatorContextExtension
elementh Nov 16, 2023
3a8589e
docs: refactor and add summaries for BundledNavigatorContextExtensions
elementh Nov 16, 2023
562af84
feat: delete old provider code
elementh Nov 16, 2023
99176d1
refactor: simplify bundled actions namespaces
elementh Nov 16, 2023
ebd37b9
refactor: rework bundled extension ActionType
elementh Nov 16, 2023
2d09536
refactor: rework bundled extension Update
elementh Nov 16, 2023
6932792
fix: correct typo on ActionType.NavigatorContextBuilderOptionsExtensions
elementh Nov 16, 2023
0e0dce0
fix: correct MessageAction.Timestamp hiding inherited member
elementh Nov 16, 2023
403b170
fix: correct username not being used correctly for Bot entity
elementh Nov 16, 2023
4ec3d3b
refactor: make Success and Error protected functions.
elementh Nov 16, 2023
f1fb4be
refactor: delete dead code
elementh Nov 16, 2023
84ef496
docs: add summaries for ActionPriorityAttribute.cs and ActionTypeAttr…
elementh Nov 16, 2023
d3f1cfe
docs: update summary for BaseAction.cs
elementh Nov 16, 2023
491e66a
docs: add and update summaries for IActionLauncher.cs, NavigatorOptio…
elementh Nov 16, 2023
d2bfb87
refactor: make Status struct readonly
elementh Nov 16, 2023
1f0a207
docs: add summary for Status.cs
elementh Nov 16, 2023
a430497
docs: update summary for UnknownAction.cs
elementh Nov 16, 2023
41e6a7a
docs: update summaries for some configuration extensions
elementh Nov 16, 2023
97bd1bf
refactor: delete dead code
elementh Nov 16, 2023
7331dd5
docs: update summary for NavigatorDbContext.cs
elementh Nov 17, 2023
02d486c
docs: update summary for INavigatorOptions.cs and NavigatorOptions.cs
elementh Nov 17, 2023
4b97424
docs: update summary for TelegramMiddleware.cs
elementh Nov 17, 2023
d9604f3
docs: update summaries for INavigatorContext.cs and INavigatorContext…
elementh Nov 17, 2023
7e108ad
docs: update summary for INavigatorContextAccessor.cs
elementh Nov 17, 2023
11689ca
docs: update summary for INavigatorContext.cs
elementh Nov 17, 2023
dd14d70
docs: update summaries for INavigatorClient.cs and NavigatorConfigura…
elementh Nov 17, 2023
292756e
docs: update summary for NavigatorRouteConfiguration.cs
elementh Nov 17, 2023
b0eedc2
docs: update summary for INavigatorContextBuilder.cs
elementh Nov 17, 2023
fd47257
docs: update summary for NavigatorOptionsCollectionExtensions.cs
elementh Nov 17, 2023
2a29026
docs: update summary for Chat.cs
elementh Nov 17, 2023
6d2d45d
docs: update summary for Chat.cs on Store Extension
elementh Nov 17, 2023
27b5168
docs: update summaries for NavigatorException.cs and NavigatorStoreEx…
elementh Nov 17, 2023
22bf928
docs: update summaries for Conversation.cs and NavigatorContextExtens…
elementh Nov 17, 2023
c87126c
docs: update summaries for some Update actions
elementh Nov 17, 2023
c59d497
docs: update summary for PollAnswerAction.cs
elementh Nov 17, 2023
9185763
docs: update summary for INavigatorContextBuilderOptions.cs
elementh Nov 17, 2023
5fcec36
docs: update summary for NavigatorContextBuilderOptions.cs
elementh Nov 17, 2023
c6a2944
docs: update summary for some Update actions
elementh Nov 17, 2023
e3a9d26
docs: update summary for some IActionMiddleware.cs
elementh Nov 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Navigator.Extensions.Store/Context/NavigatorDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,24 @@ public NavigatorDbContext(DbContextOptions<NavigatorDbContext> options) : base(o
{
}

/// <summary>
/// Bots.
/// </summary>
public required DbSet<Bot> Bots { get; set; }

/// <summary>
/// Users.
/// </summary>
public required DbSet<User> Users { get; set; }

/// <summary>
/// Chats.
/// </summary>
public required DbSet<Chat> Chats { get; set; }

/// <summary>
/// Conversations.
/// </summary>
public required DbSet<Conversation> Conversations { get; set; }

/// <inheritdoc />
Expand Down
22 changes: 22 additions & 0 deletions src/Navigator.Extensions.Store/Entities/Chat.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Navigator.Entities;

namespace Navigator.Extensions.Store.Entities;

/// <summary>
Expand Down Expand Up @@ -32,10 +34,30 @@ public Chat(Navigator.Entities.Chat chat)
}


/// <summary>
/// Id of the chat.
/// </summary>
public long Id { get; set; }

/// <summary>
/// Title of the chat.
/// <remarks>
/// Optional.
/// </remarks>
/// </summary>
public string? Title { get; set; }

/// <summary>
/// Type of the chat, can be any of <see cref="Navigator.Entities.Chat.ChatType"/>.
/// </summary>
public Navigator.Entities.Chat.ChatType Type { get; set; }

/// <summary>
/// If the supergroup chat is a forum (has topics enabled).
/// <remarks>
/// Optional.
/// </remarks>
/// </summary>
public bool? IsForum { get; set; }

/// <summary>
Expand Down
9 changes: 9 additions & 0 deletions src/Navigator.Extensions.Store/Entities/Conversation.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace Navigator.Extensions.Store.Entities;

/// <summary>
/// Conversation.
/// </summary>
public class Conversation
{
/// <summary>
Expand All @@ -21,13 +24,19 @@ public Conversation(User user, Chat chat)
FirstInteractionAt = DateTime.UtcNow;
}

/// <summary>
/// Id of the user.
/// </summary>
public long UserId { get; set; }

/// <summary>
/// User.
/// </summary>
public User User { get; set; } = null!;

/// <summary>
/// Id of the chat.
/// </summary>
public long ChatId { get; set; }

/// <summary>
Expand Down
5 changes: 3 additions & 2 deletions src/Navigator.Extensions.Store/NavigatorContextExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Navigator.Context;
using Navigator.Extensions.Bundled.OriginalEvent;
using Navigator.Extensions.Store.Context;
using Telegram.Bot.Types;

namespace Navigator.Extensions.Store;

/// <summary>
/// Extensions for <see cref="NavigatorContext"/>.
/// </summary>
public static class NavigatorContextExtensions
{
#region NavigatorStore
Expand Down
7 changes: 7 additions & 0 deletions src/Navigator.Extensions.Store/NavigatorStoreException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@

namespace Navigator.Extensions.Store;

/// <summary>
/// Navigator Store exception.
/// </summary>
public class NavigatorStoreException : NavigatorException
{
/// <inheritdoc />
public NavigatorStoreException()
{
}

/// <inheritdoc />
protected NavigatorStoreException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}

/// <inheritdoc />
public NavigatorStoreException(string? message) : base(message)
{
}

/// <inheritdoc />
public NavigatorStoreException(string? message, Exception? innerException) : base(message, innerException)
{
}
Expand Down
33 changes: 29 additions & 4 deletions src/Navigator/Actions/ActionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,49 @@

namespace Navigator.Actions;

/// <summary>
/// Implement to handle an action.
/// </summary>
/// <typeparam name="TAction"></typeparam>
public abstract class ActionHandler<TAction> : IRequestHandler<TAction, Status> where TAction : IAction
{
/// <summary>
/// Context for the action.
/// </summary>
public readonly INavigatorContext Context;

/// <summary>
/// Default constructor.
/// </summary>
/// <param name="navigatorContextAccessor"></param>
protected ActionHandler(INavigatorContextAccessor navigatorContextAccessor)
{
Context = navigatorContextAccessor.NavigatorContext;
}

/// <summary>
/// Handles the action.
/// </summary>
/// <param name="action"></param>
/// <param name="cancellationToken"></param>
/// <returns><see cref="Status"/></returns>
public abstract Task<Status> Handle(TAction action, CancellationToken cancellationToken);

public static Status Success()
/// <summary>
/// Called when the action was handled successfully.
/// </summary>
/// <returns><see cref="Status"/></returns>
protected static Status Success()
{
return new(true);
return new Status(true);
}

public static Status Error()
/// <summary>
/// Called when the action was not handled successfully.
/// </summary>
/// <returns><see cref="Status"/></returns>
protected static Status Error()
{
return new(false);
return new Status(false);
}
}
6 changes: 0 additions & 6 deletions src/Navigator/Actions/ActionHandlerExtensions.cs

This file was deleted.

7 changes: 7 additions & 0 deletions src/Navigator/Actions/Attributes/ActionPriorityAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ namespace Navigator.Actions.Attributes;
[System.AttributeUsage(System.AttributeTargets.Class)]
public class ActionPriorityAttribute : System.Attribute
{
/// <summary>
/// Priority.
/// </summary>
public readonly ushort Priority;

/// <summary>
/// Sets the action priority.
/// </summary>
/// <param name="priority"></param>
public ActionPriorityAttribute(ushort priority)
{
Priority = priority;
Expand Down
12 changes: 11 additions & 1 deletion src/Navigator/Actions/Attributes/ActionTypeAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
namespace Navigator.Actions.Attributes;

/// <summary>
/// Attribute for setting the action type.
/// </summary>
[System.AttributeUsage(System.AttributeTargets.Class)]
public class ActionTypeAttribute : System.Attribute
{
public string ActionType;
/// <summary>
/// Action type.
/// </summary>
public readonly string ActionType;

/// <summary>
/// Sets the action type.
/// </summary>
/// <param name="action"></param>
public ActionTypeAttribute(string action)
{
ActionType = action;
Expand Down
3 changes: 3 additions & 0 deletions src/Navigator/Actions/BaseAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public abstract class BaseAction : IAction
/// </summary>
protected INavigatorContext Context => _navigatorContextAccessor.NavigatorContext;

/// <summary>
/// Priority of the request.
/// </summary>
public virtual ushort Priority { get; protected set; } = Actions.Priority.Default;

/// <summary>
Expand Down
7 changes: 7 additions & 0 deletions src/Navigator/Actions/IActionLauncher.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
namespace Navigator.Actions;

/// <summary>
/// Action launcher interface.
/// </summary>
public interface IActionLauncher
{
/// <summary>
/// Launches one or more actions.
/// </summary>
/// <returns></returns>
Task Launch();
}
2 changes: 1 addition & 1 deletion src/Navigator/Actions/IActionMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Navigator.Actions;

/// <summary>
/// TODO
/// Interface to implement middleware for actions.
/// </summary>
/// <typeparam name="TAction"></typeparam>
/// <typeparam name="TResponse"></typeparam>
Expand Down
3 changes: 3 additions & 0 deletions src/Navigator/Actions/NavigatorOptionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Navigator.Actions;

/// <summary>
/// Extensions for <see cref="NavigatorOptions"/>.
/// </summary>
public static class NavigatorOptionsExtensions
{
#region NavigatorActionTypeCollection
Expand Down
14 changes: 14 additions & 0 deletions src/Navigator/Actions/Priority.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
namespace Navigator.Actions;

/// <summary>
/// Priority presets.
/// </summary>
public static class Priority
{
/// <summary>
/// Low priority.
/// </summary>
public const ushort Low = 15000;

/// <summary>
/// Default priority
/// </summary>
public const ushort Default = 10000;

/// <summary>
/// High priority.
/// </summary>
public const ushort High = 5000;
}
16 changes: 15 additions & 1 deletion src/Navigator/Actions/Status.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
namespace Navigator.Actions;

public struct Status
/// <summary>
/// Represents the outcome of an action.
/// </summary>
public readonly struct Status
{
private readonly bool _isSuccess;

/// <summary>
/// Is success.
/// </summary>
public bool IsSuccess => _isSuccess;

/// <summary>
/// Is error.
/// </summary>
public bool IsError => !_isSuccess;

/// <summary>
/// Default constructor.
/// </summary>
/// <param name="isSuccess"></param>
public Status(bool isSuccess)
{
_isSuccess = isSuccess;
Expand Down
17 changes: 0 additions & 17 deletions src/Navigator/Bundled/Actions/ActionHandlerExtensions.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Navigator.Context.Accessor;
using Navigator.Telegram;

namespace Navigator.Bundled.Actions.Bundled;
namespace Navigator.Bundled.Actions;

/// <summary>
/// Command based action.
Expand Down
6 changes: 3 additions & 3 deletions src/Navigator/Bundled/Actions/Messages/MessageAction.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Navigator.Actions;
using Navigator.Actions.Attributes;
using Navigator.Bundled.Extensions.Update;
using Navigator.Context.Accessor;
using Navigator.Extensions.Bundled;
using Telegram.Bot.Types;

namespace Navigator.Bundled.Actions.Messages;
Expand All @@ -25,7 +25,7 @@ public abstract class MessageAction : BaseAction
/// <summary>
/// Timestamp of the message creation.
/// </summary>
public readonly DateTime Timestamp;
public new readonly DateTime Timestamp;

/// <summary>
/// Determines if this message is a reply to another message.
Expand All @@ -40,7 +40,7 @@ public abstract class MessageAction : BaseAction
/// <inheritdoc />
protected MessageAction(INavigatorContextAccessor navigatorContextAccessor) : base(navigatorContextAccessor)
{
var update = navigatorContextAccessor.NavigatorContext.GetOriginalEvent();
var update = navigatorContextAccessor.NavigatorContext.GetUpdate();

Message = update.Message!;
ChatId = Context.Conversation.Chat!.Id;
Expand Down
1 change: 0 additions & 1 deletion src/Navigator/Bundled/Actions/Messages/PhotoAction.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Navigator.Actions.Attributes;
using Navigator.Bundled.Actions.Bundled;
using Navigator.Context.Accessor;
using Navigator.Telegram;
using Telegram.Bot.Types;
Expand Down
1 change: 0 additions & 1 deletion src/Navigator/Bundled/Actions/Messages/TextAction.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Navigator.Actions.Attributes;
using Navigator.Bundled.Actions.Bundled;
using Navigator.Context.Accessor;
using Navigator.Telegram;

Expand Down
Loading
Loading