Commit 56f4426e authored by hasan khaddour's avatar hasan khaddour

update api

parent b4cba512
......@@ -8,18 +8,18 @@ using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
namespace WebPresentation.Controllers
namespace API.Controllers
{
[Route("api/[controller]")]
[ApiController]
[AllowAnonymous]
public class AccessAPIController : BaseController
public class AccessController : BaseController
{
private readonly SignInManager<User> _signInManager;
private readonly IPatientService _patientSerivce;
public AccessAPIController(UserManager<User> userManager,
public AccessController(UserManager<User> userManager,
SignInManager<User> signInManager,
IPatientService patientService):base(userManager)
{
......@@ -97,17 +97,17 @@ namespace WebPresentation.Controllers
}
[HttpGet("log")]
public IActionResult i()
{
return Ok(new { message = "Logout successful" });
}
[HttpPost("logout")]
public async Task<IActionResult> Logout()
{
await _signInManager.SignOutAsync();
return Ok(new { message = "Logout successful" });
}
}
[HttpGet("log")]
public IActionResult Log()
{
return Ok(new { message = "log successful" });
}
}
}
\ No newline at end of file
......@@ -6,7 +6,7 @@ using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Mvc;
namespace WebPresentation.Controllers
namespace API.Controllers
{
[Authorize]
[ApiController]
......@@ -30,7 +30,11 @@ namespace WebPresentation.Controllers
protected String GetUserName() {
return GetCurrentUser().UserName;
}
protected String GetUserEmail()
{
return GetCurrentUser().Email;
}
protected String GetUserId() {
return GetCurrentUser().Id;
......
......@@ -6,15 +6,15 @@ using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace WebPresentation.Controllers
namespace API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class CrudAPIController<TModel> : BaseController where TModel : DomainBase
public class CrudController<TModel> : BaseController where TModel : DomainBase
{
protected readonly IService<TModel> _service;
public CrudAPIController(
public CrudController(
IService<TModel> service,
UserManager<User> userManager)
......@@ -23,6 +23,7 @@ namespace WebPresentation.Controllers
_service = service;
}
[HttpGet]
public async virtual Task<IActionResult> GetAll()
{
IEnumerable<TModel> models = await _service.GetAll();
......@@ -49,7 +50,7 @@ namespace WebPresentation.Controllers
return Ok(ModifiedModel);
}
[HttpPut("delete")]
[HttpDelete("{id}")]
public IActionResult Delete(int id)
{
......@@ -58,7 +59,7 @@ namespace WebPresentation.Controllers
return Ok(new { mesage ="deleted"});
}
[HttpPost("create")]
[HttpPut]
public IActionResult Create(TModel model)
{
......
......@@ -10,16 +10,16 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebPresentation.Controllers
namespace API.Controllers
{
[Route("api/[controller]")]
[ApiController]
[AllowAnonymous]
public class MedicalStateApiController : CrudAPIController<MedicalStateModel>
public class MedicalStateController : CrudController<MedicalStateModel>
{
private readonly IPatientService _patientService;
public MedicalStateApiController(
public MedicalStateController(
IMedicalStateService medicalstateService,
IPatientService patientService,
UserManager<User> userManager)
......@@ -30,10 +30,9 @@ namespace WebPresentation.Controllers
public override async Task<IActionResult> GetAll()
{
string u = GetUserId();
var ps = await _patientService.GetAll();
var pId=ps.Where(p => p.User.Id == u).FirstOrDefault().Id;
var meds = ((IMedicalStateService)_service).GetAllPatientMedicalStates(pId);
var ps = await _patientService.GetByUserEmail(GetUserEmail());
var pId=ps.Id;
var meds = await ((IMedicalStateService)_service).GetAllPatientMedicalStates(pId);
return Ok(meds);
}
......
......@@ -9,13 +9,13 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebPresentation.Controllers
namespace API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class MedicineAPIController : CrudAPIController<MedicineModel>
public class MedicineController : CrudController<MedicineModel>
{
public MedicineAPIController(
public MedicineController(
IMedicineService medicalstateService,
UserManager<User> userManager)
: base(medicalstateService, userManager)
......
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
namespace API.Midlewares
{
public class ExceptionHandler
{
private readonly RequestDelegate _next;
public ExceptionHandler(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext httpContext)
{
try
{
await _next(httpContext);
}
catch (Exception ex)
{
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment