mirror of
https://github.com/XFox111/PhonebookService.git
synced 2026-04-22 06:29:55 +03:00
Initial commit.
- Created and set up main projects - Created classes for Domain
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
namespace PhonebookService.Domain.Models;
|
||||
|
||||
#pragma warning disable CS8618 // Non-nullable property must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
|
||||
|
||||
/// <summary>
|
||||
/// Entity model that represents a record in a phonebook
|
||||
/// </summary>
|
||||
public class PhonebookRecord
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Email { get; set; }
|
||||
|
||||
public string PhoneNumber { get; set; }
|
||||
|
||||
public string FirstName { get; set; }
|
||||
|
||||
public string LastName { get; set; }
|
||||
|
||||
public string StreetAddress { get; set; }
|
||||
|
||||
public string City { get; set; }
|
||||
|
||||
public string ZipCode { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentValidation" Version="11.5.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,39 @@
|
||||
namespace PhonebookService.Domain.Queries;
|
||||
|
||||
/// <summary>
|
||||
/// A model that represents a search/filter query for phonebook
|
||||
/// </summary>
|
||||
public class PhonebookFilterQuery
|
||||
{
|
||||
/// <summary>
|
||||
/// Number of a page to show. Starts from one.
|
||||
/// </summary>
|
||||
/// <value>Default is 1</value>
|
||||
public int Page { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Optional property to filter records that contain the value in their <see cref="Models.PhonebookRecord.FirstName"/>
|
||||
/// </summary>
|
||||
public string? FirstName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional property to filter records that match the city name
|
||||
/// </summary>
|
||||
public string? City { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional property to filter records that match the phone number
|
||||
/// </summary>
|
||||
public string? Phone { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional property to filter records that match the zip code
|
||||
/// </summary>
|
||||
public string? ZipCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional property to sort the result collection by <see cref="FirstName"/>
|
||||
/// </summary>
|
||||
/// <value>Default is 0 (None)</value>
|
||||
public SortMode Sort { get; set; } = SortMode.None;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace PhonebookService.Domain.Queries;
|
||||
|
||||
/// <summary>
|
||||
/// Sorting options for <see cref="PhonebookFilterQuery"/>
|
||||
/// </summary>
|
||||
public enum SortMode
|
||||
{
|
||||
Ascending = 1,
|
||||
None = 0,
|
||||
Descending = -1
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using PhonebookService.Domain.Models;
|
||||
using PhonebookService.Domain.Queries;
|
||||
|
||||
namespace PhonebookService.Domain.Repositories;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for the phonebook repository
|
||||
/// </summary>
|
||||
public interface IPhonebookRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// Get items list based on the provided query
|
||||
/// </summary>
|
||||
/// <param name="query">Parameters for filtering and pagination</param>
|
||||
/// <returns>Collection of <see cref="Models.PhonebookRecord"/></returns>
|
||||
Task<ICollection<PhonebookRecord>> GetItemsAsync(PhonebookFilterQuery query);
|
||||
|
||||
/// <summary>
|
||||
/// Get one item by its ID
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the item</param>
|
||||
/// <returns>Matched <see cref="Models.PhonebookRecord"/> or null if none found</returns>
|
||||
Task<PhonebookRecord?> GetItemByIdAsync(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Add new item to a database
|
||||
/// </summary>
|
||||
/// <param name="item"><see cref="Models.PhonebookRecord"/> entity</param>
|
||||
/// <returns>The result <see cref="Models.PhonebookRecord"/> with assigned Id</returns>
|
||||
Task<PhonebookRecord> CreateItemAsync(PhonebookRecord item);
|
||||
|
||||
/// <summary>
|
||||
/// Updates provided item in a database
|
||||
/// </summary>
|
||||
/// <param name="item">item to update. Id is required</param>
|
||||
/// <returns>The result <see cref="Models.PhonebookRecord"/> with assigned Id</returns>
|
||||
Task<PhonebookRecord> UpdateItemAsync(PhonebookRecord item);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes provided item from a database
|
||||
/// </summary>
|
||||
/// <param name="item"><see cref="Models.PhonebookRecord"/> to delete</param>
|
||||
Task DeleteItemAsync(PhonebookRecord item);
|
||||
}
|
||||
Reference in New Issue
Block a user