Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding_Typescript #14

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
876eda1
adding user role and its configuration in DbContext
AhmadHddad Oct 14, 2020
dd05648
adding userRole
AhmadHddad Oct 14, 2020
550e250
adding role
AhmadHddad Oct 14, 2020
de452b3
updating user for identity
AhmadHddad Oct 14, 2020
9b38908
updating gitIgnore
AhmadHddad Oct 14, 2020
f880d14
Merge branch 'UpgradingDotNet' of https://github.com/AhmadHddad/ICare…
AhmadHddad Oct 14, 2020
8a333c7
updating to 3.1.9
AhmadHddad Oct 16, 2020
100dc5a
adding CreateHostBuilder for allowing ef core access to db COntext
AhmadHddad Oct 16, 2020
f8cc1eb
message if availble
AhmadHddad Oct 16, 2020
05ef9ee
adding default! to null-forgive
AhmadHddad Oct 16, 2020
4a44aa8
removing unessary properties
AhmadHddad Oct 16, 2020
3011213
adding UnAuthorizedException
AhmadHddad Oct 16, 2020
f664524
configuring statup for adding roles and policies
AhmadHddad Oct 16, 2020
2759adc
default!; and renaming
AhmadHddad Oct 16, 2020
ec179e1
renaming
AhmadHddad Oct 16, 2020
3c36afa
removing unessary param
AhmadHddad Oct 16, 2020
23ae9a1
adding enums
AhmadHddad Nov 26, 2020
2e729d7
adding .eslintrc
AhmadHddad Nov 26, 2020
dfe6b5c
renmaing
AhmadHddad Jan 3, 2021
62c31bd
outSourcing code
AhmadHddad Jan 3, 2021
6d268a2
migration
AhmadHddad Jan 3, 2021
44eaaa0
adding connection string to appsettings.dev
AhmadHddad May 5, 2021
123e886
upgrading to .net to 5.0
AhmadHddad May 5, 2021
bd47932
commenting roles for now
AhmadHddad May 5, 2021
e0c6bdb
fixing program
AhmadHddad May 5, 2021
3a9667e
fixing design time, commenting roels
AhmadHddad May 5, 2021
56a83f5
null chekc
AhmadHddad May 5, 2021
030773f
new migration with new db
AhmadHddad May 5, 2021
09940ba
configuraing logging leves
AhmadHddad May 7, 2021
ff21d60
configuaring launch settings to swagger
AhmadHddad May 7, 2021
d5273db
commenting unessary code
AhmadHddad May 7, 2021
0dfffda
configurating routing and swagger
AhmadHddad May 7, 2021
4ea2a78
updating language version
AhmadHddad May 7, 2021
886f211
minor fixes
AhmadHddad May 7, 2021
1caad6e
adding space
AhmadHddad May 8, 2021
796081f
enhancments, and null checks
AhmadHddad May 8, 2021
9b38397
adding base controller
AhmadHddad May 10, 2021
db74d5b
inherting from base controller
AhmadHddad May 10, 2021
2a77dfd
renamings
AhmadHddad May 10, 2021
5220731
enhancing automapper injection, routs to lower case
AhmadHddad May 10, 2021
a20fed6
adding bogus to generate some fake data
AhmadHddad May 10, 2021
bb4d87d
adding phone number to doctors and patients with dtos
AhmadHddad May 10, 2021
5646561
adding seed data api
AhmadHddad May 10, 2021
058ffed
phone number
AhmadHddad May 10, 2021
168f0e1
upgrading packages and adding typescript packages
AhmadHddad May 15, 2021
9e27044
removing jsconfig
AhmadHddad May 15, 2021
fff9344
adding tscofnig
AhmadHddad May 15, 2021
5611ec9
adding env
AhmadHddad May 15, 2021
7b24e08
replacing constants.js to .ts
AhmadHddad May 15, 2021
2df43c2
fixing .js issues
AhmadHddad May 15, 2021
0ffc555
removing eslint
AhmadHddad May 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ ICareAPI/.history
ICareAPI/ICareApi.code-workspace
TODO.md
icare.code-workspace
ICareClient/.vscode/launch.json
ICareClient/.vscode
52 changes: 13 additions & 39 deletions ICareAPI/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
using Microsoft.IdentityModel.Tokens;
using ICareAPI.Repositories;
using ICareAPI.Dtos;
using ICareAPI.Helpers;
using ICareAPI.Models;
using Microsoft.AspNetCore.Authorization;

