- Timestamp:
- 11/14/20 12:27:30 (4 years ago)
- Branches:
- master
- Children:
- 68454c6
- Parents:
- ad60966
- Location:
- Farmatiko
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
Farmatiko/ClientApp/src/app/admin/admin.component.html
rad60966 r1db5673 76 76 <input matInput [(ngModel)]="this.head.Passwd"> 77 77 </mat-form-field><br> 78 <button onclick="createHead()" mat-raised-button color="primary">Create</button>78 <button (click)="createHead()" mat-raised-button color="primary">Create</button> 79 79 </div> 80 80 </mat-tab> -
Farmatiko/ClientApp/src/app/dashboard/dashboard.component.ts
rad60966 r1db5673 43 43 44 44 claimPharmacy(pharmacy: IPharmacy) { 45 if(pharmacy && !this.head.Pharmacy.find(x => x === pharmacy)) { 46 this.request = null; 47 this.request.Pharmacy = pharmacy; 48 this.request.PharmacyHead = this.head; 49 this.dataService.claimPharmacy(this.request) 50 .subscribe((req: IPharmacyHeadRequest) => { 51 if(req) { 52 this.openSnackBar("Claiming request sent!", "OK"); 53 } 54 else { 55 this.openSnackBar("Unable to send a request", "Try again"); 56 } 57 }, 58 (err: any) => console.log(err), 59 () => console.log('Claiming request sent!')); 45 if(this.head.Pharmacy != null) { 46 if(pharmacy && !this.head.Pharmacy.find(x => x === pharmacy)) { 47 this.request = {}; 48 this.request.Pharmacy = pharmacy; 49 this.request.PharmacyHead = this.head; 50 this.dataService.claimPharmacy(this.request) 51 .subscribe((req) => { 52 if(req) { 53 this.openSnackBar("Claiming request sent!", "OK"); 54 } 55 else { 56 this.openSnackBar("Unable to send a request", "Try again"); 57 } 58 }, 59 (err: any) => console.log(err), 60 () => console.log('Claiming request sent!')); 61 } 62 } 63 else { 64 if(pharmacy) { 65 this.request = {}; 66 this.request.Pharmacy = pharmacy; 67 this.request.PharmacyHead = this.head; 68 this.dataService.claimPharmacy(this.request) 69 .subscribe((req) => { 70 if(req) { 71 this.openSnackBar("Claiming request sent!", "OK"); 72 } 73 else { 74 this.openSnackBar("Unable to send a request", "Try again"); 75 } 76 }, 77 (err: any) => console.log(err), 78 () => console.log('Claiming request sent!')); 79 } 60 80 } 61 81 } -
Farmatiko/ClientApp/src/app/login/login.component.ts
rad60966 r1db5673 54 54 .subscribe( 55 55 (data) => { 56 if(data.role == 'Admin') {56 if(data.role === 'Admin') { 57 57 this.router.navigate(['/admin']); 58 58 } -
Farmatiko/ClientApp/src/app/shared/data.service.ts
rad60966 r1db5673 6 6 7 7 import { IHealthFacilities, IHealthcareWorkers, IMedicine, IPandemic, IPharmacy, IPharmacyHead, IPharmacyHeadRequest } from './interfaces'; 8 import { environment } from '../../environments/environment'; 8 9 9 10 @Injectable() 10 11 export class DataService { 11 baseFacilitiesUrl: string = '/api/facilities';12 baseWorkersUrl: string = '/api/workers';13 baseMedicineUrl: string = '/api/medicines';14 basePandemicUrl: string = '/api/pandemic';15 basePharmacyUrl: string = '/api/pharmacy';16 basePharmacyHead: string = '/api/pharmacyhead';12 baseFacilitiesUrl: string = `${environment.baseApiUrl}api/facilities`; 13 baseWorkersUrl: string = `${environment.baseApiUrl}api/workers`; 14 baseMedicineUrl: string = `${environment.baseApiUrl}api/medicines`; 15 basePandemicUrl: string = `${environment.baseApiUrl}api/pandemic`; 16 basePharmacyUrl: string = `${environment.baseApiUrl}api/pharmacy`; 17 basePharmacyHead: string = `${environment.baseApiUrl}api/pharmacyhead`; 17 18 18 19 constructor(private http: HttpClient) { … … 179 180 //PharmacyHead PUT 180 181 updatePharmacyHead(head: IPharmacyHead) : Observable<IPharmacyHead> { 181 return this.http.put<IPharmacyHead>(this.basePharmacyHead + '/' + head.id, head)182 return this.http.put<IPharmacyHead>(this.basePharmacyHead, head) 182 183 .pipe( 183 184 map((data) => { -
Farmatiko/ClientApp/src/app/shared/interfaces.ts
rad60966 r1db5673 57 57 originalUserName?: string; 58 58 Role?: string; 59 } 60 59 } 61 60 export interface IPharmacyHeadRequest { 62 61 id?: string; -
Farmatiko/ClientApp/src/app/shared/services/auth.service.ts
rad60966 r1db5673 9 9 10 10 interface LoginResult { 11 user name: string;11 userName: string; 12 12 role: string; 13 13 originalUserName?: string; … … 36 36 this.http.get<LoginResult>(`${this.apiUrl}/user`).subscribe((x) => { 37 37 this._user.next({ 38 Email: x.user name,38 Email: x.userName, 39 39 Passwd: x.head.Passwd, 40 40 Role: x.role, … … 64 64 map((x) => { 65 65 this._user.next({ 66 Email: x.user name,66 Email: x.userName, 67 67 Passwd: x.head.Passwd, 68 68 Role: x.role, … … 105 105 map((x) => { 106 106 this._user.next({ 107 Email: x.user name,107 Email: x.userName, 108 108 Passwd: x.head.Passwd, 109 109 Role: x.role, -
Farmatiko/ClientApp/tsconfig.json
rad60966 r1db5673 2 2 "compileOnSave": false, 3 3 "compilerOptions": { 4 "baseUrl": "https://localhost: 44342/",4 "baseUrl": "https://localhost:5001/", 5 5 "module": "esnext", 6 6 "outDir": "./dist/out-tsc", -
Farmatiko/Controllers/AdminController.cs
rad60966 r1db5673 11 11 { 12 12 [ApiController] 13 [Authorize(Roles = " PharmacyHead")]13 [Authorize(Roles = "Admin")] 14 14 public class AdminController : Controller 15 15 { -
Farmatiko/Controllers/FarmatikoController.cs
rad60966 r1db5673 27 27 //_JSONservice.GetProcessedHealthFacilitiesFromJSON(); 28 28 //_JSONservice.GetProcessedMedicinesFromJSON(); 29 //_JSONservice.GetProcessedPandemicsFromJSONApi();29 _JSONservice.GetProcessedPandemicsFromJSONApi(); 30 30 } 31 31 [HttpGet] -
Farmatiko/Controllers/LoginController.cs
rad60966 r1db5673 61 61 Role = role, 62 62 AccessToken = jwtResult.AccessToken, 63 RefreshToken = jwtResult.RefreshToken.TokenString, 63 RefreshToken = jwtResult.RefreshToken.TokenString, 64 64 Head = _pHService.GetPharmacyHead(request.UserName) 65 65 }); … … 110 110 return Ok(new LoginResult 111 111 { 112 /*UserName = userName, 113 114 Role = User.FindFirst(ClaimTypes.Role)?.Value ?? string.Empty, 115 AccessToken = jwtResult.AccessToken, 116 RefreshToken = jwtResult.RefreshToken.TokenString*/ 117 112 118 UserName = userName, 113 119 Role = User.FindFirst(ClaimTypes.Role)?.Value ?? string.Empty, 114 120 AccessToken = jwtResult.AccessToken, 115 RefreshToken = jwtResult.RefreshToken.TokenString 121 RefreshToken = jwtResult.RefreshToken.TokenString, 122 Head = _pHService.GetPharmacyHead(userName) 116 123 }); 117 124 } … … 156 163 OriginalUserName = userName, 157 164 AccessToken = jwtResult.AccessToken, 158 RefreshToken = jwtResult.RefreshToken.TokenString 165 RefreshToken = jwtResult.RefreshToken.TokenString, 166 Head = _pHService.GetPharmacyHead(userName) 159 167 }); 160 168 } … … 186 194 OriginalUserName = null, 187 195 AccessToken = jwtResult.AccessToken, 188 RefreshToken = jwtResult.RefreshToken.TokenString 196 RefreshToken = jwtResult.RefreshToken.TokenString, 197 Head = _pHService.GetPharmacyHead(userName) 189 198 }); 190 199 } … … 204 213 public class LoginResult 205 214 { 206 [JsonPropertyName("user name")]215 [JsonPropertyName("userName")] 207 216 public string UserName { get; set; } 208 217 … … 219 228 public string RefreshToken { get; set; } 220 229 [JsonPropertyName("head")] 221 public PharmacyHeadHead { get; set; }230 public object Head { get; set; } 222 231 } 223 232 … … 230 239 public class ImpersonationRequest 231 240 { 232 [JsonPropertyName("user name")]241 [JsonPropertyName("userName")] 233 242 public string UserName { get; set; } 234 243 } -
Farmatiko/Controllers/PharmacyHeadController.cs
rad60966 r1db5673 19 19 20 20 //GET 21 /*[HttpGet] 21 /* 22 [HttpGet] 22 23 [Route("api/pharmacyhead")] 23 24 public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo() … … 26 27 return PHeads; 27 28 }*/ 29 28 30 [HttpGet] 29 31 [Route("api/pharmacyhead/{Id}")] … … 34 36 } 35 37 //POST 38 /* 36 39 [HttpPost] 37 40 [Route("api/pharmacyhead/add")] … … 40 43 bool Success = await _PHService.Add(pharmacyHead); 41 44 return Ok(Success); 42 } 45 }*/ 43 46 44 47 /*[HttpPost] … … 49 52 }*/ 50 53 [HttpPut] 51 [Route("api/pharmacyhead/{Id}")] 54 [Route("api/pharmacyhead")] 55 [Authorize(Roles = "Admin")] 56 [Authorize(Roles = "PharmacyHead")] 52 57 public async Task UpdatePharmacyHead([FromBody]PharmacyHead pharmacyHead) 53 58 { -
Farmatiko/Farmatiko.csproj
rad60966 r1db5673 15 15 <ItemGroup> 16 16 <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.9" /> 17 <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.10" /> 18 <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.10" /> 17 19 <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.1.6" /> 18 <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1. 6" />19 <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1. 6">20 <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.10" /> 21 <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.10"> 20 22 <PrivateAssets>all</PrivateAssets> 21 23 <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> 22 24 </PackageReference> 23 <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1. 6">25 <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.10"> 24 26 <PrivateAssets>all</PrivateAssets> 25 27 <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> 26 28 </PackageReference> 29 <PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> 27 30 <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" /> 28 31 </ItemGroup> … … 38 41 <Compile Remove="Controllers\WeatherForecastController.cs" /> 39 42 <Compile Remove="WeatherForecast.cs" /> 43 </ItemGroup> 44 45 <ItemGroup> 46 <None Include="..\.editorconfig" Link=".editorconfig" /> 40 47 </ItemGroup> 41 48 -
Farmatiko/Startup.cs
rad60966 r1db5673 18 18 using FarmatikoServices.Infrastructure; 19 19 using System; 20 20 using Newtonsoft.Json.Serialization; 21 21 namespace Farmatiko 22 22 { … … 45 45 46 46 services.AddControllersWithViews(); 47 services.AddControllersWithViews().AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); 47 48 // In production, the Angular files will be served from this directory 48 49 services.AddSpaStaticFiles(configuration => … … 53 54 services.AddEntityFrameworkNpgsql().AddDbContext<FarmatikoDataContext>(opt => opt.UseNpgsql(connectionString)); 54 55 55 services.Add Transient<IPHRepo, PHRepo>();56 services.AddScoped<IPHRepo, PHRepo>(); 56 57 services.AddTransient<IRepository, Repository>(); 57 58 services.AddTransient<IAdminRepo, AdminRepo>();
Note:
See TracChangeset
for help on using the changeset viewer.