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

update api

parent b4cba512
...@@ -8,18 +8,18 @@ using Microsoft.AspNetCore.Mvc; ...@@ -8,18 +8,18 @@ using Microsoft.AspNetCore.Mvc;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace WebPresentation.Controllers namespace API.Controllers
{ {
[Route("api/[controller]")] [Route("api/[controller]")]
[ApiController] [ApiController]
[AllowAnonymous] [AllowAnonymous]
public class AccessAPIController : BaseController public class AccessController : BaseController
{ {
private readonly SignInManager<User> _signInManager; private readonly SignInManager<User> _signInManager;
private readonly IPatientService _patientSerivce; private readonly IPatientService _patientSerivce;
public AccessAPIController(UserManager<User> userManager, public AccessController(UserManager<User> userManager,
SignInManager<User> signInManager, SignInManager<User> signInManager,
IPatientService patientService):base(userManager) IPatientService patientService):base(userManager)
{ {
...@@ -97,17 +97,17 @@ namespace WebPresentation.Controllers ...@@ -97,17 +97,17 @@ namespace WebPresentation.Controllers
} }
[HttpGet("log")]
public IActionResult i()
{
return Ok(new { message = "Logout successful" });
}
[HttpPost("logout")] [HttpPost("logout")]
public async Task<IActionResult> Logout() public async Task<IActionResult> Logout()
{ {
await _signInManager.SignOutAsync(); await _signInManager.SignOutAsync();
return Ok(new { message = "Logout successful" }); 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; ...@@ -6,7 +6,7 @@ using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace WebPresentation.Controllers namespace API.Controllers
{ {
[Authorize] [Authorize]
[ApiController] [ApiController]
...@@ -30,7 +30,11 @@ namespace WebPresentation.Controllers ...@@ -30,7 +30,11 @@ namespace WebPresentation.Controllers
protected String GetUserName() { protected String GetUserName() {
return GetCurrentUser().UserName; return GetCurrentUser().UserName;
} }
protected String GetUserEmail()
{
return GetCurrentUser().Email;
}
protected String GetUserId() { protected String GetUserId() {
return GetCurrentUser().Id; return GetCurrentUser().Id;
......
...@@ -6,15 +6,15 @@ using Microsoft.AspNetCore.Mvc; ...@@ -6,15 +6,15 @@ using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace WebPresentation.Controllers namespace API.Controllers
{ {
[Route("api/[controller]")] [Route("api/[controller]")]
[ApiController] [ApiController]
public class CrudAPIController<TModel> : BaseController where TModel : DomainBase public class CrudController<TModel> : BaseController where TModel : DomainBase
{ {
protected readonly IService<TModel> _service; protected readonly IService<TModel> _service;
public CrudAPIController( public CrudController(
IService<TModel> service, IService<TModel> service,
UserManager<User> userManager) UserManager<User> userManager)
...@@ -23,6 +23,7 @@ namespace WebPresentation.Controllers ...@@ -23,6 +23,7 @@ namespace WebPresentation.Controllers
_service = service; _service = service;
} }
[HttpGet]
public async virtual Task<IActionResult> GetAll() public async virtual Task<IActionResult> GetAll()
{ {
IEnumerable<TModel> models = await _service.GetAll(); IEnumerable<TModel> models = await _service.GetAll();
...@@ -49,7 +50,7 @@ namespace WebPresentation.Controllers ...@@ -49,7 +50,7 @@ namespace WebPresentation.Controllers
return Ok(ModifiedModel); return Ok(ModifiedModel);
} }
[HttpPut("delete")] [HttpDelete("{id}")]
public IActionResult Delete(int id) public IActionResult Delete(int id)
{ {
...@@ -58,7 +59,7 @@ namespace WebPresentation.Controllers ...@@ -58,7 +59,7 @@ namespace WebPresentation.Controllers
return Ok(new { mesage ="deleted"}); return Ok(new { mesage ="deleted"});
} }
[HttpPost("create")] [HttpPut]
public IActionResult Create(TModel model) public IActionResult Create(TModel model)
{ {
......
...@@ -10,16 +10,16 @@ using System.Collections.Generic; ...@@ -10,16 +10,16 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace WebPresentation.Controllers namespace API.Controllers
{ {
[Route("api/[controller]")] [Route("api/[controller]")]
[ApiController] [ApiController]
[AllowAnonymous] [AllowAnonymous]
public class MedicalStateApiController : CrudAPIController<MedicalStateModel> public class MedicalStateController : CrudController<MedicalStateModel>
{ {
private readonly IPatientService _patientService; private readonly IPatientService _patientService;
public MedicalStateApiController( public MedicalStateController(
IMedicalStateService medicalstateService, IMedicalStateService medicalstateService,
IPatientService patientService, IPatientService patientService,
UserManager<User> userManager) UserManager<User> userManager)
...@@ -30,10 +30,9 @@ namespace WebPresentation.Controllers ...@@ -30,10 +30,9 @@ namespace WebPresentation.Controllers
public override async Task<IActionResult> GetAll() public override async Task<IActionResult> GetAll()
{ {
string u = GetUserId(); var ps = await _patientService.GetByUserEmail(GetUserEmail());
var ps = await _patientService.GetAll(); var pId=ps.Id;
var pId=ps.Where(p => p.User.Id == u).FirstOrDefault().Id; var meds = await ((IMedicalStateService)_service).GetAllPatientMedicalStates(pId);
var meds = ((IMedicalStateService)_service).GetAllPatientMedicalStates(pId);
return Ok(meds); return Ok(meds);
} }
......
...@@ -9,13 +9,13 @@ using System.Collections.Generic; ...@@ -9,13 +9,13 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace WebPresentation.Controllers namespace API.Controllers
{ {
[Route("api/[controller]")] [Route("api/[controller]")]
[ApiController] [ApiController]
public class MedicineAPIController : CrudAPIController<MedicineModel> public class MedicineController : CrudController<MedicineModel>
{ {
public MedicineAPIController( public MedicineController(
IMedicineService medicalstateService, IMedicineService medicalstateService,
UserManager<User> userManager) UserManager<User> userManager)
: base(medicalstateService, 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