From 985dd17dc089e2f36aa4aff30981c5cc0e5c29ac Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sat, 11 May 2019 11:46:30 -0500 Subject: [PATCH] Added market commands --- GeoffreyApp/api/commands.py | 31 +++++++++++++++++++++++++++---- GeoffreyApp/models.py | 6 ++++-- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/GeoffreyApp/api/commands.py b/GeoffreyApp/api/commands.py index f328da9..2e49712 100644 --- a/GeoffreyApp/api/commands.py +++ b/GeoffreyApp/api/commands.py @@ -165,7 +165,7 @@ def add_town(x_pos, z_pos, name=None, discord_uuid=None, mc_uuid=None): :request: POST :param x_pos: MC X Coordinate :param z_pos: MC Z Coordinate - :param name: Shop Name (If None, Defaults to Player's Shop) + :param name: Town Name (If None, Defaults to Player's Town) :param discord_uuid: Discord UUID :param mc_uuid: Minecraft UUID :return: JSON representation of the new town @@ -182,10 +182,10 @@ def add_farm(x_pos, z_pos, name=None, discord_uuid=None, mc_uuid=None): :request: POST :param x_pos: MC X Coordinate :param z_pos: MC Z Coordinate - :param name: Shop Name (If None, Defaults to Player's Shop) + :param name: Farm Name (If None, Defaults to Player's Farm) :param discord_uuid: Discord UUID :param mc_uuid: Minecraft UUID - :return: JSON representation of the new town + :return: JSON representation of the new farm :raises: EntryNameNotUniqueError, PlayerNotFound, LocationLookupError :help: Adds your public farm to the database. """ @@ -193,6 +193,22 @@ def add_farm(x_pos, z_pos, name=None, discord_uuid=None, mc_uuid=None): return add_location(x_pos, z_pos, name=name, discord_uuid=discord_uuid, mc_uuid=mc_uuid, loc_type=PublicFarm) +@command("POST") +def add_market(x_pos, z_pos, name=None, discord_uuid=None, mc_uuid=None): + """ + :request: POST + :param x_pos: MC X Coordinate + :param z_pos: MC Z Coordinate + :param name: Market Name (If None, Defaults to Player's Market) + :param discord_uuid: Discord UUID + :param mc_uuid: Minecraft UUID + :return: JSON representation of the market + :raises: EntryNameNotUniqueError, PlayerNotFound, LocationLookupError + :help: Adds your market to the database. + """ + + return add_location(x_pos, z_pos, name=name, discord_uuid=discord_uuid, mc_uuid=mc_uuid, loc_type=Market) + @command("POST") def add_tunnel(tunnel_direction, tunnel_number, location_name=None, discord_uuid=None, mc_uuid=None): @@ -339,6 +355,13 @@ def add_resource(resource_name, farm_name=None, discord_uuid=None, mc_uuid=None) @command("GET") def find_farm(resource_name): + """ + :request: GET + :param resource_name: Resource to search for + :return: List of top matching farms + :raises: ResourceNotFoundError + :help: Lists farms that produce an object + """ if len(resource_name) == 0: raise EmptryString @@ -350,7 +373,7 @@ def selling(item_name): """ :request: GET :param item_name: Item name to search for - :return: List of top matching shops, sorted by the + :return: List of top matching shops, sorted by the date last restocke :raises: ItemNotFound :help: Lists shops selling an item. Sorted by when they were last restocked. """ diff --git a/GeoffreyApp/models.py b/GeoffreyApp/models.py index 082f932..837655b 100644 --- a/GeoffreyApp/models.py +++ b/GeoffreyApp/models.py @@ -309,8 +309,10 @@ class Market(Location): info_page = "GeoffreyMarketInfo" def get_shops(self, market_radius=100, limit=10): - shops = Shop.objects.filter(x_coord__range=(self.x_coord - market_radius, self.x_coord + market_radius), - z_coord__range=(self.z_coord - market_radius, self.z_coord + market_radius) + x = int(self.x_coord) + z = int(self.z_coord) + shops = Shop.objects.filter(x_coord__range=(x - market_radius, x + market_radius), + z_coord__range=(z - market_radius, z + market_radius) )[:limit] return shops