-
Notifications
You must be signed in to change notification settings - Fork 550
Expand file tree
/
Copy pathStoreController.cs
More file actions
53 lines (45 loc) · 1.83 KB
/
Copy pathStoreController.cs
File metadata and controls
53 lines (45 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using Grand.Business.Core.Interfaces.Common.Security;
using Grand.Domain.Permissions;
using Grand.Domain.Stores;
using Grand.Module.Api.Attributes;
using Grand.Module.Api.DTOs.Common;
using Grand.Module.Api.Queries.Models.Common;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
namespace Grand.Module.Api.Controllers;
public class StoreController : BaseApiController
{
private readonly IMediator _mediator;
private readonly IPermissionService _permissionService;
public StoreController(IMediator mediator, IPermissionService permissionService)
{
_mediator = mediator;
_permissionService = permissionService;
}
[EndpointDescription("Get entity from Store by key")]
[EndpointName("GetStoreById")]
[HttpGet("{key}")]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(StoreDto))]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> Get([FromRoute] string key)
{
if (!await _permissionService.Authorize(PermissionSystemName.Stores)) return Forbid();
var store = await _mediator.Send(new GetGenericQuery<StoreDto, Store>(key));
if (!store.Any()) return NotFound();
return Ok(store.FirstOrDefault());
}
[EndpointDescription("Get entities from Store")]
[EndpointName("GetStores")]
[HttpGet]
[EnableQuery]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable<StoreDto>))]
public async Task<IActionResult> Get()
{
if (!await _permissionService.Authorize(PermissionSystemName.Stores)) return Forbid();
return Ok(await _mediator.Send(new GetGenericQuery<StoreDto, Store>()));
}
}