Added a way to set a primary location

+ Can be retrieved from the GraphQL API
+ Fixed `resolve_player` query
doc_update
Joey Hines 2020-08-22 13:29:49 -05:00
parent ec49b7c873
commit 2f846de921
3 changed files with 48 additions and 6 deletions

View File

@ -853,3 +853,23 @@ def mod_remove_owner(player_name, loc_name):
location = get_location(owner, loc_name)
location.owner.remove(owner)
@command(RequestTypes.POST, permission_level=PermissionLevel.PLAYER)
def primary_location(loc_name, discord_uuid=None, mc_uuid=None):
"""
:request: POST
:param loc_name: location to set as primary
:param discord_uuid: player discord uuid
:param mc_uuid: player mc uuid
:return: json representation of the primary location
"""
player = get_player(discord_uuid, mc_uuid)
loc = get_location(player, loc_name)
player.primary_location = loc
player.save()
return loc.json

View File

@ -14,10 +14,13 @@ class UnauthorizedQuery(Exception):
def __init__(self):
super().__init__("GraphQL Request Not Authorized")
class PlayerType(DjangoObjectType):
class Meta:
model = Player
fields = ("id", "name", "discord_uuid", "mc_uuid")
fields = ("id", "name", "discord_uuid", "mc_uuid", "primary_location")
primary_location = graphene.Field("GeoffreyApp.api.schema.LocationType")
class TunnelType(DjangoObjectType):
@ -135,7 +138,7 @@ class ProtectedAPI():
class Query(graphene.ObjectType):
player = graphene.Field(PlayerType, id=graphene.Argument(graphene.Int, required=False), name=graphene.Argument(graphene.String, required=False), discord_uuid=graphene.Argument(graphene.String, required=False))
player = graphene.Field(PlayerType, id=graphene.Argument(graphene.Int, required=False), name=graphene.Argument(graphene.String, required=False), mc_uuid=graphene.Argument(graphene.String, required=False), discord_uuid=graphene.Argument(graphene.String, required=False))
locations = graphene.List(LocationType, id=graphene.Argument(graphene.Int, required=False), name=graphene.Argument(graphene.String, required=False))
shops = graphene.List(ShopType, id=graphene.Argument(graphene.Int, required=False), name=graphene.Argument(graphene.String, required=False))
towns = graphene.List(TownType, id=graphene.Argument(graphene.Int, required=False), name=graphene.Argument(graphene.String, required=False))
@ -145,8 +148,19 @@ class Query(graphene.ObjectType):
points_of_interest = graphene.List(PointOfInterestType, id=graphene.Argument(graphene.Int, required=False), name=graphene.Argument(graphene.String, required=False))
@ProtectedAPI.protected_api()
def resolve_player(root, info, id, name, discord_uuid, mc_uuid):
return Player.objects.get(pk=id, name=name, discord_uuid=discord_uuid, mc_uuid=mc_uuid)
def resolve_player(root, info, id=None, name=None, discord_uuid=None, mc_uuid=None):
query = Player.objects
if id is not None:
query = query.filter(id=id)
elif name is not None:
query = query.filter(name__iexact=name)
elif discord_uuid is not None:
query = query.filter(discord_uuid=discord_uuid)
elif mc_uuid is not None:
query = query.filter(mc_uuid=mc_uuid)
return query.get()
@ProtectedAPI.protected_api()
def resolve_locations(root, info, id=None, name=None):

View File

@ -83,6 +83,11 @@ class Player(models.Model):
Discord UUID
"""
primary_location = models.OneToOneField("Location", on_delete=models.DO_NOTHING, null=True)
"""
User's primary location
"""
@property
def loc_count(self):
"""
@ -101,12 +106,14 @@ class Player(models.Model):
"name" : "self.name",
"mc_uuid": "self.mc_uuid",
"discord_uuid": "self.discord_uuid",
"primary_location": "self.primary_location"
}
"""
return {"name": self.name,
"mc_uuid": self.mc_uuid,
"discord_uuid": self.discord_uuid
"discord_uuid": self.discord_uuid,
"primary_location": self.primary_location.json
}
@property
@ -218,7 +225,8 @@ class Location(models.Model):
"owner": self.get_owners,
"location": self.position,
"tunnel": None if self.tunnel is None else self.tunnel.tunnel_str,
"link": self.link
"link": self.link,
"primary_location": self.player.primary_location
}
@property