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

Commit

Permalink
Use snake case for DB model properties (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaffter authored Sep 10, 2021
1 parent a3d2da4 commit 5fe6628
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 50 deletions.
18 changes: 9 additions & 9 deletions server/openapi_server/controllers/challenge_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ def create_challenge(account_name): # noqa: E501
challenge_create_request = ChallengeCreateRequest.from_dict(connexion.request.get_json()) # noqa: E501
challenge = DbChallenge(
name=challenge_create_request.name,
displayName=challenge_create_request.display_name,
display_name=challenge_create_request.display_name,
description=challenge_create_request.description,
websiteUrl=challenge_create_request.website_url,
website_url=challenge_create_request.website_url,
status=challenge_create_request.status,
startDate=challenge_create_request.start_date,
endDate=challenge_create_request.end_date,
platformId=challenge_create_request.platform_id,
start_date=challenge_create_request.start_date,
end_date=challenge_create_request.end_date,
platform_id=challenge_create_request.platform_id,
doi=challenge_create_request.doi,
fullName="%s/%s" % (account_name, challenge_create_request.name),
ownerId=account_id
full_name="%s/%s" % (account_name, challenge_create_request.name),
owner_id=account_id
).save()
challenge_id = challenge.to_dict().get("id")
res = ChallengeCreateResponse(id=challenge_id)
Expand Down Expand Up @@ -93,7 +93,7 @@ def delete_challenge(account_name, challenge_name): # noqa: E501
account = DbAccount.objects.get(login=account_name)
account_id = account.to_dict().get("id")

DbChallenge.objects.get(ownerId=account_id, name=challenge_name).delete() # noqa: E501
DbChallenge.objects.get(owner_id=account_id, name=challenge_name).delete() # noqa: E501
res = {}
status = 200
except DoesNotExist:
Expand Down Expand Up @@ -122,7 +122,7 @@ def get_challenge(account_name, challenge_name): # noqa: E501
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
db_user = DbChallenge.objects.get(owner_id=account_id, name=challenge_name) # noqa: E501
res = Challenge.from_dict(db_user.to_dict())
status = 200
except DoesNotExist:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def create_challenge_platform(): # noqa: E501
challenge_platform_create_request = ChallengePlatformCreateRequest.from_dict(connexion.request.get_json()) # noqa: E501
challenge_platform = DbChallengePlatform(
name=challenge_platform_create_request.name,
displayName=challenge_platform_create_request.display_name,
websiteUrl=challenge_platform_create_request.website_url,
avatarUrl=challenge_platform_create_request.avatar_url
display_name=challenge_platform_create_request.display_name,
website_url=challenge_platform_create_request.website_url,
avatar_url=challenge_platform_create_request.avatar_url
).save()
challenge_platform_id = challenge_platform.to_dict().get("id")
res = ChallengePlatformCreateResponse(id=challenge_platform_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def create_org_membership(): # noqa: E501
org = DbOrgMembership(
state=org_membership_request.state,
role=org_membership_request.role,
organizationId=org_membership_request.organization_id,
userId=org_membership_request.user_id
organization_id=org_membership_request.organization_id,
user_id=org_membership_request.user_id
).save()
org_id = org.to_dict().get("id")
res = OrgMembershipCreateResponse(id=org_id)
Expand Down Expand Up @@ -126,9 +126,9 @@ def list_org_memberships(limit=None, offset=None, org_id=None, user_id=None): #
:rtype: PageOfOrgMemberships
"""
try:
org_id_q = Q(organizationId=org_id) \
org_id_q = Q(organization_id=org_id) \
if org_id is not None else Q()
user_id_q = Q(userId=user_id) \
user_id_q = Q(user_id=user_id) \
if user_id is not None else Q()

db_org_memberships = DbOrgMembership.objects(
Expand Down
2 changes: 1 addition & 1 deletion server/openapi_server/controllers/user_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def create_user(): # noqa: E501
login=user_create_request.login,
email=user_create_request.email,
name=user_create_request.name,
avatarUrl=user_create_request.avatar_url,
avatar_url=user_create_request.avatar_url,
type="User" # TODO: Use enum value
).save()
user_id = user.to_dict().get("id")
Expand Down
1 change: 0 additions & 1 deletion server/openapi_server/dbmodels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from __future__ import absolute_import
# import models into model package
from openapi_server.dbmodels.challenge import Challenge
from openapi_server.dbmodels.challenge_results import ChallengeResults
from openapi_server.dbmodels.grant import Grant
from openapi_server.dbmodels.organization import Organization
from openapi_server.dbmodels.person import Person
Expand Down
14 changes: 7 additions & 7 deletions server/openapi_server/dbmodels/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
class Challenge(Document):
id = ObjectIdField(primary_key=True, default=ObjectId)
name = StringField(required=True)
displayName = StringField(min_length=3, max_length=60)
display_name = StringField(min_length=3, max_length=60)
description = StringField(required=True)
fullName = StringField(required=True, unique=True)
ownerId = ReferenceField(Account)
websiteUrl = URLField()
full_name = StringField(required=True, unique=True)
owner_id = ReferenceField(Account)
website_url = URLField()
status = StringField(
required=True,
choices=["active", "upcoming", "completed"] # TODO: DRY
)
startDate = DateTimeField()
endDate = DateTimeField()
platformId = ReferenceField(ChallengePlatform)
start_date = DateTimeField()
end_date = DateTimeField()
platform_id = ReferenceField(ChallengePlatform)
doi = StringField()

# summary = StringField()
Expand Down
10 changes: 5 additions & 5 deletions server/openapi_server/dbmodels/challenge_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
class ChallengePlatform(Document):
id = ObjectIdField(primary_key=True, default=ObjectId)
name = StringField(required=True, unique=True)
displayName = StringField(required=True, unique=True)
websiteUrl = URLField(required=True)
avatarUrl = URLField()
createdAt = DateTimeField(required=True, default=datetime.datetime.now)
updatedAt = DateTimeField(required=True, default=datetime.datetime.now)
display_name = StringField(required=True, unique=True)
website_url = URLField(required=True)
avatar_url = URLField()
created_at = DateTimeField(required=True, default=datetime.datetime.now)
updated_at = DateTimeField(required=True, default=datetime.datetime.now)

def to_dict(self):
doc = self.to_mongo().to_dict()
Expand Down
11 changes: 0 additions & 11 deletions server/openapi_server/dbmodels/challenge_results.py

This file was deleted.

4 changes: 2 additions & 2 deletions server/openapi_server/dbmodels/org_membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class OrgMembership(Document):
required=True,
choices=["admin", "member"] # TODO: DRY
)
organizationId = ReferenceField(Organization)
userId = ReferenceField(User, unique_with='organizationId')
organization_id = ReferenceField(Organization)
user_id = ReferenceField(User, unique_with='organization_id')

def to_dict(self):
doc = self.to_mongo().to_dict()
Expand Down
6 changes: 3 additions & 3 deletions server/openapi_server/dbmodels/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
class Organization(Account):
email = EmailField()
name = StringField()
avatarUrl = URLField()
avatar_url = URLField()
description = StringField()
createdAt = DateTimeField(required=True, default=datetime.datetime.now)
updatedAt = DateTimeField(required=True, default=datetime.datetime.now)
created_at = DateTimeField(required=True, default=datetime.datetime.now)
updated_at = DateTimeField(required=True, default=datetime.datetime.now)

def to_dict(self):
doc = self.to_mongo().to_dict()
Expand Down
6 changes: 3 additions & 3 deletions server/openapi_server/dbmodels/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
class User(Account):
email = EmailField()
name = StringField()
avatarUrl = URLField()
createdAt = DateTimeField(required=True, default=datetime.datetime.now)
updatedAt = DateTimeField(required=True, default=datetime.datetime.now)
avatar_url = URLField()
created_at = DateTimeField(required=True, default=datetime.datetime.now)
updated_at = DateTimeField(required=True, default=datetime.datetime.now)

def to_dict(self):
doc = self.to_mongo().to_dict()
Expand Down
1 change: 0 additions & 1 deletion server/openapi_server/test/integration/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from openapi_server.dbmodels.challenge import Challenge
from openapi_server.dbmodels.challenge_platform import ChallengePlatform
from openapi_server.dbmodels.challenge_results import ChallengeResults
from openapi_server.dbmodels.grant import Grant
from openapi_server.dbmodels.organization import Organization
from openapi_server.dbmodels.person import Person
Expand Down

0 comments on commit 5fe6628

Please sign in to comment.