forked from TencentBlueKing/bk-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:新增文件夹收藏相关接口 TencentBlueKing#1082 (TencentBlueKing#1083)
* feat:新增文件夹收藏相关接口 TencentBlueKing#1082 * feat:新增文件夹收藏相关接口 TencentBlueKing#1082 * feat:新增文件夹收藏相关接口 TencentBlueKing#1012 * feat:新增文件夹收藏相关接口文档 TencentBlueKing#1082
- Loading branch information
1 parent
7a3ca2d
commit 2cb50a0
Showing
11 changed files
with
636 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# 收藏文件夹相关接口 | ||
|
||
[toc] | ||
|
||
## 创建收藏文件夹 | ||
|
||
- API: POST /repository/api/favorite/create | ||
- API 名称: create_favorite | ||
- 功能说明: | ||
|
||
- 中文:创建收藏文件夹 | ||
- English:create favorite folder | ||
- 请求体 | ||
|
||
```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 | ||
- API 名称: favorite_page | ||
- 功能说明: | ||
|
||
- 中文:分页查询收藏文件夹 | ||
- English:list favorite page | ||
- 请求体 | ||
|
||
```json | ||
{ | ||
"projectId": "", | ||
"repoName": "", | ||
"pageNumber": 1, | ||
"pageSize": 20 | ||
} | ||
``` | ||
- 请求字段说明 | ||
|
||
|
||
| 字段 | 类型 | 是否必须 | 默认值 | 说明 | Description | | ||
| ------------ | -------- | ---------- | -------- | ---------- | -------------- | | ||
| projectId | string | 否 | 无 | 项目名称 | project name | | ||
| repoName | string | 否 | 无 | 仓库名称 | repo name | | ||
| 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" | ||
} | ||
] | ||
}, | ||
"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 | | ||
|
||
## 删除收藏文件夹 | ||
|
||
- API: DELETE /repository/api/favorite/delete/{id} | ||
- API 名称: delete favorite | ||
- 功能说明: | ||
|
||
- 中文:删除收藏文件夹 | ||
- English:delete favorite | ||
- 请求体 | ||
此接口请求体为空 | ||
- 请求字段说明 | ||
|
||
|
||
| 字段 | 类型 | 是否必须 | 默认值 | 说明 | Description | | ||
| ------ | -------- | ---------- | -------- | ------ | ------------- | | ||
| id | string | 是 | 无 | id | id | | ||
- 响应体 | ||
|
||
```json | ||
{ | ||
"code": 0, | ||
"message": null, | ||
"data": null, | ||
"traceId": null | ||
} | ||
``` |
48 changes: 48 additions & 0 deletions
48
...tory/src/main/kotlin/com/tencent/bkrepo/repository/pojo/favorite/FavoriteCreateRequset.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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 io.swagger.annotations.ApiModelProperty | ||
import java.time.LocalDateTime | ||
|
||
data class FavoriteCreateRequset( | ||
@ApiModelProperty("项目id") | ||
val projectId: String, | ||
@ApiModelProperty("仓库Name") | ||
val repoName: String, | ||
@ApiModelProperty("文件夹路径") | ||
val path: String, | ||
@ApiModelProperty("收藏用户") | ||
val userId: String, | ||
@ApiModelProperty("收藏时间") | ||
val createdDate: LocalDateTime | ||
) |
42 changes: 42 additions & 0 deletions
42
...sitory/src/main/kotlin/com/tencent/bkrepo/repository/pojo/favorite/FavoritePageRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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 FavoritePageRequest( | ||
var projectId: String?, | ||
var repoName: String?, | ||
var pageNumber: Int = DEFAULT_PAGE_NUMBER, | ||
var pageSize: Int = DEFAULT_PAGE_SIZE | ||
) |
45 changes: 45 additions & 0 deletions
45
...repository/src/main/kotlin/com/tencent/bkrepo/repository/pojo/favorite/FavoriteRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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 io.swagger.annotations.ApiModel | ||
import io.swagger.annotations.ApiModelProperty | ||
|
||
@ApiModel("创建收藏文件夹的请求") | ||
data class FavoriteRequest( | ||
@ApiModelProperty("项目id") | ||
val projectId: String, | ||
@ApiModelProperty("仓库id") | ||
val repoName: String, | ||
@ApiModelProperty("文件夹路径") | ||
val path: String | ||
) |
106 changes: 106 additions & 0 deletions
106
...itory/src/main/kotlin/com/tencent/bkrepo/repository/controller/user/FavoriteController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* 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.controller.user | ||
|
||
import com.tencent.bkrepo.auth.pojo.enums.PermissionAction | ||
import com.tencent.bkrepo.common.api.constant.HttpStatus | ||
import com.tencent.bkrepo.common.api.pojo.Page | ||
import com.tencent.bkrepo.common.api.pojo.Response | ||
import com.tencent.bkrepo.common.security.manager.PermissionManager | ||
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.FavoriteRequest | ||
import com.tencent.bkrepo.repository.service.folder.FolderService | ||
import io.swagger.annotations.Api | ||
import io.swagger.annotations.ApiOperation | ||
import org.springframework.web.bind.annotation.DeleteMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestAttribute | ||
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 | ||
|
||
@Api("用户收藏接口") | ||
@RestController | ||
@RequestMapping("/api/favorite") | ||
class FavoriteController( | ||
private val folderService: FolderService, | ||
private val permissionManager: PermissionManager | ||
) { | ||
|
||
@ApiOperation("创建收藏文件夹") | ||
@PostMapping( "/create") | ||
fun mkFavorite( | ||
@RequestAttribute userId: String, | ||
@RequestBody favoriteRequest: FavoriteRequest | ||
): Response<Void> { | ||
with(favoriteRequest) { | ||
permissionManager.checkNodePermission(PermissionAction.VIEW, projectId, repoName, path) | ||
val createRequest = FavoriteCreateRequset( | ||
projectId = projectId, | ||
repoName = repoName, | ||
path = path, | ||
createdDate = LocalDateTime.now(), | ||
userId = userId | ||
) | ||
folderService.createFavorite(createRequest) | ||
return ResponseBuilder.success() | ||
} | ||
} | ||
|
||
@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) | ||
return ResponseBuilder.success() | ||
} | ||
return ResponseBuilder.fail(HttpStatus.BAD_REQUEST.value, "id not existed") | ||
} | ||
|
||
@ApiOperation("收藏文件夹分页查询") | ||
@PostMapping("/page") | ||
fun pageFavorite( | ||
@RequestBody favoritePageRequest: FavoritePageRequest | ||
): Response<Page<TFavorites>> { | ||
return ResponseBuilder.success(folderService.pageFavorite(favoritePageRequest)) | ||
} | ||
|
||
} |
Oops, something went wrong.