update
All checks were successful
CI - Build and Push / Build and Push Docker Image (push) Successful in 52s
All checks were successful
CI - Build and Push / Build and Push Docker Image (push) Successful in 52s
This commit is contained in:
29
app/internal/handler/getposthandler.go
Normal file
29
app/internal/handler/getposthandler.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.cialloo.com/CiallooWeb/Blog/app/internal/logic"
|
||||
"git.cialloo.com/CiallooWeb/Blog/app/internal/svc"
|
||||
"git.cialloo.com/CiallooWeb/Blog/app/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// Get a blog post by ID
|
||||
func GetPostHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.GetPostReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := logic.NewGetPostLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetPost(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
29
app/internal/handler/listpostshandler.go
Normal file
29
app/internal/handler/listpostshandler.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.cialloo.com/CiallooWeb/Blog/app/internal/logic"
|
||||
"git.cialloo.com/CiallooWeb/Blog/app/internal/svc"
|
||||
"git.cialloo.com/CiallooWeb/Blog/app/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// Get a list of blog posts
|
||||
func ListPostsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ListPostsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := logic.NewListPostsLogic(r.Context(), svcCtx)
|
||||
resp, err := l.ListPosts(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
29
app/internal/handler/listtagshandler.go
Normal file
29
app/internal/handler/listtagshandler.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.cialloo.com/CiallooWeb/Blog/app/internal/logic"
|
||||
"git.cialloo.com/CiallooWeb/Blog/app/internal/svc"
|
||||
"git.cialloo.com/CiallooWeb/Blog/app/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// Get a list of blog tags
|
||||
func ListTagsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ListTagsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := logic.NewListTagsLogic(r.Context(), svcCtx)
|
||||
resp, err := l.ListTags(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,30 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
rest.WithPrefix("/api/blog"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// Get a blog post by ID
|
||||
Method: http.MethodPost,
|
||||
Path: "/post",
|
||||
Handler: GetPostHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// Get a list of blog posts
|
||||
Method: http.MethodPost,
|
||||
Path: "/posts",
|
||||
Handler: ListPostsHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// Get a list of blog tags
|
||||
Method: http.MethodPost,
|
||||
Path: "/tags",
|
||||
Handler: ListTagsHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithPrefix("/api/blog/view"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.SuperAdminAuthMiddleware},
|
||||
@@ -58,17 +82,17 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
{
|
||||
// Get presigned URL for file download
|
||||
Method: http.MethodPost,
|
||||
Path: "/file/download",
|
||||
Path: "/download",
|
||||
Handler: DownloadPresignedURLHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// Get presigned URL for file upload
|
||||
Method: http.MethodPost,
|
||||
Path: "/file/upload",
|
||||
Path: "/upload",
|
||||
Handler: UploadPresignedURLHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithPrefix("/api/blog"),
|
||||
rest.WithPrefix("/api/blog/file"),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user