增加社团信息查询接口

master
pan 4 years ago
parent 1bdf4a1ae2
commit e5e16b5247
  1. 13
      src/Controller.kt
  2. 24
      src/Service.kt
  3. 23
      src/Vo.kt
  4. 15
      test/ApplicationTest.kt

@ -261,6 +261,19 @@ fun Application.AssociationController() {
}
log.info("----end-----")
}
post("/load"){
log.info("社团id查询")
withToken<ShowAssociationVo>(call = call){
try {
call.respond(ApiResponse(message = "社团查询成功",body=AssociationService.load(vo=it)))
} catch (e: Exception) {
log.error(e)
call.respond(Simple.error("社团查询失败"))
}
}
log.info("----end-----")
}
}
}
}

@ -641,6 +641,30 @@ object AssociationService : AbstractService() {
}
}
}
private fun toAssociationVo(it: Association):AssociationVo{
return AssociationVo(id=it.id.value,name=it.name,desc = it.desc,
logo = it.logo.filepath,faculty = AssociationFaculty.valueOf(it.faculty),
level = it.level?.let { AssociationLevel.valueOf(it) })
}
fun load(vo:ShowAssociationVo): AssociationMainVo {
return transaction {
val associationVo= (Association.findById(vo.id)?:throw AssociationIdError(vo.id)).let {
AssociationVo(id=it.id.value,name=it.name,desc = it.desc,
logo = it.logo.filepath,faculty = AssociationFaculty.valueOf(it.faculty),
level = it.level?.let { AssociationLevel.valueOf(it) })}
val head=Users.innerJoin(AssociationMembers)
.slice(Users.columns)
.select { AssociationMembers.isHead eq true and (AssociationMembers.associationId eq vo.id) }
.firstOrNull()?.let {
UserInfoVo(name = it[Users.name],headImg = it[Users.imgId]?.let { ImageFile.findById(it)?:throw FileIdError(it.value) }?.filepath,
desc = it[Users.desc])
}?:throw IllegalArgumentException("无法找到社团[${vo.id}]")
AssociationMainVo(associationVo = associationVo,head = head)
}
}
}
/**

@ -154,17 +154,14 @@ data class NotificationDto(val receiverId:Int, val receiverClient:ClientType, ov
data class NotificationVo(val title:String,val content:String,val id:Int,val createTime: Long)
enum class ApplyStatus{
//已受理
Accept,
//已审核
Check
}
data class SearchAssociationVo(val name:String, val desc:String,
override val clientType: ClientType=ClientType.Foreground, override val token: Token
):ClientBaseVo()
data class ShowAssociationVo(val id: Int,
override val token: Token,
override val clientType: ClientType=ClientType.Foreground):ClientBaseVo()
/**
* 社团级别
*
@ -230,7 +227,17 @@ data class AssociationMemberVo(
val isHead:Boolean
)
//用户社团
/**
* 活动照片
*
* @property path
*/
data class AssociationActPhotoVo(val path:String)
data class AssociationMainVo(val associationVo: AssociationVo,val head: UserInfoVo,
val photos:List<AssociationActPhotoVo>?=null)
//前台社团注册资料
data class AssociationCheckVo(
override val id: Int,
override val name: String,

@ -10,8 +10,7 @@ import com.google.gson.Gson
import io.ktor.config.*
import io.ktor.http.*
import io.ktor.server.testing.*
import org.jetbrains.exposed.sql.alias
import org.jetbrains.exposed.sql.innerJoin
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction
import java.io.File
@ -115,12 +114,12 @@ class ApplicationTest {
fun testAudit(){
initApp {
transaction {
val nextAudit=AuditLeggings.alias("nextAudit")
Associations.innerJoin(otherTable = AuditLeggings).innerJoin(nextAudit,{AuditLeggings.nextAudit},{nextAudit[AuditLeggings.id]})
.slice(Associations.columns)
.select {
nextAudit[AuditLeggings.result] eq true
}.toList()
Users.innerJoin(AssociationMembers)
.slice(Users.columns)
.select { AssociationMembers.isHead eq true and (AssociationMembers.associationId eq 1) }
.firstOrNull()?.let {
println(it[Users.name])
}
}
}
}

Loading…
Cancel
Save