Added link info endpoint
This commit is contained in:
28
internal/handler/getlinkhandler.go
Normal file
28
internal/handler/getlinkhandler.go
Normal file
@ -0,0 +1,28 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"5feet11/internal/logic"
|
||||
"5feet11/internal/svc"
|
||||
"5feet11/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func GetLinkHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ExpandReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.Error(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := logic.NewGetLinkLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetLink(&req)
|
||||
if err != nil {
|
||||
httpx.Error(w, err)
|
||||
} else {
|
||||
httpx.OkJson(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
@ -22,6 +22,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/api/v1/links",
|
||||
Handler: ShortenUrlHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/v1/links/:id",
|
||||
Handler: GetLinkHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user