Skip to content

Commit 4fceb39

Browse files
committed
Add access_count incrementer to DraftRetrieveApi
Changes to be committed: modified: biocompute/apis.py modified: biocompute/services.py modified: prefix/services.py
1 parent 2811005 commit 4fceb39

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

biocompute/apis.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
from rest_framework.response import Response
1515
from tests.fixtures.example_bco import BCO_000001
1616
from config.services import legacy_api_converter, response_constructor
17-
from biocompute.services import BcoDraftSerializer
17+
from biocompute.services import BcoDraftSerializer, bco_counter_increment
1818
from biocompute.selectors import retrieve_bco
1919
from prefix.selectors import user_can_draft
2020

21-
2221
hostname = settings.PUBLIC_HOSTNAME
2322

2423
BCO_DRAFT_SCHEMA = openapi.Schema(
@@ -171,13 +170,16 @@ class DraftRetrieveApi(APIView):
171170
172171
API View to Retrieve a Draft Object
173172
174-
This view allows authenticated users to retrieve the contents of a specific draft object
175-
identified by its BioCompute Object (BCO) accession number. The operation ensures that
176-
only users with appropriate permissions can access the draft contents.
173+
This view allows authenticated users to retrieve the contents of a specific
174+
draft object identified by its BioCompute Object (BCO) accession number.
175+
The operation ensures that only users with appropriate permissions can
176+
access the draft contents. Upo successfull retrieval of object the
177+
`access_count` is for this object is incremented.
177178
178179
Parameters:
179-
- bco_accession (str): A string parameter passed in the URL path that uniquely identifies
180-
the draft object to be retrieved.
180+
- bco_accession (str):
181+
A string parameter passed in the URL path that uniquely identifies the
182+
draft object to be retrieved.
181183
"""
182184

183185
@swagger_auto_schema(
@@ -210,4 +212,5 @@ def get(self, request, bco_accession):
210212
data={"message": f"User, {requester}, does not have draft permissions"\
211213
+ f" for {bco_accession}."})
212214
else:
215+
bco_counter_increment(bco_instance)
213216
return Response(status=status.HTTP_200_OK, data=bco_instance.contents)

biocompute/services.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/usr/bin/env python3
22
# biocopmute/services.py
33

4+
from biocompute.models import Bco
45
from django.conf import settings
6+
from django.contrib.auth.models import User
57
from django.db import transaction
8+
from django.db.models import F
69
from django.utils import timezone
7-
from biocompute.models import Bco
810
from prefix.models import Prefix
911
from prefix.services import prefix_counter_increment
10-
from django.contrib.auth.models import User
1112
from rest_framework import serializers
1213

1314
"""BioCompute Services
@@ -176,3 +177,17 @@ def create_bco_id(prefix_instance: Prefix) -> str:
176177
unique_id_found = True
177178

178179
return bco_id
180+
181+
def bco_counter_increment(bco_instance: Bco) -> int:
182+
"""BCO Counter Increment
183+
184+
Simple incrementing function.
185+
Counter for BCO object_id asignment.
186+
"""
187+
188+
bco_instance.access_count = F('access_count') + 1
189+
bco_instance.save()
190+
191+
bco_instance.refresh_from_db()
192+
193+
return bco_instance.access_count

prefix/services.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
#!/usr/bin/env python3
22
# prefix/services.py
33

4-
import re
5-
from urllib.parse import urlparse
64
from django.conf import settings
7-
from django.contrib.auth.models import Permission
5+
from django.contrib.auth.models import User, Permission
86
from django.contrib.contenttypes.models import ContentType
9-
from django.db import utils
7+
from django.db import transaction, utils
8+
from django.db.models import F
109
from django.utils import timezone
1110
from prefix.models import Prefix
12-
from django.db import transaction
13-
from django.contrib.auth.models import User
14-
from django.db.models import F
11+
from prefix.selectors import get_prefix_object
1512
from rest_framework import serializers
16-
from prefix.selectors import get_prefix_permissions, get_prefix_object
1713

1814
"""Prefix Services
1915

0 commit comments

Comments
 (0)