parent
42757aa7e8
commit
28afd457e9
|
@ -16,11 +16,14 @@ import org.apache.kafka.common.KafkaException
|
|||
import org.babyfish.jimmer.kt.new
|
||||
import org.springframework.kafka.core.KafkaTemplate
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.RequestBody
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import java.time.LocalDateTime
|
||||
import java.util.UUID
|
||||
|
||||
const val UPLOAD_FILE_TOPIC = "upload_file"
|
||||
|
||||
|
@ -32,6 +35,10 @@ class KnowledgeController(
|
|||
private val knowledgeFileAttributeRepository: KnowledgeFileAttributeRepository
|
||||
) {
|
||||
|
||||
@GetMapping("/{knowledgeId}")
|
||||
suspend fun getKnowledgeBrief(@PathVariable knowledgeId: UUID): Knowledge =
|
||||
knowledgeRepository.findNullable(knowledgeId, Knowledge.AS_PARENT_FETCHER) ?: throw BusinessError(ErrorCode.RESOURCE_NOT_FOUND)
|
||||
|
||||
@SaCheckRole("1")
|
||||
@Transactional(rollbackFor = [Throwable::class])
|
||||
@PostMapping("/file")
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package cn.edu.hfut.auto.knowledge.controller
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckRole
|
||||
import cn.edu.hfut.auto.knowledge.entity.Tag
|
||||
import cn.edu.hfut.auto.knowledge.repository.TagRepository
|
||||
import org.springframework.web.bind.annotation.*
|
||||
|
||||
@RequestMapping("/tag")
|
||||
@RestController
|
||||
class TagController(
|
||||
private val tagRepository: TagRepository
|
||||
) {
|
||||
@GetMapping
|
||||
suspend fun queryTags(name: String): List<Tag> = tagRepository.findTagsByNameStartsWith(name)
|
||||
|
||||
@SaCheckRole("1")
|
||||
@PutMapping
|
||||
suspend fun putTags(@RequestBody tags: List<Tag>) {
|
||||
val deleting = tagRepository.findAll()
|
||||
.toMutableSet()
|
||||
.apply {
|
||||
removeAll(tags.toSet())
|
||||
}
|
||||
tagRepository.deleteAll(deleting)
|
||||
tagRepository.saveAll(tags)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package cn.edu.hfut.auto.knowledge.controller
|
||||
|
||||
import cn.edu.hfut.auto.knowledge.entity.User
|
||||
import cn.edu.hfut.auto.knowledge.exception.BusinessError
|
||||
import cn.edu.hfut.auto.knowledge.exception.ErrorCode
|
||||
import cn.edu.hfut.auto.knowledge.repository.UserRepository
|
||||
import cn.edu.hfut.auto.knowledge.util.getLoginUser
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@RequestMapping("/user")
|
||||
@RestController
|
||||
class UserController(
|
||||
private val userRepository: UserRepository,
|
||||
private val objectMapper: ObjectMapper
|
||||
) {
|
||||
@GetMapping(path = ["", "/{userId}"])
|
||||
suspend fun getUserInformation(@PathVariable(required = false) userId: Long?): User =
|
||||
userRepository.findNullable(userId ?: getLoginUser(objectMapper).id, User.BRIEF_FETCHER)
|
||||
?: throw BusinessError(ErrorCode.RESOURCE_NOT_FOUND)
|
||||
|
||||
}
|
|
@ -28,12 +28,13 @@ interface Knowledge {
|
|||
companion object {
|
||||
val BRIEF_FETCHER = newFetcher(Knowledge::class).by {
|
||||
allScalarFields()
|
||||
knowledgeFileAttribute()
|
||||
knowledgeFileAttribute(KnowledgeFileAttribute.BRIEF_FETCHER)
|
||||
}
|
||||
val AS_PARENT_FETCHER = newFetcher(Knowledge::class).by {
|
||||
allScalarFields()
|
||||
parent()
|
||||
children(BRIEF_FETCHER)
|
||||
knowledgeFileAttribute()
|
||||
knowledgeFileAttribute(KnowledgeFileAttribute.BRIEF_FETCHER)
|
||||
}
|
||||
val AS_CHILD_FETCHER = newFetcher(Knowledge::class).by {
|
||||
allScalarFields()
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cn.edu.hfut.auto.knowledge.entity
|
||||
|
||||
import org.babyfish.jimmer.sql.*
|
||||
import org.babyfish.jimmer.sql.kt.fetcher.newFetcher
|
||||
import org.babyfish.jimmer.sql.meta.UUIDIdGenerator
|
||||
import java.util.*
|
||||
|
||||
|
@ -28,4 +29,13 @@ interface KnowledgeFileAttribute {
|
|||
|
||||
@ManyToMany(mappedBy = "knowledgeFiles")
|
||||
val notes: List<Note>
|
||||
|
||||
companion object {
|
||||
val BRIEF_FETCHER = newFetcher(KnowledgeFileAttribute::class).by {
|
||||
allScalarFields()
|
||||
tags {
|
||||
allScalarFields()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import org.babyfish.jimmer.sql.Entity
|
|||
import org.babyfish.jimmer.sql.GeneratedValue
|
||||
import org.babyfish.jimmer.sql.Id
|
||||
import org.babyfish.jimmer.sql.ManyToOne
|
||||
import org.babyfish.jimmer.sql.kt.fetcher.newFetcher
|
||||
import org.babyfish.jimmer.sql.meta.UUIDIdGenerator
|
||||
import java.time.LocalDateTime
|
||||
import java.util.*
|
||||
|
@ -15,10 +16,21 @@ interface Notice {
|
|||
val id: UUID
|
||||
val viewed: Boolean
|
||||
val createTime: LocalDateTime
|
||||
|
||||
@ManyToOne
|
||||
val note: Note
|
||||
|
||||
@ManyToOne
|
||||
val comment: Comment
|
||||
|
||||
@ManyToOne
|
||||
val targetUser: User
|
||||
|
||||
companion object {
|
||||
val BRIEF_FETCHER = newFetcher(Notice::class).by {
|
||||
allScalarFields()
|
||||
note { allScalarFields() }
|
||||
comment { allScalarFields() }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package cn.edu.hfut.auto.knowledge.entity
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import org.babyfish.jimmer.sql.*
|
||||
import org.babyfish.jimmer.sql.kt.fetcher.newFetcher
|
||||
|
||||
@Entity
|
||||
@Table(name = "t_user")
|
||||
|
@ -28,4 +29,12 @@ interface User {
|
|||
|
||||
@ManyToMany(mappedBy = "starers")
|
||||
val starredNotes: List<Note>
|
||||
|
||||
companion object {
|
||||
val BRIEF_FETCHER = newFetcher(User::class).by {
|
||||
allScalarFields()
|
||||
password(false)
|
||||
notices(Notice.BRIEF_FETCHER)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package cn.edu.hfut.auto.knowledge.repository
|
||||
|
||||
import cn.edu.hfut.auto.knowledge.entity.Tag
|
||||
import org.babyfish.jimmer.spring.repository.KRepository
|
||||
|
||||
interface TagRepository : KRepository<Tag, Long> {
|
||||
fun findTagsByNameStartsWith(name: String): List<Tag>
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package cn.edu.hfut.auto.knowledge.util
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil
|
||||
import cn.edu.hfut.auto.knowledge.entity.User
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.fasterxml.jackson.module.kotlin.readValue
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun getLoginUser(objectMapper: ObjectMapper): User =
|
||||
objectMapper.readValue<User>(StpUtil.getLoginId() as String)
|
Loading…
Reference in New Issue