Fix:3; Refactor:2; Feat3; Docs:1 #23
@@ -9,7 +9,9 @@ import top.fatweb.oxygen.api.entity.common.ResponseCode
|
||||
import top.fatweb.oxygen.api.entity.common.ResponseResult
|
||||
import top.fatweb.oxygen.api.entity.tool.ToolBase
|
||||
import top.fatweb.oxygen.api.param.PageSortParam
|
||||
import top.fatweb.oxygen.api.param.tool.*
|
||||
import top.fatweb.oxygen.api.param.tool.ToolCreateParam
|
||||
import top.fatweb.oxygen.api.param.tool.ToolUpdateParam
|
||||
import top.fatweb.oxygen.api.param.tool.ToolUpgradeParam
|
||||
import top.fatweb.oxygen.api.service.tool.IEditService
|
||||
import top.fatweb.oxygen.api.vo.PageVo
|
||||
import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo
|
||||
@@ -210,40 +212,4 @@ class EditController(
|
||||
fun delete(@PathVariable id: Long): ResponseResult<Nothing> =
|
||||
if (editService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
|
||||
else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED)
|
||||
|
||||
/**
|
||||
* Add favorite tool
|
||||
*
|
||||
* @param toolFavoriteAddParam Add favorite tool parameters
|
||||
* @return Response object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see ToolFavoriteAddParam
|
||||
* @see ResponseResult
|
||||
*/
|
||||
@Operation(summary = "收藏工具")
|
||||
@PostMapping("/favorite")
|
||||
fun addFavorite(@RequestBody toolFavoriteAddParam: ToolFavoriteAddParam): ResponseResult<Nothing> {
|
||||
editService.addFavorite(toolFavoriteAddParam)
|
||||
|
||||
return ResponseResult.databaseSuccess(ResponseCode.DATABASE_INSERT_SUCCESS)
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove favorite tool
|
||||
*
|
||||
* @param toolFavoriteRemoveParam Remove favorite tool parameters
|
||||
* @return Response object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see ToolFavoriteRemoveParam
|
||||
* @see ResponseResult
|
||||
*/
|
||||
@Operation(summary = "收藏工具")
|
||||
@DeleteMapping("/favorite")
|
||||
fun addFavorite(@RequestBody toolFavoriteRemoveParam: ToolFavoriteRemoveParam): ResponseResult<Nothing> {
|
||||
editService.removeFavorite(toolFavoriteRemoveParam)
|
||||
|
||||
return ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,14 @@ package top.fatweb.oxygen.api.controller.tool
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation
|
||||
import jakarta.validation.Valid
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import top.fatweb.oxygen.api.annotation.BaseController
|
||||
import top.fatweb.oxygen.api.annotation.Trim
|
||||
import top.fatweb.oxygen.api.entity.common.ResponseCode
|
||||
import top.fatweb.oxygen.api.entity.common.ResponseResult
|
||||
import top.fatweb.oxygen.api.param.PageSortParam
|
||||
import top.fatweb.oxygen.api.param.tool.ToolFavoriteAddParam
|
||||
import top.fatweb.oxygen.api.param.tool.ToolFavoriteRemoveParam
|
||||
import top.fatweb.oxygen.api.param.tool.ToolStoreGetParam
|
||||
import top.fatweb.oxygen.api.service.tool.IStoreService
|
||||
import top.fatweb.oxygen.api.vo.PageVo
|
||||
@@ -60,4 +62,40 @@ class StoreController(
|
||||
@GetMapping("/{username}")
|
||||
fun get(@PathVariable username: String, @Valid pageSortParam: PageSortParam): ResponseResult<PageVo<ToolVo>> =
|
||||
ResponseResult.databaseSuccess(data = storeService.getPage(pageSortParam, username.trim()))
|
||||
|
||||
/**
|
||||
* Add favorite tool
|
||||
*
|
||||
* @param toolFavoriteAddParam Add favorite tool parameters
|
||||
* @return Response object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see ToolFavoriteAddParam
|
||||
* @see ResponseResult
|
||||
*/
|
||||
@Operation(summary = "收藏工具")
|
||||
@PostMapping("/favorite")
|
||||
fun addFavorite(@RequestBody toolFavoriteAddParam: ToolFavoriteAddParam): ResponseResult<Nothing> {
|
||||
storeService.addFavorite(toolFavoriteAddParam)
|
||||
|
||||
return ResponseResult.databaseSuccess(ResponseCode.DATABASE_INSERT_SUCCESS)
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove favorite tool
|
||||
*
|
||||
* @param toolFavoriteRemoveParam Remove favorite tool parameters
|
||||
* @return Response object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see ToolFavoriteRemoveParam
|
||||
* @see ResponseResult
|
||||
*/
|
||||
@Operation(summary = "收藏工具")
|
||||
@DeleteMapping("/favorite")
|
||||
fun addFavorite(@RequestBody toolFavoriteRemoveParam: ToolFavoriteRemoveParam): ResponseResult<Nothing> {
|
||||
storeService.removeFavorite(toolFavoriteRemoveParam)
|
||||
|
||||
return ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.extension.service.IService
|
||||
import top.fatweb.oxygen.api.entity.tool.Tool
|
||||
import top.fatweb.oxygen.api.entity.tool.ToolBase
|
||||
import top.fatweb.oxygen.api.param.PageSortParam
|
||||
import top.fatweb.oxygen.api.param.tool.*
|
||||
import top.fatweb.oxygen.api.param.tool.ToolCreateParam
|
||||
import top.fatweb.oxygen.api.param.tool.ToolUpdateParam
|
||||
import top.fatweb.oxygen.api.param.tool.ToolUpgradeParam
|
||||
import top.fatweb.oxygen.api.vo.PageVo
|
||||
import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo
|
||||
import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo
|
||||
@@ -154,24 +156,4 @@ interface IEditService : IService<Tool> {
|
||||
* @since 1.0.0
|
||||
*/
|
||||
fun delete(id: Long): Boolean
|
||||
|
||||
/***
|
||||
* Add favorite
|
||||
*
|
||||
* @param toolFavoriteAddParam Add favorite tool parameters
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see ToolFavoriteAddParam
|
||||
*/
|
||||
fun addFavorite(toolFavoriteAddParam: ToolFavoriteAddParam)
|
||||
|
||||
/***
|
||||
* Remove favorite tool
|
||||
*
|
||||
* @param toolFavoriteRemoveParam Remove favorite tool parameters
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see ToolFavoriteRemoveParam
|
||||
*/
|
||||
fun removeFavorite(toolFavoriteRemoveParam: ToolFavoriteRemoveParam)
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package top.fatweb.oxygen.api.service.tool
|
||||
import com.baomidou.mybatisplus.extension.service.IService
|
||||
import top.fatweb.oxygen.api.entity.tool.Tool
|
||||
import top.fatweb.oxygen.api.param.PageSortParam
|
||||
import top.fatweb.oxygen.api.param.tool.ToolFavoriteAddParam
|
||||
import top.fatweb.oxygen.api.param.tool.ToolFavoriteRemoveParam
|
||||
import top.fatweb.oxygen.api.param.tool.ToolStoreGetParam
|
||||
import top.fatweb.oxygen.api.vo.PageVo
|
||||
import top.fatweb.oxygen.api.vo.tool.ToolVo
|
||||
@@ -42,4 +44,24 @@ interface IStoreService : IService<Tool> {
|
||||
* @see ToolVo
|
||||
*/
|
||||
fun getPage(pageSortParam: PageSortParam, username: String): PageVo<ToolVo>
|
||||
|
||||
/***
|
||||
* Add favorite
|
||||
*
|
||||
* @param toolFavoriteAddParam Add favorite tool parameters
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see ToolFavoriteAddParam
|
||||
*/
|
||||
fun addFavorite(toolFavoriteAddParam: ToolFavoriteAddParam)
|
||||
|
||||
/***
|
||||
* Remove favorite tool
|
||||
*
|
||||
* @param toolFavoriteRemoveParam Remove favorite tool parameters
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see ToolFavoriteRemoveParam
|
||||
*/
|
||||
fun removeFavorite(toolFavoriteRemoveParam: ToolFavoriteRemoveParam)
|
||||
}
|
||||
@@ -14,7 +14,9 @@ import top.fatweb.oxygen.api.entity.tool.*
|
||||
import top.fatweb.oxygen.api.exception.*
|
||||
import top.fatweb.oxygen.api.mapper.tool.EditMapper
|
||||
import top.fatweb.oxygen.api.param.PageSortParam
|
||||
import top.fatweb.oxygen.api.param.tool.*
|
||||
import top.fatweb.oxygen.api.param.tool.ToolCreateParam
|
||||
import top.fatweb.oxygen.api.param.tool.ToolUpdateParam
|
||||
import top.fatweb.oxygen.api.param.tool.ToolUpgradeParam
|
||||
import top.fatweb.oxygen.api.service.tool.*
|
||||
import top.fatweb.oxygen.api.util.WebUtil
|
||||
import top.fatweb.oxygen.api.vo.PageVo
|
||||
@@ -37,8 +39,7 @@ class EditServiceImpl(
|
||||
private val toolTemplateService: IToolTemplateService,
|
||||
private val toolCategoryService: IToolCategoryService,
|
||||
private val toolDataService: IToolDataService,
|
||||
private val rToolCategoryService: IRToolCategoryService,
|
||||
private val toolFavoriteService: IToolFavoriteService
|
||||
private val rToolCategoryService: IRToolCategoryService
|
||||
) : ServiceImpl<EditMapper, Tool>(), IEditService {
|
||||
override fun getTemplate(platform: ToolBase.Platform): List<ToolTemplateVo> =
|
||||
toolTemplateService.list(
|
||||
@@ -270,48 +271,4 @@ class EditServiceImpl(
|
||||
rToolCategoryService.remove(KtQueryWrapper(RToolCategory()).eq(RToolCategory::toolId, tool.id))
|
||||
return this.removeById(id)
|
||||
}
|
||||
|
||||
@Transactional
|
||||
override fun addFavorite(toolFavoriteAddParam: ToolFavoriteAddParam) {
|
||||
if (toolFavoriteService.exists(
|
||||
KtQueryWrapper(ToolFavorite())
|
||||
.eq(ToolFavorite::userId, WebUtil.getLoginUserId())
|
||||
.eq(ToolFavorite::username, toolFavoriteAddParam.username)
|
||||
.eq(ToolFavorite::toolId, toolFavoriteAddParam.toolId)
|
||||
.eq(ToolFavorite::platform, toolFavoriteAddParam.platform)
|
||||
)
|
||||
) {
|
||||
throw RecordAlreadyExists()
|
||||
}
|
||||
|
||||
this.detail(
|
||||
toolFavoriteAddParam.username!!,
|
||||
toolFavoriteAddParam.toolId!!,
|
||||
"latest",
|
||||
toolFavoriteAddParam.platform!!
|
||||
)
|
||||
|
||||
toolFavoriteService.save(
|
||||
ToolFavorite().apply {
|
||||
userId = WebUtil.getLoginUserId()
|
||||
username = toolFavoriteAddParam.username
|
||||
toolId = toolFavoriteAddParam.toolId
|
||||
platform = toolFavoriteAddParam.platform
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Transactional
|
||||
override fun removeFavorite(toolFavoriteRemoveParam: ToolFavoriteRemoveParam) {
|
||||
if (!toolFavoriteService.remove(
|
||||
KtQueryWrapper(ToolFavorite())
|
||||
.eq(ToolFavorite::userId, WebUtil.getLoginUserId())
|
||||
.eq(ToolFavorite::username, toolFavoriteRemoveParam.username)
|
||||
.eq(ToolFavorite::toolId, toolFavoriteRemoveParam.toolId)
|
||||
.eq(ToolFavorite::platform, toolFavoriteRemoveParam.platform)
|
||||
)
|
||||
) {
|
||||
throw NoRecordFoundException()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,23 @@
|
||||
package top.fatweb.oxygen.api.service.tool.impl
|
||||
|
||||
import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import top.fatweb.oxygen.api.converter.tool.ToolConverter
|
||||
import top.fatweb.oxygen.api.entity.tool.Tool
|
||||
import top.fatweb.oxygen.api.entity.tool.ToolFavorite
|
||||
import top.fatweb.oxygen.api.exception.NoRecordFoundException
|
||||
import top.fatweb.oxygen.api.exception.RecordAlreadyExists
|
||||
import top.fatweb.oxygen.api.mapper.tool.StoreMapper
|
||||
import top.fatweb.oxygen.api.param.PageSortParam
|
||||
import top.fatweb.oxygen.api.param.tool.ToolFavoriteAddParam
|
||||
import top.fatweb.oxygen.api.param.tool.ToolFavoriteRemoveParam
|
||||
import top.fatweb.oxygen.api.param.tool.ToolStoreGetParam
|
||||
import top.fatweb.oxygen.api.service.tool.IEditService
|
||||
import top.fatweb.oxygen.api.service.tool.IStoreService
|
||||
import top.fatweb.oxygen.api.service.tool.IToolFavoriteService
|
||||
import top.fatweb.oxygen.api.util.WebUtil
|
||||
import top.fatweb.oxygen.api.vo.PageVo
|
||||
import top.fatweb.oxygen.api.vo.tool.ToolVo
|
||||
@@ -24,7 +33,10 @@ import top.fatweb.oxygen.api.vo.tool.ToolVo
|
||||
* @see IStoreService
|
||||
*/
|
||||
@Service
|
||||
class StoreServiceImpl : ServiceImpl<StoreMapper, Tool>(), IStoreService {
|
||||
class StoreServiceImpl(
|
||||
private val editService: IEditService,
|
||||
private val toolFavoriteService: IToolFavoriteService
|
||||
) : ServiceImpl<StoreMapper, Tool>(), IStoreService {
|
||||
override fun getPage(toolStoreGetParam: ToolStoreGetParam): PageVo<ToolVo> {
|
||||
val toolIdsPage = Page<Long>(toolStoreGetParam.currentPage, 20)
|
||||
toolIdsPage.setOptimizeCountSql(false)
|
||||
@@ -50,4 +62,48 @@ class StoreServiceImpl : ServiceImpl<StoreMapper, Tool>(), IStoreService {
|
||||
|
||||
return ToolConverter.toolPageToToolPageVo(toolPage)
|
||||
}
|
||||
|
||||
@Transactional
|
||||
override fun addFavorite(toolFavoriteAddParam: ToolFavoriteAddParam) {
|
||||
if (toolFavoriteService.exists(
|
||||
KtQueryWrapper(ToolFavorite())
|
||||
.eq(ToolFavorite::userId, WebUtil.getLoginUserId())
|
||||
.eq(ToolFavorite::username, toolFavoriteAddParam.username)
|
||||
.eq(ToolFavorite::toolId, toolFavoriteAddParam.toolId)
|
||||
.eq(ToolFavorite::platform, toolFavoriteAddParam.platform)
|
||||
)
|
||||
) {
|
||||
throw RecordAlreadyExists()
|
||||
}
|
||||
|
||||
editService.detail(
|
||||
toolFavoriteAddParam.username!!,
|
||||
toolFavoriteAddParam.toolId!!,
|
||||
"latest",
|
||||
toolFavoriteAddParam.platform!!
|
||||
)
|
||||
|
||||
toolFavoriteService.save(
|
||||
ToolFavorite().apply {
|
||||
userId = WebUtil.getLoginUserId()
|
||||
username = toolFavoriteAddParam.username
|
||||
toolId = toolFavoriteAddParam.toolId
|
||||
platform = toolFavoriteAddParam.platform
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Transactional
|
||||
override fun removeFavorite(toolFavoriteRemoveParam: ToolFavoriteRemoveParam) {
|
||||
if (!toolFavoriteService.remove(
|
||||
KtQueryWrapper(ToolFavorite())
|
||||
.eq(ToolFavorite::userId, WebUtil.getLoginUserId())
|
||||
.eq(ToolFavorite::username, toolFavoriteRemoveParam.username)
|
||||
.eq(ToolFavorite::toolId, toolFavoriteRemoveParam.toolId)
|
||||
.eq(ToolFavorite::platform, toolFavoriteRemoveParam.platform)
|
||||
)
|
||||
) {
|
||||
throw NoRecordFoundException()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user