Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions backend/gamedata/api/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
GamePlanetCOGCProgram,
GamePlanetCOGCProgramChoices,
GamePlanetInfrastructureReport,
GamePlanetProductionFee,
GamePlanetResource,
GameRecipe,
GameRecipeInput,
Expand Down Expand Up @@ -88,6 +89,12 @@ class Meta:
fields = ['resource_type', 'factor', 'daily_extraction', 'material_ticker', 'max_daily_extraction']


class GamePlanetProductionFeeSerializer(serializers.ModelSerializer):
class Meta:
model = GamePlanetProductionFee
fields = ['category', 'workforce_level', 'fee_amount', 'fee_currency']


class GamePlanetCOGCProgramSerializer(serializers.ModelSerializer):
class Meta:
model = GamePlanetCOGCProgram
Expand All @@ -97,6 +104,7 @@ class Meta:
class GamePlanetSerializer(serializers.ModelSerializer):
resources = GamePlanetResourceSerializer(many=True, read_only=True)
cogc_programs = GamePlanetCOGCProgramSerializer(many=True, read_only=True)
production_fees = GamePlanetProductionFeeSerializer(many=True, read_only=True)

active_cogc_program_type = serializers.CharField(read_only=True)

Expand All @@ -122,6 +130,7 @@ class Meta:
'cogc_program_status',
'resources',
'cogc_programs',
'production_fees',
'active_cogc_program_type',
]

Expand Down
2 changes: 1 addition & 1 deletion backend/gamedata/models/game_planet.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def queryset_gameplanet() -> QuerySet:
.values('program_type')[:1]
)

return GamePlanet.objects.prefetch_related('cogc_programs', 'resources').annotate(
return GamePlanet.objects.prefetch_related('cogc_programs', 'resources', 'production_fees').annotate(
active_cogc_program_type=Subquery(active_program_sub)
)

Expand Down
5 changes: 5 additions & 0 deletions backend/tests/gamedata/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ def planet_factory(**kwargs):
return lambda **kwargs: baker.make('gamedata.GamePlanet', make_m2m=True, **kwargs)


@pytest.fixture()
def production_fee_factory(**kwargs):
return lambda **kwargs: baker.make('gamedata.GamePlanetProductionFee', **kwargs)


@pytest.fixture()
def building_cost_factory(**kwargs):
return lambda **kwargs: baker.make('gamedata.GameBuildingCost', **kwargs)
Expand Down
19 changes: 19 additions & 0 deletions backend/tests/gamedata/test_gamedata_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ def test_retrieve(self, api_client, planet_factory):
assert response.status_code == 200
assert response.data['planet_natural_id'] == planet_natural_id

def test_retrieve_production_fees(self, api_client, planet_factory, production_fee_factory):
planet_natural_id = 'OT-580b'
planet = planet_factory(planet_natural_id=planet_natural_id)
production_fee_factory(
planet=planet,
category='METALLURGY',
workforce_level='PIONEER',
fee_amount=50.0,
fee_currency='AIC',
)

url = reverse('data:planet-detail', kwargs={'planet_natural_id': planet_natural_id})
response = api_client.get(url)

assert response.status_code == 200
assert response.data['production_fees'] == [
{'category': 'METALLURGY', 'workforce_level': 'PIONEER', 'fee_amount': 50.0, 'fee_currency': 'AIC'}
]

def test_multiple(self, api_client, planet_factory):
planet_natural_ids = ['OT-580b', 'ZV-759b', 'EW-688c']

Expand Down