Ignore:
Timestamp:
11/05/20 06:57:35 (4 years ago)
Author:
DimitarSlezenkovski <dslezenkovski@…>
Branches:
master
Children:
afc9a9a
Parents:
1f4846d
Message:

Add SystemService, Auth, fix a lil bugs :)

Location:
Farmatiko/Controllers
Files:
1 added
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • Farmatiko/Controllers/AdminController.cs

    r1f4846d rd23bf72  
    55using FarmatikoData.Models;
    66using FarmatikoServices.FarmatikoServiceInterfaces;
     7using Microsoft.AspNetCore.Authorization;
    78using Microsoft.AspNetCore.Mvc;
    89
    910namespace Farmatiko.Controllers
    1011{
     12    [ApiController]
     13    [Authorize(Roles = "PharmacyHead")]
    1114    public class AdminController : Controller
    1215    {
     
    4043        [HttpPost]
    4144        [Route("api/pharmacyhead/add")]
    42         public async Task<IActionResult> AddPharmacyHead(PharmacyHead pharmacyHead)
     45        public async Task<IActionResult> AddPharmacyHead([FromBody]PharmacyHead pharmacyHead)
    4346        {
    4447            await _service.AddPharmacyHead(pharmacyHead);
     
    4649        }
    4750
    48         [HttpPost]
     51        [HttpDelete]
    4952        [Route("api/pharmacyhead/delete/{Id}")]
    50         public async Task<IActionResult> RemovePharmacyHead([FromQuery]int Id)
     53        public async Task<IActionResult> RemovePharmacyHead([FromRoute] int Id)
    5154        {
    5255            await _service.RemovePharmacyHead(Id);
    5356            return Ok();
    5457        }
    55         [HttpPost]
    56         public IActionResult RejectRequset(RequestPharmacyHead req)
     58        [HttpDelete]
     59        [Route("api/pharmacyhead/requests/{Id}")]
     60        public IActionResult RejectRequest([FromRoute] int Id)
    5761        {
    58             bool Success = _adminService.RejectRequest(req);
     62            bool Success = _adminService.RejectRequest(Id);
    5963            return Ok(Success);
    6064        }
    6165        [HttpPost]
    62         public async Task<IActionResult> ApproveRequest(PharmacyHead pharmacyHead)
     66        [Route("api/pharmacyhead/{Id}")]
     67        public async Task<IActionResult> ApproveRequest([FromRoute]int Id, [FromBody]PharmacyHead pharmacyHead)
    6368        {
     69            int id = Id;
    6470            await _phservice.UpdatePharmacyHead(pharmacyHead);
    6571            return Ok();
  • Farmatiko/Controllers/ErrorController.cs

    r1f4846d rd23bf72  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Threading.Tasks;
     1using System.Net;
     2using Microsoft.AspNetCore.Diagnostics;
    53using Microsoft.AspNetCore.Mvc;
     4using Microsoft.Extensions.Logging;
    65
    76namespace Farmatiko.Controllers
    87{
     8    [ApiController]
    99    public class ErrorController : Controller
    1010    {
    11         public IActionResult Index()
     11        private readonly ILogger<ErrorController> _logger;
     12
     13        public ErrorController(ILogger<ErrorController> logger)
    1214        {
    13             return View();
     15            _logger = logger;
     16        }
     17        [Route("/Error")]
     18        public IActionResult Error()
     19        {
     20            var exception = HttpContext.Features.Get<IExceptionHandlerFeature>();
     21            var statusCode = exception.Error.GetType().Name switch
     22            {
     23                "ArgumentException" => HttpStatusCode.BadRequest,
     24                "Exception" => HttpStatusCode.InternalServerError,
     25                /*"NotFoundResult" => HttpStatusCode.NotFound,*/
     26                _ => HttpStatusCode.ServiceUnavailable
     27            };
     28            _logger.LogInformation(statusCode.ToString() + " " + exception.ToString());
     29            return Problem(detail: exception.Error.Message, statusCode: (int)statusCode);
    1430        }
    1531    }
  • Farmatiko/Controllers/FarmatikoController.cs

    r1f4846d rd23bf72  
    1111    {
    1212        private readonly IService _service;
    13         public FarmatikoController(IService service)
     13        private readonly IProcessJSONService _JSONservice;
     14        public FarmatikoController(IService service, IProcessJSONService JSONservice)
    1415        {
    1516            _service = service;
     17            _JSONservice = JSONservice;
    1618        }
    1719        // Workers
    1820        //Get
     21        [HttpGet]
     22        [Route("api/getData")]
     23        public void InsertData()
     24        {
     25            //_JSONservice.DownloadPharmaciesExcel();
     26            //_JSONservice.GetProcessedHealthcareWorkersFromJSON();
     27            //_JSONservice.GetProcessedHealthFacilitiesFromJSON();
     28            //_JSONservice.GetProcessedMedicinesFromJSON();
     29            //_JSONservice.GetProcessedPandemicsFromJSONApi();
     30        }
    1931        [HttpGet]
    2032        [Route("api/workers")]
     
    2537        }
    2638        [HttpGet]
    27         [Route("api/workers/search/{Query}")]
    28         public async Task<IEnumerable<HealthcareWorker>> SearchWorkers(string Query)
     39        [Route("api/workers/search/{query}")]
     40        public async Task<IEnumerable<HealthcareWorker>> SearchWorkers([FromRoute]string query)
    2941        {
    30             return await _service.SearchWorkers(Query);
     42            return await _service.SearchWorkers(query);
    3143        }
    3244        [HttpGet]
    3345        [Route("api/workers/{id}")]
    34         public async Task<HealthcareWorker> GetWorker(int Id)
     46        public async Task<HealthcareWorker> GetWorker([FromRoute] int Id)
    3547        {
    3648            return await _service.GetWorker(Id);
     
    4860        }
    4961        [HttpGet]
    50         [Route("api/facilities/search/{Query}")]
    51         public async Task<IEnumerable<HealthFacility>> SearchFacilities(string Query)
     62        [Route("api/facilities/search/{query}")]
     63        public async Task<IEnumerable<HealthFacility>> SearchFacilities([FromRoute] string query)
    5264        {
    53             return await _service.SearchFacilities(Query);
     65            return await _service.SearchFacilities(query);
    5466        }
    5567        [HttpGet]
    56         [Route("api/facilities/{Id}")]
    57         public async Task<HealthFacility> GetFacility(int Id)
     68        [Route("api/facilities/{id}")]
     69        public async Task<HealthFacility> GetFacility([FromRoute] int id)
    5870        {
    59             return await _service.GetFacility(Id);
     71            return await _service.GetFacility(id);
    6072        }
    6173        //Post
     
    7082        }
    7183        [HttpGet]
    72         [Route("api/medicines/search/{Query}")]
    73         public async Task<IEnumerable<Medicine>> SearchMedicines(string Query)
     84        [Route("api/medicines/search/{query}")]
     85        public async Task<IEnumerable<Medicine>> SearchMedicines([FromRoute] string query)
    7486        {
    75             return await _service.SearchMedicines(Query);
     87            return await _service.SearchMedicines(query);
    7688        }
    7789        [HttpGet]
    7890        [Route("api/medicines/{Id}")]
    79         public async Task<Medicine> GetMedicine(int Id)
     91        public async Task<Medicine> GetMedicine([FromRoute] int Id)
    8092        {
    8193            return await _service.GetMedicine(Id);
     
    98110        [HttpGet]
    99111        [Route("api/pharmacy/search/{Query}")]
    100         public async Task<IEnumerable<Pharmacy>> SearchPharmacies(string Query)
     112        public async Task<IEnumerable<Pharmacy>> SearchPharmacies([FromRoute] string Query)
    101113        {
    102114            return await _service.SearchPharmacies(Query);
     
    104116        [HttpGet]
    105117        [Route("api/pharmacy/{Id}")]
    106         public async Task<Pharmacy> GetPharmacy(int Id)
     118        public async Task<Pharmacy> GetPharmacy([FromRoute] int Id)
    107119        {
    108120            return await _service.GetPharmacy(Id);
  • Farmatiko/Controllers/PharmacyHeadController.cs

    r1f4846d rd23bf72  
    1 using System.Collections;
    2 using System.Collections.Generic;
    3 using System.Linq;
     1using System.Collections.Generic;
    42using System.Threading.Tasks;
    5 using FarmatikoData.FarmatikoRepoInterfaces;
    63using FarmatikoData.Models;
    74using FarmatikoServices.FarmatikoServiceInterfaces;
     5using Microsoft.AspNetCore.Authorization;
    86using Microsoft.AspNetCore.Mvc;
    97
     
    119{
    1210    [ApiController]
     11    [Authorize(Roles = "PharmacyHead")]
    1312    public class PharmacyHeadController : Controller
    1413    {
     
    2019
    2120        //GET
    22         //Mi trebaat rutite
    23         [HttpGet]
     21        /*[HttpGet]
    2422        [Route("api/pharmacyhead")]
    25         public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo(string Token)
     23        public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo()
    2624        {
    27             var PHeads = await _PHService.GetPharmacyHeadInfo(Token);
     25            var PHeads = await _PHService.GetPharmacyHeadInfo();
    2826            return PHeads;
    29         }
     27        }*/
    3028        [HttpGet]
    3129        [Route("api/pharmacyhead/{Id}")]
    32         public async Task<PharmacyHead> GetPharmacyHeadById(int Id)
     30        public async Task<PharmacyHead> GetPharmacyHeadById([FromRoute]int Id)
    3331        {
    3432            var Phead = await _PHService.GetPharmacyHeadByIdAsync(Id);
     
    3836        [HttpPost]
    3937        [Route("api/pharmacyhead/add")]
    40         public async Task<IActionResult> AddPharmacyHead(PharmacyHead pharmacyHead)
     38        public async Task<IActionResult> AddPharmacyHead([FromBody]PharmacyHead pharmacyHead)
    4139        {
    4240            bool Success = await _PHService.Add(pharmacyHead);
     
    4442        }
    4543
    46         [HttpPost]
     44        /*[HttpPost]
    4745        [Route("api/pharmacyhead/login")]
    4846        public async Task<int> Login([FromBody]PharmacyHead pharmacyHead)
    4947        {
    5048            return await _PHService.Login(pharmacyHead);
    51         }
     49        }*/
    5250        [HttpPut]
    5351        [Route("api/pharmacyhead/{Id}")]
     
    5856        [HttpPost]
    5957        [Route("api/pharmacyhead/requests")]
    60         public async Task<IActionResult> ClaimPharmacy(RequestPharmacyHead pharmacy)
     58        public async Task<IActionResult> ClaimPharmacy([FromBody]RequestPharmacyHead pharmacy)
    6159        {
    6260            bool Success = await _PHService.ClaimPharmacy(pharmacy);
     
    6563        [HttpDelete]
    6664        [Route("api/pharmacyhead/delete/{Id}")]
    67         public async Task<IActionResult> Remove([FromQuery] int Id)
     65        public async Task<IActionResult> Remove([FromRoute] int Id)
    6866        {
    6967            bool Success = await _PHService.Remove(Id);
     
    7270        [HttpPost]
    7371        [Route("api/pharmacyhead/requests/{Id}")]
    74         public async Task<IActionResult> RemoveClaimingRequest([FromQuery] int Id)
     72        public async Task<IActionResult> RemoveClaimingRequest([FromRoute] int Id)
    7573        {
    7674            bool Success = await _PHService.RemoveClaimingRequest(Id);
Note: See TracChangeset for help on using the changeset viewer.