some fix
parent
2319c09f71
commit
0bda997f99
|
|
@ -10,6 +10,6 @@ object Const {
|
|||
val msgNotFoundById = "根据id没有找到对应资源"
|
||||
val msgInsertUserFailed = "新增用户失败,请检查参数,或许已有相同用户存在"
|
||||
val msgUpdateUserFailed = "更新用户信息失败"
|
||||
val msgPasswdIsRequired = "密码不能为空"
|
||||
val msgInvalidParams = "参数错误"
|
||||
val msgOperationFailed = "操作失败"
|
||||
}
|
||||
|
|
@ -15,9 +15,9 @@ import util.responseSuccess
|
|||
class CrtlGroup : Controller() {
|
||||
private val service: Service = Service()
|
||||
|
||||
@GET("/{userId: [0-9]+}")
|
||||
@GET("/byUser/{userId: [0-9]+}")
|
||||
@Produces(Produces.JSON)
|
||||
fun getGroupByUser(@Param userId: Int): JSONResponse {
|
||||
fun getGroupByUser(@Param("userId") userId: Int): JSONResponse {
|
||||
val user = service.getUserById(userId)
|
||||
|
||||
return if (user == null) {
|
||||
|
|
@ -32,10 +32,21 @@ class CrtlGroup : Controller() {
|
|||
}
|
||||
}
|
||||
|
||||
@GET("/{id: [0-9]+}")
|
||||
@Produces(Produces.JSON)
|
||||
fun getGroupById(@Param("id") id:Int):JSONResponse {
|
||||
val group = service.getGroupById(id)
|
||||
return if (group == null) {
|
||||
responseNotFoundById()
|
||||
} else {
|
||||
return responseSuccess(group)
|
||||
}
|
||||
}
|
||||
|
||||
@POST("/")
|
||||
@Produces(Produces.JSON)
|
||||
fun addGroup(): JSONResponse {
|
||||
val group: ModelGroup? = request.createEntityFromBody(ModelGroup::class.java)
|
||||
val group: ModelGroup? = request.createEntityFromParameters(ModelGroup::class.java)
|
||||
if (group == null) {
|
||||
return responseInvalidParams()
|
||||
}
|
||||
|
|
@ -50,8 +61,8 @@ class CrtlGroup : Controller() {
|
|||
|
||||
@POST("/{groupId: [0-9]+}")
|
||||
@Produces(Produces.JSON)
|
||||
fun updateGroup(@Param groupId: Int): JSONResponse {
|
||||
val group: ModelGroup? = request.createEntityFromBody(ModelGroup::class.java)
|
||||
fun updateGroup(@Param("groupId") groupId: Int): JSONResponse {
|
||||
val group: ModelGroup? = request.createEntityFromParameters(ModelGroup::class.java)
|
||||
if (group == null) {
|
||||
return responseInvalidParams()
|
||||
}
|
||||
|
|
@ -66,7 +77,7 @@ class CrtlGroup : Controller() {
|
|||
|
||||
@POST("/del/{id: [0-9]+}")
|
||||
@Produces(Produces.JSON)
|
||||
fun delGroup(@Param id: Int): JSONResponse {
|
||||
fun delGroup(@Param("id") id: Int): JSONResponse {
|
||||
val group = service.getGroupById(id)
|
||||
|
||||
if (group == null) {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class CtrlMenu : Controller() {
|
|||
|
||||
@GET("/{id: [0-9]+}")
|
||||
@Produces(Produces.JSON)
|
||||
fun getMenuById(@Param id: Int): JSONResponse {
|
||||
fun getMenuById(@Param("id") id: Int): JSONResponse {
|
||||
val menu = service.getMenuById(id)
|
||||
if (menu == null) {
|
||||
return responseNotFoundById()
|
||||
|
|
@ -27,7 +27,7 @@ class CtrlMenu : Controller() {
|
|||
|
||||
@GET("/byRole/{roleId: [0-9]+}")
|
||||
@Produces(Produces.JSON)
|
||||
fun getMenuByRole(@Param roleId: Int): JSONResponse {
|
||||
fun getMenuByRole(@Param("roleId") roleId: Int): JSONResponse {
|
||||
val role = service.getRoleById(roleId)
|
||||
if (role == null) {
|
||||
return responseNotFoundById()
|
||||
|
|
@ -40,7 +40,7 @@ class CtrlMenu : Controller() {
|
|||
@POST("/")
|
||||
@Produces(Produces.JSON)
|
||||
fun addMenu(): JSONResponse {
|
||||
val menu: ModelMenu? = request.createEntityFromBody(ModelMenu::class.java)
|
||||
val menu: ModelMenu? = request.createEntityFromParameters(ModelMenu::class.java)
|
||||
if (menu == null) {
|
||||
return responseInvalidParams()
|
||||
}
|
||||
|
|
@ -55,7 +55,7 @@ class CtrlMenu : Controller() {
|
|||
|
||||
@POST("/{id: [0-9]+}")
|
||||
@Produces(Produces.JSON)
|
||||
fun updateMenu(@Param id: Int): JSONResponse {
|
||||
fun updateMenu(@Param("id") id: Int): JSONResponse {
|
||||
val menu: ModelMenu? = request.createEntityFromBody(ModelMenu::class.java)
|
||||
if (menu == null) {
|
||||
return responseInvalidParams()
|
||||
|
|
@ -71,7 +71,7 @@ class CtrlMenu : Controller() {
|
|||
|
||||
@POST("/del/{id: [0-9]+}")
|
||||
@Produces(Produces.JSON)
|
||||
fun deleteMenu(@Param id: Int): JSONResponse {
|
||||
fun deleteMenu(@Param("id") id: Int): JSONResponse {
|
||||
val menu = service.getMenuById(id)
|
||||
if (menu == null) {
|
||||
return responseNotFoundById()
|
||||
|
|
@ -87,7 +87,7 @@ class CtrlMenu : Controller() {
|
|||
|
||||
@POST("/bindPerm/{menuId: [0-9]+}/{permId: [0-9]+}")
|
||||
@Produces(Produces.JSON)
|
||||
fun bindMenuToPerm(@Param menuId: Int, @Param permId: Int): JSONResponse {
|
||||
fun bindMenuToPerm(@Param("menuId") menuId: Int, @Param("permId") permId: Int): JSONResponse {
|
||||
val menu = service.getMenuById(menuId)
|
||||
val perm = service.getPermById(permId)
|
||||
|
||||
|
|
@ -105,7 +105,7 @@ class CtrlMenu : Controller() {
|
|||
|
||||
@POST("/unbindPerm/{menuId: [0-9]+}/{permId: [0-9]+}")
|
||||
@Produces(Produces.JSON)
|
||||
fun unbindMenuToPerm(@Param menuId: Int, @Param permId: Int): JSONResponse {
|
||||
fun unbindMenuToPerm(@Param("menuId") menuId: Int, @Param("permId") permId: Int): JSONResponse {
|
||||
val menu = service.getMenuById(menuId)
|
||||
val perm = service.getPermById(permId)
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class CtrlPerm : Controller() {
|
|||
|
||||
@GET("/{id: [0-9]+}")
|
||||
@Produces(Produces.JSON)
|
||||
fun getPermById(@Param id: Int): JSONResponse {
|
||||
fun getPermById(@Param("id") id: Int): JSONResponse {
|
||||
val perm = service.getPermById(id)
|
||||
return if (perm == null) {
|
||||
responseNotFoundById()
|
||||
|
|
@ -27,7 +27,7 @@ class CtrlPerm : Controller() {
|
|||
|
||||
@POST("/byRole/{roleId: [0-9]+}")
|
||||
@Produces(Produces.JSON)
|
||||
fun getPermByRoleId(@Param roleId: Int): JSONResponse {
|
||||
fun getPermByRoleId(@Param("roleId") roleId: Int): JSONResponse {
|
||||
val role = service.getRoleById(roleId)
|
||||
if (role == null) {
|
||||
return responseNotFoundById()
|
||||
|
|
@ -56,7 +56,7 @@ class CtrlPerm : Controller() {
|
|||
@POST("/{id: [0-9]+}")
|
||||
@Produces(Produces.JSON)
|
||||
fun updatePerm(): JSONResponse {
|
||||
val perm: ModelPerm? = request.createEntityFromBody(ModelPerm::class.java)
|
||||
val perm: ModelPerm? = request.createEntityFromParameters(ModelPerm::class.java)
|
||||
if (perm == null) {
|
||||
return responseInvalidParams()
|
||||
}
|
||||
|
|
@ -71,7 +71,7 @@ class CtrlPerm : Controller() {
|
|||
|
||||
@POST("/del/{id: [0-9]+}")
|
||||
@Produces(Produces.JSON)
|
||||
fun deletePerm(@Param id: Int): JSONResponse {
|
||||
fun deletePerm(@Param("id") id: Int): JSONResponse {
|
||||
val perm = service.getPermById(id)
|
||||
if (perm == null) {
|
||||
return responseNotFoundById()
|
||||
|
|
@ -87,7 +87,7 @@ class CtrlPerm : Controller() {
|
|||
|
||||
@POST("/bindRole/{permId: [0-9]+}/{roleId: [0-9]+}")
|
||||
@Produces(Produces.JSON)
|
||||
fun bindPermToRole(@Param permId: Int,@Param roleId: Int): JSONResponse {
|
||||
fun bindPermToRole(@Param("permId") permId: Int, @Param("roleId") roleId: Int): JSONResponse {
|
||||
val perm = service.getPermById(permId)
|
||||
val role = service.getRoleById(roleId)
|
||||
|
||||
|
|
@ -105,7 +105,7 @@ class CtrlPerm : Controller() {
|
|||
|
||||
@POST("/unbindRole/{permId: [0-9]+}/{roleId: [0-9]+}")
|
||||
@Produces(Produces.JSON)
|
||||
fun unbindPermToRole(@Param permId: Int,@Param roleId: Int): JSONResponse {
|
||||
fun unbindPermToRole(@Param("permId") permId: Int, @Param("roleId") roleId: Int): JSONResponse {
|
||||
val perm = service.getPermById(permId)
|
||||
val role = service.getRoleById(roleId)
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class CtrlRole : Controller() {
|
|||
|
||||
@GET("/{id: [0-9]+}")
|
||||
@Produces(Produces.JSON)
|
||||
fun getRoleById(@Param id: Int): JSONResponse {
|
||||
fun getRoleById(@Param("id") id: Int): JSONResponse {
|
||||
val role = service.getRoleById(id)
|
||||
if (role == null) {
|
||||
return responseNotFoundById()
|
||||
|
|
@ -25,9 +25,9 @@ class CtrlRole : Controller() {
|
|||
return responseSuccess(role)
|
||||
}
|
||||
|
||||
@GET("/byUserId/{userId: [0-9]+}")
|
||||
@GET("/byUser/{userId: [0-9]+}")
|
||||
@Produces(Produces.JSON)
|
||||
fun getRoleByUserId(@Param userId: Int): JSONResponse {
|
||||
fun getRoleByUserId(@Param("userId") userId: Int): JSONResponse {
|
||||
val user = service.getUserById(userId)
|
||||
if (user == null) {
|
||||
return responseNotFoundById()
|
||||
|
|
@ -44,7 +44,7 @@ class CtrlRole : Controller() {
|
|||
@POST("/")
|
||||
@Produces(Produces.JSON)
|
||||
fun addRole(): JSONResponse {
|
||||
val role: ModelRole? = request.createEntityFromBody(ModelRole::class.java)
|
||||
val role: ModelRole? = request.createEntityFromParameters(ModelRole::class.java)
|
||||
if (role == null) {
|
||||
return responseInvalidParams()
|
||||
}
|
||||
|
|
@ -59,7 +59,7 @@ class CtrlRole : Controller() {
|
|||
|
||||
@POST("/del/{id: [0-9]+}")
|
||||
@Produces(Produces.JSON)
|
||||
fun delRole(@Param roleId: Int): JSONResponse {
|
||||
fun delRole(@Param("roleId") roleId: Int): JSONResponse {
|
||||
val role = service.getRoleById(roleId)
|
||||
if (role == null) {
|
||||
responseNotFoundById()
|
||||
|
|
|
|||
|
|
@ -55,10 +55,11 @@ class Service {
|
|||
|
||||
fun saveGroup(group: ModelGroup): Boolean {
|
||||
try {
|
||||
println(groupToInsertSQL(group))
|
||||
DBUtil.getConnection().createStatement()
|
||||
.execute(groupToInsertSQL(group))
|
||||
return true
|
||||
} catch (e: Exception) {
|
||||
} catch (e: Exception) { e.printStackTrace()
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
@ -174,8 +175,19 @@ class Service {
|
|||
}
|
||||
|
||||
fun getPermByRoleId(roleId: Int): List<ModelPerm> {
|
||||
//todo join
|
||||
throw NotImplementedException()
|
||||
val conn = DBUtil.getConnection()
|
||||
val rs = conn.createStatement()
|
||||
.executeQuery("""
|
||||
select * from perm t
|
||||
where exists(
|
||||
select * from mapping_perm_role m where m.roleid = $roleId
|
||||
)
|
||||
""".trim())
|
||||
val list = mutableListOf<ModelPerm>()
|
||||
while (rs.next()) {
|
||||
list.add(rsToPerm(rs))
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fun savePerm(perm: ModelPerm): Boolean {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package util
|
|||
|
||||
import config.Const
|
||||
import model.*
|
||||
import ro.pippo.core.Request
|
||||
import java.sql.ResultSet
|
||||
import java.sql.Timestamp
|
||||
import java.time.Instant
|
||||
|
|
@ -16,7 +15,7 @@ fun responseOperationFailed(): JSONResponse {
|
|||
}
|
||||
|
||||
fun responseInvalidParams(): JSONResponse {
|
||||
return JSONResponse(Const.codeInvalidParams, Const.msgPasswdIsRequired, null)
|
||||
return JSONResponse(Const.codeInvalidParams, Const.msgInvalidParams, null)
|
||||
}
|
||||
|
||||
fun responseSuccess(result: Any): JSONResponse {
|
||||
|
|
|
|||
Loading…
Reference in New Issue