Add project files
This commit is contained in:
13
T120B165-ImgBoard/Dtos/Comment/CommentDto.cs
Normal file
13
T120B165-ImgBoard/Dtos/Comment/CommentDto.cs
Normal 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)
|
||||
);
|
||||
}
|
||||
}
|
||||
4
T120B165-ImgBoard/Dtos/Comment/CreateCommentDto.cs
Normal file
4
T120B165-ImgBoard/Dtos/Comment/CreateCommentDto.cs
Normal file
@@ -0,0 +1,4 @@
|
||||
namespace T120B165_ImgBoard.Dtos.Comment;
|
||||
|
||||
public record CreateCommentDto(string Text);
|
||||
public record EditCommentDto(string Text);
|
||||
3
T120B165-ImgBoard/Dtos/LoginDto.cs
Normal file
3
T120B165-ImgBoard/Dtos/LoginDto.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
namespace T120B165_ImgBoard.Dtos;
|
||||
|
||||
public record LoginDto(string Email, string Password);
|
||||
34
T120B165-ImgBoard/Dtos/Post/CreatePostDto.cs
Normal file
34
T120B165-ImgBoard/Dtos/Post/CreatePostDto.cs
Normal 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)]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
T120B165-ImgBoard/Dtos/Post/PostDto.cs
Normal file
25
T120B165-ImgBoard/Dtos/Post/PostDto.cs
Normal 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
|
||||
);
|
||||
}
|
||||
}
|
||||
3
T120B165-ImgBoard/Dtos/RefreshDto.cs
Normal file
3
T120B165-ImgBoard/Dtos/RefreshDto.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
namespace T120B165_ImgBoard.Dtos;
|
||||
|
||||
public record RefreshDto(string RefreshToken);
|
||||
10
T120B165-ImgBoard/Dtos/RegisterDto.cs
Normal file
10
T120B165-ImgBoard/Dtos/RegisterDto.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace T120B165_ImgBoard.Dtos;
|
||||
|
||||
public record RegisterDto(
|
||||
string UserName,
|
||||
[EmailAddress]
|
||||
string Email,
|
||||
string Password
|
||||
);
|
||||
11
T120B165-ImgBoard/Dtos/SlimUserDto.cs
Normal file
11
T120B165-ImgBoard/Dtos/SlimUserDto.cs
Normal 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);
|
||||
}
|
||||
};
|
||||
14
T120B165-ImgBoard/Dtos/Tag/CreateTagDto.cs
Normal file
14
T120B165-ImgBoard/Dtos/Tag/CreateTagDto.cs
Normal 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);
|
||||
3
T120B165-ImgBoard/Dtos/TokenDto.cs
Normal file
3
T120B165-ImgBoard/Dtos/TokenDto.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
namespace T120B165_ImgBoard.Dtos;
|
||||
|
||||
public record TokenDto(string AccessToken, string RefreshToken);
|
||||
5
T120B165-ImgBoard/Dtos/UserDto.cs
Normal file
5
T120B165-ImgBoard/Dtos/UserDto.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
using T120B165_ImgBoard.Models;
|
||||
|
||||
namespace T120B165_ImgBoard.Dtos;
|
||||
|
||||
public record UserDto(int Id, string Name, string Email);
|
||||
Reference in New Issue
Block a user