Skip to content

Commit

Permalink
Fix serialize bug in create user, and add delete user feature. (#66)
Browse files Browse the repository at this point in the history
* Fix serialize bug in create user, and add delete user feature.

* Fix serialize bug in create user, and add delete user feature.
  • Loading branch information
h56983577 authored Dec 10, 2024
1 parent 3697fea commit c39aebd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
7 changes: 6 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ application {
}

repositories {
maven(url = "https://maven.aliyun.com/repository/public/")
maven(url = "https://maven.aliyun.com/repository/google/")
maven(url = "https://maven.aliyun.com/repository/gradle-plugin/")
maven(url = "https://maven.aliyun.com/repository/jcenter/")
maven(url = "https://maven.aliyun.com/nexus/content/groups/public/")
mavenCentral()
maven(url = "https://jitpack.io")
maven(url = "https://www.jitpack.io")
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,8 @@ data class CreateUserRequest(
/* 所在单位 */
val departmentId: kotlin.Int,
/* 1 for student, 2 for teacher, 4 for admin */
val role: CreateUserRequest.Role,
val role: kotlin.Int,
/* 姓名 */
val name: kotlin.String? = null
)
{
/**
* 1 for student, 2 for teacher, 4 for admin
* Values: _1,_2,_4
*/
enum class Role(val value: kotlin.Int){
_1(1),
_2(2),
_4(4);
}
}

13 changes: 9 additions & 4 deletions cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/route/Admin.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package cn.edu.buaa.scs.route

import cn.edu.buaa.scs.controller.models.CreateUserRequest
import cn.edu.buaa.scs.model.Authentication
import cn.edu.buaa.scs.controller.models.DeleteAdminUserRequest
import cn.edu.buaa.scs.model.UserRole
import cn.edu.buaa.scs.service.admin
import cn.edu.buaa.scs.utils.token
import cn.edu.buaa.scs.utils.user
import io.ktor.server.application.*
import io.ktor.server.request.*
import io.ktor.server.response.*
Expand All @@ -16,11 +14,18 @@ fun Route.adminRoute() {
route("/user") {
post {
val req = call.receive<CreateUserRequest>()
val role = UserRole.fromLevel(req.role.value)
val role = UserRole.fromLevel(req.role)
val name = req.name
val departmentId = req.departmentId
call.respond(convertUserModel(call.admin.addUser(req.id, name, role, departmentId)))
}

delete {
val req = call.receive<DeleteAdminUserRequest>()
val userIds = req.userIds
call.admin.deleteUsers(userIds)
call.respond("OK")
}
}
}
}
11 changes: 11 additions & 0 deletions cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/Admin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ package cn.edu.buaa.scs.service
import cn.edu.buaa.scs.error.AuthorizationException
import cn.edu.buaa.scs.model.User
import cn.edu.buaa.scs.model.UserRole
import cn.edu.buaa.scs.model.Users
import cn.edu.buaa.scs.model.users
import cn.edu.buaa.scs.utils.user
import io.ktor.server.application.*
import cn.edu.buaa.scs.storage.mysql
import org.ktorm.dsl.delete
import org.ktorm.dsl.inList

val ApplicationCall.admin: AdminService
get() = AdminService.getSvc(this) { AdminService(this) }
Expand All @@ -19,4 +24,10 @@ class AdminService(val call: ApplicationCall) : IService {

return User.createNewUnActiveUser(id, name, role, departmentId)
}

fun deleteUsers(userIds: List<String>) {
mysql.delete(Users) {
it.id inList userIds
}
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-7.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit c39aebd

Please sign in to comment.