Skip to content

Commit

Permalink
feat:收藏项目接口新增 #1175 (#1176)
Browse files Browse the repository at this point in the history
* feat:收藏项目接口新增 #1175

* feat:收藏项目接口新增 #1175

* feat:收藏项目接口新增 #1175

* feat:收藏项目接口新增 #1175

* feat:收藏项目接口新增 #1175
  • Loading branch information
lannoy0523 authored Sep 21, 2023
1 parent 02b95e0 commit ad0ca30
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 29 deletions.
114 changes: 106 additions & 8 deletions docs/apidoc/node/favorites.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"repoName" : "generic-local",
"path" : "/123",
"userId" : "admin",
"createdDate" : "2020-07-27T16:02:31.394"
"createdDate" : "2020-07-27T16:02:31.394",
"type": "NODE"
}
]
},
Expand All @@ -93,22 +94,23 @@
- record字段说明


| 字段 | 类型 | 说明 | Description |
| ------------- | -------- | -------------- | ---------------------- |
| id | string | id | id |
| 字段 | 类型 | 说明 | Description |
| ------------- |--------|----------------------| ---------------------- |
| id | string | id | id |
| projectId | string | 节点所属项目 | node project id |
| repoName | string | 节点所属仓库 | node repository name |
| path | string | 目录完整路径 | node path |
| userId | string | 创建者 | userId |
| createdDate | string | 创建时间 | create time |
| userId | string | 创建者 | userId |
| createdDate | string | 创建时间 | create time |
| type | string | 类型 | data type |

## 删除收藏文件夹
## 删除收藏

- API: DELETE /repository/api/favorite/delete/{id}
- API 名称: delete favorite
- 功能说明:

