package com.gyf.csams import io.ktor.application.* import io.ktor.request.* import io.ktor.response.* import io.ktor.routing.* fun Application.AccountController() { routing { route(path = "$ApiPathPrefix/account"){ route(path="/register") { /** * 检测学号是否已注册 */ get(path = "/checkId") { val studentId = call.request.queryParameters["studentId"] if (studentId?.isNotEmpty() == true) { if (Service.registered(studentId)) { call.respond(ApiResponse(code = 200, message = "学号已注册", body = true)) } else { call.respond(ApiResponse(code = 200, message = "学号可注册", body = false)) } } else { call.respond(Simple.error("学号检测失败,请联系管理员")) } } /** * 注册账号 */ post { val userVo = call.receive() val userResDto = Service.register(userVo) if (userResDto != null) { call.respond(ApiResponse(code = 200, message = "注册成功", userResDto)) } else { call.respond(ApiResponse(code = 400, message = "注册失败", body = null)) } } } } } }