Skip to content

Commit

Permalink
Merge pull request #12 from navigatorframework/feature/improve-develo…
Browse files Browse the repository at this point in the history
…per-experience

feature: improve developer experience
  • Loading branch information
elementh authored Nov 17, 2023
2 parents a508bfa + e3a9d26 commit 08fb3ab
Show file tree
Hide file tree
Showing 69 changed files with 592 additions and 518 deletions.
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

0 comments on commit 08fb3ab

Please sign in to comment.