Add project files

This commit is contained in:
2025-10-04 13:27:29 +03:00
parent 75eba696c9
commit cc53824229
46 changed files with 3328 additions and 7 deletions

View File

@@ -0,0 +1,13 @@
namespace T120B165_ImgBoard.Dtos.Comment;
public record CommentDto(int Id, string Text, SlimUserDto Author)
{
public static CommentDto FromComment(Models.Comment comment)
{
return new CommentDto(
Id: comment.Id,
Text: comment.Text,
Author: SlimUserDto.FromUser(comment.Author)
);
}
}

View File

@@ -0,0 +1,4 @@
namespace T120B165_ImgBoard.Dtos.Comment;
public record CreateCommentDto(string Text);
public record EditCommentDto(string Text);

View File

@@ -0,0 +1,3 @@
namespace T120B165_ImgBoard.Dtos;
public record LoginDto(string Email, string Password);

View File

@@ -0,0 +1,34 @@
using System.ComponentModel.DataAnnotations;
namespace T120B165_ImgBoard.Dtos.Post;
public record CreatePostDto(string Title,
[Required]
string Description,
[Required]
List<string> Tags,
[Required]
string FileName,
[Required]
string FileMimeType,
[Required]
[Range(0, long.MaxValue, ErrorMessage = "The {0} must be a valid number and at least {1}.")]
long? FileSize
);
public record EditPostDto(string? Title, string? Description, List<string>? Tags): IValidatableObject
{
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
var allEmpty = string.IsNullOrWhiteSpace(Title) &&
string.IsNullOrWhiteSpace(Description) &&
Tags == null;
if (allEmpty)
{
yield return new ValidationResult(
"You must provide at least one value to edit: Title, Description, or Tags.",
[nameof(Title), nameof(Description), nameof(Tags)]
);
}
}
}

View File

@@ -0,0 +1,25 @@
using File = T120B165_ImgBoard.Models.File;
namespace T120B165_ImgBoard.Dtos.Post;
public record PostDto(
int Id,
string Title,
string Description,
SlimUserDto Author,
List<Models.Tag> Tags,
string? FileUrl
)
{
public static PostDto FromPost(Models.Post post, string? fileUrl)
{
return new PostDto(
Id: post.Id,
Title: post.Title,
Description: post.Description,
Author: SlimUserDto.FromUser(post.Author),
Tags: post.Tags,
FileUrl: fileUrl
);
}
}

View File

@@ -0,0 +1,3 @@
namespace T120B165_ImgBoard.Dtos;
public record RefreshDto(string RefreshToken);

View File

@@ -0,0 +1,10 @@
using System.ComponentModel.DataAnnotations;
namespace T120B165_ImgBoard.Dtos;
public record RegisterDto(
string UserName,
[EmailAddress]
string Email,
string Password
);

View File

@@ -0,0 +1,11 @@
using T120B165_ImgBoard.Models;
namespace T120B165_ImgBoard.Dtos;
public record SlimUserDto(string UserId, string UserName)
{
public static SlimUserDto FromUser(User user)
{
return new SlimUserDto(user.Id, user.UserName);
}
};

View File

@@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations;
using T120B165_ImgBoard.Models;
namespace T120B165_ImgBoard.Dtos.Tag;
public record CreateTagDto(
[Required]
TagType Type,
[Required]
[StringLength(64)]
string Name
);
public record EditTagDto([Required] TagType Type);

View File

@@ -0,0 +1,3 @@
namespace T120B165_ImgBoard.Dtos;
public record TokenDto(string AccessToken, string RefreshToken);

View File

@@ -0,0 +1,5 @@
using T120B165_ImgBoard.Models;
namespace T120B165_ImgBoard.Dtos;
public record UserDto(int Id, string Name, string Email);