Skip to content
Open

1 lab #604

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
482 changes: 482 additions & 0 deletions 351002/Valinski/.gitignore

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Application.Dtos;

namespace Application.Abstractions;

public interface ILabelService
{
Task<LabelGetDto> CreateLabelAsync(LabelCreateDto labelCreateDto);
Task<List<LabelGetDto>> GetAllLabelsAsync();
Task<LabelGetDto> GetLabelByIdAsync(long id);
Task<LabelGetDto> UpdateLabelAsync(LabelUpdateDto labelUpdateDto);
Task<bool> DeleteLabelAsync(long id);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Application.Dtos;

namespace Application.Abstractions;

public interface IReactionService
{
Task<ReactionGetDto> CreateReactionAsync(ReactionCreateDto reactionCreateDto);
Task<List<ReactionGetDto>> GetAllReactionsAsync();
Task<ReactionGetDto> GetReactionByIdAsync(long id);
Task<ReactionGetDto> UpdateReactionAsync(ReactionUpdateDto reactionUpdateDto);
Task<bool> DeleteReactionAsync(long id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Application.Dtos;

namespace Application.Abstractions;

public interface ITopicService
{
Task<TopicGetDto> CreateTopicAsync(TopicCreateDto topicCreateDto);
Task<List<TopicGetDto>> GetAllTopicsAsync();
Task<TopicGetDto> GetTopicByIdAsync(long id);
Task<TopicGetDto> UpdateTopicAsync(TopicUpdateDto topicUpdateDto);
Task<bool> DeleteTopicAsync(long id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Application.Dtos;

namespace Application.Abstractions;

public interface IUserService
{
Task<UserGetDto> CreateUserAsync(UserCreateDto createDto);
Task<List<UserGetDto>> GetAllUsers();
Task<UserGetDto> GetUserById(long id);
Task<UserGetDto> UpdateUserAsync(UserUpdateDto updateDto);
Task<bool> DeleteUserAsync(long id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Domain\Domain.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Application.Dtos;

public class LabelCreateDto
{
public string Name { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Application.Dtos;

public class LabelGetDto
{
public long Id { get; set; }
public string Name { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Application.Dtos;

public class LabelUpdateDto
{
public long Id { get; set; }
public string Name { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Application.Dtos;

public class ReactionCreateDto
{
public long TopicId { get; set; }
public string Content { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Application.Dtos;

public class ReactionGetDto
{
public long Id { get; set; }
public long TopicId { get; set; }
public string Content { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Application.Dtos;

public class ReactionUpdateDto
{
public long Id { get; set; }
public long TopicId { get; set; }
public string Content { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Application.Dtos;

public class TopicCreateDto
{
public long UserId { get; init; }
public string Title { get; init; }
public string Content { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Application.Dtos;

public class TopicGetDto
{
public long Id { get; init; }
public long UserId { get; init; }
public string Title { get; init; }
public string Content { get; init; }
public DateTime CreatedAt { get; init; }
public DateTime ModifiedAt { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Application.Dtos;

public class TopicUpdateDto
{
public long Id { get; set; }
public long UserId { get; set; }
public string Title { get; set; }
public string Content { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Application.Dtos;

public class UserCreateDto
{
public string Login { get; set; }
public string Password { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Application.Dtos;

public class UserGetDto
{
public long Id { get; init; }
public string Login { get; init; }
public string Firstname { get; init; }
public string Lastname { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Application.Dtos;

public class UserUpdateDto
{
public long Id { get; init; }
public string Login { get; init; }
public string Password { get; init; }
public string Firstname { get; init; }
public string Lastname { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Application.Dtos;
using Domain.Models;

namespace Application.Interfaces;

public interface ILabelRepository
{
Task<List<Label>> GetAllLabelsAsync();
Task<Label?> GetLabelByIdAsync(long id);
Task<Label> CreateLabelAsync(LabelCreateDto labelCreateDto);
Task DeleteLabelAsync (long id);
Task<Label> UpdateLabelAsync(LabelUpdateDto labelUpdateDto);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Reflection.Emit;
using Application.Dtos;
using Domain.Models;

namespace Application.Interfaces;

public interface IReactionRepository
{
Task<List<Reaction>> GetAllReactionsAsync();
Task<Reaction?> GetReactionByIdAsync(long id);
Task<Reaction> CreateReactionAsync(ReactionCreateDto reactionCreateDto);
Task DeleteReactionAsync (long id);
Task<Reaction> UpdateReactionAsync(ReactionUpdateDto reactionUpdateDto);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Application.Dtos;
using Domain.Models;

namespace Application.Interfaces;

public interface ITopicRepository
{
Task<List<Topic>> GetAllTopicsAsync();
Task<Topic?> GetTopicByIdAsync(long id);
Task<Topic> CreateTopicAsync(TopicCreateDto topicCreateDto);
Task DeleteTopicAsync (long id);
Task<Topic> UpdateTopicAsync(TopicUpdateDto topicUpdateDto);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Application.Dtos;
using Domain.Models;

namespace Application.Interfaces;

public interface IUserRepository
{
Task<List<User>> GetAllUsersAsync();
Task<User?> GetUserByIdAsync(long id);
Task<User> CreateUserAsync(UserCreateDto userDto);
Task DeleteUsersAsync(long userId);
Task<User> UpdateUserAsync(UserUpdateDto userDto);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Application.Dtos;
using AutoMapper;
using Domain.Models;

namespace Application.Profiles;

public class LabelDtoProfile : Profile
{
public LabelDtoProfile()
{
CreateMap<Label, LabelGetDto>().ReverseMap();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Application.Dtos;
using AutoMapper;
using Domain.Models;

namespace Application.Profiles;

public class ReactionDtoProfile : Profile
{
public ReactionDtoProfile()
{
CreateMap<Reaction, ReactionGetDto>().ReverseMap();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Application.Dtos;
using AutoMapper;
using Domain.Models;

namespace Application.Profiles;

public class TopicDtoProfile : Profile
{
public TopicDtoProfile()
{
CreateMap<Topic, TopicGetDto>().ReverseMap();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Application.Dtos;
using AutoMapper;
using Domain.Models;

namespace Application.Profiles;

public class UserDtoProfile : Profile
{
public UserDtoProfile()
{
CreateMap<User, UserGetDto>().ReverseMap();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Application.Abstractions;
using Application.Dtos;
using Application.Interfaces;
using AutoMapper;

namespace Application.Services;

public class LabelService : ILabelService
{
private readonly ILabelRepository _labelRepository;
private readonly IMapper _mapper;

public LabelService(ILabelRepository labelRepository, IMapper mapper)
{
_labelRepository = labelRepository;
_mapper = mapper;
}

public async Task<LabelGetDto> CreateLabelAsync(LabelCreateDto labelCreateDto)
{
var label = await _labelRepository.CreateLabelAsync(labelCreateDto);
return _mapper.Map<LabelGetDto>(label);
}

public async Task<List<LabelGetDto>> GetAllLabelsAsync()
{
return _mapper.Map<List<LabelGetDto>>(await _labelRepository.GetAllLabelsAsync());
}

public async Task<LabelGetDto> GetLabelByIdAsync(long id)
{
var label = await _labelRepository.GetLabelByIdAsync(id);
return _mapper.Map<LabelGetDto>(label);
}

public async Task<LabelGetDto> UpdateLabelAsync(LabelUpdateDto labelUpdateDto)
{
if (await _labelRepository.GetLabelByIdAsync(labelUpdateDto.Id) == null)
{
return null;
}

var updated = await _labelRepository.UpdateLabelAsync(labelUpdateDto);
return _mapper.Map<LabelGetDto>(updated);
}

public async Task<bool> DeleteLabelAsync(long id)
{
if (await _labelRepository.GetLabelByIdAsync(id) == null)
{
return false;
}

await _labelRepository.DeleteLabelAsync(id);
return true;
}
}
Loading