From cc6696bc7fcc16931d9989c322b8a50c05216643 Mon Sep 17 00:00:00 2001 From: Thomas Schaffter Date: Thu, 28 Oct 2021 15:32:19 -0700 Subject: [PATCH] Add ChallengeSponsors (#190) * Run openapi-generator to add challenge sponsor stub * Add code for challenge sponsors * Sorchallenge controller functions in alphabetic order * Rename CloudProvider to ComputeProvider * Rename CloudProvider to ComputeProvider * Revert "Rename CloudProvider to ComputeProvider" This reverts commit 0d1a6958582def8953db915c9031588dc0bebc77. * Rename DB model parameter value to ComputeProvider --- .../controllers/challenge_controller.py | 543 ++++++++++-------- .../dbmodels/challenge_sponsor.py | 22 + server/openapi_server/models/__init__.py | 10 +- .../models/challenge_sponsor.py | 164 ++++++ .../challenge_sponsor_create_request.py | 130 +++++ ...y => challenge_sponsor_create_response.py} | 24 +- .../models/challenge_sponsor_list.py | 70 +++ .../models/challenge_sponsor_role.py | 45 ++ server/openapi_server/models/page_of_tags.py | 194 ------- .../models/page_of_tags_all_of.py | 70 --- server/openapi_server/models/tag.py | 110 ---- .../models/tag_create_request.py | 76 --- server/openapi_server/openapi/openapi.yaml | 528 ++++++++--------- 13 files changed, 986 insertions(+), 1000 deletions(-) create mode 100644 server/openapi_server/dbmodels/challenge_sponsor.py create mode 100644 server/openapi_server/models/challenge_sponsor.py create mode 100644 server/openapi_server/models/challenge_sponsor_create_request.py rename server/openapi_server/models/{tag_create_response.py => challenge_sponsor_create_response.py} (58%) create mode 100644 server/openapi_server/models/challenge_sponsor_list.py create mode 100644 server/openapi_server/models/challenge_sponsor_role.py delete mode 100644 server/openapi_server/models/page_of_tags.py delete mode 100644 server/openapi_server/models/page_of_tags_all_of.py delete mode 100644 server/openapi_server/models/tag.py delete mode 100644 server/openapi_server/models/tag_create_request.py diff --git a/server/openapi_server/controllers/challenge_controller.py b/server/openapi_server/controllers/challenge_controller.py index 4a8fb2e..38300f2 100644 --- a/server/openapi_server/controllers/challenge_controller.py +++ b/server/openapi_server/controllers/challenge_controller.py @@ -8,6 +8,7 @@ from openapi_server.dbmodels.challenge_platform import ChallengePlatform as DbChallengePlatform # noqa: E501 from openapi_server.dbmodels.challenge_organizer import ChallengeOrganizer as DbChallengeOrganizer # noqa: E501 from openapi_server.dbmodels.challenge_readme import ChallengeReadme as DbChallengeReadme # noqa: E501 +from openapi_server.dbmodels.challenge_sponsor import ChallengeSponsor as DbChallengeSponsor # noqa: E501 from openapi_server.dbmodels.starred_challenge import StarredChallenge as DbStarredChallenge # noqa: E501 from openapi_server.dbmodels.user import User as DbUser # noqa: E501 from openapi_server.models.challenge import Challenge # noqa: E501 @@ -19,6 +20,10 @@ from openapi_server.models.challenge_organizer_create_request import ChallengeOrganizerCreateRequest # noqa: E501 from openapi_server.models.challenge_organizer_create_response import ChallengeOrganizerCreateResponse # noqa: E501 from openapi_server.models.challenge_organizer_list import ChallengeOrganizerList # noqa: E501 +from openapi_server.models.challenge_sponsor import ChallengeSponsor # noqa: E501 +from openapi_server.models.challenge_sponsor_create_request import ChallengeSponsorCreateRequest # noqa: E501 +from openapi_server.models.challenge_sponsor_create_response import ChallengeSponsorCreateResponse # noqa: E501 +from openapi_server.models.challenge_sponsor_list import ChallengeSponsorList # noqa: E501 from openapi_server.models.user import User from openapi_server.models.array_of_topics import ArrayOfTopics # noqa: E501 from openapi_server.models.error import Error # noqa: E501 @@ -92,6 +97,98 @@ def create_challenge(account_name): # noqa: E501 return res, status +def create_challenge_organizer(account_name, challenge_name): # noqa: E501 + """Create a challenge organizer + + Create a challenge organizer # 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: ChallengeOrganizerCreateResponse + """ + if connexion.request.is_json: + try: + try: + challenge_full_name = f"{account_name}/{challenge_name}" + print(f"challenge: {challenge_full_name}") + db_challenge = DbChallenge.objects.get(fullName=challenge_full_name) # noqa: E501 + except DoesNotExist: + status = 400 + res = Error(f"The challenge {challenge_full_name} was not found", status) # noqa: E501 + return res, status + + organizer_create_request = ChallengeOrganizerCreateRequest.from_dict(connexion.request.get_json()) # noqa: E501 + organizer = DbChallengeOrganizer( + name=organizer_create_request.name, + login=organizer_create_request.login, # TODO check that login exists # noqa: E501 + roles=organizer_create_request.roles, + challengeId=db_challenge.id + ).save() + organizer_id = organizer.to_dict().get("id") + + res = ChallengeOrganizerCreateResponse(id=organizer_id) + status = 201 + except NotUniqueError as error: + status = 409 + res = Error("Conflict", status, str(error)) + except Exception as error: + status = 500 + res = Error("Internal error", status, str(error)) + else: + status = 400 + res = Error("Bad request", status, "Missing body") + return res, status + + +def create_challenge_sponsor(account_name, challenge_name): # noqa: E501 + """Create a challenge sponsor + + Create a challenge sponsor # 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: ChallengeSponsorCreateResponse + """ + if connexion.request.is_json: + try: + try: + challenge_full_name = f"{account_name}/{challenge_name}" + print(f"challenge: {challenge_full_name}") + db_challenge = DbChallenge.objects.get(fullName=challenge_full_name) # noqa: E501 + except DoesNotExist: + status = 400 + res = Error(f"The challenge {challenge_full_name} was not found", status) # noqa: E501 + return res, status + + sponsor_create_request = ChallengeSponsorCreateRequest.from_dict(connexion.request.get_json()) # noqa: E501 + sponsor = DbChallengeSponsor( + name=sponsor_create_request.name, + login=sponsor_create_request.login, # TODO check that login exists # noqa: E501 + roles=sponsor_create_request.roles, + challengeId=db_challenge.id + ).save() + sponsor_id = sponsor.to_dict().get("id") + + res = ChallengeSponsorCreateResponse(id=sponsor_id) + status = 201 + except NotUniqueError as error: + status = 409 + res = Error("Conflict", status, str(error)) + except Exception as error: + status = 500 + res = Error("Internal error", status, str(error)) + else: + status = 400 + res = Error("Bad request", status, "Missing body") + return res, status + + def delete_all_challenges(): # noqa: E501 """Delete all challenges @@ -144,23 +241,23 @@ def delete_challenge(account_name, challenge_name): # noqa: E501 return res, status -def get_challenge(account_name, challenge_name): # noqa: E501 - """Get a challenge +def delete_challenge_organizer(account_name, challenge_name, organizer_id): # noqa: E501 + """Delete a challenge organizer - Returns the challenge specified # noqa: E501 + Deletes the challenge organizer specified # 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 organizer_id: The identifier of the challenge organizer + :type organizer_id: str - :rtype: Challenge + :rtype: object """ 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 = Challenge.from_dict(db_challenge.to_dict()) + DbChallengeOrganizer.objects.get(id=organizer_id).delete() + res = {} status = 200 except DoesNotExist: status = 404 @@ -171,64 +268,71 @@ def get_challenge(account_name, challenge_name): # noqa: E501 return res, status -def list_account_challenges(account_name, limit=None, offset=None): # noqa: E501 - """List all the challenges owned by the specified account +def delete_challenge_sponsor(account_name, challenge_name, sponsor_id): # noqa: E501 + """Delete a challenge sponsor - List all the challenges owned by the specified account # noqa: E501 + Deletes the challenge sponsor specified # noqa: E501 :param account_name: The name of the account that owns the challenge :type account_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 + :param challenge_name: The name of the challenge + :type challenge_name: str + :param sponsor_id: The identifier of the challenge sponsor + :type sponsor_id: str - :rtype: PageOfChallenges + :rtype: object + """ + try: + DbChallengeSponsor.objects.get(id=sponsor_id).delete() + res = {} + 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 get_challenge(account_name, challenge_name): # noqa: E501 + """Get a challenge + + Returns the challenge specified # 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: Challenge """ try: account = DbAccount.objects.get(login=account_name) account_id = account.to_dict().get("id") - db_challenges = DbChallenge.objects(ownerId=account_id).skip(offset).limit(limit) # noqa: E501 - challenges = [Challenge.from_dict(d.to_dict()) for d in db_challenges] - next_ = "" - if len(challenges) == limit: - next_ = "%s/challenges/%s?limit=%s&offset=%s" % \ - (config.server_api_url, account_name, limit, offset + limit) - - total = db_challenges.count() - res = PageOfChallenges( - offset=offset, - limit=limit, - paging={ - "next": next_ - }, - total_results=total, - challenges=challenges) + db_challenge = DbChallenge.objects.get(ownerId=account_id, name=challenge_name) # noqa: E501 + res = Challenge.from_dict(db_challenge.to_dict()) status = 200 - except TypeError: # TODO: may need include different exceptions for 400 - status = 400 - res = Error("Bad request", status) + 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_challenge_stargazers(account_name, challenge_name, limit=None, offset=None): # noqa: E501 - """List stargazers +def get_challenge_readme(account_name, challenge_name): # noqa: E501 + """Get a challenge README - Lists the people that have starred the repository. # noqa: E501 + Returns the challenge README specified # 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 + :rtype: ChallengeReadme """ try: try: @@ -240,29 +344,9 @@ def list_challenge_stargazers(account_name, challenge_name, limit=None, offset=N return res, status challenge_id = db_challenge.to_dict().get("id") - db_starred_challenges = DbStarredChallenge.objects(challengeId=challenge_id).skip(offset).limit(limit) # noqa: E501 - stargazer_ids = [d.to_dict().get("userId") for d in db_starred_challenges] # noqa: E501 - db_stargazers = DbUser.objects(id__in=stargazer_ids) - stargazers = [User.from_dict(d.to_dict()) for d in db_stargazers] - - next_ = "" - if len(stargazers) == limit: - next_ = "%s/challenges/%s/%s/stargazers?limit=%s&offset=%s" % \ - (config.server_api_url, account_name, challenge_name, limit, offset + limit) # noqa: E501 - - total = db_starred_challenges.count() - res = PageOfUsers( - offset=offset, - limit=limit, - paging={ - "next": next_ - }, - total_results=total, - users=stargazers) + db_readme = DbChallengeReadme.objects.get(challengeId=challenge_id) + res = ChallengeReadme.from_dict(db_readme.to_dict()) status = 200 - except TypeError: # TODO: may need include different exceptions for 400 - status = 400 - res = Error("Bad request", status) except DoesNotExist: status = 404 res = Error("The specified resource was not found", status) @@ -272,27 +356,43 @@ def list_challenge_stargazers(account_name, challenge_name, limit=None, offset=N return res, status -def list_challenge_topics(account_name, challenge_name): # noqa: E501 - """List stargazers +def list_account_challenges(account_name, limit=None, offset=None): # noqa: E501 + """List all the challenges owned by the specified account - Lists the challenge topics. # noqa: E501 + List all the challenges owned by the specified account # 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: ArrayOfTopics + :rtype: PageOfChallenges """ 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")) + db_challenges = DbChallenge.objects(ownerId=account_id).skip(offset).limit(limit) # noqa: E501 + challenges = [Challenge.from_dict(d.to_dict()) for d in db_challenges] + next_ = "" + if len(challenges) == limit: + next_ = "%s/challenges/%s?limit=%s&offset=%s" % \ + (config.server_api_url, account_name, limit, offset + limit) + + total = db_challenges.count() + res = PageOfChallenges( + offset=offset, + limit=limit, + paging={ + "next": next_ + }, + total_results=total, + challenges=challenges) status = 200 - except DoesNotExist: - status = 404 - res = Error("The specified resource was not found", status) + except TypeError: # TODO: may need include different exceptions for 400 + status = 400 + res = Error("Bad request", status) except Exception as error: status = 500 res = Error("Internal error", status, str(error)) @@ -379,62 +479,17 @@ def list_challenges(limit=None, offset=None, sort=None, direction=None, search_t return res, status -# def create_challenge_readme(account_name, challenge_name): # noqa: E501 -# """Create a challenge README - -# Create a challenge README # 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: ChallengeReadmeCreateResponse -# """ -# if connexion.request.is_json: -# try: -# try: -# challenge_full_name = f"{account_name}/{challenge_name}" -# db_challenge = DbChallenge.objects.get(fullName=challenge_full_name) # noqa: E501 -# except DoesNotExist: -# status = 400 -# res = Error(f"The challenge {challenge_full_name} was not found", status) # noqa: E501 -# return res, status - -# challenge_id = db_challenge.to_dict().get("id") -# challenge_readme_create_request = ChallengeReadmeCreateRequest.from_dict(connexion.request.get_json()) # noqa: E501 - -# readme = DbChallengeReadme( -# text=challenge_readme_create_request.text, -# challengeId=challenge_id -# ).save() - -# readme_id = readme.to_dict().get("id") -# res = ChallengeReadmeCreateResponse(id=readme_id) -# status = 201 -# except NotUniqueError as error: -# status = 409 -# res = Error("Conflict", status, str(error)) -# except Exception as error: -# status = 500 -# res = Error("Internal error", status, str(error)) -# else: -# status = 400 -# res = Error("Bad request", status, "Missing body") -# return res, status - - -def get_challenge_readme(account_name, challenge_name): # noqa: E501 - """Get a challenge README +def list_challenge_organizers(account_name, challenge_name): # noqa: E501 + """List organizers - Returns the challenge README specified # noqa: E501 + Lists the organizers of the challenge. # 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: ChallengeReadme + :rtype: ChallengeOrganizerList """ try: try: @@ -446,9 +501,13 @@ def get_challenge_readme(account_name, challenge_name): # noqa: E501 return res, status challenge_id = db_challenge.to_dict().get("id") - db_readme = DbChallengeReadme.objects.get(challengeId=challenge_id) - res = ChallengeReadme.from_dict(db_readme.to_dict()) + db_organizers = DbChallengeOrganizer.objects(challengeId=challenge_id) # noqa: E501 + organizers = [ChallengeOrganizer.from_dict(d.to_dict()) for d in db_organizers] # noqa: E501 + res = ChallengeOrganizerList(challenge_organizers=organizers) status = 200 + except TypeError: # TODO: may need include different exceptions for 400 + status = 400 + res = Error("Bad request", status) except DoesNotExist: status = 404 res = Error("The specified resource was not found", status) @@ -458,145 +517,119 @@ def get_challenge_readme(account_name, challenge_name): # noqa: E501 return res, status -def update_challenge_readme(account_name, challenge_name): # noqa: E501 - """Update a challenge README +def list_challenge_sponsors(account_name, challenge_name): # noqa: E501 + """List sponsors - Update a challenge README # noqa: E501 + Lists the sponsors of the challenge. # 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: object + :rtype: ChallengeSponsorList """ - if connexion.request.is_json: + try: try: - challenge_readme_update_request = ChallengeReadmeUpdateRequest.from_dict(connexion.request.get_json()) # noqa: E501 - - try: - challenge_full_name = f"{account_name}/{challenge_name}" - db_challenge = DbChallenge.objects.get(fullName=challenge_full_name) # noqa: E501 - except DoesNotExist: - status = 400 - res = Error(f"The challenge {challenge_full_name} was not found", status) # noqa: E501 - return res, status - - challenge_id = db_challenge.to_dict().get("id") - db_readme = DbChallengeReadme.objects.get(challengeId=challenge_id) - db_readme.text = challenge_readme_update_request.text - db_readme.save() + challenge_full_name = f"{account_name}/{challenge_name}" + db_challenge = DbChallenge.objects.get(fullName=challenge_full_name) # noqa: E501 + except DoesNotExist: + status = 400 + res = Error(f"The challenge {challenge_full_name} was not found", status) # noqa: E501 + return res, status - res = {} - status = 200 - except NotUniqueError as error: - status = 409 - res = Error("Conflict", status, str(error)) - except Exception as error: - status = 500 - res = Error("Internal error", status, str(error)) - else: + challenge_id = db_challenge.to_dict().get("id") + db_sponsors = DbChallengeSponsor.objects(challengeId=challenge_id) # noqa: E501 + sponsors = [ChallengeSponsor.from_dict(d.to_dict()) for d in db_sponsors] # noqa: E501 + res = ChallengeSponsorList(challenge_sponsors=sponsors) + status = 200 + except TypeError: # TODO: may need include different exceptions for 400 status = 400 - res = Error("Bad request", status, "Missing body") + res = Error("Bad request", status) + 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 delete_challenge_readme(account_name, challenge_name): # noqa: E501 -# """Delete a challenge README - -# Deletes the challenge README specified # 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: object -# """ -# try: -# try: -# challenge_full_name = f"{account_name}/{challenge_name}" -# db_challenge = DbChallenge.objects.get(fullName=challenge_full_name) # noqa: E501 -# except DoesNotExist: -# status = 400 -# res = Error(f"The challenge {challenge_full_name} was not found", status) # noqa: E501 -# return res, status - -# challenge_id = db_challenge.to_dict().get("id") -# DbChallengeReadme.objects.get(challengeId=challenge_id).delete() -# res = {} -# 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 create_challenge_organizer(account_name, challenge_name): # noqa: E501 - """Create a challenge organizer +def list_challenge_stargazers(account_name, challenge_name, limit=None, offset=None): # noqa: E501 + """List stargazers - Create a challenge organizer # noqa: E501 + 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: ChallengeOrganizerCreateResponse + :rtype: PageOfUsers """ - if connexion.request.is_json: + try: try: - try: - challenge_full_name = f"{account_name}/{challenge_name}" - print(f"challenge: {challenge_full_name}") - db_challenge = DbChallenge.objects.get(fullName=challenge_full_name) # noqa: E501 - except DoesNotExist: - status = 400 - res = Error(f"The challenge {challenge_full_name} was not found", status) # noqa: E501 - return res, status + challenge_full_name = f"{account_name}/{challenge_name}" + db_challenge = DbChallenge.objects.get(fullName=challenge_full_name) # noqa: E501 + except DoesNotExist: + status = 400 + res = Error(f"The challenge {challenge_full_name} was not found", status) # noqa: E501 + return res, status - organizer_create_request = ChallengeOrganizerCreateRequest.from_dict(connexion.request.get_json()) # noqa: E501 - organizer = DbChallengeOrganizer( - name=organizer_create_request.name, - login=organizer_create_request.login, # TODO check that login exists # noqa: E501 - roles=organizer_create_request.roles, - challengeId=db_challenge.id - ).save() - organizer_id = organizer.to_dict().get("id") + challenge_id = db_challenge.to_dict().get("id") + db_starred_challenges = DbStarredChallenge.objects(challengeId=challenge_id).skip(offset).limit(limit) # noqa: E501 + stargazer_ids = [d.to_dict().get("userId") for d in db_starred_challenges] # noqa: E501 + db_stargazers = DbUser.objects(id__in=stargazer_ids) + stargazers = [User.from_dict(d.to_dict()) for d in db_stargazers] - res = ChallengeOrganizerCreateResponse(id=organizer_id) - status = 201 - except NotUniqueError as error: - status = 409 - res = Error("Conflict", status, str(error)) - except Exception as error: - status = 500 - res = Error("Internal error", status, str(error)) - else: + next_ = "" + if len(stargazers) == limit: + next_ = "%s/challenges/%s/%s/stargazers?limit=%s&offset=%s" % \ + (config.server_api_url, account_name, challenge_name, limit, offset + limit) # noqa: E501 + + total = db_starred_challenges.count() + res = PageOfUsers( + offset=offset, + limit=limit, + paging={ + "next": next_ + }, + total_results=total, + users=stargazers) + status = 200 + except TypeError: # TODO: may need include different exceptions for 400 status = 400 - res = Error("Bad request", status, "Missing body") + res = Error("Bad request", status) + 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 delete_challenge_organizer(account_name, challenge_name, organizer_id): # noqa: E501 - """Delete a challenge organizer +def list_challenge_topics(account_name, challenge_name): # noqa: E501 + """List stargazers - Deletes the challenge organizer specified # noqa: E501 + 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 - :param organizer_id: The identifier of the challenge organizer - :type organizer_id: str - :rtype: object + :rtype: ArrayOfTopics """ try: - DbChallengeOrganizer.objects.get(id=organizer_id).delete() - res = {} + 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 @@ -607,40 +640,44 @@ def delete_challenge_organizer(account_name, challenge_name, organizer_id): # n return res, status -def list_challenge_organizers(account_name, challenge_name): # noqa: E501 - """List organizers +def update_challenge_readme(account_name, challenge_name): # noqa: E501 + """Update a challenge README - Lists the organizers of the challenge. # noqa: E501 + Update a challenge README # 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: ChallengeOrganizerList + :rtype: object """ - try: + if connexion.request.is_json: try: - challenge_full_name = f"{account_name}/{challenge_name}" - db_challenge = DbChallenge.objects.get(fullName=challenge_full_name) # noqa: E501 - except DoesNotExist: - status = 400 - res = Error(f"The challenge {challenge_full_name} was not found", status) # noqa: E501 - return res, status + challenge_readme_update_request = ChallengeReadmeUpdateRequest.from_dict(connexion.request.get_json()) # noqa: E501 - challenge_id = db_challenge.to_dict().get("id") - db_organizers = DbChallengeOrganizer.objects(challengeId=challenge_id) # noqa: E501 - organizers = [ChallengeOrganizer.from_dict(d.to_dict()) for d in db_organizers] # noqa: E501 - print(organizers) - res = ChallengeOrganizerList(challenge_organizers=organizers) - status = 200 - except TypeError: # TODO: may need include different exceptions for 400 + try: + challenge_full_name = f"{account_name}/{challenge_name}" + db_challenge = DbChallenge.objects.get(fullName=challenge_full_name) # noqa: E501 + except DoesNotExist: + status = 400 + res = Error(f"The challenge {challenge_full_name} was not found", status) # noqa: E501 + return res, status + + challenge_id = db_challenge.to_dict().get("id") + db_readme = DbChallengeReadme.objects.get(challengeId=challenge_id) + db_readme.text = challenge_readme_update_request.text + db_readme.save() + + res = {} + status = 200 + except NotUniqueError as error: + status = 409 + res = Error("Conflict", status, str(error)) + except Exception as error: + status = 500 + res = Error("Internal error", status, str(error)) + else: status = 400 - res = Error("Bad request", status) - 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)) + res = Error("Bad request", status, "Missing body") return res, status diff --git a/server/openapi_server/dbmodels/challenge_sponsor.py b/server/openapi_server/dbmodels/challenge_sponsor.py new file mode 100644 index 0000000..c5ba5f6 --- /dev/null +++ b/server/openapi_server/dbmodels/challenge_sponsor.py @@ -0,0 +1,22 @@ +import datetime +from bson import ObjectId +from mongoengine import DateTimeField, Document, ObjectIdField, StringField, ListField, ReferenceField, IntField # noqa: E501 + +from openapi_server.dbmodels.challenge import Challenge + + +class ChallengeSponsor(Document): + id = ObjectIdField(primary_key=True, default=ObjectId) + name = StringField(required=True) + login = StringField() + roles = ListField(StringField(choices=["ChallengeOrganizer", "ComputeProvider", "DataProvider", "Funder", "Other"]), default=[]) # noqa: E501 + challengeId = ReferenceField(Challenge, required=True) + createdAt = DateTimeField(required=True, default=datetime.datetime.now) + updatedAt = DateTimeField(required=True, default=datetime.datetime.now) + v = IntField(db_field='__v') + + def to_dict(self): + doc = self.to_mongo().to_dict() + doc['id'] = str(self.pk) + doc.pop('challengeId', None) + return doc diff --git a/server/openapi_server/models/__init__.py b/server/openapi_server/models/__init__.py index aa5a58d..9555927 100644 --- a/server/openapi_server/models/__init__.py +++ b/server/openapi_server/models/__init__.py @@ -22,6 +22,11 @@ from openapi_server.models.challenge_readme_create_request import ChallengeReadmeCreateRequest from openapi_server.models.challenge_readme_create_response import ChallengeReadmeCreateResponse from openapi_server.models.challenge_readme_update_request import ChallengeReadmeUpdateRequest +from openapi_server.models.challenge_sponsor import ChallengeSponsor +from openapi_server.models.challenge_sponsor_create_request import ChallengeSponsorCreateRequest +from openapi_server.models.challenge_sponsor_create_response import ChallengeSponsorCreateResponse +from openapi_server.models.challenge_sponsor_list import ChallengeSponsorList +from openapi_server.models.challenge_sponsor_role import ChallengeSponsorRole from openapi_server.models.challenge_status import ChallengeStatus from openapi_server.models.date_range import DateRange from openapi_server.models.error import Error @@ -48,15 +53,10 @@ from openapi_server.models.page_of_org_memberships_all_of import PageOfOrgMembershipsAllOf from openapi_server.models.page_of_organizations import PageOfOrganizations from openapi_server.models.page_of_organizations_all_of import PageOfOrganizationsAllOf -from openapi_server.models.page_of_tags import PageOfTags -from openapi_server.models.page_of_tags_all_of import PageOfTagsAllOf from openapi_server.models.page_of_users import PageOfUsers from openapi_server.models.page_of_users_all_of import PageOfUsersAllOf from openapi_server.models.response_page_metadata import ResponsePageMetadata from openapi_server.models.response_page_metadata_paging import ResponsePageMetadataPaging -from openapi_server.models.tag import Tag -from openapi_server.models.tag_create_request import TagCreateRequest -from openapi_server.models.tag_create_response import TagCreateResponse from openapi_server.models.user import User from openapi_server.models.user_all_of import UserAllOf from openapi_server.models.user_create_request import UserCreateRequest diff --git a/server/openapi_server/models/challenge_sponsor.py b/server/openapi_server/models/challenge_sponsor.py new file mode 100644 index 0000000..6af5c99 --- /dev/null +++ b/server/openapi_server/models/challenge_sponsor.py @@ -0,0 +1,164 @@ +# 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.models.challenge_sponsor_create_request import ChallengeSponsorCreateRequest +from openapi_server.models.challenge_sponsor_create_response import ChallengeSponsorCreateResponse +from openapi_server.models.challenge_sponsor_role import ChallengeSponsorRole +import re +from openapi_server import util + +from openapi_server.models.challenge_sponsor_create_request import ChallengeSponsorCreateRequest # noqa: E501 +from openapi_server.models.challenge_sponsor_create_response import ChallengeSponsorCreateResponse # noqa: E501 +from openapi_server.models.challenge_sponsor_role import ChallengeSponsorRole # noqa: E501 +import re # noqa: E501 + +class ChallengeSponsor(Model): + """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + + Do not edit the class manually. + """ + + def __init__(self, id=None, name=None, login=None, roles=None): # noqa: E501 + """ChallengeSponsor - a model defined in OpenAPI + + :param id: The id of this ChallengeSponsor. # noqa: E501 + :type id: str + :param name: The name of this ChallengeSponsor. # noqa: E501 + :type name: str + :param login: The login of this ChallengeSponsor. # noqa: E501 + :type login: str + :param roles: The roles of this ChallengeSponsor. # noqa: E501 + :type roles: List[ChallengeSponsorRole] + """ + self.openapi_types = { + 'id': str, + 'name': str, + 'login': str, + 'roles': List[ChallengeSponsorRole] + } + + self.attribute_map = { + 'id': 'id', + 'name': 'name', + 'login': 'login', + 'roles': 'roles' + } + + self._id = id + self._name = name + self._login = login + self._roles = roles + + @classmethod + def from_dict(cls, dikt) -> 'ChallengeSponsor': + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The ChallengeSponsor of this ChallengeSponsor. # noqa: E501 + :rtype: ChallengeSponsor + """ + return util.deserialize_model(dikt, cls) + + @property + def id(self): + """Gets the id of this ChallengeSponsor. + + The unique identifier of a challenge sponsor # noqa: E501 + + :return: The id of this ChallengeSponsor. + :rtype: str + """ + return self._id + + @id.setter + def id(self, id): + """Sets the id of this ChallengeSponsor. + + The unique identifier of a challenge sponsor # noqa: E501 + + :param id: The id of this ChallengeSponsor. + :type id: str + """ + if id is None: + raise ValueError("Invalid value for `id`, must not be `None`") # noqa: E501 + + self._id = id + + @property + def name(self): + """Gets the name of this ChallengeSponsor. + + + :return: The name of this ChallengeSponsor. + :rtype: str + """ + return self._name + + @name.setter + def name(self, name): + """Sets the name of this ChallengeSponsor. + + + :param name: The name of this ChallengeSponsor. + :type name: str + """ + if name is None: + raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 + + self._name = name + + @property + def login(self): + """Gets the login of this ChallengeSponsor. + + The user or organization account name # noqa: E501 + + :return: The login of this ChallengeSponsor. + :rtype: str + """ + return self._login + + @login.setter + def login(self, login): + """Sets the login of this ChallengeSponsor. + + The user or organization account name # noqa: E501 + + :param login: The login of this ChallengeSponsor. + :type login: str + """ + if login is not None and len(login) > 25: + raise ValueError("Invalid value for `login`, length must be less than or equal to `25`") # noqa: E501 + if login is not None and len(login) < 3: + raise ValueError("Invalid value for `login`, length must be greater than or equal to `3`") # noqa: E501 + if login is not None and not re.search(r'^[a-z0-9]+(?:-[a-z0-9]+)*$', login): # noqa: E501 + raise ValueError("Invalid value for `login`, must be a follow pattern or equal to `/^[a-z0-9]+(?:-[a-z0-9]+)*$/`") # noqa: E501 + + self._login = login + + @property + def roles(self): + """Gets the roles of this ChallengeSponsor. + + + :return: The roles of this ChallengeSponsor. + :rtype: List[ChallengeSponsorRole] + """ + return self._roles + + @roles.setter + def roles(self, roles): + """Sets the roles of this ChallengeSponsor. + + + :param roles: The roles of this ChallengeSponsor. + :type roles: List[ChallengeSponsorRole] + """ + + self._roles = roles diff --git a/server/openapi_server/models/challenge_sponsor_create_request.py b/server/openapi_server/models/challenge_sponsor_create_request.py new file mode 100644 index 0000000..509de86 --- /dev/null +++ b/server/openapi_server/models/challenge_sponsor_create_request.py @@ -0,0 +1,130 @@ +# 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.models.challenge_sponsor_role import ChallengeSponsorRole +import re +from openapi_server import util + +from openapi_server.models.challenge_sponsor_role import ChallengeSponsorRole # noqa: E501 +import re # noqa: E501 + +class ChallengeSponsorCreateRequest(Model): + """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + + Do not edit the class manually. + """ + + def __init__(self, name=None, login=None, roles=None): # noqa: E501 + """ChallengeSponsorCreateRequest - a model defined in OpenAPI + + :param name: The name of this ChallengeSponsorCreateRequest. # noqa: E501 + :type name: str + :param login: The login of this ChallengeSponsorCreateRequest. # noqa: E501 + :type login: str + :param roles: The roles of this ChallengeSponsorCreateRequest. # noqa: E501 + :type roles: List[ChallengeSponsorRole] + """ + self.openapi_types = { + 'name': str, + 'login': str, + 'roles': List[ChallengeSponsorRole] + } + + self.attribute_map = { + 'name': 'name', + 'login': 'login', + 'roles': 'roles' + } + + self._name = name + self._login = login + self._roles = roles + + @classmethod + def from_dict(cls, dikt) -> 'ChallengeSponsorCreateRequest': + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The ChallengeSponsorCreateRequest of this ChallengeSponsorCreateRequest. # noqa: E501 + :rtype: ChallengeSponsorCreateRequest + """ + return util.deserialize_model(dikt, cls) + + @property + def name(self): + """Gets the name of this ChallengeSponsorCreateRequest. + + + :return: The name of this ChallengeSponsorCreateRequest. + :rtype: str + """ + return self._name + + @name.setter + def name(self, name): + """Sets the name of this ChallengeSponsorCreateRequest. + + + :param name: The name of this ChallengeSponsorCreateRequest. + :type name: str + """ + if name is None: + raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 + + self._name = name + + @property + def login(self): + """Gets the login of this ChallengeSponsorCreateRequest. + + The user or organization account name # noqa: E501 + + :return: The login of this ChallengeSponsorCreateRequest. + :rtype: str + """ + return self._login + + @login.setter + def login(self, login): + """Sets the login of this ChallengeSponsorCreateRequest. + + The user or organization account name # noqa: E501 + + :param login: The login of this ChallengeSponsorCreateRequest. + :type login: str + """ + if login is not None and len(login) > 25: + raise ValueError("Invalid value for `login`, length must be less than or equal to `25`") # noqa: E501 + if login is not None and len(login) < 3: + raise ValueError("Invalid value for `login`, length must be greater than or equal to `3`") # noqa: E501 + if login is not None and not re.search(r'^[a-z0-9]+(?:-[a-z0-9]+)*$', login): # noqa: E501 + raise ValueError("Invalid value for `login`, must be a follow pattern or equal to `/^[a-z0-9]+(?:-[a-z0-9]+)*$/`") # noqa: E501 + + self._login = login + + @property + def roles(self): + """Gets the roles of this ChallengeSponsorCreateRequest. + + + :return: The roles of this ChallengeSponsorCreateRequest. + :rtype: List[ChallengeSponsorRole] + """ + return self._roles + + @roles.setter + def roles(self, roles): + """Sets the roles of this ChallengeSponsorCreateRequest. + + + :param roles: The roles of this ChallengeSponsorCreateRequest. + :type roles: List[ChallengeSponsorRole] + """ + + self._roles = roles diff --git a/server/openapi_server/models/tag_create_response.py b/server/openapi_server/models/challenge_sponsor_create_response.py similarity index 58% rename from server/openapi_server/models/tag_create_response.py rename to server/openapi_server/models/challenge_sponsor_create_response.py index dbe42c1..ae22ace 100644 --- a/server/openapi_server/models/tag_create_response.py +++ b/server/openapi_server/models/challenge_sponsor_create_response.py @@ -9,16 +9,16 @@ from openapi_server import util -class TagCreateResponse(Model): +class ChallengeSponsorCreateResponse(Model): """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). Do not edit the class manually. """ def __init__(self, id=None): # noqa: E501 - """TagCreateResponse - a model defined in OpenAPI + """ChallengeSponsorCreateResponse - a model defined in OpenAPI - :param id: The id of this TagCreateResponse. # noqa: E501 + :param id: The id of this ChallengeSponsorCreateResponse. # noqa: E501 :type id: str """ self.openapi_types = { @@ -32,34 +32,34 @@ def __init__(self, id=None): # noqa: E501 self._id = id @classmethod - def from_dict(cls, dikt) -> 'TagCreateResponse': + def from_dict(cls, dikt) -> 'ChallengeSponsorCreateResponse': """Returns the dict as a model :param dikt: A dict. :type: dict - :return: The TagCreateResponse of this TagCreateResponse. # noqa: E501 - :rtype: TagCreateResponse + :return: The ChallengeSponsorCreateResponse of this ChallengeSponsorCreateResponse. # noqa: E501 + :rtype: ChallengeSponsorCreateResponse """ return util.deserialize_model(dikt, cls) @property def id(self): - """Gets the id of this TagCreateResponse. + """Gets the id of this ChallengeSponsorCreateResponse. - The unique identifier of a tag # noqa: E501 + The unique identifier of a challenge sponsor # noqa: E501 - :return: The id of this TagCreateResponse. + :return: The id of this ChallengeSponsorCreateResponse. :rtype: str """ return self._id @id.setter def id(self, id): - """Sets the id of this TagCreateResponse. + """Sets the id of this ChallengeSponsorCreateResponse. - The unique identifier of a tag # noqa: E501 + The unique identifier of a challenge sponsor # noqa: E501 - :param id: The id of this TagCreateResponse. + :param id: The id of this ChallengeSponsorCreateResponse. :type id: str """ if id is None: diff --git a/server/openapi_server/models/challenge_sponsor_list.py b/server/openapi_server/models/challenge_sponsor_list.py new file mode 100644 index 0000000..a4b6289 --- /dev/null +++ b/server/openapi_server/models/challenge_sponsor_list.py @@ -0,0 +1,70 @@ +# 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.models.challenge_sponsor import ChallengeSponsor +from openapi_server import util + +from openapi_server.models.challenge_sponsor import ChallengeSponsor # noqa: E501 + +class ChallengeSponsorList(Model): + """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + + Do not edit the class manually. + """ + + def __init__(self, challenge_sponsors=None): # noqa: E501 + """ChallengeSponsorList - a model defined in OpenAPI + + :param challenge_sponsors: The challenge_sponsors of this ChallengeSponsorList. # noqa: E501 + :type challenge_sponsors: List[ChallengeSponsor] + """ + self.openapi_types = { + 'challenge_sponsors': List[ChallengeSponsor] + } + + self.attribute_map = { + 'challenge_sponsors': 'challengeSponsors' + } + + self._challenge_sponsors = challenge_sponsors + + @classmethod + def from_dict(cls, dikt) -> 'ChallengeSponsorList': + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The ChallengeSponsorList of this ChallengeSponsorList. # noqa: E501 + :rtype: ChallengeSponsorList + """ + return util.deserialize_model(dikt, cls) + + @property + def challenge_sponsors(self): + """Gets the challenge_sponsors of this ChallengeSponsorList. + + A list of ChallengeSponsors # noqa: E501 + + :return: The challenge_sponsors of this ChallengeSponsorList. + :rtype: List[ChallengeSponsor] + """ + return self._challenge_sponsors + + @challenge_sponsors.setter + def challenge_sponsors(self, challenge_sponsors): + """Sets the challenge_sponsors of this ChallengeSponsorList. + + A list of ChallengeSponsors # noqa: E501 + + :param challenge_sponsors: The challenge_sponsors of this ChallengeSponsorList. + :type challenge_sponsors: List[ChallengeSponsor] + """ + if challenge_sponsors is None: + raise ValueError("Invalid value for `challenge_sponsors`, must not be `None`") # noqa: E501 + + self._challenge_sponsors = challenge_sponsors diff --git a/server/openapi_server/models/challenge_sponsor_role.py b/server/openapi_server/models/challenge_sponsor_role.py new file mode 100644 index 0000000..28c7903 --- /dev/null +++ b/server/openapi_server/models/challenge_sponsor_role.py @@ -0,0 +1,45 @@ +# 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 ChallengeSponsorRole(Model): + """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + + Do not edit the class manually. + """ + + """ + allowed enum values + """ + CHALLENGEORGANIZER = "ChallengeOrganizer" + COMPUTEPROVIDER = "ComputeProvider" + DATAPROVIDER = "DataProvider" + FUNDER = "Funder" + OTHER = "Other" + def __init__(self): # noqa: E501 + """ChallengeSponsorRole - a model defined in OpenAPI + + """ + self.openapi_types = { + } + + self.attribute_map = { + } + + @classmethod + def from_dict(cls, dikt) -> 'ChallengeSponsorRole': + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The ChallengeSponsorRole of this ChallengeSponsorRole. # noqa: E501 + :rtype: ChallengeSponsorRole + """ + return util.deserialize_model(dikt, cls) diff --git a/server/openapi_server/models/page_of_tags.py b/server/openapi_server/models/page_of_tags.py deleted file mode 100644 index 497e976..0000000 --- a/server/openapi_server/models/page_of_tags.py +++ /dev/null @@ -1,194 +0,0 @@ -# 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.models.page_of_tags_all_of import PageOfTagsAllOf -from openapi_server.models.response_page_metadata import ResponsePageMetadata -from openapi_server.models.response_page_metadata_paging import ResponsePageMetadataPaging -from openapi_server.models.tag import Tag -from openapi_server import util - -from openapi_server.models.page_of_tags_all_of import PageOfTagsAllOf # noqa: E501 -from openapi_server.models.response_page_metadata import ResponsePageMetadata # noqa: E501 -from openapi_server.models.response_page_metadata_paging import ResponsePageMetadataPaging # noqa: E501 -from openapi_server.models.tag import Tag # noqa: E501 - -class PageOfTags(Model): - """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - - Do not edit the class manually. - """ - - def __init__(self, offset=None, limit=None, paging=None, total_results=None, tags=None): # noqa: E501 - """PageOfTags - a model defined in OpenAPI - - :param offset: The offset of this PageOfTags. # noqa: E501 - :type offset: int - :param limit: The limit of this PageOfTags. # noqa: E501 - :type limit: int - :param paging: The paging of this PageOfTags. # noqa: E501 - :type paging: ResponsePageMetadataPaging - :param total_results: The total_results of this PageOfTags. # noqa: E501 - :type total_results: int - :param tags: The tags of this PageOfTags. # noqa: E501 - :type tags: List[Tag] - """ - self.openapi_types = { - 'offset': int, - 'limit': int, - 'paging': ResponsePageMetadataPaging, - 'total_results': int, - 'tags': List[Tag] - } - - self.attribute_map = { - 'offset': 'offset', - 'limit': 'limit', - 'paging': 'paging', - 'total_results': 'totalResults', - 'tags': 'tags' - } - - self._offset = offset - self._limit = limit - self._paging = paging - self._total_results = total_results - self._tags = tags - - @classmethod - def from_dict(cls, dikt) -> 'PageOfTags': - """Returns the dict as a model - - :param dikt: A dict. - :type: dict - :return: The PageOfTags of this PageOfTags. # noqa: E501 - :rtype: PageOfTags - """ - return util.deserialize_model(dikt, cls) - - @property - def offset(self): - """Gets the offset of this PageOfTags. - - Index of the first result that must be returned # noqa: E501 - - :return: The offset of this PageOfTags. - :rtype: int - """ - return self._offset - - @offset.setter - def offset(self, offset): - """Sets the offset of this PageOfTags. - - Index of the first result that must be returned # noqa: E501 - - :param offset: The offset of this PageOfTags. - :type offset: int - """ - if offset is None: - raise ValueError("Invalid value for `offset`, must not be `None`") # noqa: E501 - - self._offset = offset - - @property - def limit(self): - """Gets the limit of this PageOfTags. - - Maximum number of results returned # noqa: E501 - - :return: The limit of this PageOfTags. - :rtype: int - """ - return self._limit - - @limit.setter - def limit(self, limit): - """Sets the limit of this PageOfTags. - - Maximum number of results returned # noqa: E501 - - :param limit: The limit of this PageOfTags. - :type limit: int - """ - if limit is None: - raise ValueError("Invalid value for `limit`, must not be `None`") # noqa: E501 - - self._limit = limit - - @property - def paging(self): - """Gets the paging of this PageOfTags. - - - :return: The paging of this PageOfTags. - :rtype: ResponsePageMetadataPaging - """ - return self._paging - - @paging.setter - def paging(self, paging): - """Sets the paging of this PageOfTags. - - - :param paging: The paging of this PageOfTags. - :type paging: ResponsePageMetadataPaging - """ - if paging is None: - raise ValueError("Invalid value for `paging`, must not be `None`") # noqa: E501 - - self._paging = paging - - @property - def total_results(self): - """Gets the total_results of this PageOfTags. - - Total number of results in the result set # noqa: E501 - - :return: The total_results of this PageOfTags. - :rtype: int - """ - return self._total_results - - @total_results.setter - def total_results(self, total_results): - """Sets the total_results of this PageOfTags. - - Total number of results in the result set # noqa: E501 - - :param total_results: The total_results of this PageOfTags. - :type total_results: int - """ - if total_results is None: - raise ValueError("Invalid value for `total_results`, must not be `None`") # noqa: E501 - - self._total_results = total_results - - @property - def tags(self): - """Gets the tags of this PageOfTags. - - An array of Tags # noqa: E501 - - :return: The tags of this PageOfTags. - :rtype: List[Tag] - """ - return self._tags - - @tags.setter - def tags(self, tags): - """Sets the tags of this PageOfTags. - - An array of Tags # noqa: E501 - - :param tags: The tags of this PageOfTags. - :type tags: List[Tag] - """ - if tags is None: - raise ValueError("Invalid value for `tags`, must not be `None`") # noqa: E501 - - self._tags = tags diff --git a/server/openapi_server/models/page_of_tags_all_of.py b/server/openapi_server/models/page_of_tags_all_of.py deleted file mode 100644 index 002dfb8..0000000 --- a/server/openapi_server/models/page_of_tags_all_of.py +++ /dev/null @@ -1,70 +0,0 @@ -# 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.models.tag import Tag -from openapi_server import util - -from openapi_server.models.tag import Tag # noqa: E501 - -class PageOfTagsAllOf(Model): - """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - - Do not edit the class manually. - """ - - def __init__(self, tags=None): # noqa: E501 - """PageOfTagsAllOf - a model defined in OpenAPI - - :param tags: The tags of this PageOfTagsAllOf. # noqa: E501 - :type tags: List[Tag] - """ - self.openapi_types = { - 'tags': List[Tag] - } - - self.attribute_map = { - 'tags': 'tags' - } - - self._tags = tags - - @classmethod - def from_dict(cls, dikt) -> 'PageOfTagsAllOf': - """Returns the dict as a model - - :param dikt: A dict. - :type: dict - :return: The PageOfTags_allOf of this PageOfTagsAllOf. # noqa: E501 - :rtype: PageOfTagsAllOf - """ - return util.deserialize_model(dikt, cls) - - @property - def tags(self): - """Gets the tags of this PageOfTagsAllOf. - - An array of Tags # noqa: E501 - - :return: The tags of this PageOfTagsAllOf. - :rtype: List[Tag] - """ - return self._tags - - @tags.setter - def tags(self, tags): - """Sets the tags of this PageOfTagsAllOf. - - An array of Tags # noqa: E501 - - :param tags: The tags of this PageOfTagsAllOf. - :type tags: List[Tag] - """ - if tags is None: - raise ValueError("Invalid value for `tags`, must not be `None`") # noqa: E501 - - self._tags = tags diff --git a/server/openapi_server/models/tag.py b/server/openapi_server/models/tag.py deleted file mode 100644 index 8b742c1..0000000 --- a/server/openapi_server/models/tag.py +++ /dev/null @@ -1,110 +0,0 @@ -# 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.models.tag_create_request import TagCreateRequest -from openapi_server.models.tag_create_response import TagCreateResponse -import re -from openapi_server import util - -from openapi_server.models.tag_create_request import TagCreateRequest # noqa: E501 -from openapi_server.models.tag_create_response import TagCreateResponse # noqa: E501 -import re # noqa: E501 - -class Tag(Model): - """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - - Do not edit the class manually. - """ - - def __init__(self, id=None, name=None): # noqa: E501 - """Tag - a model defined in OpenAPI - - :param id: The id of this Tag. # noqa: E501 - :type id: str - :param name: The name of this Tag. # noqa: E501 - :type name: str - """ - self.openapi_types = { - 'id': str, - 'name': str - } - - self.attribute_map = { - 'id': 'id', - 'name': 'name' - } - - self._id = id - self._name = name - - @classmethod - def from_dict(cls, dikt) -> 'Tag': - """Returns the dict as a model - - :param dikt: A dict. - :type: dict - :return: The Tag of this Tag. # noqa: E501 - :rtype: Tag - """ - return util.deserialize_model(dikt, cls) - - @property - def id(self): - """Gets the id of this Tag. - - The unique identifier of a tag # noqa: E501 - - :return: The id of this Tag. - :rtype: str - """ - return self._id - - @id.setter - def id(self, id): - """Sets the id of this Tag. - - The unique identifier of a tag # noqa: E501 - - :param id: The id of this Tag. - :type id: str - """ - if id is None: - raise ValueError("Invalid value for `id`, must not be `None`") # noqa: E501 - - self._id = id - - @property - def name(self): - """Gets the name of this Tag. - - The name of a tag # noqa: E501 - - :return: The name of this Tag. - :rtype: str - """ - return self._name - - @name.setter - def name(self, name): - """Sets the name of this Tag. - - The name of a tag # noqa: E501 - - :param name: The name of this Tag. - :type name: str - """ - if name is None: - raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 - if name is not None and len(name) > 30: - raise ValueError("Invalid value for `name`, length must be less than or equal to `30`") # noqa: E501 - if name is not None and len(name) < 3: - raise ValueError("Invalid value for `name`, length must be greater than or equal to `3`") # noqa: E501 - if name is not None and not re.search(r'^[a-z0-9]+(?:-[a-z0-9]+)*$', name): # noqa: E501 - raise ValueError("Invalid value for `name`, must be a follow pattern or equal to `/^[a-z0-9]+(?:-[a-z0-9]+)*$/`") # noqa: E501 - - self._name = name diff --git a/server/openapi_server/models/tag_create_request.py b/server/openapi_server/models/tag_create_request.py deleted file mode 100644 index fe62674..0000000 --- a/server/openapi_server/models/tag_create_request.py +++ /dev/null @@ -1,76 +0,0 @@ -# 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 -import re -from openapi_server import util - -import re # noqa: E501 - -class TagCreateRequest(Model): - """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - - Do not edit the class manually. - """ - - def __init__(self, name=None): # noqa: E501 - """TagCreateRequest - a model defined in OpenAPI - - :param name: The name of this TagCreateRequest. # noqa: E501 - :type name: str - """ - self.openapi_types = { - 'name': str - } - - self.attribute_map = { - 'name': 'name' - } - - self._name = name - - @classmethod - def from_dict(cls, dikt) -> 'TagCreateRequest': - """Returns the dict as a model - - :param dikt: A dict. - :type: dict - :return: The TagCreateRequest of this TagCreateRequest. # noqa: E501 - :rtype: TagCreateRequest - """ - return util.deserialize_model(dikt, cls) - - @property - def name(self): - """Gets the name of this TagCreateRequest. - - The name of a tag # noqa: E501 - - :return: The name of this TagCreateRequest. - :rtype: str - """ - return self._name - - @name.setter - def name(self, name): - """Sets the name of this TagCreateRequest. - - The name of a tag # noqa: E501 - - :param name: The name of this TagCreateRequest. - :type name: str - """ - if name is None: - raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 - if name is not None and len(name) > 30: - raise ValueError("Invalid value for `name`, length must be less than or equal to `30`") # noqa: E501 - if name is not None and len(name) < 3: - raise ValueError("Invalid value for `name`, length must be greater than or equal to `3`") # noqa: E501 - if name is not None and not re.search(r'^[a-z0-9]+(?:-[a-z0-9]+)*$', name): # noqa: E501 - raise ValueError("Invalid value for `name`, must be a follow pattern or equal to `/^[a-z0-9]+(?:-[a-z0-9]+)*$/`") # noqa: E501 - - self._name = name diff --git a/server/openapi_server/openapi/openapi.yaml b/server/openapi_server/openapi/openapi.yaml index 905da21..5b352ed 100644 --- a/server/openapi_server/openapi/openapi.yaml +++ b/server/openapi_server/openapi/openapi.yaml @@ -899,6 +899,160 @@ paths: tags: - Challenge x-openapi-router-controller: openapi_server.controllers.challenge_controller + /challenges/{accountName}/{challengeName}/sponsors: + get: + description: Lists the sponsors of the challenge. + operationId: list_challenge_sponsors + parameters: + - description: The name of the account that owns the challenge + explode: false + in: path + name: accountName + required: true + schema: + $ref: '#/components/schemas/AccountLogin' + style: simple + - description: The name of the challenge + explode: false + in: path + name: challengeName + required: true + schema: + $ref: '#/components/schemas/ChallengeName' + style: simple + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/ChallengeSponsorList' + description: Success + "404": + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + description: The specified resource was not found + "500": + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + description: The request cannot be fulfilled due to an unexpected server + error + summary: List sponsors + tags: + - Challenge + x-openapi-router-controller: openapi_server.controllers.challenge_controller + post: + description: Create a challenge sponsor + operationId: create_challenge_sponsor + parameters: + - description: The name of the account that owns the challenge + explode: false + in: path + name: accountName + required: true + schema: + $ref: '#/components/schemas/AccountLogin' + style: simple + - description: The name of the challenge + explode: false + in: path + name: challengeName + required: true + schema: + $ref: '#/components/schemas/ChallengeName' + style: simple + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/ChallengeSponsorCreateRequest' + required: true + responses: + "201": + content: + application/json: + schema: + $ref: '#/components/schemas/ChallengeSponsorCreateResponse' + description: Success + "400": + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + description: Invalid request + "409": + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + description: The request conflicts with current state of the target resource + "500": + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + description: The request cannot be fulfilled due to an unexpected server + error + summary: Create a challenge sponsor + tags: + - Challenge + x-openapi-router-controller: openapi_server.controllers.challenge_controller + /challenges/{accountName}/{challengeName}/sponsors/{sponsorId}: + delete: + description: Deletes the challenge sponsor specified + operationId: delete_challenge_sponsor + parameters: + - description: The name of the account that owns the challenge + explode: false + in: path + name: accountName + required: true + schema: + $ref: '#/components/schemas/AccountLogin' + style: simple + - description: The name of the challenge + explode: false + in: path + name: challengeName + required: true + schema: + $ref: '#/components/schemas/ChallengeName' + style: simple + - description: The identifier of the challenge sponsor + explode: false + in: path + name: sponsorId + required: true + schema: + $ref: '#/components/schemas/ChallengeSponsorId' + style: simple + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/EmptyObject' + description: Success + "400": + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + description: The specified resource was not found + "500": + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + description: The request cannot be fulfilled due to an unexpected server + error + summary: Delete a challenge sponsor + tags: + - Challenge + x-openapi-router-controller: openapi_server.controllers.challenge_controller /challenges/{accountName}/{challengeName}/stargazers: get: description: Lists the people that have starred the challenge. @@ -1609,194 +1763,6 @@ paths: tags: - Organization x-openapi-router-controller: openapi_server.controllers.organization_controller - /tags: - delete: - description: Delete all tags - operationId: delete_all_tags - responses: - "200": - content: - application/json: - schema: - $ref: '#/components/schemas/EmptyObject' - description: Success - "500": - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - description: The request cannot be fulfilled due to an unexpected server - error - summary: Delete all tags - tags: - - Tag - x-openapi-router-controller: openapi_server.controllers.tag_controller - get: - description: Returns the tags - operationId: list_tags - parameters: - - description: Maximum number of results returned - explode: true - in: query - name: limit - required: false - schema: - default: 10 - maximum: 100 - minimum: 10 - type: integer - style: form - - description: Index of the first result that must be returned - explode: true - in: query - name: offset - required: false - schema: - default: 0 - minimum: 0 - type: integer - style: form - responses: - "200": - content: - application/json: - schema: - $ref: '#/components/schemas/PageOfTags' - description: Success - "400": - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - description: Invalid request - "500": - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - description: The request cannot be fulfilled due to an unexpected server - error - summary: Get all tags - tags: - - Tag - x-openapi-router-controller: openapi_server.controllers.tag_controller - post: - description: Create a tag with the specified name - operationId: create_tag - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/TagCreateRequest' - required: true - responses: - "201": - content: - application/json: - schema: - $ref: '#/components/schemas/TagCreateResponse' - description: Success - links: - GetTagById: - $ref: '#/components/links/GetTagById' - DeleteTagById: - $ref: '#/components/links/DeleteTagById' - "400": - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - description: Invalid request - "409": - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - description: The request conflicts with current state of the target resource - "500": - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - description: The request cannot be fulfilled due to an unexpected server - error - summary: Create a tag - tags: - - Tag - x-openapi-router-controller: openapi_server.controllers.tag_controller - /tags/{tagId}: - delete: - description: Deletes the tag specified - operationId: delete_tag - parameters: - - description: The unique identifier of the tag - explode: false - in: path - name: tagId - required: true - schema: - $ref: '#/components/schemas/TagId' - style: simple - responses: - "200": - content: - application/json: - schema: - $ref: '#/components/schemas/EmptyObject' - description: Success - "404": - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - description: The specified resource was not found - "500": - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - description: The request cannot be fulfilled due to an unexpected server - error - summary: Delete a tag - tags: - - Tag - x-openapi-router-controller: openapi_server.controllers.tag_controller - get: - description: Returns the tag specified - operationId: get_tag - parameters: - - description: The unique identifier of the tag - explode: false - in: path - name: tagId - required: true - schema: - $ref: '#/components/schemas/TagId' - style: simple - responses: - "200": - content: - application/json: - schema: - $ref: '#/components/schemas/Tag' - description: Success - "404": - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - description: The specified resource was not found - "500": - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - description: The request cannot be fulfilled due to an unexpected server - error - summary: Get a tag - tags: - - Tag - x-openapi-router-controller: openapi_server.controllers.tag_controller /user: get: description: Get the authenticated user @@ -2464,18 +2430,6 @@ components: operationId: deleteOrganization parameters: organizationId: $response.body#/organizationId - GetTagById: - description: | - The `id` value returned in the response can be used as the `tagId` parameter in `GET /tags/{tagId}` - operationId: getTag - parameters: - tagId: $response.body#/tagId - DeleteTagById: - description: | - The `id` value returned in the response can be used as the `tagId` parameter in `DELETE /tags/{tagId}` - operationId: deleteTag - parameters: - tagId: $response.body#/tagId GetUserById: description: | The `userName` value returned in the response can be used as the `userName` parameter in `GET /users/{userName}` @@ -3012,6 +2966,83 @@ components: required: - text type: object + ChallengeSponsorId: + description: The unique identifier of a challenge sponsor + example: 507f1f77bcf86cd799439011 + type: string + ChallengeSponsorCreateResponse: + description: The unique identifier of a challenge sponsor + example: + id: 507f1f77bcf86cd799439011 + properties: + id: + description: The unique identifier of a challenge sponsor + example: 507f1f77bcf86cd799439011 + type: string + required: + - id + title: ChallengeSponsorCreateResponse + type: object + ChallengeSponsorRole: + description: The role of a challenge sponsor + enum: + - ChallengeOrganizer + - ComputeProvider + - DataProvider + - Funder + - Other + example: DataProvider + title: ChallengeSponsorRole + type: string + ChallengeSponsorCreateRequest: + description: The information used to create a challenge sponsor + example: + name: IBM + login: ibm + roles: + - ComputeProvider + - DataProvider + properties: + name: + type: string + login: + description: The user or organization account name + example: awesome-user + maxLength: 25 + minLength: 3 + pattern: ^[a-z0-9]+(?:-[a-z0-9]+)*$ + type: string + roles: + items: + $ref: '#/components/schemas/ChallengeSponsorRole' + type: array + required: + - name + type: object + ChallengeSponsor: + allOf: + - $ref: '#/components/schemas/ChallengeSponsorCreateResponse' + - $ref: '#/components/schemas/ChallengeSponsorCreateRequest' + description: A challenge sponsor + title: ChallengeSponsor + type: object + ChallengeSponsorList: + description: A list of challenge sponsors + example: + challengeSponsors: + - null + - null + properties: + challengeSponsors: + description: A list of ChallengeSponsors + items: + $ref: '#/components/schemas/ChallengeSponsor' + title: challengeSponsors + type: array + required: + - challengeSponsors + title: ChallengeSponsorList + type: object UserCreateResponse: description: The response returned after the creation of the user example: @@ -3167,6 +3198,23 @@ components: description: A page of Grants title: PageOfGrants type: object + HealthCheck: + description: Represents the health of a service + example: + status: pass + properties: + status: + description: Indicates whether the service status is acceptable or not + enum: + - pass + - fail + - warn + title: status + type: string + required: + - status + title: HealthCheck + type: object OrganizationCreateResponse: description: The unique identifier of the org created example: @@ -3307,59 +3355,6 @@ components: description: A page of org memberships title: PageOfOrgMemberships type: object - TagId: - description: The unique identifier of a tag - example: 507f1f77bcf86cd799439011 - type: string - TagCreateResponse: - description: The unique identifier of the tag created - example: - id: 507f1f77bcf86cd799439011 - properties: - id: - description: The unique identifier of a tag - example: 507f1f77bcf86cd799439011 - type: string - required: - - id - title: TagCreateResponse - type: object - TagName: - description: The name of a tag - example: awesome-tag - maxLength: 30 - minLength: 3 - pattern: ^[a-z0-9]+(?:-[a-z0-9]+)*$ - type: string - TagCreateRequest: - description: The information required to create a tag - example: - name: awesome-tag - properties: - name: - description: The name of a tag - example: awesome-tag - maxLength: 30 - minLength: 3 - pattern: ^[a-z0-9]+(?:-[a-z0-9]+)*$ - type: string - required: - - name - type: object - Tag: - allOf: - - $ref: '#/components/schemas/TagCreateResponse' - - $ref: '#/components/schemas/TagCreateRequest' - description: A tag that can be assigned to a resource - title: Tag - type: object - PageOfTags: - allOf: - - $ref: '#/components/schemas/ResponsePageMetadata' - - $ref: '#/components/schemas/PageOfTags_allOf' - description: A page of Tags - title: PageOfTags - type: object UserCreateRequest: description: The information required to create a user account example: @@ -3396,23 +3391,6 @@ components: - login - password type: object - HealthCheck: - description: Represents the health of a service - example: - status: pass - properties: - status: - description: Indicates whether the service status is acceptable or not - enum: - - pass - - fail - - warn - title: status - type: string - required: - - status - title: HealthCheck - type: object ResponsePageMetadata_paging: description: Links to navigate to different pages of results properties: @@ -3588,16 +3566,6 @@ components: required: - orgMemberships type: object - PageOfTags_allOf: - properties: - tags: - description: An array of Tags - items: - $ref: '#/components/schemas/Tag' - type: array - required: - - tags - type: object securitySchemes: BearerAuth: bearerFormat: JWT