Skip to content
Merged
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
Expand Up @@ -70,6 +70,12 @@
.WithEnvironment("MSSQL_SA_PASSWORD", infrastructureSettings.SqlServer.Password)
.WithHttpEndpoint(port: infrastructureSettings.SqlServer.HostPort, targetPort: infrastructureSettings.SqlServer.TargetPort, isProxied: true);

var couchbase = builder.AddContainer("nt-reviewservice-db", "couchbase:community")
.WithEnvironment("CB_USERNAME", "Administrator")
.WithEnvironment("CB_PASSWORD", "password")
.WithEndpoint(port: 8091, targetPort:8091, scheme:"http")
.WithEndpoint(port: 8093, targetPort:8093);


var authServiceInstances = new List<IResourceBuilder<ProjectResource>>();
foreach(var port in serviceSettings.AuthService.InstancePorts)
Expand Down Expand Up @@ -171,7 +177,8 @@

var reviewService = builder.AddProject<Projects.ReviewService_Presenation_Api>("nt-reviewservice-service")
.WithEnvironment(Constants.Global.EnvironmentVariables.RunningWithVariable, Constants.Global.EnvironmentVariables.RunningWithValue)
.WithUrls(c => c.Urls.ForEach(u => u.DisplayText = $"Open API ({u.Endpoint?.EndpointName})"));
.WithUrls(c => c.Urls.ForEach(u => u.DisplayText = $"Open API ({u.Endpoint?.EndpointName})"))
.WaitFor(couchbase);


