Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(Backend-Mavericks): Assessment(Bahailu Abera) #329

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand All @@ -19,6 +19,7 @@
<ProjectReference Include="..\CineFlex.Application\CineFlex.Application.csproj" />
<ProjectReference Include="..\CineFlex.Domain\CineFlex.Domain.csproj" />
<ProjectReference Include="..\CineFlex.Persistence\CineFlex.Persistence.csproj" />
<ProjectReference Include="..\CineFlex.Identity\CineFlex.Identity.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using CineFlex.Application.Responses;
using CineFlex.Application.Features.Authentication.DTOs;
using CineFlex.Application.Features.Authentication.CQRS.Commands;

namespace CineFlex.API.Controllers
{
[ApiController]
[Route("api/auth")]
public class AuthController : BaseApiController
{
private readonly IMediator _mediator;

public AuthController(IMediator mediator)
{
_mediator = mediator;
}

[HttpPost("signin")]
public async Task<IActionResult> SignIn(SigninFormDto signinForm)
{
var command = new SigninCommand { SigninForm = signinForm };
var response = await _mediator.Send(command);
return HandleResult(response);
}

[HttpPost("signup")]
public async Task<IActionResult> SignUp(SignupFromDto signupForm)
{
var command = new SignupCommand { SignupForm = signupForm };
var response = await _mediator.Send(command);
return HandleResult(response);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using CineFlex.Application.Features.MovieBookings.CQRS.Commands;
using CineFlex.Application.Features.MovieBookings.CQRS.Queries;
using CineFlex.Application.Features.MovieBookings.DTO;
using CineFlex.Application.Responses;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace CineFlex.API.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class MovieBookingController : BaseApiController
{
private readonly IMediator _mediator;

public MovieBookingController(IMediator mediator)
{
_mediator = mediator;
}

[HttpGet("GetAll")]
public async Task<ActionResult<List<MovieBookingDto>>> GetAll()
{
var query = new GetMovieBookingListQuery();
var response = await _mediator.Send(query);
return HandleResult(response);
}

[HttpGet("{id}")]
public async Task<IActionResult> Get(int id)
{
var query = new GetMovieBookingQuery { Id = id };
var response = await _mediator.Send(query);
return HandleResult(response);
}

[HttpPost("CreateMovieBooking")]
public async Task<IActionResult> Create([FromBody] CreateMovieBookingDto createMovieBookingDto)
{
var command = new CreateMovieBookingCommand { MovieBookingDto = createMovieBookingDto };
var response = await _mediator.Send(command);
return HandleResult(response);
}

[HttpDelete("{id}")]
public async Task<IActionResult> Delete(int id)
{
var command = new DeleteMovieBookingCommand { Id = id };
var response = await _mediator.Send(command);
return HandleResult(response);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using CineFlex.Application.Features.Seat.CQRS.Commands;
using CineFlex.Application.Features.Seat.CQRS.Queries;
using CineFlex.Application.Features.Seat.DTO;
using CineFlex.Application.Responses;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace CineFlex.API.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class SeatController : BaseApiController
{
private readonly IMediator _mediator;

public SeatController(IMediator mediator)
{
_mediator = mediator;
}

[HttpGet("GetAll")]
public async Task<ActionResult<List<SeatDto>>> GetAll()
{
var query = new GetSeatListQuery();
var response = await _mediator.Send(query);
return HandleResult(response);
}

[HttpGet("{id}")]
public async Task<IActionResult> Get(int id)
{
var query = new GetSeatQuery { Id = id };
var response = await _mediator.Send(query);
return HandleResult(response);
}

[HttpPost("CreateSeat")]
public async Task<IActionResult> Create([FromBody] CreateSeatDto createSeatDto)
{
var command = new CreateSeatCommand { SeatDto = createSeatDto };
var response = await _mediator.Send(command);
return HandleResult(response);
}

[HttpPut("UpdateSeat")]
public async Task<IActionResult> Update([FromBody] UpdateSeatDto updateSeatDto)
{
var command = new UpdateSeatCommand { updateSeatDto = updateSeatDto };
var response = await _mediator.Send(command);
return HandleResult(response);
}

[HttpDelete("{id}")]
public async Task<IActionResult> Delete(int id)
{
var command = new DeleteSeatCommand { Id = id };
var response = await _mediator.Send(command);
return HandleResult(response);
}
}
}
15 changes: 4 additions & 11 deletions Backend/backend_assessment/CineFlex/CineFlex.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
using CineFlex.Persistence;
using Microsoft.OpenApi.Models;
using Microsoft.AspNetCore.Identity;
using CineFlex.Identity;

var builder = WebApplication.CreateBuilder(args);

// Add services
builder.Services.ConfigureApplicationServices();
builder.Services.ConfigurePersistenceServices(builder.Configuration);
builder.Services.ConfigureIdentityService(builder.Configuration);
builder.Services.AddHttpContextAccessor();
AddSwaggerDoc(builder.Services);
builder.Services.AddControllers();


builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

Expand All @@ -26,22 +27,18 @@

var app = builder.Build();


if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}


app.UseCors("CorsPolicy");
app.UseAuthentication();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "CineFlex.Api v1"));
app.UseHttpsRedirection();

app.UseAuthorization();


app.MapControllers();

app.Run();
Expand All @@ -50,14 +47,10 @@ void AddSwaggerDoc(IServiceCollection services)
{
services.AddSwaggerGen(c =>
{


c.SwaggerDoc("v1", new OpenApiInfo
c.SwaggerDoc("v1", new OpenApiInfo
{
Version = "v1",
Title = "CineFlex Api",

Title = "CineFlex Api"
});

});
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"CineFlexConnectionString": "User ID=postgres;Password=1234;Server=localhost;Port=5432;Database=CineFlex;Integrated Security=true;Pooling=true;"
"CineFlexConnectionString": "User ID=bahailu;Password=bahailu12;Server=localhost;Port=5432;Database=sample;Integrated Security=true;Pooling=true;"
},
"Logging": {
"LogLevel": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


using CineFlex.Application.Features.Authentication.DTOs;

namespace CineFlex.Application.Contracts.Identity;

public interface IAuthService
{
Task<SignupResponse> RegisterUserAsync(SignupFromDto signupForm);
Task<SigninResponse> LoginUserAsync(SigninFormDto signinForm);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
using CineFlex.Domain;
using CineFlex.Application.Features.Cinema.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CineFlex.Application.Features.Cinema.Dtos;

namespace CineFlex.Application.Contracts.Persistence
{
public interface ICinemaRepository : IGenericRepository<CinemaEntity>
{
Task<IEnumerable<CinemaEntity>> GetCinemasByLocationAsync(string location);
Task<IEnumerable<CinemaEntity>> GetCinemasByContactInformationAsync(string contactInformation);
Task<IEnumerable<CinemaDto>> GetAllCinemasAsync();
Task<CinemaDto> GetCinemaByIdAsync(int cinemaId);
Task<CinemaDto> AddCinemaAsync(CreateCinemaDto cinemaDto);
Task<CinemaDto> UpdateCinemaAsync(UpdateCinemaDto cinemaDto);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using CineFlex.Domain;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace CineFlex.Application.Contracts.Persistence
{
public interface IMovieBookingRepository : IGenericRepository<MovieBooking>
{
Task<IEnumerable<MovieBooking>> GetMovieBookingsByUserId(string userId);
Task<IEnumerable<MovieBooking>> GetMovieBookingsByMovieId(int movieId);
Task<IEnumerable<MovieBooking>> GetMovieBookingsByCinemaId(int cinemaId);
Task<IEnumerable<MovieBooking>> GetMovieBookingsBySeatId(int seatId);
Task<IEnumerable<MovieBooking>> GetMovieBookingsByUserIdAndMovieId(string userId, int movieId);
Task<IEnumerable<MovieBooking>> GetMovieBookingsByUserIdAndCinemaId(string userId, int cinemaId);
Task<IEnumerable<MovieBooking>> GetMovieBookingsByUserIdAndSeatId(string userId, int seatId);
Task<IEnumerable<MovieBooking>> GetMovieBookingsByMovieIdAndCinemaId(int movieId, int cinemaId);
Task<IEnumerable<MovieBooking>> GetMovieBookingsByMovieIdAndSeatId(int movieId, int seatId);
Task<IEnumerable<MovieBooking>> GetMovieBookingsByCinemaIdAndSeatId(int cinemaId, int seatId);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using CineFlex.Domain;
using CineFlex.Application.Features.Movies.DTOs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;

namespace CineFlex.Application.Contracts.Persistence
{
public interface IMovieRepository : IGenericRepository<Movie>
{

Task<IEnumerable<MovieDto>> GetAllMoviesAsync();
Task<MovieDto> GetMovieByIdAsync(int movieId);
Task<MovieDto> AddMovieAsync(CreateMovieDto movieDto);
Task<MovieDto> UpdateMovieAsync(UpdateMovieDto movieDto);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using CineFlex.Domain;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace CineFlex.Application.Contracts.Persistence
{
public interface ISeatRepository : IGenericRepository<Seats>
{
Task<IEnumerable<Seats>> GetSeatsByCinemaIdAsync(int cinemaId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public interface IUnitOfWork : IDisposable
{
IMovieRepository MovieRepository { get; }
ICinemaRepository CinemaRepository { get; }
ISeatRepository SeatRepository { get; }

IMovieBookingRepository MovieBookingRepository { get; }

Task<int> Save();

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

using CineFlex.Application.Features.Authentication.DTOs;
using CineFlex.Application.Responses;
using MediatR;

namespace CineFlex.Application.Features.Authentication.CQRS.Commands;

public class SigninCommand : IRequest<BaseCommandResponse<SigninResponse>>
{
public SigninFormDto SigninForm { get; set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

using CineFlex.Application.Features.Authentication.DTOs;
using CineFlex.Application.Responses;
using MediatR;

namespace CineFlex.Application.Features.Authentication.CQRS.Commands;

public class SignupCommand: IRequest<BaseCommandResponse<SignupResponse>>
{
public SignupFromDto SignupForm { get; set; } = null!;
}
Loading