- 中文:删除收藏文件夹
- 中文:删除收藏
- English:delete favorite
- 请求体
此接口请求体为空
Expand All @@ -128,3 +130,99 @@
"traceId": null
}
```
## 创建收藏文件夹

- API: POST /repository/api/favorite/create/project/{projectId}
- API 名称: create_favorite_project
- 功能说明:

- 中文:创建收藏项目
- English:create favorite project
- 请求体
```json
{
"projectId": "",
"repoName": "",
"path": ""
}
```
- 请求字段说明


| 字段 | 类型 | 是否必须 | 默认值 | 说明 | Description |
| ----------- | -------- | ---------- | -------- | ---------- | -------------- |
| projectId | string | 是 | 无 | 项目名称 | project name |
| repoName | string | 是 | 无 | 仓库名称 | repo name |
| path | string | 是 | 无 | 完整路径 | path |

- 响应体

```json
{
"code": 0,
"message": null,
"data": null,
"traceId": null
}
```
## 分页查询收藏项目

- API: POST /repository/api/favorite/page/project
- API 名称: favorite_project_page
- 功能说明:

- 中文:分页查询收藏项目
- English:list favorite project page
- 请求体

```json
{
"pageNumber": 1,
"pageSize": 20
}
```
- 请求字段说明


| 字段 | 类型 | 是否必须 | 默认值 | 说明 | Description |
| ------------ | -------- | ---------- | -------- | ---------- | -------------- |
| pageNumber | int | 否 | 1 | 当前页 | current page |
| pageSize | int | 否 | 20 | 分页大小 | page size |
- 响应体

```json
{
"code": 0,
"message": null,
"data": {
"pageNumber": 1,
"pageSize": 20,
"totalRecords": 1,
"totalPages": 1,
"records": [
{
"id" : "64e4634342ad44416be9f675",
"projectId" : "blueking",
"repoName" : "generic-local",
"path" : "/123",
"userId" : "admin",
"createdDate" : "2020-07-27T16:02:31.394",
"type": "PROJECT"
}
]
},
"traceId": null
}
```
- record字段说明


| 字段 | 类型 | 说明 | Description |
| ------------- |--------|----------------------| ---------------------- |
| id | string | id | id |
| projectId | string | 节点所属项目 | node project id |
| repoName | string | 节点所属仓库 | node repository name |
| path | string | 目录完整路径 | node path |
| userId | string | 创建者 | userId |
| createdDate | string | 创建时间 | create time |
| type | string | 类型 | data type |
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ data class FavoriteCreateRequset(
@ApiModelProperty("收藏用户")
val userId: String,
@ApiModelProperty("收藏时间")
val createdDate: LocalDateTime
val createdDate: LocalDateTime,
@ApiModelProperty("类型")
val type: String? = "NODE",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license.
*
* A copy of the MIT License is included in this file.
*
*
* Terms of the MIT License:
* ---------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.tencent.bkrepo.repository.pojo.favorite

import com.tencent.bkrepo.common.api.constant.DEFAULT_PAGE_NUMBER
import com.tencent.bkrepo.common.api.constant.DEFAULT_PAGE_SIZE

data class FavoriteProjectPageRequest(
var pageNumber: Int = DEFAULT_PAGE_NUMBER,
var pageSize: Int = DEFAULT_PAGE_SIZE
)
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
package com.tencent.bkrepo.repository.controller.user

import com.tencent.bkrepo.auth.pojo.enums.PermissionAction
import com.tencent.bkrepo.auth.pojo.enums.ResourceType
import com.tencent.bkrepo.common.api.constant.HttpStatus
import com.tencent.bkrepo.common.api.pojo.Page
import com.tencent.bkrepo.common.api.pojo.Response
Expand All @@ -40,8 +41,9 @@ import com.tencent.bkrepo.common.service.util.ResponseBuilder
import com.tencent.bkrepo.repository.model.TFavorites
import com.tencent.bkrepo.repository.pojo.favorite.FavoriteCreateRequset
import com.tencent.bkrepo.repository.pojo.favorite.FavoritePageRequest
import com.tencent.bkrepo.repository.pojo.favorite.FavoriteProjectPageRequest
import com.tencent.bkrepo.repository.pojo.favorite.FavoriteRequest
import com.tencent.bkrepo.repository.service.folder.FolderService
import com.tencent.bkrepo.repository.service.favorites.FavoriteService
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.springframework.web.bind.annotation.DeleteMapping
Expand All @@ -57,7 +59,7 @@ import java.time.LocalDateTime
@RestController
@RequestMapping("/api/favorite")
class FavoriteController(
private val folderService: FolderService,
private val favoriteService: FavoriteService,
private val permissionManager: PermissionManager
) {

Expand All @@ -76,20 +78,24 @@ class FavoriteController(
createdDate = LocalDateTime.now(),
userId = userId
)
folderService.createFavorite(createRequest)
favoriteService.createFavorite(createRequest)
return ResponseBuilder.success()
}
}

@ApiOperation("删除收藏文件夹")
@ApiOperation("删除收藏")
@DeleteMapping("/delete/{id}")
fun removeFavorite(
@RequestAttribute userId: String,
@PathVariable id:String
): Response<Void> {
folderService.getFavoriteById(id)?.let {
permissionManager.checkNodePermission(PermissionAction.VIEW, it.projectId, it.repoName, it.path)
folderService.removeFavorite(id)
favoriteService.getFavoriteById(id)?.let {
if (it.type == ResourceType.PROJECT.name) {
permissionManager.isAdminUser(userId)
} else {
permissionManager.checkNodePermission(PermissionAction.VIEW, it.projectId, it.repoName, it.path)
}
favoriteService.removeFavorite(id)
return ResponseBuilder.success()
}
return ResponseBuilder.fail(HttpStatus.BAD_REQUEST.value, "id not existed")
Expand All @@ -100,7 +106,35 @@ class FavoriteController(
fun pageFavorite(
@RequestBody favoritePageRequest: FavoritePageRequest
): Response<Page<TFavorites>> {
return ResponseBuilder.success(folderService.pageFavorite(favoritePageRequest))
return ResponseBuilder.success(favoriteService.pageFavorite(favoritePageRequest))
}

@ApiOperation("创建项目收藏")
@PostMapping( "/create/project")
fun mkProjectFavorite(
@RequestAttribute userId: String,
@RequestBody favoriteRequest: FavoriteRequest
): Response<Void> {
with(favoriteRequest) {
permissionManager.isAdminUser(userId)
val createRequest = FavoriteCreateRequset(
projectId = projectId,
repoName = repoName,
path = path,
createdDate = LocalDateTime.now(),
userId = userId,
type = ResourceType.PROJECT.name
)
favoriteService.createFavorite(createRequest)
return ResponseBuilder.success()
}
}

@ApiOperation("收藏项目分页查询")
@PostMapping("/page/project")
fun pageProjectFavorite(
@RequestBody favoriteProjectPageRequest: FavoriteProjectPageRequest
): Response<Page<TFavorites>> {
return ResponseBuilder.success(favoriteService.pageProjectFavorite(favoriteProjectPageRequest))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

package com.tencent.bkrepo.repository.model

import com.tencent.bkrepo.auth.pojo.enums.ResourceType
import org.springframework.data.mongodb.core.index.CompoundIndex
import org.springframework.data.mongodb.core.index.CompoundIndexes
import org.springframework.data.mongodb.core.mapping.Document
Expand All @@ -40,7 +41,7 @@ import java.time.LocalDateTime
@CompoundIndexes(
CompoundIndex(
name = "favorites_idx",
def = "{'userId': 1, 'repoName': 1, 'projectId': 1, 'path': 1}",
def = "{'userId': 1, 'projectId': 1,'repoName': 1, 'path': 1, 'type':1}",
background = true,
unique = true
)
Expand All @@ -51,5 +52,6 @@ data class TFavorites(
var projectId: String,
var repoName: String,
var path: String,
var createdDate: LocalDateTime
var createdDate: LocalDateTime,
var type: String? = ResourceType.NODE.name
)
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,23 @@
* SOFTWARE.
*/

package com.tencent.bkrepo.repository.service.folder
package com.tencent.bkrepo.repository.service.favorites

import com.tencent.bkrepo.common.api.pojo.Page
import com.tencent.bkrepo.repository.model.TFavorites
import com.tencent.bkrepo.repository.pojo.favorite.FavoriteCreateRequset
import com.tencent.bkrepo.repository.pojo.favorite.FavoritePageRequest
import com.tencent.bkrepo.repository.pojo.favorite.FavoriteProjectPageRequest

interface FolderService {
// 创建收藏文件夹
interface FavoriteService {
// 创建收藏
fun createFavorite(favoriteRequest: FavoriteCreateRequset)
// 删除收藏文件夹
// 删除收藏
fun removeFavorite(id: String)
// 获取列表
// 获取收藏文件列表
fun pageFavorite(favoritePageRequest: FavoritePageRequest): Page<TFavorites>
// 获取特定的收藏数据
fun getFavoriteById(id: String): TFavorites?
// 获取收藏项目
fun pageProjectFavorite(favoritePageRequest: FavoriteProjectPageRequest): Page<TFavorites>
}
Loading

0 comments on commit ad0ca30

Please sign in to comment.