namespace ICareAPI.Controllers
{
[Route("api/[controller]")]
[ApiController]
[AllowAnonymous]
public class AuthController : ControllerBase
{

Expand All @@ -34,61 +35,34 @@ public AuthController(IAuthRepository repo, IConfiguration config)
public async Task<IActionResult> Register(UserForRegisterDto userForRegisterDto)
{

userForRegisterDto.Email = userForRegisterDto.Email.ToLower();

if (await _repo.EmailExists(userForRegisterDto.Email))
var newUser = new User
{
return BadRequest("User Already Exists");
}
else
{
var newUser = new User
{
Email = userForRegisterDto.Email,
UserName = userForRegisterDto.UserName
};
Email = userForRegisterDto.Email,
UserName = userForRegisterDto.UserName
};


var createdUser = await _repo.Register(newUser, userForRegisterDto.Password);
return StatusCode(201);
}
var reg = await _repo.Register(newUser, userForRegisterDto.Password);
return StatusCode(201);
}


[HttpPost("login")]
public async Task<IActionResult> Login(UserForLoginDto userForLoginDto)
{
var userFromRepo = await _repo.Login(userForLoginDto.Email.ToLower(), userForLoginDto.Password);
var user = await _repo.Login(userForLoginDto.Email.ToLower(), userForLoginDto.Password);

if (userFromRepo == null)
if (user is null)
{
return Unauthorized("Email Or Password Is Wrong");
return Unauthorized();
}
else
{

var claims = new[] {
new Claim(ClaimTypes.NameIdentifier, userFromRepo.Id.ToString()),
new Claim(ClaimTypes.Name, userFromRepo.UserName),
};


var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config.GetSection("AppSettings:Token").Value));

var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha512Signature);

var tokenDecriptor = new SecurityTokenDescriptor
{
Subject = new ClaimsIdentity(claims),
Expires = DateTime.Now.AddDays(1),
SigningCredentials = creds
};

var tokenHandler = new JwtSecurityTokenHandler();

var token = tokenHandler.CreateToken(tokenDecriptor);
var token = _repo.GenerateUserToken(user);

return Ok(new { token = tokenHandler.WriteToken(token), Expires = DateTime.Now.AddDays(1) });
return Ok(token);
}
}

Expand Down
15 changes: 15 additions & 0 deletions ICareAPI/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using ICareAPI.Helpers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace ICareAPI.Controllers
{
[Authorize]
[Route("api/[controller]")]
[ApiController]
[ServiceFilter(typeof(LogUserActivity))]
public class BaseController : ControllerBase
{

}
}
22 changes: 9 additions & 13 deletions ICareAPI/Controllers/DoctorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@

