Skip to content

Commit

Permalink
#71 fix : modify get location function (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
0321minji authored Aug 21, 2024
1 parent cf390ae commit 800f91d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lands/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,21 @@ def get_item_image(self, obj):

def get_locations(self, obj):
user_email = self.context.get('user_email')
locations = obj.locations.get(land__user__email=user_email)
return LandApi.LocationSerializer(locations).data
try:
location, created = obj.locations.get_or_create(
land__user__email=user_email,
defaults={
'x': 0,
'y': 0,
'z': 0,
'show': False
}
)
except Exception as e:
# 예외가 발생하면 적절한 에러 메시지를 반환합니다.
return {'error': str(e)}

return LandApi.LocationSerializer(location).data

class LandItemOutputSerializer(serializers.Serializer):
land = serializers.SerializerMethodField()
Expand Down

0 comments on commit 800f91d

Please sign in to comment.