Changeset 1db5673 for Farmatiko


Ignore:
Timestamp:
11/14/20 12:27:30 (3 years ago)
Author:
DimitarSlezenkovski <dslezenkovski@…>
Branches:
master
Children:
68454c6
Parents:
ad60966
Message:

Fix bugs, add some more

Location:
Farmatiko
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • Farmatiko/ClientApp/src/app/admin/admin.component.html

    rad60966 r1db5673  
    7676            <input matInput [(ngModel)]="this.head.Passwd">
    7777          </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>
    7979          </div>
    8080        </mat-tab>
  • Farmatiko/ClientApp/src/app/dashboard/dashboard.component.ts

    rad60966 r1db5673  
    4343 
    4444  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      }
    6080    }
    6181  }
  • Farmatiko/ClientApp/src/app/login/login.component.ts

    rad60966 r1db5673  
    5454      .subscribe(
    5555        (data) => {
    56           if(data.role == 'Admin') {
     56          if(data.role === 'Admin') {
    5757            this.router.navigate(['/admin']);
    5858          }
  • Farmatiko/ClientApp/src/app/shared/data.service.ts

    rad60966 r1db5673  
    66
    77import { IHealthFacilities, IHealthcareWorkers, IMedicine, IPandemic, IPharmacy, IPharmacyHead, IPharmacyHeadRequest } from './interfaces';
     8import { environment } from '../../environments/environment';
    89
    910@Injectable()
    1011export 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`;
    1718
    1819    constructor(private http: HttpClient) {
     
    179180    //PharmacyHead PUT
    180181    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)
    182183                   .pipe(
    183184                        map((data) => {
  • Farmatiko/ClientApp/src/app/shared/interfaces.ts

    rad60966 r1db5673  
    5757    originalUserName?: string;
    5858    Role?: string;
    59 
    60 
     59}
    6160export interface IPharmacyHeadRequest {
    6261    id?: string;
  • Farmatiko/ClientApp/src/app/shared/services/auth.service.ts

    rad60966 r1db5673  
    99
    1010interface LoginResult {
    11   username: string;
     11  userName: string;
    1212  role: string;
    1313  originalUserName?: string;
     
    3636        this.http.get<LoginResult>(`${this.apiUrl}/user`).subscribe((x) => {
    3737          this._user.next({
    38             Email: x.username,
     38            Email: x.userName,
    3939            Passwd: x.head.Passwd,
    4040            Role: x.role,
     
    6464        map((x) => {
    6565          this._user.next({
    66             Email: x.username,
     66            Email: x.userName,
    6767            Passwd: x.head.Passwd,
    6868            Role: x.role,
     
    105105        map((x) => {
    106106          this._user.next({
    107             Email: x.username,
     107            Email: x.userName,
    108108            Passwd: x.head.Passwd,
    109109            Role: x.role,
  • Farmatiko/ClientApp/tsconfig.json

    rad60966 r1db5673  
    22  "compileOnSave": false,
    33  "compilerOptions": {
    4     "baseUrl": "https://localhost:44342/",
     4    "baseUrl": "https://localhost:5001/",
    55    "module": "esnext",
    66    "outDir": "./dist/out-tsc",
  • Farmatiko/Controllers/AdminController.cs

    rad60966 r1db5673  
    1111{
    1212    [ApiController]
    13     [Authorize(Roles = "PharmacyHead")]
     13    [Authorize(Roles = "Admin")]
    1414    public class AdminController : Controller
    1515    {
  • Farmatiko/Controllers/FarmatikoController.cs

    rad60966 r1db5673  
    2727            //_JSONservice.GetProcessedHealthFacilitiesFromJSON();
    2828            //_JSONservice.GetProcessedMedicinesFromJSON();
    29             //_JSONservice.GetProcessedPandemicsFromJSONApi();
     29            _JSONservice.GetProcessedPandemicsFromJSONApi();
    3030        }
    3131        [HttpGet]
  • Farmatiko/Controllers/LoginController.cs

    rad60966 r1db5673  
    6161                Role = role,
    6262                AccessToken = jwtResult.AccessToken,
    63                 RefreshToken = jwtResult.RefreshToken.TokenString,
     63                RefreshToken = jwtResult.RefreshToken.TokenString, 
    6464                Head = _pHService.GetPharmacyHead(request.UserName)
    6565            });
     
    110110                return Ok(new LoginResult
    111111                {
     112                    /*UserName = userName,
     113                   
     114                    Role = User.FindFirst(ClaimTypes.Role)?.Value ?? string.Empty,
     115                    AccessToken = jwtResult.AccessToken,
     116                    RefreshToken = jwtResult.RefreshToken.TokenString*/
     117
    112118                    UserName = userName,
    113119                    Role = User.FindFirst(ClaimTypes.Role)?.Value ?? string.Empty,
    114120                    AccessToken = jwtResult.AccessToken,
    115                     RefreshToken = jwtResult.RefreshToken.TokenString
     121                    RefreshToken = jwtResult.RefreshToken.TokenString,
     122                    Head = _pHService.GetPharmacyHead(userName)
    116123                });
    117124            }
     
    156163                OriginalUserName = userName,
    157164                AccessToken = jwtResult.AccessToken,
    158                 RefreshToken = jwtResult.RefreshToken.TokenString
     165                RefreshToken = jwtResult.RefreshToken.TokenString,
     166                Head = _pHService.GetPharmacyHead(userName)
    159167            });
    160168        }
     
    186194                OriginalUserName = null,
    187195                AccessToken = jwtResult.AccessToken,
    188                 RefreshToken = jwtResult.RefreshToken.TokenString
     196                RefreshToken = jwtResult.RefreshToken.TokenString,
     197                Head = _pHService.GetPharmacyHead(userName)
    189198            });
    190199        }
     
    204213    public class LoginResult
    205214    {
    206         [JsonPropertyName("username")]
     215        [JsonPropertyName("userName")]
    207216        public string UserName { get; set; }
    208217
     
    219228        public string RefreshToken { get; set; }
    220229        [JsonPropertyName("head")]
    221         public PharmacyHead Head { get; set; }
     230        public object Head { get; set; }
    222231    }
    223232
     
    230239    public class ImpersonationRequest
    231240    {
    232         [JsonPropertyName("username")]
     241        [JsonPropertyName("userName")]
    233242        public string UserName { get; set; }
    234243    }
  • Farmatiko/Controllers/PharmacyHeadController.cs

    rad60966 r1db5673  
    1919
    2020        //GET
    21         /*[HttpGet]
     21        /*
     22        [HttpGet]
    2223        [Route("api/pharmacyhead")]
    2324        public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo()
     
    2627            return PHeads;
    2728        }*/
     29
    2830        [HttpGet]
    2931        [Route("api/pharmacyhead/{Id}")]
     
    3436        }
    3537        //POST
     38        /*
    3639        [HttpPost]
    3740        [Route("api/pharmacyhead/add")]
     
    4043            bool Success = await _PHService.Add(pharmacyHead);
    4144            return Ok(Success);
    42         }
     45        }*/
    4346
    4447        /*[HttpPost]
     
    4952        }*/
    5053        [HttpPut]
    51         [Route("api/pharmacyhead/{Id}")]
     54        [Route("api/pharmacyhead")]
     55        [Authorize(Roles = "Admin")]
     56        [Authorize(Roles = "PharmacyHead")]
    5257        public async Task UpdatePharmacyHead([FromBody]PharmacyHead pharmacyHead)
    5358        {
  • Farmatiko/Farmatiko.csproj

    rad60966 r1db5673  
    1515  <ItemGroup>
    1616    <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" />
    1719    <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">
    2022      <PrivateAssets>all</PrivateAssets>
    2123      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    2224    </PackageReference>
    23     <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.6">
     25    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.10">
    2426      <PrivateAssets>all</PrivateAssets>
    2527      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    2628    </PackageReference>
     29    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    2730    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
    2831  </ItemGroup>
     
    3841    <Compile Remove="Controllers\WeatherForecastController.cs" />
    3942    <Compile Remove="WeatherForecast.cs" />
     43  </ItemGroup>
     44
     45  <ItemGroup>
     46    <None Include="..\.editorconfig" Link=".editorconfig" />
    4047  </ItemGroup>
    4148
  • Farmatiko/Startup.cs

    rad60966 r1db5673  
    1818using FarmatikoServices.Infrastructure;
    1919using System;
    20 
     20using Newtonsoft.Json.Serialization;
    2121namespace Farmatiko
    2222{
     
    4545
    4646            services.AddControllersWithViews();
     47            services.AddControllersWithViews().AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
    4748            // In production, the Angular files will be served from this directory
    4849            services.AddSpaStaticFiles(configuration =>
     
    5354            services.AddEntityFrameworkNpgsql().AddDbContext<FarmatikoDataContext>(opt => opt.UseNpgsql(connectionString));
    5455
    55             services.AddTransient<IPHRepo, PHRepo>();
     56            services.AddScoped<IPHRepo, PHRepo>();
    5657            services.AddTransient<IRepository, Repository>();
    5758            services.AddTransient<IAdminRepo, AdminRepo>();
Note: See TracChangeset for help on using the changeset viewer.