namespace ICareAPI.Controllers
{
[Route("api/doctors")]
[ApiController]
[Authorize]
[ServiceFilter(typeof(LogUserActivity))]

public class DoctorsController : ControllerBase
public class DoctorsController : BaseController
{
private readonly IDoctorRepository _repo;
private readonly IPatientDoctorRepository _patientDoctorRepo;
Expand All @@ -41,7 +37,7 @@ IPatientRepository patientRepository
public async Task<IActionResult> GetDoctors([FromQuery] PaginationParams paginationParams)
{

var doctors = await _repo.GetDoctorsList(paginationParams);
var doctors = await _repo.GetDoctorsListAsync(paginationParams);

HttpContext.Response.AddPagination(doctors.CurrnetPage, doctors.PageSize, doctors.TotalCount, doctors.TotalPages);

Expand All @@ -51,10 +47,10 @@ public async Task<IActionResult> GetDoctors([FromQuery] PaginationParams paginat

// GET api/doctor/5
[HttpGet("{id}")]
public async Task<IActionResult> GetDoctorById(int id, bool withAssignedPatients = false)
public async Task<IActionResult> GetDoctorById(int id)
{

var doctor = await _repo.GetDoctor(id);
var doctor = await _repo.GetDoctorAsync(id);

return Ok(doctor);

Expand All @@ -69,7 +65,7 @@ public async Task<IActionResult> AddDoctor(DoctorForAddDto doctor)
if (ModelState.IsValid)
{

var addedDoctor = await _repo.AddDoctor(_mapper.Map<Doctor>(doctor));
var addedDoctor = await _repo.AddDoctorAsync(_mapper.Map<Doctor>(doctor));
return Ok(addedDoctor);
}
else
Expand All @@ -93,7 +89,7 @@ public async Task<IActionResult> AddDoctor(DoctorForAddDto doctor)
public async Task<ActionResult> DeleteDoctor(int id)
{

var deleted = await _repo.DeleteDoctor(id);
var deleted = await _repo.DeleteDoctorAsync(id);

return Ok(deleted);
}
Expand All @@ -116,7 +112,7 @@ public async Task<ActionResult> GetAssignedPatients(int id, [FromQuery] Paginati
public async Task<ActionResult> GetUnAssignedPatients(int doctorId, [FromQuery] PaginationParams paginationParams)
{

var unAssignedPatients = await _patientRepository.GetUnAssignedPatientsToDoctor(doctorId, paginationParams);
var unAssignedPatients = await _patientRepository.GetUnAssignedPatientsToDoctorAsync(doctorId, paginationParams);

HttpContext.Response.AddPagination(unAssignedPatients.CurrnetPage, unAssignedPatients.PageSize, unAssignedPatients.TotalCount, unAssignedPatients.TotalPages);

Expand Down Expand Up @@ -153,11 +149,11 @@ public async Task<IActionResult> RemovePatientDoctor(int doctorId, int patientId
public async Task<ActionResult> EditDoctor(DoctorForEditDto doctorForEdit)
{

var doctor = await _repo.GetDoctor(doctorForEdit.Id);
var doctor = await _repo.GetDoctorAsync(doctorForEdit.Id);

var mappedDoctor = _mapper.Map<DoctorForEditDto, Doctor>(doctorForEdit, doctor);

return Ok(await _repo.EditDoctor(mappedDoctor));
return Ok(await _repo.EditDoctorAsync(mappedDoctor));

}

Expand Down
24 changes: 10 additions & 14 deletions ICareAPI/Controllers/PatientsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
namespace ICareAPI.Controllers

{
[ServiceFilter(typeof(LogUserActivity))]
[Authorize]
[Route("api/patients")]
[ApiController]
public class PatientsController : ControllerBase
public class PatientsController : BaseController
{
private readonly IPatientRepository _repo;
private readonly IMapper _mapper;
Expand All @@ -33,7 +29,7 @@ public PatientsController(IPatientRepository repo, IMapper mapper, IPatientDocto
[HttpGet]
public async Task<IActionResult> Patients(bool? withRecords, [FromQuery] PaginationParams paginationParams)
{
var pations = await _repo.GetPatients(true, paginationParams);
var pations = await _repo.GetPatientsAsync(true, paginationParams);

if (pations != null && withRecords == true)
{
Expand All @@ -56,7 +52,7 @@ public async Task<IActionResult> Patients(bool? withRecords, [FromQuery] Paginat
[HttpGet("{id}")]
public async Task<IActionResult> GetPatientById(int id, bool? withRecords)
{
var pation = await _repo.GetPatient(id, withRecords);
var pation = await _repo.GetPatientAsync(id, withRecords);

var patientToReturn = _mapper.Map<PatientForDetailsDto>(pation);
return Ok(patientToReturn);
Expand All @@ -67,7 +63,7 @@ public async Task<IActionResult> GetPatientById(int id, bool? withRecords)

public async Task<IActionResult> GetPatientsStatistics(int id)
{
var patient = await _repo.GetPatient(id, true);
var patient = await _repo.GetPatientAsync(id, true);

var mappedPatient = _mapper.Map<PatientForDetailsDto>(patient);

Expand Down Expand Up @@ -98,9 +94,9 @@ public async Task<IActionResult> EditPatient(PatientForEditDto patient)
if (ModelState.IsValid)
{

var patientToEdit = await _repo.GetPatient(patient.Id);
var patientToEdit = await _repo.GetPatientAsync(patient.Id);
var mappedPatient = _mapper.Map<PatientForEditDto, Patient>(patient, patientToEdit);
var newPation = await _repo.EditPatient(mappedPatient);
var newPation = await _repo.EditPatientAsync(mappedPatient);

return Ok(patientToEdit);
}
Expand All @@ -113,10 +109,10 @@ public async Task<IActionResult> EditPatient(PatientForEditDto patient)
[HttpDelete("{id}")]
public async Task<IActionResult> DeletePatient(int id)
{
var patientForDelete = await _repo.GetPatient(id, false);
var patientForDelete = await _repo.GetPatientAsync(id, false);


var deletedPatient = await _repo.DeletePatient(patientForDelete);
var deletedPatient = await _repo.DeletePatientAsync(patientForDelete);

return Ok(deletedPatient);

Expand All @@ -127,7 +123,7 @@ public async Task<IActionResult> DeletePatient(int id)
public async Task<IActionResult> PatchPatient(int id, JsonPatchDocument<PatientForEditDto> patient)
{

var patientToPatch = _repo.GetPatient(id, false).Result;
var patientToPatch = _repo.GetPatientAsync(id, false).Result;

if (patientToPatch != null)
{
Expand All @@ -147,7 +143,7 @@ public async Task<IActionResult> PatchPatient(int id, JsonPatchDocument<PatientF

var patientForRepo = _mapper.Map<JsonPatchDocument<Patient>>(patient);

var x = await _repo.PatchPatient(id, patientForRepo);
var x = await _repo.PatchPatientAsync(id, patientForRepo);

if (x == 0)
{
Expand Down
Loading