Added new entity
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
namespace BeReadyBackend.DTO.Posts;
|
||||
|
||||
public class GetPostDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? Libelle { get; set; }
|
||||
public DateTime CreationDate { get; set; }
|
||||
public int Likes { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
public string? UserUsername { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using BeReadyBackend.DTO.Posts;
|
||||
using BeReadyBackend.Repositories;
|
||||
using BeReadyBackend.Services;
|
||||
using BeReadyBackend.Specifications.Posts;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace BeReadyBackend.Endpoints.Posts;
|
||||
|
||||
public class GetAllPostsEndpoint(PostsRepository postsRepository, UserService userService) : EndpointWithoutRequest<List<GetPostDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/Posts/");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
int userId = userService.GetUserIdFromToken();
|
||||
await Send.OkAsync(await postsRepository.ProjectToListAsync<GetPostDto>(new GetPostNotMeSpec(userId), ct), ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace BeReadyBackend.Endpoints.Posts;
|
||||
|
||||
public class PatchLikeEndpoint
|
||||
{
|
||||
|
||||
}
|
||||
@@ -34,11 +34,6 @@ public class GetAllUserChallengesEndpoint(UsersRepository usersRepository, UserS
|
||||
.Select(x => mapper.Map<GetUserChallengeDto>(x.RandomChallenge))
|
||||
);
|
||||
|
||||
if (user.UserGroups is not null)
|
||||
challenges.AddRange(
|
||||
user.UserGroups.Select(x => mapper.Map<GetUserChallengeDto>(x.Group))
|
||||
);
|
||||
|
||||
await Send.OkAsync(challenges.OrderByDescending(x => x.ChallengeStartDate).ToList(), ct);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using BeReadyBackend.DTO.Designations;
|
||||
using BeReadyBackend.DTO.Friends;
|
||||
using BeReadyBackend.DTO.Groups;
|
||||
using BeReadyBackend.DTO.Messages;
|
||||
using BeReadyBackend.DTO.Posts;
|
||||
using BeReadyBackend.DTO.RandomChallenges;
|
||||
using BeReadyBackend.DTO.Users;
|
||||
using BeReadyBackend.Models;
|
||||
@@ -65,5 +66,7 @@ public class EntityToDtoMappings : Profile
|
||||
CreateMap<RandomChallenge, GetRandomChallengeDto>();
|
||||
|
||||
CreateMap<Designation, GetDesignationDto>();
|
||||
|
||||
CreateMap<Post, GetPostDto>();
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,5 @@ public class Post
|
||||
[Required] public DateTime CreationDate { get; set; }
|
||||
[Required] public int Likes { get; set; } = 0;
|
||||
|
||||
public User? User { get; set; }
|
||||
public int UserId { get; set; }
|
||||
public List<UserPost>? UserPosts { get; set; }
|
||||
}
|
||||
@@ -25,4 +25,5 @@ public class User
|
||||
public List<UserRandomChallenge>? UserRandomChallenges { get; set; }
|
||||
public List<UserAchievement>? UserAchievements { get; set; }
|
||||
public List<UserGroup>? UserGroups { get; set; }
|
||||
public List<UserPost>? UserPosts { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace BeReadyBackend.Models;
|
||||
|
||||
public class UserPost
|
||||
{
|
||||
public User? User { get; set; }
|
||||
public int UserId { get; set; }
|
||||
|
||||
public Post? Post { get; set; }
|
||||
public int PostId { get; set; }
|
||||
|
||||
public bool IsLiked { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Ardalis.Specification;
|
||||
using BeReadyBackend.Models;
|
||||
|
||||
namespace BeReadyBackend.Specifications.Posts;
|
||||
|
||||
public class GetPostNotMeSpec : Specification<Post>
|
||||
{
|
||||
public GetPostNotMeSpec(int userId)
|
||||
{
|
||||
Query
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.UserId != userId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using BeReadyBackend.DTO.Posts;
|
||||
using FastEndpoints;
|
||||
using FluentValidation;
|
||||
|
||||
namespace BeReadyBackend.Validators.Posts;
|
||||
|
||||
public class GetPostDtoValidator : Validator<GetPostDto>
|
||||
{
|
||||
public GetPostDtoValidator()
|
||||
{
|
||||
RuleFor(x => x.Id)
|
||||
.NotEmpty()
|
||||
.WithMessage("Id is required")
|
||||
.GreaterThan(0)
|
||||
.WithMessage("Id must be greater than zero");
|
||||
|
||||
RuleFor(x => x.Libelle)
|
||||
.NotEmpty()
|
||||
.WithMessage("Libelle cannot be empty")
|
||||
.MaximumLength(200)
|
||||
.WithMessage("Libelle cannot exceed 100 characters")
|
||||
.MinimumLength(2)
|
||||
.WithMessage("Libelle must exceed 2 characters");
|
||||
|
||||
RuleFor(x => x.CreationDate)
|
||||
.NotEmpty()
|
||||
.WithMessage("CreationDate cannot be empty");
|
||||
|
||||
RuleFor(x => x.Likes)
|
||||
.NotEmpty()
|
||||
.WithMessage("Likes cannot be empty");
|
||||
|
||||
RuleFor(x => x.UserId)
|
||||
.NotEmpty()
|
||||
.WithMessage("UserId cannot be empty")
|
||||
.GreaterThan(0)
|
||||
.WithMessage("UserId must be greater than zero");
|
||||
|
||||
RuleFor(x => x.UserUsername)
|
||||
.NotEmpty()
|
||||
.WithMessage("UserUsername cannot be empty");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user