1234567891011121314151617181920212223242526272829 |
- package handler
- import (
- "net/http"
- "bookstore/api/internal/logic"
- "bookstore/api/internal/svc"
- "bookstore/api/internal/types"
- "github.com/tal-tech/go-zero/rest/httpx"
- )
- func AddHandler(ctx *svc.ServiceContext) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
- var req types.AddReq
- if err := httpx.Parse(r, &req); err != nil {
- httpx.Error(w, err)
- return
- }
- l := logic.NewAddLogic(r.Context(), ctx)
- resp, err := l.Add(req)
- if err != nil {
- httpx.Error(w, err)
- } else {
- httpx.WriteJson(w, http.StatusOK, resp)
- }
- }
- }
|