import Vapor import Fluent import SwiftMsgpack import JWT struct ToolController: RouteCollection { func boot(routes: any RoutesBuilder) throws { let group = routes.grouped("tool") group.post("signup", use: self.signup) } @Sendable func signup(req: Request) async throws -> Response { let body = try req.content.decode(SignupReq.self, using: MsgPackDecoder()) guard let session = try await Session.query(on: req.db).filter(\.$id == body.access_token).first(), session.type == SessionType.ZAT else { throw Abort(.forbidden, reason: "Invalid access token") } let accountId = session.$account.id if let player = try await Player.query(on: req.db).filter(\.$account.$id == accountId).first() { } else { guard let account = try await Account.query(on: req.db).filter(\.$id == accountId).first() else { throw Abort(.forbidden, reason: "Account ID does not exist") } // Create new Player let player = try Player.createDefault(account: account) try await player.save(on: req.db) } throw Abort(.notImplemented) } } struct SignupReq: Content { let app_secret: String let access_token: String let storage_directory_path: String let app_admin: String let kakao_pid: String let device_id: Double let idp_code: String }