Skip to content

Commit

Permalink
Closed #11, update puzzle stats after delver to attendee
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Dec 18, 2023
1 parent 6238cfd commit f86d079
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
23 changes: 22 additions & 1 deletion api/repository/puzzleStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,28 @@ export class D1PuzzleStatsRepository implements Repository<Stats> {
return new Stats(id, events)
}

async save(_stats: Stats): Promise<void> {
async save(stats: Stats): Promise<void> {
const stmt = this.db.prepare(
`INSERT INTO puzzle_stat_events (id, type, aggregate_id, version, payload, occurred_at) VALUES (?, ?, ?, ?, ?, ?)`
)

const pendingEventSize = stats.domainEvents.length
const versionStart = stats.version - pendingEventSize + 1
const events = stats.domainEvents.map((event, idx) => ({
id: event.id,
type: event.constructor.name,
aggregateId: event.aggregateId,
version: versionStart + idx,
payload: JSON.stringify(event),
occurredAt: event.occurredAt.toISOString(),
}))

await this.db.batch(
events.map(({ id, type, aggregateId, version, payload, occurredAt }) =>
stmt.bind(id, type, aggregateId, version, payload, occurredAt)
)
)

return
}

Expand Down
34 changes: 34 additions & 0 deletions features/puzzle_delivery.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,40 @@ Feature: Puzzle Delivery
}
"""
And the response status should be 200
Scenario: POST /event/puzzle/deliver will update puzzle stats
Given there have some booths
| token | name | event_id |
| 1024914b-ee65-4728-b687-8341f5affa89 | COSCUP | SITCON |
And event "SITCON" have a puzzle config
"""
{
"pieces": {
"=": 1
}
}
"""
And there have some attendees
| token | event_id | display_name |
| f185f505-d8c0-43ce-9e7b-bb9e8909072d | COSCUP2023 | Aotoki |
When I make a POST request to "/event/puzzle/deliver?token=1024914b-ee65-4728-b687-8341f5affa89&event_id=SITCON":
"""
{
"receiver": "f185f505-d8c0-43ce-9e7b-bb9e8909072d"
}
"""
And I make a GET request to "/event/puzzle/dashboard?event_id=SITCON"
Then the response json should be:
"""
[
{
"puzzle": "=", "quantity": 1, "currency": 1
},
{
"puzzle": "total", "quantity": 1, "currency": 1
}
]
"""
And the response status should be 200
Scenario: POST /event/puzzle/deliver with unpermitted booth token
Given there have some attendees
| token | event_id | display_name |
Expand Down

0 comments on commit f86d079

Please sign in to comment.