source: Farmatiko/Controllers/AdminController.cs@ db484c9

Last change on this file since db484c9 was db484c9, checked in by DimitarSlezenkovski <dslezenkovski@…>, 23 months ago

Fix bugs

  • Property mode set to 100644
File size: 2.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Threading.Tasks;
5using FarmatikoData.DTOs;
6using FarmatikoData.Models;
7using FarmatikoServices.FarmatikoServiceInterfaces;
8using Microsoft.AspNetCore.Authorization;
9using Microsoft.AspNetCore.Mvc;
10
11namespace Farmatiko.Controllers
12{
13 [ApiController]
14 [Authorize(Roles = "Admin")]
15 public class AdminController : Controller
16 {
17 private readonly IAdminService _adminService;
18 private readonly IService _service;
19 private readonly IPHService _phservice;
20 public AdminController(IAdminService adminService, IService service, IPHService phservice)
21 {
22 _adminService = adminService;
23 _service = service;
24 _phservice = phservice;
25 }
26
27 //GET
28 [HttpGet]
29 [Route("api/pharmacyhead")]
30 public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeads()
31 {
32 return await _adminService.GetPharmacyHeads();
33 }
34
35 [HttpGet]
36 [Route("api/pharmacyhead/requests")]
37 public async Task<IEnumerable<RequestPharmacyHead>> GetClaimingRequests()
38 {
39 return await _adminService.GetClaimingRequests();
40 }
41
42
43 //POST
44 [HttpPost]
45 [Route("api/pharmacyhead/add")]
46 public async Task<IActionResult> AddPharmacyHead([FromBody]PharmacyHead pharmacyHead)
47 {
48 await _service.AddPharmacyHead(pharmacyHead);
49 return Ok("Pharmacy added.");
50 }
51
52 [HttpDelete]
53 [Route("api/pharmacyhead/delete/{Id}")]
54 public async Task<IActionResult> RemovePharmacyHead([FromRoute] int Id)
55 {
56 await _service.RemovePharmacyHead(Id);
57 return Ok();
58 }
59 [HttpDelete]
60 [Route("api/pharmacyhead/requests/{Id}")]
61 public IActionResult RejectRequest([FromRoute] int Id)
62 {
63 bool Success = _adminService.RejectRequest(Id);
64 return Ok(Success);
65 }
66 [HttpPost]
67 [Route("api/pharmacyhead/{Id}")]
68 public async Task<IActionResult> ApproveRequest([FromRoute]int Id, [FromBody]PharmacyHeadDto pharmacyHead)
69 {
70 await _phservice.UpdatePharmacyHead(pharmacyHead);
71 return Ok();
72 }
73
74 }
75}
Note: See TracBrowser for help on using the repository browser.