Skip to content
Open
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
39 changes: 39 additions & 0 deletions EventBor.Backend.API/Controllers/EventsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Microsoft.AspNetCore.Mvc;
using EventBor.Backend.Application.Services;
using EventBor.Backend.Application.DTOs.Events;

namespace EventBor.Backend.API.Controllers;

[ApiController]
[Route("api/[controller]")]
public class EventsController : ControllerBase
{
private readonly IEventService _eventService;

public EventsController(IEventService eventService)
{
_eventService = eventService;
}

[HttpPost]
public async Task<IActionResult> PostAsync([FromBody] EventForCreationDto dto)
=> Ok(await _eventService.AddAsync(dto));

[HttpGet]
public async Task<IActionResult> GetAllAsync()
=> Ok(await _eventService.RetrieveAllAsync());

[HttpGet("{id}")]
public async Task<IActionResult> GetAsync([FromRoute(Name = "id")] long id)
=> Ok(await _eventService.RetrieveByIdAsync(id));


[HttpDelete("{id}")]
public async Task<IActionResult> DeleteAsync([FromRoute(Name = "id")] long id)
=> Ok(await _eventService.RemoveAsync(id));


[HttpPut("{id}")]
public async Task<IActionResult> PutAsync([FromRoute(Name = "id")] long id, [FromBody] EventForUpdateDto dto)
=> Ok(await _eventService.ModifyAsync(id, dto));
}
24 changes: 24 additions & 0 deletions EventBor.Backend.Application/DTOs/Events/EventForCreationDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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; }
}
26 changes: 26 additions & 0 deletions EventBor.Backend.Application/DTOs/Events/EventForResultDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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; }
}
24 changes: 24 additions & 0 deletions EventBor.Backend.Application/DTOs/Events/EventForUpdateDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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; }
}
2 changes: 2 additions & 0 deletions EventBor.Backend.Application/Dependencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public static IServiceCollection AddApplication(
this IServiceCollection services)
{
services.AddScoped<IUserService, UserService>();
services.AddScoped<IEventService, EventService>();
services.AddScoped<ICategoryService, CategoryService>();

return services;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="5.0.17" />
<PackageReference Include="AutoMapper" Version="12.0.1" />
</ItemGroup>

Expand Down
9 changes: 8 additions & 1 deletion EventBor.Backend.Application/Mappers/MapperProfile.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
using AutoMapper;
using EventBor.Backend.Application.DTOs.Categories;
using EventBor.Backend.Domain.Entities;
using EventBor.Backend.Application.DTOs.Events;
using EventBor.Backend.Application.DTOs.Categories;

namespace EventBor.Backend.Application.Mappers;

public class MapperProfile : Profile
{
public MapperProfile()
{
// Event
CreateMap<Event, EventForResultDto>().ReverseMap();
CreateMap<Event, EventForUpdateDto>().ReverseMap();
CreateMap<Event, EventForCreationDto>().ReverseMap();

// Category
CreateMap<Category, CategoryForResultDto>().ReverseMap();
CreateMap<Category, CategoryForUpdateDto>().ReverseMap();
CreateMap<Category, CategoryForCreationDto>().ReverseMap();

}
}
86 changes: 86 additions & 0 deletions EventBor.Backend.Application/Services/EventService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using AutoMapper;
using Microsoft.EntityFrameworkCore;
using EventBor.Backend.Domain.Entities;
using EventBor.Backend.Application.DTOs.Events;
using EventBor.Backend.Application.Commons.Exceptions;
using EventBor.Backend.Infrastructure.Database.Repositories;

namespace EventBor.Backend.Application.Services;

public class EventService : IEventService
{
private readonly IMapper _mapper;
private readonly IEventRepository _eventRepository;

public EventService(IMapper mapper, IEventRepository eventRepository)
{
_mapper = mapper;
_eventRepository = eventRepository;
}
public async Task<EventForResultDto> AddAsync(EventForCreationDto dto)
{
var eventData = await _eventRepository
.SelectAll()
.Where(e => e.Title.ToLower() == dto.Title.ToLower())
.FirstOrDefaultAsync();

if(eventData is not null)
throw new CustomException(409,"Event is already exist");

var mappedEventData = _mapper.Map<Event>(dto);

return _mapper.Map<EventForResultDto>(await _eventRepository.InsertAsync(mappedEventData));
}

public async Task<EventForResultDto> ModifyAsync(long id, EventForUpdateDto dto)
{
var eventData = await _eventRepository
.SelectAll()
.Where(e => e.Id == id)
.FirstOrDefaultAsync();

if(eventData is null)
throw new CustomException(404,"Event not found");

var mappedEventData = _mapper.Map(dto, eventData);
return _mapper.Map<EventForResultDto>(_eventRepository.UpdateAsync(mappedEventData));
}

public async Task<bool> RemoveAsync(long id)
{
var eventData = await _eventRepository
.SelectAll()
.Where(e => e.Id == id)
.FirstOrDefaultAsync();
if (eventData is null)
throw new CustomException(404,"Event not found");

await _eventRepository.DeleteAsync(eventData);

return true;
}

public async Task<IEnumerable<EventForResultDto>> RetrieveAllAsync()
{
var allEventData = await _eventRepository
.SelectAll()
.AsNoTracking()
.FirstOrDefaultAsync();

return _mapper.Map<IEnumerable<EventForResultDto>>(allEventData);
}

public async Task<EventForResultDto> RetrieveByIdAsync(long id)
{
var eventData = await _eventRepository
.SelectAll()
.Where(e => e.Id == id)
.AsNoTracking()
.FirstOrDefaultAsync();

if (eventData is null)
throw new CustomException(404, "Event is not found");

return _mapper.Map<EventForResultDto>(eventData);
}
}
12 changes: 12 additions & 0 deletions EventBor.Backend.Application/Services/IEventService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using EventBor.Backend.Application.DTOs.Events;

namespace EventBor.Backend.Application.Services;

public interface IEventService
{
Task<bool> RemoveAsync(long id);
Task<EventForResultDto> RetrieveByIdAsync(long id);
Task<IEnumerable<EventForResultDto>> RetrieveAllAsync();
Task<EventForResultDto> AddAsync(EventForCreationDto dto);
Task<EventForResultDto> ModifyAsync(long id, EventForUpdateDto dto);
}
1 change: 1 addition & 0 deletions EventBor.Backend.Domain/Entities/User.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

using EventBor.Backend.Domain.Entities.Commons;
using EventBor.Backend.Domain.Enums;
using System.Text.Json.Serialization;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using EventBor.Backend.Domain.Entities;

namespace EventBor.Backend.Infrastructure.Database.Repositories;

internal class EventRepository : Repository<Event>, IEventRepository
{
public EventRepository(AppDbContext context) : base(context)
{ }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using EventBor.Backend.Domain.Entities;

namespace EventBor.Backend.Infrastructure.Database.Repositories;

public interface IEventRepository : IRepository<Event>
{
}
11 changes: 7 additions & 4 deletions EventBor.Backend.Infrastructure/Dependencies.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using EventBor.Backend.Infrastructure.Database;
using EventBor.Backend.Infrastructure.Database.Repositories;
using EventBor.Backend.Infrastructure.Database.Repositories.Categories;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using EventBor.Backend.Infrastructure.Database;
using Microsoft.Extensions.DependencyInjection;
using EventBor.Backend.Infrastructure.Database.Repositories;
using EventBor.Backend.Infrastructure.Database.Repositories.Categories;

namespace EventBor.Backend.Infrastructure;

Expand All @@ -19,8 +19,11 @@ public static IServiceCollection AddInfrastructure(


services.AddScoped(typeof(IRepository<>), typeof(Repository<>));

services.AddScoped<IUserRepository, UserRepository>();
services.AddScoped<IEventRepository, EventRepository>();
services.AddScoped<ICategoryRepository, CategoryRepository>();

return services;
}
}