source: Farmatiko/Controllers/AdminController.cs@ 1db5673

Last change on this file since 1db5673 was 1db5673, checked in by DimitarSlezenkovski <dslezenkovski@…>, 4 years ago

Fix bugs, add some more

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