diff --git a/internal/interactive/internal/errs/code.go b/internal/interactive/internal/errs/code.go new file mode 100644 index 00000000..3ecdbc9e --- /dev/null +++ b/internal/interactive/internal/errs/code.go @@ -0,0 +1,10 @@ +package errs + +var ( + SystemError = ErrorCode{Code: 503001, Msg: "系统错误"} +) + +type ErrorCode struct { + Code int + Msg string +} diff --git a/internal/interactive/internal/web/handler.go b/internal/interactive/internal/web/handler.go new file mode 100644 index 00000000..cb3c2a30 --- /dev/null +++ b/internal/interactive/internal/web/handler.go @@ -0,0 +1,55 @@ +// Copyright 2023 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package web + +import ( + "github.com/ecodeclub/ginx" + "github.com/ecodeclub/ginx/session" + "github.com/gin-gonic/gin" +) + +var _ ginx.Handler = &Handler{} + +type Handler struct { +} + +// PrivateRoutes 这边我们直接让前端来控制 biz 和 biz_id,简化实现 +// 这算是一种反范式的设计和实现方式 +func (h *Handler) PrivateRoutes(server *gin.Engine) { + g := server.Group("/intr") + g.POST("/collect", ginx.BS[CollectReq](h.Collect)) + g.POST("/like", ginx.BS[LikeReq](h.Like)) + // 统一用 POST 请求,懒得去处理不同的 + g.POST("/cnt", ginx.BS[GetCntReq](h.GetCnt)) +} + +func (h *Handler) PublicRoutes(server *gin.Engine) { + //TODO implement me + panic("implement me") +} + +func (h *Handler) Collect(ctx *ginx.Context, req CollectReq, sess session.Session) (ginx.Result, error) { + return ginx.Result{Msg: "OK"}, nil +} + +func (h *Handler) GetCnt(ctx *ginx.Context, req GetCntReq, sess session.Session) (ginx.Result, error) { + return ginx.Result{ + Data: &GetCntResp{}, + }, nil +} + +func (h *Handler) Like(ctx *ginx.Context, req LikeReq, sess session.Session) (ginx.Result, error) { + return ginx.Result{Msg: "OK"}, nil +} diff --git a/internal/interactive/internal/web/result.go b/internal/interactive/internal/web/result.go new file mode 100644 index 00000000..75a70302 --- /dev/null +++ b/internal/interactive/internal/web/result.go @@ -0,0 +1,13 @@ +package web + +import ( + "github.com/ecodeclub/ginx" + "github.com/ecodeclub/webook/internal/interactive/internal/errs" +) + +var ( + systemErrorResult = ginx.Result{ + Code: errs.SystemError.Code, + Msg: errs.SystemError.Msg, + } +) diff --git a/internal/interactive/internal/web/vo.go b/internal/interactive/internal/web/vo.go new file mode 100644 index 00000000..fc6261a0 --- /dev/null +++ b/internal/interactive/internal/web/vo.go @@ -0,0 +1,38 @@ +// Copyright 2023 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package web + +type CollectReq struct { + Biz string `json:"biz"` + BizId int64 `json:"bizId"` +} + +type LikeReq struct { + Biz string `json:"biz"` + BizId int64 `json:"bizId"` +} + +type GetCntReq struct { + Biz string `json:"biz"` + BizId int64 `json:"bizId"` +} + +type GetCntResp struct { + CollectCnt int `json:"collectCnt"` + LikeCnt int `json:"likeCnt"` + ViewCnt int `json:"viewCnt"` + Collected bool `json:"collected"` + Liked bool `json:"liked"` +}