var gateway = builder.AddProject<Projects.nt_gateway>(Constants.Gateway.ServiceName, launchProfileName: Constants.Gateway.LaunchProfile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.3.0" />
<PackageReference Include="Aspire.Hosting.Azure.CosmosDB" Version="9.3.1" />
<PackageReference Include="Aspire.Hosting.MongoDB" Version="9.3.0" />
<PackageReference Include="Aspire.Hosting.PostgreSQL" Version="9.3.0" />
<PackageReference Include="Aspire.Hosting.RabbitMQ" Version="9.3.0" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace ReviewService.Application.DTO.Reviews;

public class ReviewDto
{
public Guid ReviewId { get; set; }
public Guid MovieId { get; set; }

public string Content { get; set; } = string.Empty;
public int Rating { get; set; }
public string UserName { get; set; } = string.Empty;

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ namespace ReviewService.Application.Interfaces.Operations;

public interface IReviewService
{
public Task<IEnumerable<Review>> GetReviewsByMovieIdAsync(Guid movieId);
Task<IEnumerable<ReviewDto>> GetReviewsByMovieIdAsync(Guid movieId);
Task<Guid> CreateReviewAsync(ReviewDto reviewDto);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using MediatR;
using ReviewService.Application.DTO.Reviews;

namespace ReviewService.Application.Orchestration.Commands;

public class CreateReviewCommand : IRequest<Guid>
{
public required ReviewDto Review { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using MediatR;
using ReviewService.Application.Interfaces.Operations;

namespace ReviewService.Application.Orchestration.Commands;

public class CreateReviewCommandHandler : IRequestHandler<CreateReviewCommand, Guid>
{
private readonly IReviewService _reviewService;
public CreateReviewCommandHandler(IReviewService reviewService)
{
_reviewService = reviewService ?? throw new ArgumentNullException(nameof(reviewService));
}

public async Task<Guid> Handle(CreateReviewCommand request, CancellationToken cancellationToken)
{
return await _reviewService.CreateReviewAsync(request.Review).ConfigureAwait(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace ReviewService.Application.Orchestration.Queries;

public class GetReviewsByMovieIdQuery : IRequest<IEnumerable<Review>>
public class GetReviewsByMovieIdQuery : IRequest<IEnumerable<ReviewDto>>
{
public Guid MovieId { get; set; }
public GetReviewsByMovieIdQuery(Guid movieId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace ReviewService.Application.Orchestration.Queries;

public class GetReviewsByMovieIdQueryHandler : IRequestHandler<GetReviewsByMovieIdQuery, IEnumerable<Review>>
public class GetReviewsByMovieIdQueryHandler : IRequestHandler<GetReviewsByMovieIdQuery, IEnumerable<ReviewDto>>
{
private readonly IReviewService _reviewService;
public GetReviewsByMovieIdQueryHandler(IReviewService reviewService)
{
_reviewService = reviewService;
}

public Task<IEnumerable<Review>> Handle(GetReviewsByMovieIdQuery request, CancellationToken cancellationToken)
public Task<IEnumerable<ReviewDto>> Handle(GetReviewsByMovieIdQuery request, CancellationToken cancellationToken)
{
return _reviewService.GetReviewsByMovieIdAsync(request.MovieId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Folder Include="Commands\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="MediatR" Version="9.0.0" />
</ItemGroup>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
using ReviewService.Application.DTO.Reviews;
using ReviewService.Application.Services.Interfaces;
using AutoMapper;
using Microsoft.Extensions.Logging;
using ReviewService.Application.DTO.Reviews;
using ReviewService.Application.Interfaces.Operations;
using ReviewService.Domain.Entities;
using ReviewService.Domain.Repositories;

namespace ReviewService.Application.Services.Operations;

public class ReviewService : IReviewService
{
public Task<IEnumerable<Review>> GetReviewsByMovieIdAsync(Guid movieId)
private readonly IReviewRepository _reviewRepository;
private readonly IMapper _mapper;
private readonly ILogger _logger;
public ReviewService(IReviewRepository reviewRepository,IMapper mapper, ILogger<ReviewService> logger)
{
_reviewRepository = reviewRepository ?? throw new ArgumentNullException(nameof(reviewRepository));
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public Task<IEnumerable<ReviewDto>> GetReviewsByMovieIdAsync(Guid movieId)
{
throw new NotImplementedException();
}

public async Task<Guid> CreateReviewAsync(ReviewDto reviewDto)
{
try
{
var review = await _reviewRepository.AddAsync(_mapper.Map<ReviewDto, Review>(reviewDto)).ConfigureAwait(false);
return review.Id;
}
catch (Exception ex)
{
_logger.LogError(ex, "An error occurred while creating a review.");
throw;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="14.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ReviewService.Application.DTO\ReviewService.Application.DTO.csproj" />
<ProjectReference Include="..\ReviewService.Application.Interfaces\ReviewService.Application.Interfaces.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using ReviewService.Domain.Entities;

namespace ReviewService.Domain.Repositories;

public interface IGenericRepository<TEntity> where TEntity : class, IEntity, new()
{
Task<IEnumerable<TEntity>> GetAll();
Task<TEntity> GetByIdAsync(long id);
Task<TEntity> AddAsync(TEntity entity);
Task<TEntity> UpdateAsync(TEntity entity);
Task<TEntity> DeleteAsync(TEntity entity);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using ReviewService.Domain.Entities;

namespace ReviewService.Domain.Repositories;

public interface IReviewRepository : IGenericRepository<Review>
{
Task<IEnumerable<Review>> GetReviewsByMovieIdAsync(Guid movieId);
Task<IEnumerable<Review>> GetReviewsByUserIdAsync(Guid userId);
Task<IEnumerable<Review>> GetReviewsByRatingAsync(int rating);
Task<IEnumerable<Review>> GetReviewsByDateRangeAsync(DateTime startDate, DateTime endDate);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using ReviewService.Domain.Entities;
using ReviewService.Domain.Repositories;

namespace ReviewService.Infrastructure.Repository.Repositories;

public class GenericRepository<TEntity> : IGenericRepository<TEntity> where TEntity : class, IEntity, new()
{
public Task<TEntity> AddAsync(TEntity entity)
{
throw new NotImplementedException();
}

public Task<TEntity> DeleteAsync(TEntity entity)
{
throw new NotImplementedException();
}

public Task<IEnumerable<TEntity>> GetAll()
{
throw new NotImplementedException();
}

public Task<TEntity> GetByIdAsync(long id)
{
throw new NotImplementedException();
}

public Task<TEntity> UpdateAsync(TEntity entity)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

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

</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using AutoMapper;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using ReviewService.Presenation.Api.ViewModels;
using ReviewService.Application.Orchestration.Commands;
using ReviewService.Presenation.Api.Models;

namespace ReviewService.Api.Controllers;

Expand All @@ -8,15 +11,53 @@
public class UserReviewsController : ControllerBase
{
private readonly ILogger<UserReviewsController> _logger;
private readonly IMapper _mapper;
private readonly IMediator _mediator;

public UserReviewsController(ILogger<UserReviewsController> logger)
public UserReviewsController(IMediator mediator, IMapper mapper, ILogger<UserReviewsController> logger)
{
_logger = logger;
_mapper = mapper;
_mediator = mediator;
}

[HttpGet(Name = "GetReviewsForMovie")]
public ActionResult<GetReviewsForMovieResponse> GetReviewsForMovie(GetReviewsForMovieRequest request)
[HttpGet]
[Route("GetReviewsForMovie/{movieId}")]
public ActionResult<GetReviewsForMovieResponse> GetReviewsForMovie(Guid movieId)
{
return default!;
}

[HttpPost]
[Route("CreateReview")]
public async Task<ActionResult<CreateReviewResponse>> CreateReview(CreateReviewRequest request)
{
try
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}

var reviewId = await _mediator.Send(new CreateReviewCommand
{
Review = _mapper.Map<Application.DTO.Reviews.ReviewDto>(request)
}).ConfigureAwait(false);

if (reviewId == Guid.Empty)
{
_logger.LogError("Failed to create review. Review ID is empty.");
return BadRequest("Failed to create review.");
}
return Ok(new CreateReviewResponse
{
Id = reviewId
});
}
catch (Exception e)
{
_logger.LogError(@"An error occurred while creating the review.", e);

Check warning on line 59 in server/nt.microservice/services/ReviewService/ReviewService.Presentation.Api/Controllers/UserReviewsController.cs

View workflow job for this annotation

GitHub Actions / Build Services

Number of parameters supplied in the logging message template do not match the number of named placeholders (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2017)

Check warning on line 59 in server/nt.microservice/services/ReviewService/ReviewService.Presentation.Api/Controllers/UserReviewsController.cs

View workflow job for this annotation

GitHub Actions / Build Services

Number of parameters supplied in the logging message template do not match the number of named placeholders (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2017)
return BadRequest(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace ReviewService.Presenation.Api.Models;

public class CreateReviewRequest
{
public Guid MovieId { get; set; }
public string Content { get; set; } = string.Empty;
public int Rating { get; set; }
public string UserName { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ReviewService.Presenation.Api.Models;

public class CreateReviewResponse
{
public Guid Id { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
namespace ReviewService.Presenation.Api.ViewModels;
namespace ReviewService.Presenation.Api.Models;

public record GetReviewsForMovieRequest
{
public Guid MovieId { get; set; }
}

public record GetReviewsForMovieResponse
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="14.0.0" />
<PackageReference Include="MediatR" Version="9.0.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.4" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\infrastructure\nt.orchestrator.ServiceDefaults\nt.orchestrator.ServiceDefaults.csproj" />
<ProjectReference Include="..\ReviewService.Application.Interfaces\ReviewService.Application.Interfaces.csproj" />
<ProjectReference Include="..\ReviewService.Application.Orchestration\ReviewService.Application.Orchestration.csproj" />
</ItemGroup>

</Project>
Loading