Files
pos-system/apps/web-client-tpos-net/src/WebClientTpos.Server/Controllers/ShopController.cs
Ho Ngoc Hai 9be3450ab9 refactor(web-client-tpos): convert BFF from direct DB to HTTP proxy
- Replace Dapper/Npgsql direct DB access with HttpClient proxy to microservice APIs
- Create BffHttpClient.cs with AuthForwardingHandler (forwards JWT tokens)
- Register 9 named HttpClients: Merchant, Catalog, Order, Inventory, Membership, Wallet, Promotion, Booking, FnbEngine
- Delete BffDbConnectionFactory.cs and TenantContext.cs (no more direct DB)
- Remove Dapper and Npgsql package references from .csproj
- All 10 controllers are now thin HTTP proxy bridges
- Zero breaking changes: all api/bff/ routes preserved
2026-03-04 10:13:28 +07:00

78 lines
2.7 KiB
C#

using System.Text.Json;
using Microsoft.AspNetCore.Mvc;
using WebClientTpos.Server.Infrastructure;
namespace WebClientTpos.Server.Controllers;
/// <summary>
/// EN: Shop management controller — proxies to MerchantService for shop CRUD, settings, stats, devices.
/// VI: Controller quản lý cửa hàng — proxy đến MerchantService cho CRUD shop, settings, stats, devices.
/// </summary>
[ApiController]
[Route("api/bff")]
public class ShopController : ControllerBase
{
private readonly HttpClient _merchant;
public ShopController(IHttpClientFactory httpClientFactory)
{
_merchant = httpClientFactory.CreateClient("MerchantService");
}
/// <summary>
/// EN: Get all shops belonging to the current merchant.
/// VI: Lấy tất cả cửa hàng thuộc merchant hiện tại.
/// </summary>
[HttpGet("shops")]
public Task<IActionResult> GetShops() =>
_merchant.GetAsync("/api/v1/shops").ProxyAsync();
/// <summary>
/// EN: Get shop by ID.
/// VI: Lấy cửa hàng theo ID.
/// </summary>
[HttpGet("shops/{shopId:guid}")]
public Task<IActionResult> GetShopById(Guid shopId) =>
_merchant.GetAsync($"/api/v1/shops/{shopId}").ProxyAsync();
/// <summary>
/// EN: Update shop info.
/// VI: Cập nhật thông tin cửa hàng.
/// </summary>
[HttpPut("shops/{shopId:guid}")]
public Task<IActionResult> UpdateShop(Guid shopId, [FromBody] JsonElement body) =>
_merchant.PutAsJsonAsync($"/api/v1/shops/{shopId}", body).ProxyAsync();
/// <summary>
/// EN: Get shop settings.
/// VI: Lấy cài đặt cửa hàng.
/// </summary>
[HttpGet("shops/{shopId:guid}/settings")]
public Task<IActionResult> GetShopSettings(Guid shopId) =>
_merchant.GetAsync($"/api/v1/shops/{shopId}/settings").ProxyAsync();
/// <summary>
/// EN: Update shop settings.
/// VI: Cập nhật cài đặt cửa hàng.
/// </summary>
[HttpPut("shops/{shopId:guid}/settings")]
public Task<IActionResult> UpdateShopSettings(Guid shopId, [FromBody] JsonElement body) =>
_merchant.PutAsJsonAsync($"/api/v1/shops/{shopId}/settings", body).ProxyAsync();
/// <summary>
/// EN: Get aggregated stats per shop.
/// VI: Lấy thống kê tổng hợp theo shop.
/// </summary>
[HttpGet("shops/stats")]
public Task<IActionResult> GetShopStats() =>
_merchant.GetAsync("/api/v1/shops/stats").ProxyAsync();
/// <summary>
/// EN: Get device tokens registered for this merchant's staff.
/// VI: Lấy danh sách device token đã đăng ký cho nhân viên của merchant.
/// </summary>
[HttpGet("devices")]
public Task<IActionResult> GetDevices() =>
_merchant.GetAsync("/api/v1/devices").ProxyAsync();
}