2026-05-27 21:33:48 +03:30
|
|
|
using FluentValidation;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Meezi.API.Models.Public;
|
|
|
|
|
using Meezi.API.Services;
|
2026-06-21 05:43:07 +03:30
|
|
|
using Meezi.Core.Authorization;
|
2026-06-03 01:40:00 +03:30
|
|
|
using Meezi.Core.Enums;
|
2026-05-27 21:33:48 +03:30
|
|
|
using Meezi.Core.Interfaces;
|
2026-06-03 01:40:00 +03:30
|
|
|
using Meezi.Infrastructure.Services.Platform;
|
2026-05-27 21:33:48 +03:30
|
|
|
using Meezi.Shared;
|
|
|
|
|
|
|
|
|
|
namespace Meezi.API.Controllers;
|
|
|
|
|
|
|
|
|
|
[Route("api/cafes/{cafeId}/reviews")]
|
|
|
|
|
public class CafeReviewsController : CafeApiControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IReviewService _reviews;
|
|
|
|
|
private readonly IValidator<ReplyCafeReviewRequest> _replyValidator;
|
2026-06-03 01:40:00 +03:30
|
|
|
private readonly IPlatformCatalogService _catalog;
|
2026-05-27 21:33:48 +03:30
|
|
|
|
2026-06-03 01:40:00 +03:30
|
|
|
public CafeReviewsController(
|
|
|
|
|
IReviewService reviews,
|
|
|
|
|
IValidator<ReplyCafeReviewRequest> replyValidator,
|
|
|
|
|
IPlatformCatalogService catalog)
|
2026-05-27 21:33:48 +03:30
|
|
|
{
|
|
|
|
|
_reviews = reviews;
|
|
|
|
|
_replyValidator = replyValidator;
|
2026-06-03 01:40:00 +03:30
|
|
|
_catalog = catalog;
|
2026-05-27 21:33:48 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<IActionResult> List(
|
|
|
|
|
string cafeId,
|
|
|
|
|
ITenantContext tenant,
|
|
|
|
|
CancellationToken ct,
|
|
|
|
|
[FromQuery] int page = 1,
|
|
|
|
|
[FromQuery] int pageSize = 20)
|
|
|
|
|
{
|
|
|
|
|
if (EnsureCafeAccess(cafeId, tenant) is { } denied) return denied;
|
|
|
|
|
var data = await _reviews.GetReviewsAsync(cafeId, page, pageSize, publicOnly: false, ct);
|
|
|
|
|
return Ok(new ApiResponse<IReadOnlyList<CafeReviewDto>>(true, data));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPatch("{reviewId}/reply")]
|
|
|
|
|
public async Task<IActionResult> Reply(
|
|
|
|
|
string cafeId,
|
|
|
|
|
string reviewId,
|
|
|
|
|
[FromBody] ReplyCafeReviewRequest request,
|
|
|
|
|
ITenantContext tenant,
|
|
|
|
|
CancellationToken ct = default)
|
|
|
|
|
{
|
|
|
|
|
if (EnsureCafeAccess(cafeId, tenant) is { } denied) return denied;
|
2026-06-21 05:43:07 +03:30
|
|
|
if (EnsurePermission(tenant, Permission.ManageReviews) is { } permDenied) return permDenied;
|
2026-06-03 01:40:00 +03:30
|
|
|
|
|
|
|
|
// Replying to reviews is a paid feature (Starter+).
|
|
|
|
|
var tier = tenant.PlanTier ?? PlanTier.Free;
|
|
|
|
|
if (!await _catalog.IsFeatureEnabledForCafeAsync(cafeId, tier, "review_reply", ct))
|
|
|
|
|
return StatusCode(403, new ApiResponse<object>(false, null,
|
|
|
|
|
new ApiError("PLAN_FEATURE_DISABLED", "Replying to reviews is not included in your plan. Please upgrade.")));
|
|
|
|
|
|
2026-05-27 21:33:48 +03:30
|
|
|
var validation = await _replyValidator.ValidateAsync(request, ct);
|
|
|
|
|
if (!validation.IsValid)
|
|
|
|
|
{
|
|
|
|
|
var first = validation.Errors.First();
|
|
|
|
|
return BadRequest(new ApiResponse<object>(false, null, new ApiError("VALIDATION_ERROR", first.ErrorMessage, first.PropertyName)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var data = await _reviews.ReplyReviewAsync(cafeId, reviewId, request.Reply, ct);
|
|
|
|
|
if (data is null) return NotFoundError();
|
|
|
|
|
return Ok(new ApiResponse<CafeReviewDto>(true, data));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPatch("{reviewId}/visibility")]
|
|
|
|
|
public async Task<IActionResult> SetVisibility(
|
|
|
|
|
string cafeId,
|
|
|
|
|
string reviewId,
|
|
|
|
|
[FromBody] HideCafeReviewRequest request,
|
|
|
|
|
ITenantContext tenant,
|
|
|
|
|
CancellationToken ct = default)
|
|
|
|
|
{
|
|
|
|
|
if (EnsureCafeAccess(cafeId, tenant) is { } denied) return denied;
|
2026-06-21 05:43:07 +03:30
|
|
|
if (EnsurePermission(tenant, Permission.ManageReviews) is { } permDenied) return permDenied;
|
2026-05-27 21:33:48 +03:30
|
|
|
var data = await _reviews.SetHiddenAsync(cafeId, reviewId, request.IsHidden, ct);
|
|
|
|
|
if (data is null) return NotFoundError();
|
|
|
|
|
return Ok(new ApiResponse<CafeReviewDto>(true, data));
|
|
|
|
|
}
|
|
|
|
|
}
|