Skip to content

Commit 5fc4800

Browse files
committed
Add adminCourses to LoginUserResponse
Signed-off-by: loheagn <[email protected]>
1 parent 0cad494 commit 5fc4800

13 files changed

+50
-256
lines changed

openapi/cloudapi_v2.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3449,13 +3449,18 @@ components:
34493449
type: array
34503450
items:
34513451
type: string
3452+
adminCourses:
3453+
type: array
3454+
items:
3455+
$ref: '#/components/schemas/SimpleCourse'
34523456
required:
34533457
- userId
34543458
- username
34553459
- role
34563460
- isAssistant
34573461
- token
34583462
- paasToken
3463+
- adminCourses
34593464
ContainerServiceTemplate:
34603465
title: ContainerServiceTemplate
34613466
x-stoplight:
@@ -3560,6 +3565,20 @@ components:
35603565
- bucket
35613566
- key
35623567
- region
3568+
SimpleCourse:
3569+
title: SimpleCourse
3570+
x-stoplight:
3571+
id: 6d3ivgkgbf3rv
3572+
type: object
3573+
properties:
3574+
id:
3575+
type: integer
3576+
format: int32
3577+
name:
3578+
type: string
3579+
required:
3580+
- id
3581+
- name
35633582
securitySchemes:
35643583
Authorization:
35653584
type: apiKey

src/main/kotlin/cn/edu/buaa/scs/controller/models/ContainerRequest.kt

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/main/kotlin/cn/edu/buaa/scs/controller/models/ContainerServiceRequest.kt

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/main/kotlin/cn/edu/buaa/scs/controller/models/GetStatResourcePoolsResourcePoolIdUsed200Response.kt

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/main/kotlin/cn/edu/buaa/scs/controller/models/LoginUserResponse.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
package cn.edu.buaa.scs.controller.models
1313

14+
import cn.edu.buaa.scs.controller.models.SimpleCourse
1415

1516
/**
1617
*
@@ -20,6 +21,7 @@ package cn.edu.buaa.scs.controller.models
2021
* @param isAssistant
2122
* @param token
2223
* @param paasToken
24+
* @param adminCourses
2325
* @param projects
2426
*/
2527
data class LoginUserResponse(
@@ -29,6 +31,7 @@ data class LoginUserResponse(
2931
val isAssistant: kotlin.Boolean,
3032
val token: kotlin.String,
3133
val paasToken: kotlin.String,
34+
val adminCourses: kotlin.collections.List<SimpleCourse>,
3235
val projects: kotlin.collections.List<kotlin.String>? = null
3336
)
3437

src/main/kotlin/cn/edu/buaa/scs/controller/models/PostResourcePoolsRequest.kt

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/main/kotlin/cn/edu/buaa/scs/controller/models/ResourceExchangeRecord.kt

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/main/kotlin/cn/edu/buaa/scs/controller/models/ResourcePool.kt

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/main/kotlin/cn/edu/buaa/scs/controller/models/ResourceUsedRecord.kt

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/main/kotlin/cn/edu/buaa/scs/controller/models/ResourceUsedStatItem.kt

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/main/kotlin/cn/edu/buaa/scs/controller/models/Resource.kt renamed to src/main/kotlin/cn/edu/buaa/scs/controller/models/SimpleCourse.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ package cn.edu.buaa.scs.controller.models
1414

1515
/**
1616
*
17-
* @param cpu m, 1000m = 1core
18-
* @param memory MB
17+
* @param id
18+
* @param name
1919
*/
20-
data class Resource(
21-
/* m, 1000m = 1core */
22-
val cpu: kotlin.Int,
23-
/* MB */
24-
val memory: kotlin.Int
20+
data class SimpleCourse(
21+
val id: kotlin.Int,
22+
val name: kotlin.String
2523
)
2624

src/main/kotlin/cn/edu/buaa/scs/model/User.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,26 @@ interface User : Entity<User>, IEntity {
9191
return mysql.assistants.exists { (it.studentId eq this.id).and(it.courseId.inList(courseIdList)) }
9292
}
9393

94+
fun getAdminCourses(): List<Pair<Int, String>> {
95+
return when (this.role) {
96+
UserRole.STUDENT -> {
97+
mysql.assistants
98+
.filter { it.studentId.eq(this.id) }.map { it.courseId }
99+
.toList()
100+
.map { it.toInt() }
101+
.let { courseIdList ->
102+
if (courseIdList.isEmpty()) emptyList()
103+
else mysql.courses.filter { it.id.inList(courseIdList) }.map { it.id to it.name }.toList()
104+
}
105+
}
106+
107+
UserRole.SYS -> emptyList()
108+
UserRole.TEACHER -> {
109+
mysql.courses.filter { it.teacherId.eq(this.id) }.map { it.id to it.name }.toList()
110+
}
111+
}
112+
}
113+
94114
fun getAssistantCourseIdList(): List<Int> =
95115
mysql.assistants.filter { it.studentId eq this.id }.map { it.courseId.tryToInt() }.filterNotNull().distinct()
96116

@@ -176,4 +196,4 @@ object Users : Table<User>("user") {
176196
mysql.users.find { Users.id eq id }
177197
}
178198

179-
val Database.users get() = this.sequenceOf(Users)
199+
val Database.users get() = this.sequenceOf(Users)

src/main/kotlin/cn/edu/buaa/scs/service/Auth.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import cn.edu.buaa.scs.application
44
import cn.edu.buaa.scs.auth.generateRSAToken
55
import cn.edu.buaa.scs.cache.authRedis
66
import cn.edu.buaa.scs.controller.models.LoginUserResponse
7+
import cn.edu.buaa.scs.controller.models.SimpleCourse
78
import cn.edu.buaa.scs.model.*
89
import cn.edu.buaa.scs.storage.mysql
910
import cn.edu.buaa.scs.utils.*
@@ -119,6 +120,7 @@ class AuthService(val call: ApplicationCall) : IService {
119120
role = if (user.isStudent()) "student" else if (user.isTeacher()) "teacher" else "superAdmin",
120121
paasToken = user.paasToken,
121122
isAssistant = mysql.assistants.exists { it.studentId.eq(user.id) },
123+
adminCourses = user.getAdminCourses().map { SimpleCourse(it.first, it.second) }
122124
)
123125
}
124126

0 commit comments

Comments
 (0)