Coverage for portality / api / current / crud / journals.py: 93%
29 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-05 00:09 +0100
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-05 00:09 +0100
1# ~~APICrudJournals:Feature->APICrud:Feature~~
2from portality import models
3from portality.api.current.crud.common import CrudApi
4from portality.api.current.data_objects.journal import OutgoingJournal, JOURNAL_STRUCT
5from portality.api.common import Api400Error, Api401Error, Api404Error
7from copy import deepcopy
10class JournalsCrudApi(CrudApi):
12 API_KEY_OPTIONAL = True
14 # ~~->Swagger:Feature~~
15 # ~~->API:Documentation~~
16 SWAG_TAG = 'CRUD Journals'
17 SWAG_ID_PARAM = {
18 "description": "<div class=\"search-query-docs\">DOAJ journal ID. E.g. 4cf8b72139a749c88d043129f00e1b07 .</div>",
19 "required": True,
20 "type": "string",
21 "name": "journal_id",
22 "in": "path"
23 }
25 @classmethod
26 def retrieve_swag(cls):
27 template = deepcopy(cls.SWAG_TEMPLATE)
28 template["parameters"].append(cls.SWAG_ID_PARAM)
29 template['responses']['200'] = cls.R200
30 template['responses']['200']['schema'] = OutgoingJournal().struct_to_swag(schema_title='Journal schema',
31 struct=JOURNAL_STRUCT)
32 template['responses']['200']['description'] = '<a href="https://doaj.github.io/doaj-docs/master/data_models/OutgoingAPIJournal">Detailed documentation on the response format is available</a>. '
33 template['responses']['404'] = cls.R404
34 return cls._build_swag_response(template, api_key_override=False)
36 @classmethod
37 def retrieve(cls, jid, account):
38 # is the journal id valid
39 try:
40 j = models.Journal.pull(jid) # ~~->Journal:Model~~
41 except Exception as e:
42 raise Api400Error(str(e))
43 if j is None:
44 raise Api404Error()
46 # at this point we're happy to return the journal if it's
47 # meant to be seen by the public
48 if j.is_in_doaj():
49 return OutgoingJournal.from_model(j) # ~~->APIOutgoingJournal:Model~~
51 # if the journal is not Public then it doesn't matter who asks for it, it can't be retrieved
52 raise Api404Error()