From 40eda5477a7ac2ade3077f8905363b482c528917 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Tue, 7 Jun 2022 01:18:02 +0900 Subject: [PATCH] =?UTF-8?q?feat,wip:=20=EA=B2=BD=EB=A7=A4=EC=9E=A5=20API?= =?UTF-8?q?=20export?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/API/Auction/BidSellRiceAuction.php | 2 +- .../Auction/GetActiveResourceAuctionList.php | 36 +- .../Auction/GetUniqueItemAuctionDetail.php | 85 ++++ .../API/Auction/GetUniqueItemAuctionList.php | 90 ++++ hwe/sammo/API/Auction/OpenBuyRiceAuction.php | 2 +- hwe/sammo/API/Auction/OpenSellRiceAuction.php | 2 +- hwe/sammo/Auction.php | 6 +- hwe/sammo/DTO/AuctionInfo.php | 7 +- hwe/sammo/DTO/AuctionInfoDetail.php | 2 +- hwe/sql/schema.sql | 4 +- hwe/ts/SammoAPI.ts | 408 +++++++++++------- hwe/ts/defs/API/Auction.ts | 64 +++ 12 files changed, 525 insertions(+), 183 deletions(-) create mode 100644 hwe/sammo/API/Auction/GetUniqueItemAuctionDetail.php create mode 100644 hwe/sammo/API/Auction/GetUniqueItemAuctionList.php create mode 100644 hwe/ts/defs/API/Auction.ts diff --git a/hwe/sammo/API/Auction/BidSellRiceAuction.php b/hwe/sammo/API/Auction/BidSellRiceAuction.php index 3acb49fa..2448a08f 100644 --- a/hwe/sammo/API/Auction/BidSellRiceAuction.php +++ b/hwe/sammo/API/Auction/BidSellRiceAuction.php @@ -8,7 +8,7 @@ use sammo\AuctionSellRice; use sammo\Validator; use sammo\General; -class BidBuyRiceAuction extends \sammo\BaseAPI +class BidSellRiceAuction extends \sammo\BaseAPI { public function validateArgs(): ?string { diff --git a/hwe/sammo/API/Auction/GetActiveResourceAuctionList.php b/hwe/sammo/API/Auction/GetActiveResourceAuctionList.php index c7057341..b3608e14 100644 --- a/hwe/sammo/API/Auction/GetActiveResourceAuctionList.php +++ b/hwe/sammo/API/Auction/GetActiveResourceAuctionList.php @@ -7,6 +7,7 @@ use DateTimeInterface; use sammo\AuctionSellRice; use sammo\DB; use sammo\DTO\AuctionBidItem; +use sammo\DTO\AuctionInfo; use sammo\Enums\AuctionType; use sammo\Validator; use sammo\General; @@ -34,17 +35,18 @@ class GetActiveResourceAuctionList extends \sammo\BaseAPI $buyRiceList = []; $sellRiceList = []; - $rawAuctions = $db->query( + /** @var AuctionInfo[] */ + $auctions = array_map(fn ($raw) => AuctionInfo::fromArray($raw), $db->query( 'SELECT * FROM `ng_auction` WHERE `type` IN %ls AND `finished` != 0 ORDER BY `close_date` DESC', [ AuctionType::BuyRice->value, AuctionType::SellRice->value, ] - ); + )); $auctionIDList = []; - foreach ($rawAuctions as $rawAuction) { - $auctionIDList[] = $rawAuction['id']; + foreach ($auctions as $auction) { + $auctionIDList[] = $auction->id; } $rawHighestBids = Util::convertArrayToDict($db->query( @@ -64,17 +66,24 @@ class GetActiveResourceAuctionList extends \sammo\BaseAPI $rawHighestBids ); - foreach ($rawAuctions as $rawAuction) { - $detail = Json::decode($rawAuction['detail']); - unset($rawAuction['detail']); - $rawAuction = array_merge($rawAuction, $detail); + foreach ($auctions as $auction) { + $rawAuction = [ + 'id' => $auction->id, + 'type' => $auction->type->value, + 'hostGeneralID' => $auction->hostGeneralID, + 'hostName' => $auction->detail->hostName, + 'openDate' => TimeUtil::format($auction->openDate, false), + 'closeDate' => TimeUtil::format($auction->closeDate, false), + 'amount' => $auction->detail->amount, + 'startBidAmount' => $auction->detail->startBidAmount, + 'finishBidAmount' => $auction->detail->finishBidAmount, + ]; $highestBid = $highestBids[$rawAuction['id']] ?? null; - if($highestBid === null){ + if ($highestBid === null) { $rawAuction['highestBid'] = null; - } - else { - $rawAuction['hightestBid'] = [ + } else { + $rawAuction['highestBid'] = [ 'amount' => $highestBid->amount, 'date' => TimeUtil::format($highestBid->date, false), 'generalID' => $highestBid->generalID, @@ -95,7 +104,8 @@ class GetActiveResourceAuctionList extends \sammo\BaseAPI 'result' => true, 'buyRice' => $buyRiceList, 'sellRice' => $sellRiceList, - 'recentLogs' => $recentLogs + 'recentLogs' => $recentLogs, + 'generalID' => $session->generalID, ]; } } diff --git a/hwe/sammo/API/Auction/GetUniqueItemAuctionDetail.php b/hwe/sammo/API/Auction/GetUniqueItemAuctionDetail.php new file mode 100644 index 00000000..5428e62d --- /dev/null +++ b/hwe/sammo/API/Auction/GetUniqueItemAuctionDetail.php @@ -0,0 +1,85 @@ +args); + $v->rule('required', [ + 'auction_id', + ]) + ->rule('integer', 'auction_id'); + + if (!$v->validate()) { + return $v->errorStr(); + } + $this->args['auction_id'] = (int)$this->args['auction_id']; + return null; + } + + public function getRequiredSessionMode(): int + { + return static::REQ_GAME_LOGIN; + } + + public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag) + { + $db = DB::db(); + + $generalID = $session->generalID; + $auctionID = $this->args['auction_id']; + + $rawAuction = $db->queryFirstRow( + 'SELECT * FROM `ng_auction` WHERE `type` = %s AND `auction_id` = %s', + AuctionType::UniqueItem, + $auctionID + ); + + if (!$rawAuction) { + return '선택한 경매가 없습니다.'; + } + + $auction = AuctionInfo::fromArray($rawAuction); + + /** @var AuctionBidItem[] */ + $bidList = array_map(fn ($raw) => AuctionBidItem::fromArray($raw), $db->query( + 'SELECT * FROM `ng_auction_bid` WHERE `auction_id` = %s ORDER BY `amount` DESC', + $auctionID + ) ?? []); + + $responseBid = []; + foreach ($bidList as $bid) { + $responseBid[] = [ + 'generalName' => $bid->data->generalName, + 'amount' => $bid->amount, + 'isCallerHighestBidder' => $bid->generalID === $generalID, + 'date' => $bid->date, + ]; + } + + return [ + 'result' => true, + 'auction' => [ + 'id' => $auction->id, + 'finished' => $auction->finished, + 'title' => $auction->detail->title, + 'target' => $auction->target, + 'isCallerHost' => $auction->openerGeneralID === $generalID, + 'hostName' => $auction->detail->hostName, + 'remainCloseDateExtensionCnt' => $auction->detail->remainCloseDateExtensionCnt, + 'availableLatestBidCloseDate' => $auction->detail->availableLatestBidCloseDate, + ], + 'bidList' => $responseBid, + ]; + } +} diff --git a/hwe/sammo/API/Auction/GetUniqueItemAuctionList.php b/hwe/sammo/API/Auction/GetUniqueItemAuctionList.php new file mode 100644 index 00000000..47a3027d --- /dev/null +++ b/hwe/sammo/API/Auction/GetUniqueItemAuctionList.php @@ -0,0 +1,90 @@ +generalID; + + /** @var AuctionInfo[] */ + $auctions = array_map(fn($raw)=>AuctionInfo::fromArray($raw), $db->query( + 'SELECT * FROM `ng_auction` WHERE `type` = %s ORDER BY `close_date` DESC', + AuctionType::UniqueItem->value + ) ?? []); + + $auctionIDList = []; + foreach ($auctions as $auction) { + $auctionIDList[] = $auction->id; + } + + $rawHighestBids = Util::convertArrayToDict($db->query( + 'SELECT bid.* FROM `ng_auction_bid` bid INNER JOIN ( + SELECT `auction_id`, MAX(`amount`) as `max_amount` + FROM `ng_auction_bid` + WHERE `auction_id` IN %li + GROUP BY `auction_id` + ORDER BY `amount` + ) AS max_bid + ON bid.`auction_id` = max_bid.`auction_id` AND bid.`amount` = max_bid.`max_amount`', + $auctionIDList, + ) ?? [], 'auction_id'); + /** @var array */ + $highestBids = Util::mapWithKey( + fn ($auctionID, $bid) => AuctionBidItem::fromArray($bid), + $rawHighestBids + ); + + $response = []; + foreach ($auctions as $auction) { + $auctionID = $auction->id; + $highestBid = $highestBids[$auctionID] ?? null; + if($highestBid === null){ + continue; + } + + $response[] = [ + 'id' => $auctionID, + 'finished' => $auction->finished, + 'title' => $auction->detail->title, + 'target' => $auction->target, + 'isCallerHost' => $auction->openerGeneralID === $generalID, + 'hostName' => $auction->detail->hostName, + 'remainCloseDateExtensionCnt' => $auction->detail->remainCloseDateExtensionCnt, + 'availableLatestBidCloseDate' => $auction->detail->availableLatestBidCloseDate, + 'highestBid' => [ + 'generalName' => $highestBid->data->generalName, + 'amount' => $highestBid->amount, + 'isCallerHighestBidder' => $highestBid->generalID === $generalID, + 'date' => $highestBid->date, + ], + ]; + } + + return [ + 'result' => true, + 'list' => $response, + ]; + } +} diff --git a/hwe/sammo/API/Auction/OpenBuyRiceAuction.php b/hwe/sammo/API/Auction/OpenBuyRiceAuction.php index c51d128c..dc07a667 100644 --- a/hwe/sammo/API/Auction/OpenBuyRiceAuction.php +++ b/hwe/sammo/API/Auction/OpenBuyRiceAuction.php @@ -9,7 +9,7 @@ use sammo\Validator; use sammo\GameConst; use sammo\General; -class OpenUniqueAuction extends \sammo\BaseAPI +class OpenBuyRiceAuction extends \sammo\BaseAPI { public function validateArgs(): ?string { diff --git a/hwe/sammo/API/Auction/OpenSellRiceAuction.php b/hwe/sammo/API/Auction/OpenSellRiceAuction.php index deeabb44..c1092494 100644 --- a/hwe/sammo/API/Auction/OpenSellRiceAuction.php +++ b/hwe/sammo/API/Auction/OpenSellRiceAuction.php @@ -9,7 +9,7 @@ use sammo\Validator; use sammo\GameConst; use sammo\General; -class OpenUniqueAuction extends \sammo\BaseAPI +class OpenSellRiceAuction extends \sammo\BaseAPI { public function validateArgs(): ?string { diff --git a/hwe/sammo/Auction.php b/hwe/sammo/Auction.php index 94fdb3e7..be771268 100644 --- a/hwe/sammo/Auction.php +++ b/hwe/sammo/Auction.php @@ -111,7 +111,7 @@ abstract class Auction $this->info->closeDate = $date; $db = DB::db(); - $db->update('ng_auction', $this->info->toArrayExcept('id'), 'id = %i', $this->info->id); + $db->update('ng_auction', $this->info->toArray('id'), 'id = %i', $this->info->id); return null; } @@ -138,7 +138,7 @@ abstract class Auction $this->info->availableLatestBidCloseDate = $closeDate->add(TimeUtil::secondsToDateInterval( max(static::MIN_EXTENSION_MINUTES_PER_BID, $turnTerm * static::COEFF_EXTENSION_MINUTES_PER_BID) * 60 )); - $db->update('ng_auction', $this->info->toArrayExcept('id'), 'id = %i', $this->info->id); + $db->update('ng_auction', $this->info->toArray('id'), 'id = %i', $this->info->id); return null; } @@ -201,7 +201,7 @@ abstract class Auction $this->rollbackAuction(); } - $db->update('ng_auction', $this->info->toArrayExcept('id'), 'id = %i', $this->info->id); + $db->update('ng_auction', $this->info->toArray('id'), 'id = %i', $this->info->id); } private function bidInheritPoint(int $amount, \DateTimeImmutable $now, bool $tryExtendCloseDate): ?string diff --git a/hwe/sammo/DTO/AuctionInfo.php b/hwe/sammo/DTO/AuctionInfo.php index 3116680b..dc8a63f7 100644 --- a/hwe/sammo/DTO/AuctionInfo.php +++ b/hwe/sammo/DTO/AuctionInfo.php @@ -5,6 +5,7 @@ namespace sammo\DTO; use sammo\DTO\Attr\Convert; use sammo\DTO\Attr\JsonString; use sammo\DTO\Attr\NullIsUndefined; +use sammo\DTO\Attr\RawName; use sammo\DTO\Converter\DateTimeConverter; use sammo\Enums\AuctionType; use sammo\Enums\ResourceType; @@ -17,11 +18,15 @@ class AuctionInfo extends DTO public AuctionType $type, public bool $finished, public ?string $target, - public int $openerGeneralID, + #[RawName('host_general_id')] + public int $hostGeneralID, + #[RawName('reqResource')] public ResourceType $reqResource, + #[RawName('open_date')] #[Convert(DateTimeConverter::class)] public \DateTimeImmutable $openDate, + #[RawName('close_date')] #[Convert(DateTimeConverter::class)] public \DateTimeImmutable $closeDate, diff --git a/hwe/sammo/DTO/AuctionInfoDetail.php b/hwe/sammo/DTO/AuctionInfoDetail.php index d394fd76..e30726c2 100644 --- a/hwe/sammo/DTO/AuctionInfoDetail.php +++ b/hwe/sammo/DTO/AuctionInfoDetail.php @@ -10,7 +10,7 @@ class AuctionInfoDetail extends DTO { public function __construct( public string $title, - public string $openerName, + public string $hostName, public int $amount, #[NullIsUndefined] public ?bool $isReverse, diff --git a/hwe/sql/schema.sql b/hwe/sql/schema.sql index ef37427b..5e7746b1 100644 --- a/hwe/sql/schema.sql +++ b/hwe/sql/schema.sql @@ -696,14 +696,14 @@ CREATE TABLE `ng_auction` ( `type` ENUM('buyRice','sellRice','uniqueItem') NOT NULL COLLATE 'utf8mb4_bin', `finished` BIT(1) NOT NULL, `target` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_bin', - `opener_general_id` INT(11) NOT NULL, + `host_general_id` INT(11) NOT NULL, `req_resource` ENUM('gold','rice','inheritPoint') NOT NULL COLLATE 'utf8mb4_bin', `open_date` DATETIME NOT NULL, `close_date` DATETIME NOT NULL, `detail` LONGTEXT NOT NULL COLLATE 'utf8mb4_bin', PRIMARY KEY (`id`) USING BTREE, INDEX `by_close` (`finished`, `type`, `close_date`) USING BTREE, - INDEX `by_general_id` (`opener_general_id`, `type`, `finished`) USING BTREE, + INDEX `by_general_id` (`host_general_id`, `type`, `finished`) USING BTREE, CONSTRAINT `detail` CHECK (json_valid(`detail`)) ) COLLATE='utf8mb4_general_ci' diff --git a/hwe/ts/SammoAPI.ts b/hwe/ts/SammoAPI.ts index 041102cf..e60ddca0 100644 --- a/hwe/ts/SammoAPI.ts +++ b/hwe/ts/SammoAPI.ts @@ -1,7 +1,16 @@ import type { Args } from "./processing/args"; import { - callSammoAPI, extractHttpMethod, GET, PATCH, POST, PUT, - type APITail, type APICallT, type RawArgType, type ValidResponse, type InvalidResponse + callSammoAPI, + extractHttpMethod, + GET, + PATCH, + POST, + PUT, + type APITail, + type APICallT, + type RawArgType, + type ValidResponse, + type InvalidResponse, } from "./util/callSammoAPI"; export type { ValidResponse, InvalidResponse }; import { APIPathGen, NumVar, StrVar } from "./util/APIPathGen.js"; @@ -12,168 +21,247 @@ import type { inheritBuffType } from "./defs/API/InheritAction"; import type { SetBlockWarResponse, GeneralListResponse as NationGeneralListResponse } from "./defs/API/Nation"; import type { UploadImageResponse } from "./defs/API/Misc"; import type { GeneralLogType, GetGeneralLogResponse, JoinArgs } from "./defs/API/General"; -import type { GetConstResponse, GetCurrentHistoryResponse, GetDiplomacyResponse, GetHistoryResponse } from "./defs/API/Global"; +import type { + GetConstResponse, + GetCurrentHistoryResponse, + GetDiplomacyResponse, + GetHistoryResponse, +} from "./defs/API/Global"; import type { CachedMapResult, GeneralListResponse, ItemTypeKey, MapResult } from "./defs"; import type { VoteDetailResult, VoteListResult } from "./defs/API/Vote"; +import type { ActiveResourceAuctionList, OpenAuctionResponse, UniqueItemAuctionDetail, UniqueItemAuctionList } from "./defs/API/Auction"; const apiRealPath = { - Betting: { - Bet: PUT as APICallT<{ - bettingID: number, - bettingType: number[], - amount: number, - }>, - GetBettingDetail: NumVar('betting_id', - GET as APICallT - ), - GetBettingList: GET as APICallT<{ - req?: 'bettingNation' | 'tournament' - }, BettingListResponse>, - }, - Command: { - GetReservedCommand: GET as APICallT, - PushCommand: PUT as APICallT<{ - amount: number - }>, - RepeatCommand: PUT as APICallT<{ - amount: number - }>, - ReserveCommand: PUT as APICallT<{ - turnList: number[], - action: string, - arg?: Args - }, ReserveCommandResponse>, - ReserveBulkCommand: PUT as APICallT<{ - turnList: number[], - action: string, - arg?: Args - }[], ReserveBulkCommandResponse>, - }, - General: { - Join: POST as APICallT, - GetGeneralLog: GET as APICallT<{ - reqType: GeneralLogType, - reqTo?: number - }, GetGeneralLogResponse>, - DropItem: PUT as APICallT<{ - itemType: ItemTypeKey - }> - }, - Global: { - GeneralList: GET as APICallT, - GeneralListWithToken: GET as APICallT, - GetConst: GET as APICallT, - GetHistory: StrVar('serverID')( - NumVar('year', - NumVar('month', GET as APICallT - ))), - GetCurrentHistory: GET as APICallT, - GetMap: GET as APICallT<{ - neutralView?: 0 | 1, - showMe?: 0 | 1, - }, MapResult>, - GetCachedMap: GET as APICallT, - GetDiplomacy: GET as APICallT, - ExecuteEngine: POST as APICallT, - }, - InheritAction: { - BuyHiddenBuff: PUT as APICallT<{ - type: inheritBuffType, - level: number - }>, - BuyRandomUnique: PUT as APICallT, - BuySpecificUnique: PUT as APICallT<{ - item: string, - amount: number, - }>, - ResetSpecialWar: PUT as APICallT, - ResetTurnTime: PUT as APICallT, - SetNextSpecialWar: PUT as APICallT<{ - type: string, - }>, - }, - Misc: { - UploadImage: POST as APICallT<{ - imageData: string, - }, UploadImageResponse> - }, - NationCommand: { - GetReservedCommand: GET as APICallT, - PushCommand: PUT as APICallT<{ - amount: number - }>, - RepeatCommand: PUT as APICallT<{ - amount: number - }>, - ReserveCommand: PUT as APICallT<{ - turnList: number[], - action: string, - arg?: Args - }, ReserveCommandResponse>, - ReserveBulkCommand: PUT as APICallT<{ - turnList: number[], - action: string, - arg?: Args - }[], ReserveBulkCommandResponse>, - }, - Nation: { - GeneralList: GET as APICallT, - SetNotice: PUT as APICallT<{ - msg: string, - }>, - SetScoutMsg: PUT as APICallT<{ - msg: string, - }>, - SetBill: PATCH as APICallT<{ - amount: number, - }>, - SetRate: PATCH as APICallT<{ - amount: number, - }>, - SetSecretLimit: PATCH as APICallT<{ - amount: number, - }>, - SetBlockWar: PATCH as APICallT<{ - value: boolean, - }, SetBlockWarResponse>, - SetBlockScout: PATCH as APICallT<{ - value: boolean, - }>, - GetGeneralLog: GET as APICallT<{ - generalID: number, - reqType: GeneralLogType, - reqTo?: number - }, GetGeneralLogResponse> - }, - Vote: { - AddComment: POST as APICallT<{ - voteID: number, - text: string, - }>, - GetVoteList: GET as APICallT, - GetVoteDetail: GET as APICallT<{ - voteID: number - }, VoteDetailResult>, - NewVote: POST as APICallT<{ - title: string, - multipleOptions?: number, - endDate?: string, - options: string[], - keepOldVote?: boolean, - }>, - Vote: POST as APICallT<{ - voteID: number, - selection: number[], - }, ValidResponse & {wonLottery: boolean}>, - } + Auction: { + BidBuyRiceAuction: PUT as APICallT<{ + auctionID: number; + amount: number; + }>, + BidSellRiceAuction: PUT as APICallT<{ + auctionID: number; + amount: number; + }>, + GetActiveResourceAuctionList: GET as APICallT, + OpenBuyRiceAuction: POST as APICallT< + { + amount: number; + closeTurnCnt: number; + startBidAmount: number; + finishBidAmount: number; + }, + OpenAuctionResponse + >, + OpenSellRiceAuction: POST as APICallT< + { + amount: number; + closeTurnCnt: number; + startBidAmount: number; + finishBidAmount: number; + }, + OpenAuctionResponse + >, + + BidUniqueAuction: PUT as APICallT<{ + auctionID: number; + amount: number; + }>, + GetUniqueItemAuctionDetail: GET as APICallT<{ + auctionID: number; + }, UniqueItemAuctionDetail>, + GetUniqueItemAuctionList: GET as APICallT, + OpenUniqueAuction: POST as APICallT<{ + itemID: string, + amount: number, + }, OpenAuctionResponse>, + }, + Betting: { + Bet: PUT as APICallT<{ + bettingID: number; + bettingType: number[]; + amount: number; + }>, + GetBettingDetail: NumVar("betting_id", GET as APICallT), + GetBettingList: GET as APICallT< + { + req?: "bettingNation" | "tournament"; + }, + BettingListResponse + >, + }, + Command: { + GetReservedCommand: GET as APICallT, + PushCommand: PUT as APICallT<{ + amount: number; + }>, + RepeatCommand: PUT as APICallT<{ + amount: number; + }>, + ReserveCommand: PUT as APICallT< + { + turnList: number[]; + action: string; + arg?: Args; + }, + ReserveCommandResponse + >, + ReserveBulkCommand: PUT as APICallT< + { + turnList: number[]; + action: string; + arg?: Args; + }[], + ReserveBulkCommandResponse + >, + }, + General: { + Join: POST as APICallT, + GetGeneralLog: GET as APICallT< + { + reqType: GeneralLogType; + reqTo?: number; + }, + GetGeneralLogResponse + >, + DropItem: PUT as APICallT<{ + itemType: ItemTypeKey; + }>, + }, + Global: { + GeneralList: GET as APICallT, + GeneralListWithToken: GET as APICallT, + GetConst: GET as APICallT, + GetHistory: StrVar("serverID")(NumVar("year", NumVar("month", GET as APICallT))), + GetCurrentHistory: GET as APICallT, + GetMap: GET as APICallT< + { + neutralView?: 0 | 1; + showMe?: 0 | 1; + }, + MapResult + >, + GetCachedMap: GET as APICallT, + GetDiplomacy: GET as APICallT, + ExecuteEngine: POST as APICallT, + }, + InheritAction: { + BuyHiddenBuff: PUT as APICallT<{ + type: inheritBuffType; + level: number; + }>, + BuyRandomUnique: PUT as APICallT, + BuySpecificUnique: PUT as APICallT<{ + item: string; + amount: number; + }>, + ResetSpecialWar: PUT as APICallT, + ResetTurnTime: PUT as APICallT, + SetNextSpecialWar: PUT as APICallT<{ + type: string; + }>, + }, + Misc: { + UploadImage: POST as APICallT< + { + imageData: string; + }, + UploadImageResponse + >, + }, + NationCommand: { + GetReservedCommand: GET as APICallT, + PushCommand: PUT as APICallT<{ + amount: number; + }>, + RepeatCommand: PUT as APICallT<{ + amount: number; + }>, + ReserveCommand: PUT as APICallT< + { + turnList: number[]; + action: string; + arg?: Args; + }, + ReserveCommandResponse + >, + ReserveBulkCommand: PUT as APICallT< + { + turnList: number[]; + action: string; + arg?: Args; + }[], + ReserveBulkCommandResponse + >, + }, + Nation: { + GeneralList: GET as APICallT, + SetNotice: PUT as APICallT<{ + msg: string; + }>, + SetScoutMsg: PUT as APICallT<{ + msg: string; + }>, + SetBill: PATCH as APICallT<{ + amount: number; + }>, + SetRate: PATCH as APICallT<{ + amount: number; + }>, + SetSecretLimit: PATCH as APICallT<{ + amount: number; + }>, + SetBlockWar: PATCH as APICallT< + { + value: boolean; + }, + SetBlockWarResponse + >, + SetBlockScout: PATCH as APICallT<{ + value: boolean; + }>, + GetGeneralLog: GET as APICallT< + { + generalID: number; + reqType: GeneralLogType; + reqTo?: number; + }, + GetGeneralLogResponse + >, + }, + Vote: { + AddComment: POST as APICallT<{ + voteID: number; + text: string; + }>, + GetVoteList: GET as APICallT, + GetVoteDetail: GET as APICallT< + { + voteID: number; + }, + VoteDetailResult + >, + NewVote: POST as APICallT<{ + title: string; + multipleOptions?: number; + endDate?: string; + options: string[]; + keepOldVote?: boolean; + }>, + Vote: POST as APICallT< + { + voteID: number; + selection: number[]; + }, + ValidResponse & { wonLottery: boolean } + >, + }, } as const; export const SammoAPI = APIPathGen(apiRealPath, (path: string[], tail: APITail, pathParam) => { - const method = extractHttpMethod(tail); - return (args?: RawArgType, returnError?: boolean) => { - if (returnError) { - return callSammoAPI(method, path.join('/'), args, pathParam, true); - } - return callSammoAPI(method, path.join('/'), args, pathParam); - }; -}); \ No newline at end of file + const method = extractHttpMethod(tail); + return (args?: RawArgType, returnError?: boolean) => { + if (returnError) { + return callSammoAPI(method, path.join("/"), args, pathParam, true); + } + return callSammoAPI(method, path.join("/"), args, pathParam); + }; +}); diff --git a/hwe/ts/defs/API/Auction.ts b/hwe/ts/defs/API/Auction.ts new file mode 100644 index 00000000..5fcd792b --- /dev/null +++ b/hwe/ts/defs/API/Auction.ts @@ -0,0 +1,64 @@ +import type { ValidResponse } from "@/util/callSammoAPI"; + +export type BasicResourceAuctionBidder = { + amount: number; + date: string; + generalID: number; + generalName: string; +}; + +export type BasicResourceAuctionInfo = { + id: number; + type: "buyRice" | "sellRice"; + hostGeneralID: number; + hostName: string; + openDate: string; + closeDate: string; + amount: number; + startBidAmount: number; + finishBidAmount: number; + highestBid: BasicResourceAuctionBidder; +}; + +export type UniqueItemAuctionBidder = { + generalName: string; + amount: number; + isCallerHighestBidder: boolean; + date: string; +}; + +export type UniqueItemAuctionInfo = { + id: number; + finished: boolean; + title: string; + target: string; + isCallerHost: boolean; + hostName: string; + remainCloseDateExtensionCnt: number; + availableLatestBidCloseDate: string; +}; + +export type ActiveResourceAuctionList = ValidResponse & { + buyRice: BasicResourceAuctionInfo[]; + sellRice: BasicResourceAuctionInfo[]; + recentLogs: string[]; + generalID: number; +}; + +export type UniqueItemAuctionList = ValidResponse & { + list: ( + | UniqueItemAuctionInfo + | { + highestBid: UniqueItemAuctionBidder; + } + )[]; +}; + +export type UniqueItemAuctionDetail = ValidResponse & { + auction: UniqueItemAuctionInfo; + bidList: UniqueItemAuctionBidder[]; +} + +export type OpenAuctionResponse = ValidResponse & { + auctionID: number; +} \ No newline at end of file