runningwater 5 місяців тому
батько
коміт
03ea0a8a8b

+ 5 - 0
README.md

@@ -76,6 +76,11 @@ UNIQUE KEY `migration` (`migration`)
 
 #### 🚀 新功能
 
+- 显示话题
+- 话题列表
+- 删除话题
+- *(command)* Make policy 命令
+- 授权策略
 - 话题更新接口
 - 创建话题接口
 - 话题模型和迁移

+ 9 - 0
app/http/controllers/api/v1/topics_controller.go

@@ -14,6 +14,15 @@ type TopicsController struct {
 	BaseApiController
 }
 
+func (ctrl *TopicsController) Show(c *gin.Context) {
+	topicModel := topic.Get(c.Param("id"))
+	if topicModel.ID == 0 {
+		response.Abort404(c)
+		return
+	}
+	response.Data(c, topicModel)
+}
+
 func (ctrl *TopicsController) Index(c *gin.Context) {
 	request := requests.PaginationRequest{}
 	if ok := requests.Validate(c, &request, requests.Pagination); !ok {

+ 2 - 1
app/models/topic/topic_util.go

@@ -2,6 +2,7 @@ package topic
 
 import (
 	"github.com/gin-gonic/gin"
+	"gorm.io/gorm/clause"
 
 	"github.com/runningwater/gohub/pkg/app"
 	"github.com/runningwater/gohub/pkg/database"
@@ -9,7 +10,7 @@ import (
 )
 
 func Get(idStr string) (topic Topic) {
-	database.DB.Where("id", idStr).First(&topic)
+	database.DB.Preload(clause.Associations).Where("id", idStr).First(&topic)
 	return
 }
 

+ 13 - 0
gohub.http

@@ -146,3 +146,16 @@ Content-Type: application/json
   "body": "话题1内容, 这里是帖子描述内容帖子描述内容",
   "category_id": "3"
 }
+
+### 显示话题
+GET {{base_url}}/v1/topics/2 HTTP/1.1
+Content-Type: application/json
+
+### 话题列表
+GET {{base_url}}/v1/topics HTTP/1.1
+Content-Type: application/json
+
+### 删除话题
+DELETE {{base_url}}/v1/topics/1 HTTP/1.1
+Authorization: Bearer {{access_token}}
+Content-Type: application/json

+ 1 - 0
routes/api.go

@@ -73,6 +73,7 @@ func RegisterAPIRoutes(router *gin.Engine) {
 			tpcGroup.POST("", middlewares.AuthJWT(), tpc.Store)
 			tpcGroup.PUT("/:id", middlewares.AuthJWT(), tpc.Update)
 			tpcGroup.DELETE("/:id", middlewares.AuthJWT(), tpc.Delete)
+			tpcGroup.GET("/:id", tpc.Show)
 		}
 	}
 }