-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from romandykyi/implement-invitation-links
Implement Invitation Links
- Loading branch information
Showing
27 changed files
with
2,051 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace AdvancedTodoList.Core.Dtos; | ||
|
||
/// <summary> | ||
/// Represents a DTO for invitation link view. | ||
/// </summary> | ||
public record InvitationLinkDto(int Id, string Value, DateTime ValidTo); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace AdvancedTodoList.Core.Models.TodoLists; | ||
|
||
/// <summary> | ||
/// Represents a to-do list invitation link entity. | ||
/// </summary> | ||
public class InvitationLink : IEntity<int> | ||
{ | ||
/// <summary> | ||
/// A unique identifier for the to-do list item. | ||
/// </summary> | ||
[Key] | ||
public int Id { get; set; } | ||
|
||
/// <summary> | ||
/// Foreign key of the to-do list where the link is active. | ||
/// </summary> | ||
[ForeignKey(nameof(TodoList))] | ||
public required string TodoListId { get; set; } | ||
/// <summary> | ||
/// Navigation property to the to-do list associated with this link. | ||
/// </summary> | ||
public TodoList TodoList { get; set; } = null!; | ||
|
||
/// <summary> | ||
/// A unique string value representing the link. | ||
/// </summary> | ||
public required string Value { get; set; } | ||
|
||
/// <summary> | ||
/// Date after which the link becomes invalid. | ||
/// </summary> | ||
public DateTime ValidTo { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace AdvancedTodoList.Core.Options; | ||
|
||
/// <summary> | ||
/// A class that contains invitation link options. | ||
/// </summary> | ||
public class InvitationLinkOptions | ||
{ | ||
/// <summary> | ||
/// Size of the refresh token in bytes. | ||
/// </summary> | ||
public int Size { get; set; } | ||
|
||
/// <summary> | ||
/// Days before token expires. | ||
/// </summary> | ||
public int ExpirationDays { get; set; } | ||
} |
16 changes: 16 additions & 0 deletions
16
AdvancedTodoList.Core/Repositories/IInvitationLinksRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using AdvancedTodoList.Core.Models.TodoLists; | ||
|
||
namespace AdvancedTodoList.Core.Repositories; | ||
|
||
public interface IInvitationLinksRepository : IRepository<InvitationLink, int> | ||
{ | ||
/// <summary> | ||
/// Finds an invintation link by its value asynchronously. | ||
/// </summary> | ||
/// <param name="linkValue">Value of the link.</param> | ||
/// <returns> | ||
/// A task representing asynchronous operation which contains requested link or | ||
/// <see cref="null" /> it was not found. | ||
/// </returns> | ||
Task<InvitationLink?> FindAsync(string linkValue); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using AdvancedTodoList.Core.Dtos; | ||
using AdvancedTodoList.Core.Pagination; | ||
|
||
namespace AdvancedTodoList.Core.Services; | ||
|
||
/// <summary> | ||
/// An interface for a service that manages invitation links. | ||
/// </summary> | ||
public interface IInvitationLinksService | ||
{ | ||
/// <summary> | ||
/// Joins the caller to the to-do list by invitation list asynchronously. | ||
/// </summary> | ||
/// <param name="callerId">ID of the caller.</param> | ||
/// <param name="invitationLinkValue">Invitation link to use.</param> | ||
/// <returns> | ||
/// A task representing the asynchronous operation. The task contains | ||
/// a result of the operation. | ||
/// </returns> | ||
Task<JoinByInvitationLinkResult> JoinAsync(string callerId, string invitationLinkValue); | ||
|
||
/// <summary> | ||
/// Gets invitation links associated with the to-do list asynchronously. | ||
/// </summary> | ||
/// <param name="context">To-do list context of the operation.</param> | ||
/// <param name="parameters">Pagination parameters to use.</param> | ||
/// <returns> | ||
/// A task representing the asynchronous operation. The task contains | ||
/// a result of the operation. | ||
/// </returns> | ||
Task<ServiceResponse<Page<InvitationLinkDto>>> GetInvitationLinksAsync(TodoListContext context, | ||
PaginationParameters parameters); | ||
|
||
/// <summary> | ||
/// Creates an invitation link associated to the to-do list asynchronously. | ||
/// </summary> | ||
/// <param name="context">To-do list context.</param> | ||
/// <returns> | ||
/// A task representing the asynchronous operation. The task contains | ||
/// a result of the operation. | ||
/// </returns> | ||
Task<ServiceResponse<InvitationLinkDto>> CreateAsync(TodoListContext context); | ||
|
||
/// <summary> | ||
/// Deletes an invitation link associted to the to-do list asynchronously. | ||
/// </summary> | ||
/// <param name="context">To-do list context.</param> | ||
/// <param name="linkId">ID of the link.</param> | ||
/// <returns> | ||
/// A task representing the asynchronous operation. The task contains | ||
/// a result of the operation. | ||
/// </returns> | ||
Task<ServiceResponseStatus> DeleteAsync(TodoListContext context, int linkId); | ||
} |
42 changes: 42 additions & 0 deletions
42
AdvancedTodoList.Core/Services/JoinByInvitationLinkResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using AdvancedTodoList.Core.Dtos; | ||
|
||
namespace AdvancedTodoList.Core.Services; | ||
|
||
/// <summary> | ||
/// Represents possible results of the join to-do list by invitatation link operation. | ||
/// </summary> | ||
public class JoinByInvitationLinkResult(JoinByInvitationLinkStatus status, TodoListMemberMinimalViewDto? dto = null) | ||
{ | ||
/// <summary> | ||
/// Status of the operation. | ||
/// </summary> | ||
public JoinByInvitationLinkStatus Status { get; } = status; | ||
|
||
/// <summary> | ||
/// Gets additional DTO of the member, can be <see langword="null" />. | ||
/// </summary> | ||
public TodoListMemberMinimalViewDto? Dto { get; } = dto; | ||
} | ||
|
||
/// <summary> | ||
/// Enum that represents possible result statuses of the join to-do list by invitatation link operation. | ||
/// </summary> | ||
public enum JoinByInvitationLinkStatus | ||
{ | ||
/// <summary> | ||
/// Operation was successfull. | ||
/// </summary> | ||
Success, | ||
/// <summary> | ||
/// Invitation link was not found. | ||
/// </summary> | ||
NotFound, | ||
/// <summary> | ||
/// Invitation link is expired. | ||
/// </summary> | ||
Expired, | ||
/// <summary> | ||
/// User is already a member of the to-do list. | ||
/// </summary> | ||
UserIsAlreadyMember | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.