feat: redesign auction engine with redis sot
This commit is contained in:
1 parent
737702d78c
commit
e8bb20d988
75 files changed
+12737
-542
No files matched your search
@@ -20,7 +20,11 @@ import type { UserDocument } from '../global/database/schema';
|
||||
import { AuctionService } from './auction.service';
|
||||
import { AuctionGateway } from './auction.gateway';
|
||||
import {
|
||||
NextAuctionDto,
|
||||
OpenBiddingDto,
|
||||
PassedAuctionDto,
|
||||
PlaceBidDto,
|
||||
ResetAuctionDto,
|
||||
SoldDto,
|
||||
StartAuctionDto,
|
||||
UndoAuctionDto,
|
||||
@@ -47,18 +51,22 @@ export class AuctionController {
|
||||
return this.auctionService.start({
|
||||
matchId,
|
||||
communityId,
|
||||
startAuctionRequestId: body.startAuctionRequestId,
|
||||
actorUserId: currentUser._id,
|
||||
captains: body.captains.map((c) => ({
|
||||
teamIndex: c.teamIndex,
|
||||
userId: new mongoose.Types.ObjectId(c.userId),
|
||||
initialPoints: c.initialPoints,
|
||||
initialTeamBidPointAmount: c.initialTeamBidPointAmount,
|
||||
})),
|
||||
initialPoints: body.initialPoints ?? 1000,
|
||||
maxTimerSeconds: body.maxTimerSeconds ?? 30,
|
||||
bidExtensionSeconds: body.bidExtensionSeconds ?? 5,
|
||||
topTierThreshold: body.topTierThreshold ?? 'NONE',
|
||||
manualTopTierUserIds: (body.manualTopTierUserIds ?? []).map(
|
||||
(userId) => new mongoose.Types.ObjectId(userId),
|
||||
),
|
||||
initialTeamBidPointAmount: body.initialTeamBidPointAmount ?? 1000,
|
||||
maximumBidRoundDurationSeconds:
|
||||
body.maximumBidRoundDurationSeconds ?? 30,
|
||||
bidRoundExtensionSeconds: body.bidRoundExtensionSeconds ?? 5,
|
||||
topTierAuctionPriorityThreshold:
|
||||
body.topTierAuctionPriorityThreshold ?? 'NONE',
|
||||
manualTopTierAuctionPriorityUserIds: (
|
||||
body.manualTopTierAuctionPriorityUserIds ?? []
|
||||
).map((userId) => new mongoose.Types.ObjectId(userId)),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -67,7 +75,7 @@ export class AuctionController {
|
||||
public async getAuction(
|
||||
@Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId,
|
||||
) {
|
||||
return this.auctionService.getByMatchId(matchId);
|
||||
return this.auctionService.getStateByMatchId(matchId);
|
||||
}
|
||||
|
||||
// 공개 — 팀장 2명만 쓸 엔드포인트(트러스트 기반, 10명 동시 관전).
|
||||
@@ -76,23 +84,26 @@ export class AuctionController {
|
||||
@HttpCode(HttpStatus.OK)
|
||||
public async openBidding(
|
||||
@Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId,
|
||||
@Body() body: OpenBiddingDto = {},
|
||||
) {
|
||||
return this.auctionService.openBidding(matchId);
|
||||
return this.auctionService.openBidding(matchId, body);
|
||||
}
|
||||
|
||||
@Post('bids')
|
||||
@AllowPublicAccess()
|
||||
@HttpCode(HttpStatus.OK)
|
||||
public async placeBid(
|
||||
@CurrentUser() currentUser: UserDocument | undefined,
|
||||
@Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId,
|
||||
@Body() body: PlaceBidDto,
|
||||
) {
|
||||
return this.auctionService.placeBid({
|
||||
matchId,
|
||||
teamIndex: body.teamIndex,
|
||||
amount: body.amount,
|
||||
bidderUserId: this.resolveBidder(currentUser, body.bidderUserId),
|
||||
teamIndex: body.bidderTeamIndex,
|
||||
amount: body.bidPointAmount,
|
||||
bidRequestId: body.bidRequestId,
|
||||
clientObservedAuctionLifecycleId: body.clientObservedAuctionLifecycleId,
|
||||
clientObservedCurrentBidRoundPlayerUserId:
|
||||
body.clientObservedCurrentBidRoundPlayerUserId,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -106,16 +117,35 @@ export class AuctionController {
|
||||
return this.auctionService.markSold({
|
||||
matchId,
|
||||
assignedPosition: body.assignedPosition,
|
||||
auctionActionRequestId: body.auctionActionRequestId,
|
||||
clientObservedAuctionLifecycleId: body.clientObservedAuctionLifecycleId,
|
||||
clientObservedCurrentAuctionPlayerOrderIndex:
|
||||
body.clientObservedCurrentAuctionPlayerOrderIndex,
|
||||
clientObservedCurrentBidRoundPlayerUserId:
|
||||
body.clientObservedCurrentBidRoundPlayerUserId,
|
||||
clientObservedPhase: body.clientObservedPhase,
|
||||
clientObservedRevision: body.clientObservedRevision,
|
||||
});
|
||||
}
|
||||
|
||||
@Post('passed')
|
||||
@AllowPublicAccess()
|
||||
@HttpCode(HttpStatus.OK)
|
||||
public async markPassed(
|
||||
@Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId,
|
||||
@Body() body: PassedAuctionDto = {},
|
||||
) {
|
||||
return this.auctionService.markPassed(matchId, body);
|
||||
}
|
||||
|
||||
@Post('next')
|
||||
@AllowPublicAccess()
|
||||
@HttpCode(HttpStatus.OK)
|
||||
public async next(
|
||||
@Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId,
|
||||
@Body() body: NextAuctionDto = {},
|
||||
) {
|
||||
return this.auctionService.next(matchId);
|
||||
return this.auctionService.next(matchId, body);
|
||||
}
|
||||
|
||||
@Get('history')
|
||||
@@ -147,6 +177,14 @@ export class AuctionController {
|
||||
matchId,
|
||||
communityId,
|
||||
sequence: body.sequence,
|
||||
auctionActionRequestId: body.auctionActionRequestId,
|
||||
clientObservedAuctionLifecycleId: body.clientObservedAuctionLifecycleId,
|
||||
clientObservedCurrentAuctionPlayerOrderIndex:
|
||||
body.clientObservedCurrentAuctionPlayerOrderIndex,
|
||||
clientObservedCurrentBidRoundPlayerUserId:
|
||||
body.clientObservedCurrentBidRoundPlayerUserId,
|
||||
clientObservedPhase: body.clientObservedPhase,
|
||||
clientObservedRevision: body.clientObservedRevision,
|
||||
});
|
||||
this.auctionGateway.broadcastState(matchId.toString(), auction);
|
||||
return auction;
|
||||
@@ -161,24 +199,24 @@ export class AuctionController {
|
||||
@Param('communityId', ParseObjectIdPipe)
|
||||
communityId: mongoose.Types.ObjectId,
|
||||
@Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId,
|
||||
@Body() body: ResetAuctionDto = {},
|
||||
) {
|
||||
this.assertSameCommunity(currentUser, communityId);
|
||||
await this.auctionService.reset({ matchId, communityId });
|
||||
await this.auctionService.reset({
|
||||
matchId,
|
||||
communityId,
|
||||
auctionActionRequestId: body.auctionActionRequestId,
|
||||
clientObservedAuctionLifecycleId: body.clientObservedAuctionLifecycleId,
|
||||
clientObservedCurrentAuctionPlayerOrderIndex:
|
||||
body.clientObservedCurrentAuctionPlayerOrderIndex,
|
||||
clientObservedCurrentBidRoundPlayerUserId:
|
||||
body.clientObservedCurrentBidRoundPlayerUserId,
|
||||
clientObservedPhase: body.clientObservedPhase,
|
||||
clientObservedRevision: body.clientObservedRevision,
|
||||
});
|
||||
this.auctionGateway.broadcastReset(matchId.toString());
|
||||
}
|
||||
|
||||
private resolveBidder(
|
||||
currentUser: UserDocument | undefined,
|
||||
bodyBidder?: string,
|
||||
): mongoose.Types.ObjectId | undefined {
|
||||
if (currentUser) return currentUser._id;
|
||||
if (!bodyBidder) return undefined;
|
||||
if (!mongoose.isValidObjectId(bodyBidder)) {
|
||||
throw new BadRequestException('Invalid bidderUserId.');
|
||||
}
|
||||
return new mongoose.Types.ObjectId(bodyBidder);
|
||||
}
|
||||
|
||||
private assertSameCommunity(
|
||||
user: UserDocument,
|
||||
communityId: mongoose.Types.ObjectId,
|
||||
|
||||
Reference in new issue
Block a user