This commit is contained in:
2025-10-24 21:44:15 +08:00
parent 2f56813874
commit 289812aac3
18 changed files with 576 additions and 100 deletions

View 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 presigned URL for file download
func DownloadPresignedURLHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DownloadPresignedURLReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := logic.NewDownloadPresignedURLLogic(r.Context(), svcCtx)
resp, err := l.DownloadPresignedURL(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View 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"
)
// Ping the server to check if it's alive
func pingHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.PingReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := logic.NewPingLogic(r.Context(), svcCtx)
resp, err := l.Ping(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@@ -0,0 +1,38 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.8.4
package handler
import (
"net/http"
"git.cialloo.com/CiallooWeb/Blog/app/internal/svc"
"github.com/zeromicro/go-zero/rest"
)
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
// Get presigned URL for file download
Method: http.MethodPost,
Path: "/file/download",
Handler: DownloadPresignedURLHandler(serverCtx),
},
{
// Get presigned URL for file upload
Method: http.MethodPost,
Path: "/file/upload",
Handler: UploadPresignedURLHandler(serverCtx),
},
{
// Ping the server to check if it's alive
Method: http.MethodGet,
Path: "/ping",
Handler: pingHandler(serverCtx),
},
},
rest.WithPrefix("/api/blog"),
)
}

View 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 presigned URL for file upload
func UploadPresignedURLHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.UploadPresignedURLReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := logic.NewUploadPresignedURLLogic(r.Context(), svcCtx)
resp, err := l.UploadPresignedURL(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}