Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
Add challenge topics (#180)
Browse files Browse the repository at this point in the history
* Starting to implement topics

* Add Challenge.topics

* Regenerate

* Commit changes

* Set topics as array of string instead of set for now
  • Loading branch information
tschaffter authored Sep 21, 2021
1 parent 8babc70 commit 19abdcc
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 21 deletions.
48 changes: 42 additions & 6 deletions server/openapi_server/controllers/challenge_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from openapi_server.models.challenge_create_response import ChallengeCreateResponse # noqa: E501
from openapi_server.models.challenge_readme import ChallengeReadme # noqa: E501
from openapi_server.models.challenge_readme_update_request import ChallengeReadmeUpdateRequest # noqa: E501
from openapi_server.models.array_of_topics import ArrayOfTopics # noqa: E501
# from openapi_server.models.challenge_readme_create_request import ChallengeReadmeCreateRequest # noqa: E501
# from openapi_server.models.challenge_readme_create_response import ChallengeReadmeCreateResponse # noqa: E501
# from openapi_server.models.challenge_status import ChallengeStatus # noqa: E501
Expand Down Expand Up @@ -58,6 +59,7 @@ def create_challenge(account_name): # noqa: E501
startDate=challenge_create_request.start_date,
endDate=challenge_create_request.end_date,
platformId=challenge_create_request.platform_id,
topics=challenge_create_request.topics,
doi=challenge_create_request.doi,
fullName="%s/%s" % (account_name, challenge_create_request.name),
ownerId=account_id
Expand Down Expand Up @@ -147,8 +149,8 @@ def get_challenge(account_name, challenge_name): # noqa: E501
try:
account = DbAccount.objects.get(login=account_name)
account_id = account.to_dict().get("id")
db_user = DbChallenge.objects.get(ownerId=account_id, name=challenge_name) # noqa: E501
res = Challenge.from_dict(db_user.to_dict())
db_challenge = DbChallenge.objects.get(ownerId=account_id, name=challenge_name) # noqa: E501
res = Challenge.from_dict(db_challenge.to_dict())
status = 200
except DoesNotExist:
status = 404
Expand Down Expand Up @@ -202,19 +204,53 @@ def list_account_challenges(account_name, limit=None, offset=None): # noqa: E50
return res, status


def list_challenge_stargazers(account_name, challenge_name): # noqa: E501
def list_challenge_stargazers(account_name, challenge_name, limit=None, offset=None): # noqa: E501
"""List stargazers
Lists the people that have starred the repository. # noqa: E501
:param account_name: The name of the account that owns the challenge
:type account_name: str
:param challenge_name: The name of the challenge
:type challenge_name: str
:param limit: Maximum number of results returned
:type limit: int
:param offset: Index of the first result that must be returned
:type offset: int
:rtype: PageOfUsers
"""
return 'do some magic!'


def list_challenges(limit=None, offset=None, sort=None, direction=None, search_terms=None, tag_ids=None, status=None, platform_ids=None, start_date_range=None): # noqa: E501
def list_challenge_topics(account_name, challenge_name): # noqa: E501
"""List stargazers
Lists the challenge topics. # noqa: E501
:param account_name: The name of the account that owns the challenge
:type account_name: str
:param challenge_name: The name of the challenge
:type challenge_name: str
:rtype: ArrayOfTopics
"""
try:
account = DbAccount.objects.get(login=account_name)
account_id = account.to_dict().get("id")
db_challenge = DbChallenge.objects.get(ownerId=account_id, name=challenge_name) # noqa: E501
res = ArrayOfTopics(topics=db_challenge.to_dict().get("topics"))
status = 200
except DoesNotExist:
status = 404
res = Error("The specified resource was not found", status)
except Exception as error:
status = 500
res = Error("Internal error", status, str(error))
return res, status


def list_challenges(limit=None, offset=None, sort=None, direction=None, search_terms=None, topics=None, status=None, platform_ids=None, start_date_range=None): # noqa: E501
"""List all the challenges
Returns all the challenges # noqa: E501
Expand All @@ -229,8 +265,8 @@ def list_challenges(limit=None, offset=None, sort=None, direction=None, search_t
:type direction: str
:param search_terms: A string of search terms used to filter the results
:type search_terms: str
:param tag_ids: Array of tag ids used to filter the results
:type tag_ids: List[str]
:param topics: Array of topics used to filter the results
:type topics: List[str]
:param status: Array of challenge status used to filter the results
:type status: list | bytes
:param platform_ids: Array of challenge platform ids used to filter the results
Expand Down
3 changes: 2 additions & 1 deletion server/openapi_server/dbmodels/challenge.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from bson import ObjectId
# import datetime
from mongoengine import DateTimeField, Document, ReferenceField, StringField, ObjectIdField, URLField # noqa: E501
from mongoengine import DateTimeField, Document, ReferenceField, StringField, ObjectIdField, URLField, ListField # noqa: E501
# , ListField

from openapi_server.dbmodels.account import Account
Expand All @@ -26,6 +26,7 @@ class Challenge(Document):
startDate = DateTimeField()
endDate = DateTimeField()
platformId = ReferenceField(ChallengePlatform)
topics = ListField(StringField(unique=True), default=[])
doi = StringField()

# summary = StringField()
Expand Down
1 change: 1 addition & 0 deletions server/openapi_server/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from __future__ import absolute_import
# import models into model package
from openapi_server.models.account import Account
from openapi_server.models.array_of_topics import ArrayOfTopics
from openapi_server.models.challenge import Challenge
from openapi_server.models.challenge_all_of import ChallengeAllOf
from openapi_server.models.challenge_create_request import ChallengeCreateRequest
Expand Down
68 changes: 68 additions & 0 deletions server/openapi_server/models/array_of_topics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# coding: utf-8

from __future__ import absolute_import
from datetime import date, datetime # noqa: F401

from typing import List, Dict # noqa: F401

from openapi_server.models.base_model_ import Model
from openapi_server import util


class ArrayOfTopics(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""

def __init__(self, topics=None): # noqa: E501
"""ArrayOfTopics - a model defined in OpenAPI
:param topics: The topics of this ArrayOfTopics. # noqa: E501
:type topics: List[str]
"""
self.openapi_types = {
'topics': List[str]
}

self.attribute_map = {
'topics': 'topics'
}

self._topics = topics

@classmethod
def from_dict(cls, dikt) -> 'ArrayOfTopics':
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The ArrayOfTopics of this ArrayOfTopics. # noqa: E501
:rtype: ArrayOfTopics
"""
return util.deserialize_model(dikt, cls)

@property
def topics(self):
"""Gets the topics of this ArrayOfTopics.
An array of Topics # noqa: E501
:return: The topics of this ArrayOfTopics.
:rtype: List[str]
"""
return self._topics

@topics.setter
def topics(self, topics):
"""Sets the topics of this ArrayOfTopics.
An array of Topics # noqa: E501
:param topics: The topics of this ArrayOfTopics.
:type topics: List[str]
"""
if topics is None:
raise ValueError("Invalid value for `topics`, must not be `None`") # noqa: E501

self._topics = topics
30 changes: 29 additions & 1 deletion server/openapi_server/models/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Challenge(Model):
Do not edit the class manually.
"""

def __init__(self, id=None, name=None, display_name=None, description=None, website_url=None, status=None, start_date=None, end_date=None, platform_id=None, doi=None, full_name=None, owner_id=None, created_at=None, updated_at=None): # noqa: E501
def __init__(self, id=None, name=None, display_name=None, description=None, website_url=None, status=None, start_date=None, end_date=None, platform_id=None, topics=None, doi=None, full_name=None, owner_id=None, created_at=None, updated_at=None): # noqa: E501
"""Challenge - a model defined in OpenAPI
:param id: The id of this Challenge. # noqa: E501
Expand All @@ -46,6 +46,8 @@ def __init__(self, id=None, name=None, display_name=None, description=None, webs
:type end_date: date
:param platform_id: The platform_id of this Challenge. # noqa: E501
:type platform_id: str
:param topics: The topics of this Challenge. # noqa: E501
:type topics: List[str]
:param doi: The doi of this Challenge. # noqa: E501
:type doi: str
:param full_name: The full_name of this Challenge. # noqa: E501
Expand All @@ -67,6 +69,7 @@ def __init__(self, id=None, name=None, display_name=None, description=None, webs
'start_date': date,
'end_date': date,
'platform_id': str,
'topics': List[str],
'doi': str,
'full_name': str,
'owner_id': str,
Expand All @@ -84,6 +87,7 @@ def __init__(self, id=None, name=None, display_name=None, description=None, webs
'start_date': 'startDate',
'end_date': 'endDate',
'platform_id': 'platformId',
'topics': 'topics',
'doi': 'doi',
'full_name': 'fullName',
'owner_id': 'ownerId',
Expand All @@ -100,6 +104,7 @@ def __init__(self, id=None, name=None, display_name=None, description=None, webs
self._start_date = start_date
self._end_date = end_date
self._platform_id = platform_id
self._topics = topics
self._doi = doi
self._full_name = full_name
self._owner_id = owner_id
Expand Down Expand Up @@ -332,6 +337,29 @@ def platform_id(self, platform_id):

self._platform_id = platform_id

@property
def topics(self):
"""Gets the topics of this Challenge.
:return: The topics of this Challenge.
:rtype: List[str]
"""
return self._topics

@topics.setter
def topics(self, topics):
"""Sets the topics of this Challenge.
:param topics: The topics of this Challenge.
:type topics: List[str]
"""
if topics is not None and len(topics) > 30:
raise ValueError("Invalid value for `topics`, number of items must be less than or equal to `30`") # noqa: E501

self._topics = topics

@property
def doi(self):
"""Gets the doi of this Challenge.
Expand Down
30 changes: 29 additions & 1 deletion server/openapi_server/models/challenge_create_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ChallengeCreateRequest(Model):
Do not edit the class manually.
"""

def __init__(self, name=None, display_name=None, description=None, website_url=None, status=None, start_date=None, end_date=None, platform_id=None, doi=None): # noqa: E501
def __init__(self, name=None, display_name=None, description=None, website_url=None, status=None, start_date=None, end_date=None, platform_id=None, topics=None, doi=None): # noqa: E501
"""ChallengeCreateRequest - a model defined in OpenAPI
:param name: The name of this ChallengeCreateRequest. # noqa: E501
Expand All @@ -38,6 +38,8 @@ def __init__(self, name=None, display_name=None, description=None, website_url=N
:type end_date: date
:param platform_id: The platform_id of this ChallengeCreateRequest. # noqa: E501
:type platform_id: str
:param topics: The topics of this ChallengeCreateRequest. # noqa: E501
:type topics: List[str]
:param doi: The doi of this ChallengeCreateRequest. # noqa: E501
:type doi: str
"""
Expand All @@ -50,6 +52,7 @@ def __init__(self, name=None, display_name=None, description=None, website_url=N
'start_date': date,
'end_date': date,
'platform_id': str,
'topics': List[str],
'doi': str
}

Expand All @@ -62,6 +65,7 @@ def __init__(self, name=None, display_name=None, description=None, website_url=N
'start_date': 'startDate',
'end_date': 'endDate',
'platform_id': 'platformId',
'topics': 'topics',
'doi': 'doi'
}

Expand All @@ -73,6 +77,7 @@ def __init__(self, name=None, display_name=None, description=None, website_url=N
self._start_date = start_date
self._end_date = end_date
self._platform_id = platform_id
self._topics = topics
self._doi = doi

@classmethod
Expand Down Expand Up @@ -276,6 +281,29 @@ def platform_id(self, platform_id):

self._platform_id = platform_id

@property
def topics(self):
"""Gets the topics of this ChallengeCreateRequest.
:return: The topics of this ChallengeCreateRequest.
:rtype: List[str]
"""
return self._topics

@topics.setter
def topics(self, topics):
"""Sets the topics of this ChallengeCreateRequest.
:param topics: The topics of this ChallengeCreateRequest.
:type topics: List[str]
"""
if topics is not None and len(topics) > 30:
raise ValueError("Invalid value for `topics`, number of items must be less than or equal to `30`") # noqa: E501

self._topics = topics

@property
def doi(self):
"""Gets the doi of this ChallengeCreateRequest.
Expand Down
Loading

0 comments on commit 19abdcc

Please sign in to comment.