Skip to content

Commit ec36933

Browse files
🐛 fix: pass gameId from path variables to commands` metadata
1 parent 6ce3ae1 commit ec36933

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

generated-requests.http

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### BuildDwelling
2+
@gameId = scenario-1
23
@dwellingId = dwelling-1
3-
PUT http://localhost:8080/dwellings/{{dwellingId}}
4+
PUT http://localhost:8080/games/{{gameId}}/dwellings/{{dwellingId}}
45
Content-Type: application/json
56

67
{
@@ -12,7 +13,7 @@ Content-Type: application/json
1213
}
1314

1415
### IncreaseAvailableCreatures
15-
PUT http://localhost:8080/dwellings/{{dwellingId}}/available-creatures-increases
16+
PUT http://localhost:8080/games/{{gameId}}/dwellings/{{dwellingId}}/available-creatures-increases
1617
Content-Type: application/json
1718

1819
{
@@ -21,7 +22,7 @@ Content-Type: application/json
2122
}
2223

2324
### RecruitCreature
24-
PUT http://localhost:8080/dwellings/{{dwellingId}}/creature-recruitments
25+
PUT http://localhost:8080/games/{{gameId}}/dwellings/{{dwellingId}}/creature-recruitments
2526
Content-Type: application/json
2627

2728
{
@@ -31,6 +32,6 @@ Content-Type: application/json
3132
}
3233

3334
### Dwelling read model
34-
GET http://localhost:8080/dwellings/{{dwellingId}}
35+
GET http://localhost:8080/games/{{gameId}}/dwellings/{{dwellingId}}
3536
Content-Type: application/json
3637

src/main/java/com/dddheroes/heroesofddd/creaturerecruitment/write/builddwelling/BuildDwellingRestApi.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package com.dddheroes.heroesofddd.creaturerecruitment.write.builddwelling;
22

3+
import com.dddheroes.heroesofddd.shared.GameMetaData;
34
import org.axonframework.commandhandling.gateway.CommandGateway;
45
import org.springframework.web.bind.annotation.PathVariable;
56
import org.springframework.web.bind.annotation.PutMapping;
67
import org.springframework.web.bind.annotation.RequestBody;
8+
import org.springframework.web.bind.annotation.RequestMapping;
79
import org.springframework.web.bind.annotation.RestController;
810

911
import java.util.Map;
1012
import java.util.concurrent.CompletableFuture;
1113

1214
@RestController
15+
@RequestMapping("games/{gameId}")
1316
class BuildDwellingRestApi {
1417

1518
record Body(String creatureId, Map<String, Integer> costPerTroop) {
@@ -24,6 +27,7 @@ record Body(String creatureId, Map<String, Integer> costPerTroop) {
2427

2528
@PutMapping("/dwellings/{dwellingId}")
2629
CompletableFuture<Void> putDwellings(
30+
@PathVariable String gameId,
2731
@PathVariable String dwellingId,
2832
@RequestBody Body requestBody
2933
) {
@@ -32,6 +36,6 @@ CompletableFuture<Void> putDwellings(
3236
requestBody.creatureId(),
3337
requestBody.costPerTroop()
3438
);
35-
return commandGateway.send(command);
39+
return commandGateway.send(command, GameMetaData.withId(gameId));
3640
}
3741
}

src/main/java/com/dddheroes/heroesofddd/creaturerecruitment/write/changeavailablecreatures/IncreaseAvailableCreaturesRestApi.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package com.dddheroes.heroesofddd.creaturerecruitment.write.changeavailablecreatures;
22

3-
import com.dddheroes.heroesofddd.creaturerecruitment.write.builddwelling.BuildDwelling;
3+
import com.dddheroes.heroesofddd.shared.GameMetaData;
44
import org.axonframework.commandhandling.gateway.CommandGateway;
55
import org.springframework.web.bind.annotation.PathVariable;
66
import org.springframework.web.bind.annotation.PutMapping;
77
import org.springframework.web.bind.annotation.RequestBody;
8+
import org.springframework.web.bind.annotation.RequestMapping;
89
import org.springframework.web.bind.annotation.RestController;
910

10-
import java.util.Map;
1111
import java.util.concurrent.CompletableFuture;
1212

1313
@RestController
14+
@RequestMapping("/games/{gameId}")
1415
class IncreaseAvailableCreaturesRestApi {
1516

1617
record Body(String creatureId, Integer increaseBy) {
@@ -25,6 +26,7 @@ record Body(String creatureId, Integer increaseBy) {
2526

2627
@PutMapping("/dwellings/{dwellingId}/available-creatures-increases")
2728
CompletableFuture<Void> putDwellingAvailableCreaturesIncreases(
29+
@PathVariable String gameId,
2830
@PathVariable String dwellingId,
2931
@RequestBody Body requestBody
3032
) {
@@ -33,6 +35,6 @@ CompletableFuture<Void> putDwellingAvailableCreaturesIncreases(
3335
requestBody.creatureId(),
3436
requestBody.increaseBy()
3537
);
36-
return commandGateway.send(command);
38+
return commandGateway.send(command, GameMetaData.withId(gameId));
3739
}
3840
}

0 commit comments

Comments
 (0)