Closed samikshakarimbil closed 1 week ago
overall, looks good. here's a couple of notes:
looks good for the most part! though I have some suggestions for readability/conciseness
treat_sku
is defined the feed endpoint function's parameters, but the router URL itself still has {treat_id}
as a parameter. I don't think it will work if they don't matchJOIN
) in one query, instead of retrieving them separately. I have similar logic written for get_creatures() right now. Combined with @charm-13's suggestion for affinity, it'd be like this:
SELECT happiness, hunger, fav_treat, hated_treat, COALESCE(user_creature_connection.affinity, 0) AS affinity
FROM creatures
JOIN creature_types ON creatures.type = creature_types.type AND creatures.id = :creature
LEFT JOIN user_creature_connection ON creatures.id = user_creature_connection.creature_id AND user_id = :user_id
^ this should work even when user has no established connection with the creature
remaining_hunger
, remaining_happiness
, remaining_affinity
) could be done within the initial SQL query instead of being processed by Python. I think it would improve readability, especially since you reference stats["happiness"]
and stats["hunger"]
only once in feed_creatures().
SELECT happiness...
, you would write SELECT (100 - happiness) AS remaining_happiness...
, and reference it later on as stats['remaining_happiness']
Finished the feed and play endpoints :)