first commit
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
using Fitness_core_BE.DTOs.Place;
|
||||
using Fitness_core_BE.Helpers;
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
using Fitness_core_BE.Models.IOs;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using static Fitness_core_BE.Helpers.JwtMiddleware;
|
||||
using static Fitness_core_BE.Helpers.ApiResponseHelper;
|
||||
|
||||
namespace Fitness_core_BE.Controllers
|
||||
{
|
||||
// Staff/owner-facing management of physical access zones (Places) and which fingerprint
|
||||
// terminal (AccessDevice) sits in each. Gated on "memberships" since Places exist to
|
||||
// scope membership-plan access, not bookings.
|
||||
[ApiController]
|
||||
[Route("api/client/places")]
|
||||
public class PlaceController : ControllerBase
|
||||
{
|
||||
private readonly IPlaceService _placeService;
|
||||
|
||||
public PlaceController(IPlaceService placeService)
|
||||
{
|
||||
_placeService = placeService;
|
||||
}
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("memberships")]
|
||||
[HttpGet("")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> GetAllPlaces([FromQuery] bool includeInactive = false)
|
||||
=> Response(await _placeService.GetAllPlaces(new { includeInactive }, HttpContext));
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("memberships")]
|
||||
[HttpPost("")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> CreatePlace([FromBody] CreatePlaceRequest request)
|
||||
=> Response(await _placeService.CreatePlace(new
|
||||
{
|
||||
name = request.Name,
|
||||
description = request.Description
|
||||
}, HttpContext));
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("memberships")]
|
||||
[HttpPut("{id:guid}")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> UpdatePlace(Guid id, [FromBody] UpdatePlaceRequest request)
|
||||
{
|
||||
var payload = new Dictionary<string, object> { ["placeId"] = id };
|
||||
if (request.Name != null) payload["name"] = request.Name;
|
||||
if (request.Description != null) payload["description"] = request.Description;
|
||||
if (request.IsActive.HasValue) payload["isActive"] = request.IsActive.Value;
|
||||
|
||||
return Response(await _placeService.UpdatePlace(payload, HttpContext));
|
||||
}
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("memberships")]
|
||||
[HttpPatch("{id:guid}/status")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> SetPlaceStatus(Guid id, [FromBody] SetPlaceStatusRequest request)
|
||||
=> Response(await _placeService.SetPlaceStatus(new { placeId = id, isActive = request.IsActive }, HttpContext));
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("memberships")]
|
||||
[HttpPut("{id:guid}/device")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> AssignDevice(Guid id, [FromBody] AssignPlaceDeviceRequest request)
|
||||
=> Response(await _placeService.AssignDevice(new { placeId = id, deviceId = request.DeviceId }, HttpContext));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user