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

Add public asset fetch endpoint #998

Merged
merged 4 commits into from
Sep 5, 2022

Conversation

Ashesh3
Copy link
Member

@Ashesh3 Ashesh3 commented Sep 3, 2022

Fixes ohcnetwork/10bedicu#82

As per the discussion with @gigincg , This PR adds a new public API endpoint for retrieving an asset by it's external ID.

This endpoint can later be used to serve the asset details on a public page which can be referred to by the QR code.

GET public/asset/<id> - Returns the details of the asset identified by it's external id.

It includes only fetching a particular asset and does not allow any other operations including listing.

curl -D - "http://127.0.0.1:8000/api/v1/public/asset/b8b71bff-7cf0-4fad-9180-7fc79f2b060d/"
HTTP/1.1 200 OK
Date: Sat, 03 Sep 2022 18:29:22 GMT
Server: WSGIServer/0.2 CPython/3.10.4
Content-Type: application/json
Vary: Accept, Accept-Language, Cookie, Origin
Allow: GET, HEAD, OPTIONS
X-Frame-Options: DENY
Content-Length: 832
Content-Language: en
X-XSS-Protection: 1; mode=block

{"id":"b8b71bff-7cf0-4fad-9180-7fc79f2b060d","status":"ACTIVE","asset_type":"INTERNAL","location_object":{"id":"cce9bf87-4525-4d2e-85ca-e2164e8b4261","facility":{"id":"4a3dbe9c-8d1b-4dc1-b939-237d79d96233","name":"Hero Health Center"},"created_date":"2022-05-19T16:07:17.203203+05:30","modified_date":"2022-05-25T01:57:12.982253+05:30","name":"Loc 2","description":"","location_type":1},"created_date":"2022-05-25T01:55:51.295497+05:30","modified_date":"2022-09-03T13:58:19.823531+05:30","name":"Testttttt122","description":"","asset_class":"","is_working":true,"not_working_reason":"","serial_number":"","warranty_details":"","meta":{},"vendor_name":"","support_name":"","support_phone":"+916655877888","support_email":"","qr_code_id":null,"manufacturer":null,"warranty_amc_end_of_validity":null,"last_serviced_on":null,"notes":""}
curl -D - "http://127.0.0.1:8000/api/v1/public/asset/random-random/"
HTTP/1.1 404 Not Found
Date: Sat, 03 Sep 2022 18:29:19 GMT
Server: WSGIServer/0.2 CPython/3.10.4
Content-Type: application/json
Vary: Accept, Accept-Language, Cookie, Origin
Allow: GET, HEAD, OPTIONS
X-Frame-Options: DENY
Content-Length: 23
Content-Language: en
X-XSS-Protection: 1; mode=block

{"detail":"Not found."}

@Ashesh3 Ashesh3 requested a review from a team as a code owner September 3, 2022 18:35
@Ashesh3 Ashesh3 requested a review from gigincg September 3, 2022 18:35
care/facility/api/viewsets/asset.py Outdated Show resolved Hide resolved
care/facility/api/viewsets/asset.py Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Sep 3, 2022

Codecov Report

Merging #998 (425bcbf) into master (6bd66bf) will decrease coverage by 1.34%.
The diff coverage is 49.24%.

@@            Coverage Diff             @@
##           master     coronasafe/care_fe#998      +/-   ##
==========================================
- Coverage   54.02%   52.67%   -1.35%     
==========================================
  Files         182      183       +1     
  Lines        8990     8937      -53     
==========================================
- Hits         4857     4708     -149     
- Misses       4133     4229      +96     
Impacted Files Coverage Δ
care/facility/api/viewsets/patient.py 47.90% <0.00%> (-0.34%) ⬇️
...re/facility/management/commands/scrape_icd_data.py 0.00% <0.00%> (ø)
care/facility/models/file_upload.py 68.88% <0.00%> (ø)
care/facility/models/json_schema/asset.py 100.00% <ø> (ø)
care/facility/models/patient.py 88.09% <ø> (-6.75%) ⬇️
care/facility/static_data/icd11.py 0.00% <0.00%> (ø)
care/users/api/viewsets/users.py 42.94% <0.00%> (-12.90%) ⬇️
care/utils/assetintegration/onvif.py 38.23% <ø> (+1.09%) ⬆️
...e/facility/api/serializers/patient_consultation.py 34.14% <11.11%> (-2.84%) ⬇️
care/facility/api/viewsets/file_upload.py 48.57% <15.38%> (-2.95%) ⬇️
... and 29 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@Ashesh3
Copy link
Member Author

Ashesh3 commented Sep 4, 2022

Added caching the asset for 24 hours by it's external_id and invalidating it on the save method.

CACHE MISS
[04/Sep/2022 09:41:20] "GET /api/v1/public/asset/b8b71bff-7cf0-4fad-9180-7fc79f2b060d/ HTTP/1.1" 200 838

CACHE HIT
[04/Sep/2022 09:41:24] "GET /api/v1/public/asset/b8b71bff-7cf0-4fad-9180-7fc79f2b060d/ HTTP/1.1" 200 838

CACHE HIT
[04/Sep/2022 09:41:25] "GET /api/v1/public/asset/b8b71bff-7cf0-4fad-9180-7fc79f2b060d/ HTTP/1.1" 200 838

CACHE HIT
[04/Sep/2022 09:41:28] "GET /api/v1/public/asset/b8b71bff-7cf0-4fad-9180-7fc79f2b060d/ HTTP/1.1" 200 838

CACHE INVALIDATED
INFO 2022-09-04 09:41:37,580 receivers 1378112 281472209514784 AUDIT_LOG::put::7ab4a38924973defbfad1b5d484bcc29::20e5b23c0e0a46e1b8f00674ee50619b|devdistrictadmin|update|facility.Asset|ID:1|{"name": "Testttttt122dddddd12"}
INFO 2022-09-04 09:41:37,618 middleware 1378112 281472209514784 PUT /api/v1/asset/b8b71bff-7cf0-4fad-9180-7fc79f2b060d/ 200 User:[4|devdistrictadmin]
[04/Sep/2022 09:41:37] "PUT /api/v1/asset/b8b71bff-7cf0-4fad-9180-7fc79f2b060d/ HTTP/1.1" 200 840

CACHE MISS
[04/Sep/2022 09:43:52] "GET /api/v1/public/asset/b8b71bff-7cf0-4fad-9180-7fc79f2b060d/ HTTP/1.1" 200 840

CACHE HIT
[04/Sep/2022 09:43:58] "GET /api/v1/public/asset/b8b71bff-7cf0-4fad-9180-7fc79f2b060d/ HTTP/1.1" 200 840

@sonarcloud
Copy link

sonarcloud bot commented Sep 4, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@vigneshhari vigneshhari merged commit 99f3732 into ohcnetwork:master Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Public facing Asset details page : Asset QR
3 participants