Skip to content

Commit

Permalink
Add access_count incrementer to DraftRetrieveApi
Browse files Browse the repository at this point in the history
Changes to be committed:
	modified:   biocompute/apis.py
	modified:   biocompute/services.py
	modified:   prefix/services.py
  • Loading branch information
HadleyKing committed Apr 4, 2024
1 parent 2811005 commit 4fceb39
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
17 changes: 10 additions & 7 deletions biocompute/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
from rest_framework.response import Response
from tests.fixtures.example_bco import BCO_000001
from config.services import legacy_api_converter, response_constructor
from biocompute.services import BcoDraftSerializer
from biocompute.services import BcoDraftSerializer, bco_counter_increment
from biocompute.selectors import retrieve_bco
from prefix.selectors import user_can_draft


hostname = settings.PUBLIC_HOSTNAME

BCO_DRAFT_SCHEMA = openapi.Schema(
Expand Down Expand Up @@ -171,13 +170,16 @@ class DraftRetrieveApi(APIView):
API View to Retrieve a Draft Object
This view allows authenticated users to retrieve the contents of a specific draft object
identified by its BioCompute Object (BCO) accession number. The operation ensures that
only users with appropriate permissions can access the draft contents.
This view allows authenticated users to retrieve the contents of a specific
draft object identified by its BioCompute Object (BCO) accession number.
The operation ensures that only users with appropriate permissions can
access the draft contents. Upo successfull retrieval of object the
`access_count` is for this object is incremented.
Parameters:
- bco_accession (str): A string parameter passed in the URL path that uniquely identifies
the draft object to be retrieved.
- bco_accession (str):
A string parameter passed in the URL path that uniquely identifies the
draft object to be retrieved.
"""

@swagger_auto_schema(
Expand Down Expand Up @@ -210,4 +212,5 @@ def get(self, request, bco_accession):
data={"message": f"User, {requester}, does not have draft permissions"\
+ f" for {bco_accession}."})
else:
bco_counter_increment(bco_instance)
return Response(status=status.HTTP_200_OK, data=bco_instance.contents)
19 changes: 17 additions & 2 deletions biocompute/services.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env python3
# biocopmute/services.py

from biocompute.models import Bco
from django.conf import settings
from django.contrib.auth.models import User
from django.db import transaction
from django.db.models import F
from django.utils import timezone
from biocompute.models import Bco
from prefix.models import Prefix
from prefix.services import prefix_counter_increment
from django.contrib.auth.models import User
from rest_framework import serializers

"""BioCompute Services
Expand Down Expand Up @@ -176,3 +177,17 @@ def create_bco_id(prefix_instance: Prefix) -> str:
unique_id_found = True

return bco_id

def bco_counter_increment(bco_instance: Bco) -> int:
"""BCO Counter Increment
Simple incrementing function.
Counter for BCO object_id asignment.
"""

bco_instance.access_count = F('access_count') + 1
bco_instance.save()

bco_instance.refresh_from_db()

return bco_instance.access_count
12 changes: 4 additions & 8 deletions prefix/services.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
#!/usr/bin/env python3
# prefix/services.py

import re
from urllib.parse import urlparse
from django.conf import settings
from django.contrib.auth.models import Permission
from django.contrib.auth.models import User, Permission
from django.contrib.contenttypes.models import ContentType
from django.db import utils
from django.db import transaction, utils
from django.db.models import F
from django.utils import timezone
from prefix.models import Prefix
from django.db import transaction
from django.contrib.auth.models import User
from django.db.models import F
from prefix.selectors import get_prefix_object
from rest_framework import serializers
from prefix.selectors import get_prefix_permissions, get_prefix_object

"""Prefix Services
Expand Down

0 comments on commit 4fceb39

Please sign in to comment.