From 67c0c4ae168b97a019d9b366b2ae27f6b633d110 Mon Sep 17 00:00:00 2001 From: Mukhammadzokir <139150511+MuxammadZokir@users.noreply.github.com> Date: Wed, 31 Jan 2024 16:22:49 +0500 Subject: [PATCH 1/2] Craete eventservice and eventrespository --- .../DTOs/Events/EventForCreationDto.cs | 6 +++ .../DTOs/Events/EventForResultDto.cs | 6 +++ .../DTOs/Events/EventForUpdateDto.cs | 5 +++ EventBor.Backend.Application/Dependencies.cs | 1 + .../Services/EventService.cs | 38 +++++++++++++++++++ .../Services/IEventService.cs | 12 ++++++ .../Database/Repositories/EventRepository.cs | 9 +++++ .../Database/Repositories/IEventRepository.cs | 7 ++++ .../Dependencies.cs | 1 + 9 files changed, 85 insertions(+) create mode 100644 EventBor.Backend.Application/DTOs/Events/EventForCreationDto.cs create mode 100644 EventBor.Backend.Application/DTOs/Events/EventForResultDto.cs create mode 100644 EventBor.Backend.Application/DTOs/Events/EventForUpdateDto.cs create mode 100644 EventBor.Backend.Application/Services/EventService.cs create mode 100644 EventBor.Backend.Application/Services/IEventService.cs create mode 100644 EventBor.Backend.Infrastructure/Database/Repositories/EventRepository.cs create mode 100644 EventBor.Backend.Infrastructure/Database/Repositories/IEventRepository.cs diff --git a/EventBor.Backend.Application/DTOs/Events/EventForCreationDto.cs b/EventBor.Backend.Application/DTOs/Events/EventForCreationDto.cs new file mode 100644 index 0000000..6d02c35 --- /dev/null +++ b/EventBor.Backend.Application/DTOs/Events/EventForCreationDto.cs @@ -0,0 +1,6 @@ +namespace EventBor.Backend.Application.DTOs.Events; + +public class EventForCreationDto +{ + +} diff --git a/EventBor.Backend.Application/DTOs/Events/EventForResultDto.cs b/EventBor.Backend.Application/DTOs/Events/EventForResultDto.cs new file mode 100644 index 0000000..25f5e38 --- /dev/null +++ b/EventBor.Backend.Application/DTOs/Events/EventForResultDto.cs @@ -0,0 +1,6 @@ +namespace EventBor.Backend.Application.DTOs.Events; + +public class EventForResultDto +{ + +} diff --git a/EventBor.Backend.Application/DTOs/Events/EventForUpdateDto.cs b/EventBor.Backend.Application/DTOs/Events/EventForUpdateDto.cs new file mode 100644 index 0000000..3d717e2 --- /dev/null +++ b/EventBor.Backend.Application/DTOs/Events/EventForUpdateDto.cs @@ -0,0 +1,5 @@ +namespace EventBor.Backend.Application.DTOs.Events; + +public class EventForUpdateDto +{ +} diff --git a/EventBor.Backend.Application/Dependencies.cs b/EventBor.Backend.Application/Dependencies.cs index 286a1a9..d40d48d 100644 --- a/EventBor.Backend.Application/Dependencies.cs +++ b/EventBor.Backend.Application/Dependencies.cs @@ -9,6 +9,7 @@ public static IServiceCollection AddApplication( this IServiceCollection services) { services.AddScoped(); + services.AddScoped(); return services; } } diff --git a/EventBor.Backend.Application/Services/EventService.cs b/EventBor.Backend.Application/Services/EventService.cs new file mode 100644 index 0000000..fdda891 --- /dev/null +++ b/EventBor.Backend.Application/Services/EventService.cs @@ -0,0 +1,38 @@ +using EventBor.Backend.Application.DTOs.Events; +using EventBor.Backend.Infrastructure.Database.Repositories; + +namespace EventBor.Backend.Application.Services; + +public class EventService : IEventService +{ + private readonly IEventRepository _eventRepository; + + public EventService(IEventRepository eventRepository) + { + _eventRepository = eventRepository; + } + public Task AddAsync(EventForCreationDto dto) + { + throw new NotImplementedException(); + } + + public Task ModifyAsync(long id, EventForUpdateDto dto) + { + throw new NotImplementedException(); + } + + public Task RemoveAsync(long id) + { + throw new NotImplementedException(); + } + + public Task> RetrieveAllAsync() + { + throw new NotImplementedException(); + } + + public Task RetrieveByIdAsync(long id) + { + throw new NotImplementedException(); + } +} diff --git a/EventBor.Backend.Application/Services/IEventService.cs b/EventBor.Backend.Application/Services/IEventService.cs new file mode 100644 index 0000000..5bbc411 --- /dev/null +++ b/EventBor.Backend.Application/Services/IEventService.cs @@ -0,0 +1,12 @@ +using EventBor.Backend.Application.DTOs.Events; + +namespace EventBor.Backend.Application.Services; + +public interface IEventService +{ + Task RemoveAsync(long id); + Task RetrieveByIdAsync(long id); + Task AddAsync(EventForCreationDto dto); + Task ModifyAsync(long id, EventForUpdateDto dto); + Task> RetrieveAllAsync(); +} diff --git a/EventBor.Backend.Infrastructure/Database/Repositories/EventRepository.cs b/EventBor.Backend.Infrastructure/Database/Repositories/EventRepository.cs new file mode 100644 index 0000000..0cf6db2 --- /dev/null +++ b/EventBor.Backend.Infrastructure/Database/Repositories/EventRepository.cs @@ -0,0 +1,9 @@ +using EventBor.Backend.Domain.Entities; + +namespace EventBor.Backend.Infrastructure.Database.Repositories; + +internal class EventRepository : Repository, IEventRepository +{ + public EventRepository(AppDbContext context) : base(context) + { } +} diff --git a/EventBor.Backend.Infrastructure/Database/Repositories/IEventRepository.cs b/EventBor.Backend.Infrastructure/Database/Repositories/IEventRepository.cs new file mode 100644 index 0000000..c3faf40 --- /dev/null +++ b/EventBor.Backend.Infrastructure/Database/Repositories/IEventRepository.cs @@ -0,0 +1,7 @@ +using EventBor.Backend.Domain.Entities; + +namespace EventBor.Backend.Infrastructure.Database.Repositories; + +public interface IEventRepository : IRepository +{ +} diff --git a/EventBor.Backend.Infrastructure/Dependencies.cs b/EventBor.Backend.Infrastructure/Dependencies.cs index 6dff5e8..9c65550 100644 --- a/EventBor.Backend.Infrastructure/Dependencies.cs +++ b/EventBor.Backend.Infrastructure/Dependencies.cs @@ -19,6 +19,7 @@ public static IServiceCollection AddInfrastructure( services.AddScoped(typeof(IRepository<>), typeof(Repository<>)); services.AddScoped(); + services.AddScoped(); return services; } } From 84fe6c972c6484f792264f9535a0b76f00a9af58 Mon Sep 17 00:00:00 2001 From: Mukhammadzokir <139150511+MuxammadZokir@users.noreply.github.com> Date: Fri, 2 Feb 2024 13:22:45 +0500 Subject: [PATCH 2/2] Implemented: EventService --- .../DTOs/Events/EventForCreationDto.cs | 22 +++++- .../DTOs/Events/EventForResultDto.cs | 24 ++++++- .../DTOs/Events/EventForUpdateDto.cs | 21 +++++- .../EventBor.Backend.Application.csproj | 5 ++ .../Services/EventService.cs | 70 +++++++++++++++---- 5 files changed, 125 insertions(+), 17 deletions(-) diff --git a/EventBor.Backend.Application/DTOs/Events/EventForCreationDto.cs b/EventBor.Backend.Application/DTOs/Events/EventForCreationDto.cs index 6d02c35..1559d39 100644 --- a/EventBor.Backend.Application/DTOs/Events/EventForCreationDto.cs +++ b/EventBor.Backend.Application/DTOs/Events/EventForCreationDto.cs @@ -1,6 +1,24 @@ -namespace EventBor.Backend.Application.DTOs.Events; +using EventBor.Backend.Domain.Enums; + +namespace EventBor.Backend.Application.DTOs.Events; public class EventForCreationDto { - + public string Title { get; set; } + public DateTime StartedAt { get; set; } + public string Duration { get; set; } + public EventFormat Format { get; set; } + public string Platform { get; set; } + public string Banner { get; set; } + public EventStatus Status { get; set; } + public string Orginizer { get; set; } + public string Description { get; set; } + public string Location { get; set; } + public string Address { get; set; } + public bool IsPaid { get; set; } + public decimal Price { get; set; } + public string RegistrationLink { get; set; } + public int Capacity { get; set; } + public string Contact { get; set; } + public string OfficialPage { get; set; } } diff --git a/EventBor.Backend.Application/DTOs/Events/EventForResultDto.cs b/EventBor.Backend.Application/DTOs/Events/EventForResultDto.cs index 25f5e38..8f67b07 100644 --- a/EventBor.Backend.Application/DTOs/Events/EventForResultDto.cs +++ b/EventBor.Backend.Application/DTOs/Events/EventForResultDto.cs @@ -1,6 +1,26 @@ -namespace EventBor.Backend.Application.DTOs.Events; +using EventBor.Backend.Domain.Enums; +using Microsoft.AspNetCore.Http; + +namespace EventBor.Backend.Application.DTOs.Events; public class EventForResultDto { - + public long Id { get; set; } + public string Title { get; set; } + public DateTime StartedAt { get; set; } + public string Duration { get; set; } + public EventFormat Format { get; set; } + public string Platform { get; set; } + public IFormFile Banner { get; set; } + public EventStatus Status { get; set; } + public string Orginizer { get; set; } + public string Description { get; set; } + public string Location { get; set; } + public string Address { get; set; } + public bool IsPaid { get; set; } + public decimal Price { get; set; } + public string RegistrationLink { get; set; } + public int Capacity { get; set; } + public string Contact { get; set; } + public string OfficialPage { get; set; } } diff --git a/EventBor.Backend.Application/DTOs/Events/EventForUpdateDto.cs b/EventBor.Backend.Application/DTOs/Events/EventForUpdateDto.cs index 3d717e2..570c064 100644 --- a/EventBor.Backend.Application/DTOs/Events/EventForUpdateDto.cs +++ b/EventBor.Backend.Application/DTOs/Events/EventForUpdateDto.cs @@ -1,5 +1,24 @@ -namespace EventBor.Backend.Application.DTOs.Events; +using EventBor.Backend.Domain.Enums; + +namespace EventBor.Backend.Application.DTOs.Events; public class EventForUpdateDto { + public string Title { get; set; } + public DateTime StartedAt { get; set; } + public string Duration { get; set; } + public EventFormat Format { get; set; } + public string Platform { get; set; } + public string Banner { get; set; } + public EventStatus Status { get; set; } + public string Orginizer { get; set; } + public string Description { get; set; } + public string Location { get; set; } + public string Address { get; set; } + public bool IsPaid { get; set; } + public decimal Price { get; set; } + public string RegistrationLink { get; set; } + public int Capacity { get; set; } + public string Contact { get; set; } + public string OfficialPage { get; set; } } diff --git a/EventBor.Backend.Application/EventBor.Backend.Application.csproj b/EventBor.Backend.Application/EventBor.Backend.Application.csproj index 270eb7a..2f08015 100644 --- a/EventBor.Backend.Application/EventBor.Backend.Application.csproj +++ b/EventBor.Backend.Application/EventBor.Backend.Application.csproj @@ -6,6 +6,11 @@ enable + + + + + diff --git a/EventBor.Backend.Application/Services/EventService.cs b/EventBor.Backend.Application/Services/EventService.cs index fdda891..ea2c344 100644 --- a/EventBor.Backend.Application/Services/EventService.cs +++ b/EventBor.Backend.Application/Services/EventService.cs @@ -1,38 +1,84 @@ -using EventBor.Backend.Application.DTOs.Events; +using AutoMapper; +using EventBor.Backend.Application.DTOs.Events; +using EventBor.Backend.Domain.Entities; using EventBor.Backend.Infrastructure.Database.Repositories; +using Microsoft.EntityFrameworkCore; +using Npgsql.TypeMapping; +using System.Diagnostics.Tracing; namespace EventBor.Backend.Application.Services; public class EventService : IEventService { + private readonly IMapper _mapper; private readonly IEventRepository _eventRepository; - public EventService(IEventRepository eventRepository) + public EventService(IMapper mapper, IEventRepository eventRepository) { + _mapper = mapper; _eventRepository = eventRepository; } - public Task AddAsync(EventForCreationDto dto) + public async Task AddAsync(EventForCreationDto dto) { - throw new NotImplementedException(); + var eventData = await _eventRepository + .SelectAll() + .Where(e => e.Title.ToLower() == dto.Title.ToLower()) + .FirstOrDefaultAsync(); + + if(eventData is not null) + throw new Exception("Event is already exist"); + + var mappedEventData = _mapper.Map(dto); + + return _mapper.Map(await _eventRepository.InsertAsync(mappedEventData)); } - public Task ModifyAsync(long id, EventForUpdateDto dto) + public async Task ModifyAsync(long id, EventForUpdateDto dto) { - throw new NotImplementedException(); + var eventData = await _eventRepository + .SelectAll() + .Where(e => e.Id == id) + .FirstOrDefaultAsync(); + + if(eventData is null) + throw new Exception("Event not found"); + + var mappedEventData = _mapper.Map(dto, eventData); + return _mapper.Map(_eventRepository.UpdateAsync(mappedEventData)); } - public Task RemoveAsync(long id) + public async Task RemoveAsync(long id) { - throw new NotImplementedException(); + var eventData = await _eventRepository + .SelectAll() + .Where(e => e.Id == id) + .FirstOrDefaultAsync(); + if (eventData is null) + throw new Exception("Event not found"); + + _eventRepository.DeleteAsync(eventData); + + return true; } - public Task> RetrieveAllAsync() + public async Task> RetrieveAllAsync() { - throw new NotImplementedException(); + var allEventData = await _eventRepository + .SelectAll() + .AsNoTracking() + .FirstOrDefaultAsync(); + + return _mapper.Map>(allEventData); } - public Task RetrieveByIdAsync(long id) + public async Task RetrieveByIdAsync(long id) { - throw new NotImplementedException(); + var eventData = await _eventRepository + .SelectAll() + .Where(e => e.Id == id) + .AsNoTracking() + .FirstOrDefaultAsync(); + + return _mapper.Map(eventData); } }