feat: 迁移plant
This commit is contained in:
@@ -23,11 +23,11 @@ func AiChatHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
|
||||
l := ai.NewAiChatLogic(r.Context(), svcCtx)
|
||||
err := l.AiChat(&req)
|
||||
resp, err := l.AiChat(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
response.OkWithData(w, map[string]string{"answer": resp})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package ai
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/ai"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 清空聊天历史
|
||||
func ClearAiChatHistoryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := ai.NewClearAiChatHistoryLogic(r.Context(), svcCtx)
|
||||
err := l.ClearAiChatHistory()
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package ai
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/ai"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 删除聊天历史
|
||||
func DeleteAiChatHistoryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := ai.NewDeleteAiChatHistoryLogic(r.Context(), svcCtx)
|
||||
err := l.DeleteAiChatHistory(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,11 +15,11 @@ import (
|
||||
func GetAiChatHistoryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := ai.NewGetAiChatHistoryLogic(r.Context(), svcCtx)
|
||||
err := l.GetAiChatHistory()
|
||||
resp, err := l.GetAiChatHistory()
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package ai
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/ai"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
func GetAiChatQuotaHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := ai.NewGetAiChatQuotaLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetAiChatQuota()
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package banner
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/banner"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 创建Banner
|
||||
func CreateBannerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CreateBannerReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
l := banner.NewCreateBannerLogic(r.Context(), svcCtx)
|
||||
err := l.CreateBanner(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package banner
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/banner"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 删除Banner
|
||||
func DeleteBannerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
l := banner.NewDeleteBannerLogic(r.Context(), svcCtx)
|
||||
err := l.DeleteBanner(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package banner
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/banner"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 启用的Banner列表(客户端)
|
||||
func GetActiveBannerListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := banner.NewGetActiveBannerListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetActiveBannerList()
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package banner
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/banner"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// Banner列表
|
||||
func GetBannerListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.BannerListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
l := banner.NewGetBannerListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetBannerList(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package banner
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/banner"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 更新Banner
|
||||
func UpdateBannerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateBannerReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
l := banner.NewUpdateBannerLogic(r.Context(), svcCtx)
|
||||
err := l.UpdateBanner(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,18 +8,21 @@ import (
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/callback"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 微信支付回调
|
||||
// 注意:微信要求必须返回 200 OK,否则会持续重试,此处不走统一 response 包装
|
||||
func WechatPayCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := callback.NewWechatPayCallbackLogic(r.Context(), svcCtx)
|
||||
err := l.WechatPayCallback()
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
if err := l.WechatPayCallback(r); err != nil {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
_, _ = w.Write([]byte(`{"code":"FAIL","message":"处理失败"}`))
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write([]byte(`{"code":"SUCCESS","message":"成功"}`))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package complete
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/complete"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
func CompleteTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CompleteTaskApiReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
l := complete.NewCompleteTaskLogic(r.Context(), svcCtx)
|
||||
resp, err := l.CompleteTask(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package complete
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/complete"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
func GetAiChatHistoryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.PageReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
l := complete.NewGetAiChatHistoryLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetAiChatHistory(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package complete
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/complete"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
func GetBadgeConfigTreeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := complete.NewGetBadgeConfigTreeLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetBadgeConfigTree()
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package complete
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/complete"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
func GetExchangeItemDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdPathReq
|
||||
if err := httpx.ParsePath(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
l := complete.NewGetExchangeItemDetailLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetExchangeItemDetail(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package complete
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/complete"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
func GetLevelConfigDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdPathReq
|
||||
if err := httpx.ParsePath(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
l := complete.NewGetLevelConfigDetailLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetLevelConfigDetail(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package complete
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/complete"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
func GetWikiClassDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdPathReq
|
||||
if err := httpx.ParsePath(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
l := complete.NewGetWikiClassDetailLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetWikiClassDetail(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/config"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 创建徽章配置
|
||||
func CreateBadgeConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CreateBadgeConfigReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := config.NewCreateBadgeConfigLogic(r.Context(), svcCtx)
|
||||
err := l.CreateBadgeConfig(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/config"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 创建等级配置
|
||||
func CreateLevelConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CreateLevelConfigReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := config.NewCreateLevelConfigLogic(r.Context(), svcCtx)
|
||||
err := l.CreateLevelConfig(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/config"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 删除徽章配置
|
||||
func DeleteBadgeConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := config.NewDeleteBadgeConfigLogic(r.Context(), svcCtx)
|
||||
err := l.DeleteBadgeConfig(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/config"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 删除等级配置
|
||||
func DeleteLevelConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := config.NewDeleteLevelConfigLogic(r.Context(), svcCtx)
|
||||
err := l.DeleteLevelConfig(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,11 +23,11 @@ func GetBadgeConfigListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
|
||||
l := config.NewGetBadgeConfigListLogic(r.Context(), svcCtx)
|
||||
err := l.GetBadgeConfigList(&req)
|
||||
resp, err := l.GetBadgeConfigList(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,11 @@ func GetLevelConfigListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
|
||||
l := config.NewGetLevelConfigListLogic(r.Context(), svcCtx)
|
||||
err := l.GetLevelConfigList(&req)
|
||||
resp, err := l.GetLevelConfigList(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/config"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 更新徽章配置
|
||||
func UpdateBadgeConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateBadgeConfigReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := config.NewUpdateBadgeConfigLogic(r.Context(), svcCtx)
|
||||
err := l.UpdateBadgeConfig(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/config"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 更新等级配置
|
||||
func UpdateLevelConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateLevelConfigReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := config.NewUpdateLevelConfigLogic(r.Context(), svcCtx)
|
||||
err := l.UpdateLevelConfig(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package exchange
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/exchange"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 创建兑换商品
|
||||
func CreateExchangeItemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CreateExchangeItemReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := exchange.NewCreateExchangeItemLogic(r.Context(), svcCtx)
|
||||
err := l.CreateExchangeItem(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package exchange
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/exchange"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 删除兑换商品
|
||||
func DeleteExchangeItemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := exchange.NewDeleteExchangeItemLogic(r.Context(), svcCtx)
|
||||
err := l.DeleteExchangeItem(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,11 +23,11 @@ func GetExchangeItemListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
|
||||
l := exchange.NewGetExchangeItemListLogic(r.Context(), svcCtx)
|
||||
err := l.GetExchangeItemList(&req)
|
||||
resp, err := l.GetExchangeItemList(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package exchange
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/exchange"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
func GetExchangeOrderListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ExchangeOrderListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
l := exchange.NewGetExchangeOrderListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetExchangeOrderList(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package exchange
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/exchange"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
func GetMyExchangeOrdersHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ExchangeOrderListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
l := exchange.NewGetMyExchangeOrdersLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetMyExchangeOrders(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package exchange
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/exchange"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 更新兑换商品
|
||||
func UpdateExchangeItemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateExchangeItemReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := exchange.NewUpdateExchangeItemLogic(r.Context(), svcCtx)
|
||||
err := l.UpdateExchangeItem(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package exchange
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/exchange"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 更新订单状态
|
||||
func UpdateExchangeOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateExchangeOrderReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := exchange.NewUpdateExchangeOrderLogic(r.Context(), svcCtx)
|
||||
err := l.UpdateExchangeOrder(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,894 @@
|
||||
package legacy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
filePb "sundynix-micro-go/app/file/rpc/file"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/complete"
|
||||
plantLogic "sundynix-micro-go/app/plant/api/internal/logic/myPlant"
|
||||
postLogic "sundynix-micro-go/app/plant/api/internal/logic/post"
|
||||
topicLogic "sundynix-micro-go/app/plant/api/internal/logic/topic"
|
||||
wikiLogic "sundynix-micro-go/app/plant/api/internal/logic/wiki"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
plantModel "sundynix-micro-go/app/plant/model"
|
||||
plantPb "sundynix-micro-go/app/plant/rpc/plant"
|
||||
"sundynix-micro-go/common/response"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func idFromQuery(r *http.Request) string {
|
||||
if id := r.URL.Query().Get("id"); id != "" {
|
||||
return id
|
||||
}
|
||||
if id := r.URL.Query().Get("wikiId"); id != "" {
|
||||
return id
|
||||
}
|
||||
if id := r.URL.Query().Get("postId"); id != "" {
|
||||
return id
|
||||
}
|
||||
if id := r.URL.Query().Get("itemId"); id != "" {
|
||||
return id
|
||||
}
|
||||
return r.URL.Query().Get("classId")
|
||||
}
|
||||
|
||||
func fileListByIDs(r *http.Request, svcCtx *svc.ServiceContext, ids []string) []map[string]interface{} {
|
||||
if len(ids) == 0 {
|
||||
return []map[string]interface{}{}
|
||||
}
|
||||
resp, err := svcCtx.FileRpc.GetFilesByIds(r.Context(), &filePb.GetFilesByIdsReq{Ids: ids})
|
||||
if err != nil {
|
||||
return []map[string]interface{}{}
|
||||
}
|
||||
list := make([]map[string]interface{}, 0, len(resp.Files))
|
||||
for _, f := range resp.Files {
|
||||
list = append(list, map[string]interface{}{
|
||||
"id": f.Id, "name": f.Name, "url": f.Url, "tag": f.Tag,
|
||||
"key": f.Key, "suffix": f.Suffix, "md5": f.Md5, "createdAt": f.CreatedAt,
|
||||
})
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func PlantDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var myPlant plantModel.MyPlant
|
||||
if err := svcCtx.DB.
|
||||
Preload("CarePlans").
|
||||
Preload("CareRecords", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Order("created_at desc")
|
||||
}).
|
||||
Preload("GrowthRecords", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Order("created_at desc")
|
||||
}).
|
||||
Where("id = ?", idFromQuery(r)).First(&myPlant).Error; err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// 查图片(本地关联表 + FileRpc)
|
||||
imgList := queryImagesByPlant(svcCtx, r.Context(), myPlant.ID)
|
||||
|
||||
// 成长记录图片
|
||||
growthImgMap := queryGrowthImages(svcCtx, r.Context(), myPlant.GrowthRecords)
|
||||
|
||||
response.OkWithData(w, map[string]interface{}{
|
||||
"plant": toPlantMap(myPlant),
|
||||
"imgList": imgList,
|
||||
"carePlans": toPlanMapList(myPlant.CarePlans),
|
||||
"careRecords": toRecordMapList(myPlant.CareRecords),
|
||||
"careTasks": nil,
|
||||
"growthRecords": toGrowthMapList(myPlant.GrowthRecords, growthImgMap),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func DeletePlanHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := plantLogic.NewDeleteCarePlanLogic(r.Context(), svcCtx)
|
||||
if err := l.DeleteCarePlan(&types.IdsReq{Ids: []string{idFromQuery(r)}}); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
|
||||
func WikiDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
resp, err := svcCtx.PlantRpc.GetWikiDetail(r.Context(), &plantPb.IdReq{Id: idFromQuery(r)})
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
if resp != nil && resp.Wiki != nil {
|
||||
// 通过 FileRpc 获取完整图片信息
|
||||
imgList := fetchFileMap(svcCtx, r.Context(), resp.Wiki.OssIds)
|
||||
response.OkWithData(w, map[string]interface{}{
|
||||
"wiki": resp.Wiki, "imgList": imgListToList(imgList, resp.Wiki.OssIds),
|
||||
"classIds": resp.Wiki.ClassIds, "relatedWikiIds": resp.Wiki.RelatedWikiIds,
|
||||
})
|
||||
return
|
||||
}
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
|
||||
func WikiPageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.WikiListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := svcCtx.PlantRpc.GetWikiList(r.Context(), &plantPb.WikiListReq{
|
||||
Current: int32(req.Current),
|
||||
PageSize: int32(req.PageSize),
|
||||
Name: req.Name,
|
||||
ClassId: req.ClassId,
|
||||
IsHot: int32(req.IsHot),
|
||||
})
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// 查询所有 wiki 的图片
|
||||
var wikiIds []string
|
||||
for _, w := range resp.List {
|
||||
wikiIds = append(wikiIds, w.Id)
|
||||
}
|
||||
|
||||
// 查本地关联表获取 OSS ID
|
||||
type rel struct {
|
||||
WikiID string `gorm:"column:wiki_id"`
|
||||
OssID string `gorm:"column:oss_id"`
|
||||
}
|
||||
var rels []rel
|
||||
if len(wikiIds) > 0 {
|
||||
svcCtx.DB.Table("sundynix_plant_wiki_oss").
|
||||
Where("wiki_id IN ?", wikiIds).
|
||||
Find(&rels)
|
||||
}
|
||||
wikiOssMap := make(map[string][]string)
|
||||
var allOssIds []string
|
||||
for _, r := range rels {
|
||||
wikiOssMap[r.WikiID] = append(wikiOssMap[r.WikiID], r.OssID)
|
||||
allOssIds = append(allOssIds, r.OssID)
|
||||
}
|
||||
|
||||
// 通过 FileRpc 获取图片信息
|
||||
fileMap := fetchFileMap(svcCtx, r.Context(), allOssIds)
|
||||
|
||||
// 组装返回
|
||||
var list []map[string]interface{}
|
||||
for _, w := range resp.List {
|
||||
ossIds := wikiOssMap[w.Id]
|
||||
imgList := imgListToList(fileMap, ossIds)
|
||||
hasStarVal := 0
|
||||
if w.IsStar {
|
||||
hasStarVal = 1
|
||||
}
|
||||
list = append(list, map[string]interface{}{
|
||||
"id": w.Id, "name": w.Name, "latinName": w.LatinName,
|
||||
"aliases": w.Aliases, "genus": w.Genus, "difficulty": w.Difficulty,
|
||||
"isHot": w.IsHot, "growthHabit": w.GrowthHabit,
|
||||
"lightIntensity": w.LightIntensity, "classId": w.ClassId,
|
||||
"createdAt": w.CreatedAt, "hasStar": hasStarVal,
|
||||
"imgList": imgList,
|
||||
})
|
||||
}
|
||||
if list == nil {
|
||||
list = []map[string]interface{}{}
|
||||
}
|
||||
|
||||
response.OkWithData(w, map[string]interface{}{
|
||||
"list": list, "total": resp.Total,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// imgListToList 将 fileMap 按顺序转为列表
|
||||
func imgListToList(fileMap map[string]map[string]interface{}, ossIds []string) []map[string]interface{} {
|
||||
var list []map[string]interface{}
|
||||
for _, id := range ossIds {
|
||||
if img, ok := fileMap[id]; ok {
|
||||
list = append(list, img)
|
||||
}
|
||||
}
|
||||
if list == nil {
|
||||
list = []map[string]interface{}{}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func WikiStarHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := wikiLogic.NewToggleWikiStarLogic(r.Context(), svcCtx)
|
||||
if err := l.ToggleWikiStar(&types.IdReq{Id: idFromQuery(r)}); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
|
||||
func TopicDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := topicLogic.NewGetTopicDetailLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetTopicDetail(&types.IdPathReq{Id: idFromQuery(r)})
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
|
||||
func LikePostHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := postLogic.NewLikePostLogic(r.Context(), svcCtx)
|
||||
if err := l.LikePost(&types.IdReq{Id: idFromQuery(r)}); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
|
||||
func StarPostHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := postLogic.NewStarPostLogic(r.Context(), svcCtx)
|
||||
if err := l.StarPost(&types.IdReq{Id: idFromQuery(r)}); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
|
||||
func ExchangeItemDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := complete.NewGetExchangeItemDetailLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetExchangeItemDetail(&types.IdPathReq{Id: idFromQuery(r)})
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
|
||||
func PostPageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.PostListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
userId := fmt.Sprintf("%v", r.Context().Value("userId"))
|
||||
|
||||
db := svcCtx.DB.Model(&plantModel.Post{})
|
||||
if req.Keyword != "" {
|
||||
db = db.Where("title like ? OR content like ?", "%"+req.Keyword+"%", "%"+req.Keyword+"%")
|
||||
}
|
||||
|
||||
var total int64
|
||||
db.Count(&total)
|
||||
pageSize := req.PageSize
|
||||
if pageSize <= 0 {
|
||||
pageSize = 20
|
||||
}
|
||||
page := req.Current
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
var posts []*plantModel.Post
|
||||
if err := db.
|
||||
Preload("CommentList", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Order("created_at asc")
|
||||
}).
|
||||
Preload("LikeList").
|
||||
Limit(pageSize).Offset(offset).Order("created_at desc").Find(&posts).Error; err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// 组装完整响应
|
||||
list := buildPostListResponse(svcCtx, r.Context(), posts, userId)
|
||||
response.OkWithData(w, map[string]interface{}{
|
||||
"list": list, "total": total, "page": page, "pageSize": pageSize,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func MyPostPageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.PostListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
userId := fmt.Sprintf("%v", r.Context().Value("userId"))
|
||||
|
||||
db := svcCtx.DB.Model(&plantModel.Post{}).Where("user_id = ?", userId)
|
||||
|
||||
var total int64
|
||||
db.Count(&total)
|
||||
pageSize := req.PageSize
|
||||
if pageSize <= 0 {
|
||||
pageSize = 20
|
||||
}
|
||||
page := req.Current
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
var posts []*plantModel.Post
|
||||
if err := db.
|
||||
Preload("CommentList", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Order("created_at asc")
|
||||
}).
|
||||
Preload("LikeList").
|
||||
Limit(pageSize).Offset(offset).Order("created_at desc").Find(&posts).Error; err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
list := buildPostListResponse(svcCtx, r.Context(), posts, userId)
|
||||
response.OkWithData(w, map[string]interface{}{
|
||||
"list": list, "total": total, "page": page, "pageSize": pageSize,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ========== Post 列表辅助函数 ==========
|
||||
|
||||
// buildPostListResponse 组装完整帖子列表响应
|
||||
func buildPostListResponse(svcCtx *svc.ServiceContext, ctx context.Context, posts []*plantModel.Post, userId string) []map[string]interface{} {
|
||||
if len(posts) == 0 {
|
||||
return []map[string]interface{}{}
|
||||
}
|
||||
|
||||
var postIds []string
|
||||
for _, p := range posts {
|
||||
postIds = append(postIds, p.ID)
|
||||
}
|
||||
|
||||
// 1. 查帖子图片(本地关联表 + FileRpc)
|
||||
postImgMap := queryPostImages(svcCtx, ctx, postIds)
|
||||
|
||||
// 2. 查用户信息
|
||||
allUserIds := collectPostUserIds(posts)
|
||||
userMap := queryUserMapV2(svcCtx, allUserIds)
|
||||
|
||||
// 3. 查当前用户点赞/收藏状态
|
||||
likedSet, starredSet := queryLikeStarStatus(svcCtx, userId, postIds)
|
||||
|
||||
// 4. 组装
|
||||
var list []map[string]interface{}
|
||||
for _, p := range posts {
|
||||
item := map[string]interface{}{
|
||||
"id": p.ID, "title": p.Title, "content": p.Content,
|
||||
"userId": p.UserID, "location": p.Location,
|
||||
"viewCount": p.ViewCount, "commentCount": p.CommentCount,
|
||||
"likeCount": p.LikeCount, "starCount": p.StarCount,
|
||||
"hasReviewed": p.HasReviewed,
|
||||
"createdAt": p.CreatedAt.Format(time.RFC3339),
|
||||
"updatedAt": p.UpdatedAt.Format(time.RFC3339),
|
||||
"createdAtStr": p.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
"hasLiked": 0, "hasStar": 0,
|
||||
"imgList": postImgMap[p.ID],
|
||||
"publisher": buildPublisherInfo(userMap, p.UserID),
|
||||
"commentList": buildCommentList(userMap, p.CommentList),
|
||||
"likeList": buildLikeList(userMap, p.LikeList),
|
||||
"starList": []map[string]interface{}{},
|
||||
}
|
||||
if likedSet[p.ID] {
|
||||
item["hasLiked"] = 1
|
||||
}
|
||||
if starredSet[p.ID] {
|
||||
item["hasStar"] = 1
|
||||
}
|
||||
list = append(list, item)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func collectPostUserIds(posts []*plantModel.Post) []string {
|
||||
set := make(map[string]bool)
|
||||
for _, p := range posts {
|
||||
set[p.UserID] = true
|
||||
for _, c := range p.CommentList {
|
||||
set[c.UserID] = true
|
||||
}
|
||||
for _, l := range p.LikeList {
|
||||
set[l.UserID] = true
|
||||
}
|
||||
}
|
||||
var ids []string
|
||||
for id := range set {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// queryPostImages 查询帖子图片
|
||||
func queryPostImages(svcCtx *svc.ServiceContext, ctx context.Context, postIds []string) map[string][]map[string]interface{} {
|
||||
type rel struct {
|
||||
PostID string `gorm:"column:post_id"`
|
||||
OssID string `gorm:"column:oss_id"`
|
||||
}
|
||||
var rels []rel
|
||||
svcCtx.DB.Table("sundynix_plant_post_oss").
|
||||
Where("post_id IN ?", postIds).
|
||||
Find(&rels)
|
||||
|
||||
var allOssIds []string
|
||||
pidMap := make(map[string][]string)
|
||||
for _, r := range rels {
|
||||
pidMap[r.PostID] = append(pidMap[r.PostID], r.OssID)
|
||||
allOssIds = append(allOssIds, r.OssID)
|
||||
}
|
||||
|
||||
// 通过 FileRpc 获取文件信息
|
||||
fileInfos := fetchFileMap(svcCtx, ctx, allOssIds)
|
||||
|
||||
result := make(map[string][]map[string]interface{})
|
||||
for pid, ids := range pidMap {
|
||||
var imgs []map[string]interface{}
|
||||
for _, oid := range ids {
|
||||
if info, ok := fileInfos[oid]; ok {
|
||||
imgs = append(imgs, info)
|
||||
}
|
||||
}
|
||||
if imgs == nil {
|
||||
imgs = []map[string]interface{}{}
|
||||
}
|
||||
result[pid] = imgs
|
||||
}
|
||||
// 没有图片的帖子也返回空数组
|
||||
for _, pid := range postIds {
|
||||
if _, ok := result[pid]; !ok {
|
||||
result[pid] = []map[string]interface{}{}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// fetchFileMap 通过 FileRpc 获取文件信息
|
||||
func fetchFileMap(svcCtx *svc.ServiceContext, ctx context.Context, ids []string) map[string]map[string]interface{} {
|
||||
result := make(map[string]map[string]interface{})
|
||||
if len(ids) == 0 {
|
||||
return result
|
||||
}
|
||||
resp, err := svcCtx.FileRpc.GetFilesByIds(ctx, &filePb.GetFilesByIdsReq{Ids: ids})
|
||||
if err != nil || resp == nil {
|
||||
return result
|
||||
}
|
||||
for _, f := range resp.Files {
|
||||
result[f.Id] = map[string]interface{}{
|
||||
"id": f.Id, "name": f.Name, "url": f.Url, "tag": f.Tag,
|
||||
"key": f.Key, "suffix": f.Suffix, "md5": f.Md5,
|
||||
"createdAt": unixToTimeStr(f.CreatedAt),
|
||||
"updatedAt": unixToTimeStr(f.CreatedAt),
|
||||
"createdAtStr": unixToTimeStrShort(f.CreatedAt),
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func unixToTimeStr(ts int64) string {
|
||||
if ts == 0 {
|
||||
return ""
|
||||
}
|
||||
return time.Unix(ts, 0).Format(time.RFC3339)
|
||||
}
|
||||
|
||||
func unixToTimeStrShort(ts int64) string {
|
||||
if ts == 0 {
|
||||
return ""
|
||||
}
|
||||
return time.Unix(ts, 0).Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
// queryUserMapV2 查询用户信息
|
||||
func queryUserMapV2(svcCtx *svc.ServiceContext, ids []string) map[string]map[string]interface{} {
|
||||
result := make(map[string]map[string]interface{})
|
||||
if len(ids) == 0 {
|
||||
return result
|
||||
}
|
||||
type userRow struct {
|
||||
ID string `gorm:"column:id"`
|
||||
NickName string `gorm:"column:nick_name"`
|
||||
Name string `gorm:"column:name"`
|
||||
AvatarID string `gorm:"column:avatar_id"`
|
||||
}
|
||||
var rows []userRow
|
||||
svcCtx.DB.Table("sundynix_user").Where("id IN ?", ids).Find(&rows)
|
||||
|
||||
var avatarIds []string
|
||||
for _, row := range rows {
|
||||
if row.AvatarID != "" {
|
||||
avatarIds = append(avatarIds, row.AvatarID)
|
||||
}
|
||||
}
|
||||
// 头像通过 FileRpc 获取
|
||||
avatarMap := fetchFileMap(svcCtx, context.Background(), avatarIds)
|
||||
|
||||
for _, row := range rows {
|
||||
avatarData := map[string]interface{}{}
|
||||
if av, ok := avatarMap[row.AvatarID]; ok {
|
||||
avatarData = av
|
||||
}
|
||||
result[row.ID] = map[string]interface{}{
|
||||
"id": row.ID, "nickName": row.NickName, "name": row.Name,
|
||||
"avatarId": row.AvatarID, "avatar": avatarData,
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// queryLikeStarStatus 查询当前用户的点赞/收藏状态
|
||||
func queryLikeStarStatus(svcCtx *svc.ServiceContext, userId string, postIds []string) (likedSet, starredSet map[string]bool) {
|
||||
likedSet = make(map[string]bool)
|
||||
starredSet = make(map[string]bool)
|
||||
if len(postIds) == 0 {
|
||||
return
|
||||
}
|
||||
type rel struct {
|
||||
PostID string `gorm:"column:post_id"`
|
||||
}
|
||||
var likes []rel
|
||||
svcCtx.DB.Table("sundynix_plant_post_like").
|
||||
Where("post_id IN ? AND user_id = ?", postIds, userId).Find(&likes)
|
||||
for _, l := range likes {
|
||||
likedSet[l.PostID] = true
|
||||
}
|
||||
var stars []rel
|
||||
svcCtx.DB.Table("sundynix_plant_user_star").
|
||||
Where("target_id IN ? AND user_id = ? AND type = 'post'", postIds, userId).Find(&stars)
|
||||
for _, s := range stars {
|
||||
starredSet[s.PostID] = true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func buildPublisherInfo(userMap map[string]map[string]interface{}, userId string) map[string]interface{} {
|
||||
if u, ok := userMap[userId]; ok {
|
||||
return u
|
||||
}
|
||||
return map[string]interface{}{
|
||||
"id": userId, "nickName": "", "name": "", "avatarId": "", "avatar": map[string]interface{}{},
|
||||
}
|
||||
}
|
||||
|
||||
func buildCommentList(userMap map[string]map[string]interface{}, comments []*plantModel.PostComment) []map[string]interface{} {
|
||||
var list []map[string]interface{}
|
||||
for _, c := range comments {
|
||||
list = append(list, map[string]interface{}{
|
||||
"id": c.ID, "postId": c.PostID, "userId": c.UserID,
|
||||
"content": c.Content, "parentId": c.ParentID,
|
||||
"createdAt": c.CreatedAt.Format(time.RFC3339),
|
||||
"updatedAt": c.UpdatedAt.Format(time.RFC3339),
|
||||
"createdAtStr": c.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
"commentator": buildPublisherInfo(userMap, c.UserID),
|
||||
})
|
||||
}
|
||||
if list == nil {
|
||||
list = []map[string]interface{}{}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func buildLikeList(userMap map[string]map[string]interface{}, likes []*plantModel.PostLike) []map[string]interface{} {
|
||||
var list []map[string]interface{}
|
||||
for _, l := range likes {
|
||||
list = append(list, map[string]interface{}{
|
||||
"id": l.ID, "postId": l.PostID, "userId": l.UserID,
|
||||
"liker": buildPublisherInfo(userMap, l.UserID),
|
||||
})
|
||||
}
|
||||
if list == nil {
|
||||
list = []map[string]interface{}{}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
// ========== Plant Detail 辅助函数 ==========
|
||||
|
||||
func queryImagesByPlant(svcCtx *svc.ServiceContext, ctx context.Context, plantID string) []map[string]interface{} {
|
||||
type rel struct {
|
||||
OssID string `gorm:"column:sundynix_oss_id"`
|
||||
}
|
||||
var rels []rel
|
||||
svcCtx.DB.Table("sundynix_plant_my_plant_oss").
|
||||
Where("sundynix_my_plant_id = ?", plantID).
|
||||
Order("sundynix_oss_id asc").
|
||||
Find(&rels)
|
||||
var ids []string
|
||||
for _, r := range rels {
|
||||
ids = append(ids, r.OssID)
|
||||
}
|
||||
fileMap := fetchFileMap(svcCtx, ctx, ids)
|
||||
var result []map[string]interface{}
|
||||
for _, id := range ids {
|
||||
if f, ok := fileMap[id]; ok {
|
||||
result = append(result, f)
|
||||
}
|
||||
}
|
||||
if result == nil {
|
||||
result = []map[string]interface{}{}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func queryGrowthImages(svcCtx *svc.ServiceContext, ctx context.Context, records []*plantModel.GrowthRecord) map[string][]map[string]interface{} {
|
||||
if len(records) == 0 {
|
||||
return nil
|
||||
}
|
||||
var ids []string
|
||||
for _, gr := range records {
|
||||
ids = append(ids, gr.ID)
|
||||
}
|
||||
type rel struct {
|
||||
GrowthRecordID string `gorm:"column:growth_record_id"`
|
||||
OssID string `gorm:"column:oss_id"`
|
||||
}
|
||||
var rels []rel
|
||||
svcCtx.DB.Table("sundynix_plant_growth_record_oss").
|
||||
Where("growth_record_id IN ?", ids).
|
||||
Find(&rels)
|
||||
|
||||
var allOssIds []string
|
||||
gidMap := make(map[string][]string)
|
||||
for _, r := range rels {
|
||||
gidMap[r.GrowthRecordID] = append(gidMap[r.GrowthRecordID], r.OssID)
|
||||
allOssIds = append(allOssIds, r.OssID)
|
||||
}
|
||||
fileMap := fetchFileMap(svcCtx, ctx, allOssIds)
|
||||
|
||||
result := make(map[string][]map[string]interface{})
|
||||
for gid, ossIds := range gidMap {
|
||||
var imgs []map[string]interface{}
|
||||
for _, oid := range ossIds {
|
||||
if f, ok := fileMap[oid]; ok {
|
||||
imgs = append(imgs, f)
|
||||
}
|
||||
}
|
||||
result[gid] = imgs
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func toPlantMap(p plantModel.MyPlant) map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"id": p.ID, "createdAt": p.CreatedAt.Format(time.RFC3339),
|
||||
"updatedAt": p.UpdatedAt.Format(time.RFC3339), "createdAtStr": p.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
"userId": p.UserID, "name": p.Name, "plantTime": p.PlantTime.Format(time.RFC3339),
|
||||
"status": p.Status, "placement": p.Placement,
|
||||
"potMaterial": p.PotMaterial, "potSize": p.PotSize,
|
||||
"sunlight": p.Sunlight, "plantingMaterial": p.PlantingMaterial,
|
||||
}
|
||||
}
|
||||
|
||||
func toPlanMapList(plans []*plantModel.CarePlan) []map[string]interface{} {
|
||||
var list []map[string]interface{}
|
||||
for _, p := range plans {
|
||||
list = append(list, map[string]interface{}{
|
||||
"id": p.ID, "createdAt": p.CreatedAt.Format(time.RFC3339),
|
||||
"updatedAt": p.UpdatedAt.Format(time.RFC3339), "createdAtStr": p.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
"userId": p.UserID, "plantId": p.PlantID, "name": p.Name, "icon": p.Icon,
|
||||
"period": p.Period, "targetAction": p.TargetAction,
|
||||
})
|
||||
}
|
||||
if list == nil {
|
||||
list = []map[string]interface{}{}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func toRecordMapList(records []*plantModel.CareRecord) []map[string]interface{} {
|
||||
var list []map[string]interface{}
|
||||
for _, r := range records {
|
||||
list = append(list, map[string]interface{}{
|
||||
"id": r.ID, "createdAt": r.CreatedAt.Format(time.RFC3339),
|
||||
"updatedAt": r.UpdatedAt.Format(time.RFC3339), "createdAtStr": r.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
"userId": r.UserID, "plantId": r.PlantID, "planId": r.PlanID,
|
||||
"name": r.Name, "remark": r.Remark, "icon": r.Icon,
|
||||
})
|
||||
}
|
||||
if list == nil {
|
||||
list = []map[string]interface{}{}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func toGrowthMapList(records []*plantModel.GrowthRecord, imgMap map[string][]map[string]interface{}) []map[string]interface{} {
|
||||
var list []map[string]interface{}
|
||||
for _, gr := range records {
|
||||
imgs := imgMap[gr.ID]
|
||||
if imgs == nil {
|
||||
imgs = []map[string]interface{}{}
|
||||
}
|
||||
list = append(list, map[string]interface{}{
|
||||
"id": gr.ID, "createdAt": gr.CreatedAt.Format(time.RFC3339),
|
||||
"updatedAt": gr.UpdatedAt.Format(time.RFC3339), "createdAtStr": gr.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
"plantId": gr.PlantID, "userId": gr.UserID, "name": gr.Name,
|
||||
"tag": gr.Tag, "desc": gr.Desc, "content": gr.Content,
|
||||
"imgList": imgs,
|
||||
})
|
||||
}
|
||||
if list == nil {
|
||||
list = []map[string]interface{}{}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
// queryOssList 批量查询 Oss 图片信息(供 WikiDetailHandler 使用)
|
||||
func queryOssList(svcCtx *svc.ServiceContext, ossIds []string) []map[string]interface{} {
|
||||
if len(ossIds) == 0 {
|
||||
return []map[string]interface{}{}
|
||||
}
|
||||
type OssRow struct {
|
||||
ID string `gorm:"column:id"`
|
||||
Name string `gorm:"column:name"`
|
||||
Url string `gorm:"column:url"`
|
||||
Tag string `gorm:"column:tag"`
|
||||
Key string `gorm:"column:key"`
|
||||
Suffix string `gorm:"column:suffix"`
|
||||
CreatedAt time.Time `gorm:"column:created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at"`
|
||||
}
|
||||
var rows []OssRow
|
||||
svcCtx.DB.Table("sundynix_oss").Where("id IN ?", ossIds).Find(&rows)
|
||||
ossMap := make(map[string]OssRow)
|
||||
for _, row := range rows {
|
||||
ossMap[row.ID] = row
|
||||
}
|
||||
var result []map[string]interface{}
|
||||
for _, id := range ossIds {
|
||||
if row, ok := ossMap[id]; ok {
|
||||
result = append(result, map[string]interface{}{
|
||||
"id": row.ID, "name": row.Name, "url": row.Url, "tag": row.Tag,
|
||||
"key": row.Key, "suffix": row.Suffix,
|
||||
"createdAt": row.CreatedAt.Format(time.RFC3339),
|
||||
"updatedAt": row.UpdatedAt.Format(time.RFC3339),
|
||||
"createdAtStr": row.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func AiChatSyncHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
resp, err := svcCtx.PlantRpc.SyncAllWikiVector(r.Context(), &plantPb.PageReq{})
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
response.OkWithMsg(w, resp.Msg)
|
||||
}
|
||||
}
|
||||
|
||||
func WikiSyncQdrantHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
wikiID := idFromQuery(r)
|
||||
if wikiID == "" {
|
||||
var req types.IdReq
|
||||
_ = httpx.Parse(r, &req)
|
||||
wikiID = req.Id
|
||||
}
|
||||
if wikiID == "" {
|
||||
response.Fail(w, "wikiId 不能为空")
|
||||
return
|
||||
}
|
||||
if _, err := svcCtx.PlantRpc.SyncWikiVector(r.Context(), &plantPb.SyncWikiVectorReq{WikiId: wikiID}); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
|
||||
func WikiDeleteQdrantHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
wikiID := idFromQuery(r)
|
||||
if wikiID == "" {
|
||||
var req types.IdReq
|
||||
_ = httpx.Parse(r, &req)
|
||||
wikiID = req.Id
|
||||
}
|
||||
if wikiID == "" {
|
||||
response.Fail(w, "wikiId 不能为空")
|
||||
return
|
||||
}
|
||||
if _, err := svcCtx.PlantRpc.DeleteWikiVector(r.Context(), &plantPb.SyncWikiVectorReq{WikiId: wikiID}); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
|
||||
func WikiUploadImgHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
response.FailWithCode(w, 409, "设计/百科图片上传已迁移到 file-api,请先调用文件服务上传,再将返回的文件 id 作为 ossIds 传给 plant")
|
||||
}
|
||||
}
|
||||
|
||||
func BadgeConfigDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
resp, err := svcCtx.PlantRpc.GetBadgeConfigDetail(r.Context(), &plantPb.IdReq{Id: idFromQuery(r)})
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
|
||||
func BadgeConfigDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if _, err := svcCtx.PlantRpc.DeleteBadgeConfig(r.Context(), &plantPb.IdsReq{Ids: []string{idFromQuery(r)}}); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
|
||||
func LevelConfigDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
resp, err := svcCtx.PlantRpc.GetLevelConfigDetail(r.Context(), &plantPb.IdReq{Id: idFromQuery(r)})
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
|
||||
func MediaCheckCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var payload struct {
|
||||
TraceID string `json:"traceId"`
|
||||
PostID string `json:"postId"`
|
||||
OssID string `json:"ossId"`
|
||||
UserID string `json:"userId"`
|
||||
Status int32 `json:"status"`
|
||||
Type int32 `json:"type"`
|
||||
ErrMsg string `json:"errMsg"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := svcCtx.PlantRpc.MediaCheckCallback(r.Context(), &plantPb.MediaCheckCallbackReq{
|
||||
TraceId: payload.TraceID,
|
||||
PostId: payload.PostID,
|
||||
OssId: payload.OssID,
|
||||
UserId: payload.UserID,
|
||||
Status: payload.Status,
|
||||
Type: payload.Type,
|
||||
ErrMsg: payload.ErrMsg,
|
||||
}); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package myPlant
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/myPlant"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 删除养护计划
|
||||
func DeleteCarePlanHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := myPlant.NewDeleteCarePlanLogic(r.Context(), svcCtx)
|
||||
err := l.DeleteCarePlan(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package myPlant
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/myPlant"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
func GetTodayTaskListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := myPlant.NewGetTodayTaskListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetTodayTaskList()
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package myPlant
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/myPlant"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 快捷养护
|
||||
func QuickCareHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.QuickCareReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := myPlant.NewQuickCareLogic(r.Context(), svcCtx)
|
||||
err := l.QuickCare(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package ocr
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/ocr"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 删除识别记录
|
||||
func DeleteClassifyLogHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := ocr.NewDeleteClassifyLogLogic(r.Context(), svcCtx)
|
||||
err := l.DeleteClassifyLog(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package ocr
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/ocr"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
func GetMyClassifyLogHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := ocr.NewGetMyClassifyLogLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetMyClassifyLog()
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,11 +23,11 @@ func OcrClassifyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
|
||||
l := ocr.NewOcrClassifyLogic(r.Context(), svcCtx)
|
||||
err := l.OcrClassify(&req)
|
||||
resp, err := l.OcrClassify(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,11 @@ func GetPostDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
|
||||
l := post.NewGetPostDetailLogic(r.Context(), svcCtx)
|
||||
err := l.GetPostDetail(&req)
|
||||
resp, err := l.GetPostDetail(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,11 @@ func GetPostListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
|
||||
l := post.NewGetPostListLogic(r.Context(), svcCtx)
|
||||
err := l.GetPostList(&req)
|
||||
resp, err := l.GetPostList(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package post
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/post"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
func GetMyPostListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.PostListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
l := post.NewGetMyPostListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetMyPostList(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package post
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/post"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 收藏帖子
|
||||
func StarPostHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := post.NewStarPostLogic(r.Context(), svcCtx)
|
||||
err := l.StarPost(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,12 @@ import (
|
||||
"net/http"
|
||||
|
||||
ai "sundynix-micro-go/app/plant/api/internal/handler/ai"
|
||||
banner "sundynix-micro-go/app/plant/api/internal/handler/banner"
|
||||
callback "sundynix-micro-go/app/plant/api/internal/handler/callback"
|
||||
complete "sundynix-micro-go/app/plant/api/internal/handler/complete"
|
||||
config "sundynix-micro-go/app/plant/api/internal/handler/config"
|
||||
exchange "sundynix-micro-go/app/plant/api/internal/handler/exchange"
|
||||
legacy "sundynix-micro-go/app/plant/api/internal/handler/legacy"
|
||||
myPlant "sundynix-micro-go/app/plant/api/internal/handler/myPlant"
|
||||
ocr "sundynix-micro-go/app/plant/api/internal/handler/ocr"
|
||||
post "sundynix-micro-go/app/plant/api/internal/handler/post"
|
||||
@@ -36,6 +39,24 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/ai/history",
|
||||
Handler: ai.GetAiChatHistoryHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 清空聊天历史
|
||||
Method: http.MethodPost,
|
||||
Path: "/ai/history/clear",
|
||||
Handler: ai.ClearAiChatHistoryHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 删除聊天历史
|
||||
Method: http.MethodPost,
|
||||
Path: "/ai/history/delete",
|
||||
Handler: ai.DeleteAiChatHistoryHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 今日AI额度
|
||||
Method: http.MethodGet,
|
||||
Path: "/ai/quota",
|
||||
Handler: ai.GetAiChatQuotaHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/plant"),
|
||||
@@ -49,6 +70,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/callback/wechatpay",
|
||||
Handler: callback.WechatPayCallbackHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 微信媒体安全回调
|
||||
Method: http.MethodPost,
|
||||
Path: "/callback/mediaCheck",
|
||||
Handler: legacy.MediaCheckCallbackHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithPrefix("/api/plant"),
|
||||
)
|
||||
@@ -56,16 +83,40 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 徽章配置列表
|
||||
// AI聊天历史
|
||||
Method: http.MethodPost,
|
||||
Path: "/config/badge/list",
|
||||
Handler: config.GetBadgeConfigListHandler(serverCtx),
|
||||
Path: "/ai/history",
|
||||
Handler: complete.GetAiChatHistoryHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 等级配置列表
|
||||
// 徽章配置树
|
||||
Method: http.MethodGet,
|
||||
Path: "/config/badge/tree",
|
||||
Handler: complete.GetBadgeConfigTreeHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 等级配置详情
|
||||
Method: http.MethodGet,
|
||||
Path: "/config/level/:id",
|
||||
Handler: complete.GetLevelConfigDetailHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 兑换商品详情
|
||||
Method: http.MethodGet,
|
||||
Path: "/exchange/item/:id",
|
||||
Handler: complete.GetExchangeItemDetailHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 完成养护任务
|
||||
Method: http.MethodPost,
|
||||
Path: "/config/level/list",
|
||||
Handler: config.GetLevelConfigListHandler(serverCtx),
|
||||
Path: "/my/completeTask",
|
||||
Handler: complete.CompleteTaskHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 百科分类详情
|
||||
Method: http.MethodGet,
|
||||
Path: "/wiki/class/:id",
|
||||
Handler: complete.GetWikiClassDetailHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
@@ -74,6 +125,85 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 创建徽章配置
|
||||
Method: http.MethodPost,
|
||||
Path: "/config/badge/create",
|
||||
Handler: config.CreateBadgeConfigHandler(serverCtx),
|
||||
},
|
||||
{Method: http.MethodPost, Path: "/config/badge/add", Handler: config.CreateBadgeConfigHandler(serverCtx)},
|
||||
{
|
||||
// 删除徽章配置
|
||||
Method: http.MethodPost,
|
||||
Path: "/config/badge/delete",
|
||||
Handler: config.DeleteBadgeConfigHandler(serverCtx),
|
||||
},
|
||||
{Method: http.MethodGet, Path: "/config/badge/delete", Handler: legacy.BadgeConfigDeleteHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/config/badge/find", Handler: legacy.BadgeConfigDetailHandler(serverCtx)},
|
||||
{
|
||||
// 徽章配置列表
|
||||
Method: http.MethodPost,
|
||||
Path: "/config/badge/list",
|
||||
Handler: config.GetBadgeConfigListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 更新徽章配置
|
||||
Method: http.MethodPost,
|
||||
Path: "/config/badge/update",
|
||||
Handler: config.UpdateBadgeConfigHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 创建等级配置
|
||||
Method: http.MethodPost,
|
||||
Path: "/config/level/create",
|
||||
Handler: config.CreateLevelConfigHandler(serverCtx),
|
||||
},
|
||||
{Method: http.MethodPost, Path: "/config/level/add", Handler: config.CreateLevelConfigHandler(serverCtx)},
|
||||
{
|
||||
// 删除等级配置
|
||||
Method: http.MethodPost,
|
||||
Path: "/config/level/delete",
|
||||
Handler: config.DeleteLevelConfigHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 等级配置列表
|
||||
Method: http.MethodPost,
|
||||
Path: "/config/level/list",
|
||||
Handler: config.GetLevelConfigListHandler(serverCtx),
|
||||
},
|
||||
{Method: http.MethodGet, Path: "/config/level/list", Handler: config.GetLevelConfigListHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/config/level/detail", Handler: legacy.LevelConfigDetailHandler(serverCtx)},
|
||||
{
|
||||
// 更新等级配置
|
||||
Method: http.MethodPost,
|
||||
Path: "/config/level/update",
|
||||
Handler: config.UpdateLevelConfigHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/plant"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 创建兑换商品
|
||||
Method: http.MethodPost,
|
||||
Path: "/exchange/item/create",
|
||||
Handler: exchange.CreateExchangeItemHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 删除兑换商品
|
||||
Method: http.MethodPost,
|
||||
Path: "/exchange/item/delete",
|
||||
Handler: exchange.DeleteExchangeItemHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 更新兑换商品
|
||||
Method: http.MethodPost,
|
||||
Path: "/exchange/item/update",
|
||||
Handler: exchange.UpdateExchangeItemHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 兑换商品列表
|
||||
Method: http.MethodPost,
|
||||
@@ -81,11 +211,29 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Handler: exchange.GetExchangeItemListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 兑换商品
|
||||
// 我的兑换记录
|
||||
Method: http.MethodPost,
|
||||
Path: "/exchange/myOrders",
|
||||
Handler: exchange.GetMyExchangeOrdersHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 发起兑换
|
||||
Method: http.MethodPost,
|
||||
Path: "/exchange/order",
|
||||
Handler: exchange.CreateExchangeOrderHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 管理端订单列表
|
||||
Method: http.MethodPost,
|
||||
Path: "/exchange/order/list",
|
||||
Handler: exchange.GetExchangeOrderListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 更新订单状态
|
||||
Method: http.MethodPost,
|
||||
Path: "/exchange/order/update",
|
||||
Handler: exchange.UpdateExchangeOrderHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/plant"),
|
||||
@@ -119,10 +267,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
},
|
||||
{
|
||||
// 删除植物
|
||||
Method: http.MethodDelete,
|
||||
Method: http.MethodPost,
|
||||
Path: "/my/delete",
|
||||
Handler: myPlant.DeletePlantHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 删除养护计划
|
||||
Method: http.MethodPost,
|
||||
Path: "/my/deletePlan",
|
||||
Handler: myPlant.DeleteCarePlanHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 添加成长记录
|
||||
Method: http.MethodPost,
|
||||
@@ -135,12 +289,24 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/my/list",
|
||||
Handler: myPlant.GetMyPlantListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 今日养护任务
|
||||
Method: http.MethodGet,
|
||||
Path: "/my/todayTask",
|
||||
Handler: myPlant.GetTodayTaskListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 更新植物
|
||||
Method: http.MethodPut,
|
||||
Method: http.MethodPost,
|
||||
Path: "/my/update",
|
||||
Handler: myPlant.UpdatePlantHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 快捷养护
|
||||
Method: http.MethodPost,
|
||||
Path: "/my/quickCare",
|
||||
Handler: myPlant.QuickCareHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/plant"),
|
||||
@@ -154,6 +320,18 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/ocr/classify",
|
||||
Handler: ocr.OcrClassifyHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 删除识别记录
|
||||
Method: http.MethodPost,
|
||||
Path: "/ocr/deleteLog",
|
||||
Handler: ocr.DeleteClassifyLogHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 我的识别记录
|
||||
Method: http.MethodGet,
|
||||
Path: "/ocr/myLog",
|
||||
Handler: ocr.GetMyClassifyLogHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/plant"),
|
||||
@@ -181,7 +359,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
},
|
||||
{
|
||||
// 删除帖子
|
||||
Method: http.MethodDelete,
|
||||
Method: http.MethodPost,
|
||||
Path: "/post/delete",
|
||||
Handler: post.DeletePostHandler(serverCtx),
|
||||
},
|
||||
@@ -197,6 +375,18 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/post/list",
|
||||
Handler: post.GetPostListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 我的帖子
|
||||
Method: http.MethodPost,
|
||||
Path: "/post/my",
|
||||
Handler: post.GetMyPostListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 收藏帖子
|
||||
Method: http.MethodPost,
|
||||
Path: "/post/star",
|
||||
Handler: post.StarPostHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/plant"),
|
||||
@@ -204,6 +394,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 话题详情
|
||||
Method: http.MethodGet,
|
||||
Path: "/topic/:id",
|
||||
Handler: topic.GetTopicDetailHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 创建话题
|
||||
Method: http.MethodPost,
|
||||
@@ -212,7 +408,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
},
|
||||
{
|
||||
// 删除话题
|
||||
Method: http.MethodDelete,
|
||||
Method: http.MethodPost,
|
||||
Path: "/topic/delete",
|
||||
Handler: topic.DeleteTopicHandler(serverCtx),
|
||||
},
|
||||
@@ -222,6 +418,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/topic/list",
|
||||
Handler: topic.GetTopicListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 更新话题
|
||||
Method: http.MethodPost,
|
||||
Path: "/topic/update",
|
||||
Handler: topic.UpdateTopicHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/plant"),
|
||||
@@ -229,15 +431,28 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 我的徽章
|
||||
Method: http.MethodGet,
|
||||
Path: "/profile/badge",
|
||||
Handler: userProfile.GetMyBadgesHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 获取用户资料
|
||||
Method: http.MethodGet,
|
||||
Path: "/profile/info",
|
||||
Handler: userProfile.GetUserProfileHandler(serverCtx),
|
||||
},
|
||||
{Method: http.MethodGet, Path: "/profile/detail", Handler: userProfile.GetUserProfileHandler(serverCtx)},
|
||||
{
|
||||
// 我的收藏
|
||||
Method: http.MethodPost,
|
||||
Path: "/profile/star",
|
||||
Handler: userProfile.GetMyStarsHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 更新用户资料
|
||||
Method: http.MethodPut,
|
||||
Method: http.MethodPost,
|
||||
Path: "/profile/update",
|
||||
Handler: userProfile.UpdateUserProfileHandler(serverCtx),
|
||||
},
|
||||
@@ -260,12 +475,36 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/wiki/class/create",
|
||||
Handler: wiki.CreateWikiClassHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 删除百科分类
|
||||
Method: http.MethodPost,
|
||||
Path: "/wiki/class/delete",
|
||||
Handler: wiki.DeleteWikiClassHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 百科分类列表
|
||||
Method: http.MethodGet,
|
||||
Path: "/wiki/class/list",
|
||||
Handler: wiki.GetWikiClassListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 更新百科分类
|
||||
Method: http.MethodPost,
|
||||
Path: "/wiki/class/update",
|
||||
Handler: wiki.UpdateWikiClassHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 创建百科
|
||||
Method: http.MethodPost,
|
||||
Path: "/wiki/create",
|
||||
Handler: wiki.CreateWikiHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 删除百科
|
||||
Method: http.MethodPost,
|
||||
Path: "/wiki/delete",
|
||||
Handler: wiki.DeleteWikiHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 百科列表
|
||||
Method: http.MethodPost,
|
||||
@@ -278,6 +517,111 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/wiki/star",
|
||||
Handler: wiki.ToggleWikiStarHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 更新百科
|
||||
Method: http.MethodPost,
|
||||
Path: "/wiki/update",
|
||||
Handler: wiki.UpdateWikiHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/plant"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 创建Banner
|
||||
Method: http.MethodPost,
|
||||
Path: "/banner/create",
|
||||
Handler: banner.CreateBannerHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 删除Banner
|
||||
Method: http.MethodPost,
|
||||
Path: "/banner/delete",
|
||||
Handler: banner.DeleteBannerHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 更新Banner
|
||||
Method: http.MethodPost,
|
||||
Path: "/banner/update",
|
||||
Handler: banner.UpdateBannerHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// Banner列表(管理端)
|
||||
Method: http.MethodPost,
|
||||
Path: "/banner/list",
|
||||
Handler: banner.GetBannerListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 启用的Banner列表(客户端)
|
||||
Method: http.MethodGet,
|
||||
Path: "/banner/activeList",
|
||||
Handler: banner.GetActiveBannerListHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/plant"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{Method: http.MethodPost, Path: "/add", Handler: myPlant.CreatePlantHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/page", Handler: myPlant.GetMyPlantListHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/detail", Handler: legacy.PlantDetailHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/update", Handler: myPlant.UpdatePlantHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/deletePlant", Handler: myPlant.DeletePlantHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/deletePlan", Handler: myPlant.DeleteCarePlanHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/plan/add", Handler: myPlant.AddCarePlanHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/plan/delete", Handler: legacy.DeletePlanHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/todayTask", Handler: myPlant.GetTodayTaskListHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/completeTask", Handler: complete.CompleteTaskHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/growth/add", Handler: myPlant.AddGrowthRecordHandler(serverCtx)},
|
||||
|
||||
{Method: http.MethodPost, Path: "/wiki/add", Handler: wiki.CreateWikiHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/wiki/page", Handler: legacy.WikiPageHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/wiki/detail", Handler: legacy.WikiDetailHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/wiki/uploadImg", Handler: legacy.WikiUploadImgHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/wiki/sync-qdrant", Handler: legacy.WikiSyncQdrantHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/wiki/delete-qdrant", Handler: legacy.WikiDeleteQdrantHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/wiki/star", Handler: legacy.WikiStarHandler(serverCtx)},
|
||||
|
||||
{Method: http.MethodPost, Path: "/wiki-class/add", Handler: wiki.CreateWikiClassHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/wiki-class/update", Handler: wiki.UpdateWikiClassHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/wiki-class/page", Handler: wiki.GetWikiClassListHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/wiki-class/delete", Handler: wiki.DeleteWikiClassHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/wiki-class/list", Handler: wiki.GetWikiClassListHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/wiki-class/detail", Handler: complete.GetWikiClassDetailHandler(serverCtx)},
|
||||
|
||||
{Method: http.MethodPost, Path: "/post/publish", Handler: post.CreatePostHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/post/page", Handler: legacy.PostPageHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/post/myPost", Handler: legacy.MyPostPageHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/post/like", Handler: legacy.LikePostHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/post/star", Handler: legacy.StarPostHandler(serverCtx)},
|
||||
|
||||
{Method: http.MethodPost, Path: "/topic/add", Handler: topic.CreateTopicHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/topic/page", Handler: topic.GetTopicListHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/topic/detail", Handler: legacy.TopicDetailHandler(serverCtx)},
|
||||
|
||||
{Method: http.MethodPost, Path: "/classify/plant", Handler: ocr.OcrClassifyHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/classify/myClassifyLog", Handler: ocr.GetMyClassifyLogHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/classify/deleteClassifyLog", Handler: ocr.DeleteClassifyLogHandler(serverCtx)},
|
||||
|
||||
{Method: http.MethodGet, Path: "/exchange/list", Handler: exchange.GetExchangeItemListHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/exchange/detail", Handler: legacy.ExchangeItemDetailHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/exchange/redeem", Handler: exchange.CreateExchangeOrderHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/exchange/orders", Handler: exchange.GetMyExchangeOrdersHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/exchange/item/list", Handler: exchange.GetExchangeItemListHandler(serverCtx)},
|
||||
|
||||
{Method: http.MethodGet, Path: "/chat/history", Handler: ai.GetAiChatHistoryHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/chat/history/delete", Handler: ai.DeleteAiChatHistoryHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/chat/history/clear", Handler: ai.ClearAiChatHistoryHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/chat/quota", Handler: ai.GetAiChatQuotaHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/chat/sync", Handler: legacy.AiChatSyncHandler(serverCtx)},
|
||||
|
||||
// 快捷养护(旧版兼容)
|
||||
{Method: http.MethodPost, Path: "/quickCare", Handler: myPlant.QuickCareHandler(serverCtx)},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/plant"),
|
||||
|
||||
@@ -15,11 +15,11 @@ import (
|
||||
func GetTopicListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := topic.NewGetTopicListLogic(r.Context(), svcCtx)
|
||||
err := l.GetTopicList()
|
||||
resp, err := l.GetTopicList()
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package topic
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/topic"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
func GetTopicDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdPathReq
|
||||
if err := httpx.ParsePath(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
l := topic.NewGetTopicDetailLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetTopicDetail(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package topic
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/topic"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 更新话题
|
||||
func UpdateTopicHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateTopicReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := topic.NewUpdateTopicLogic(r.Context(), svcCtx)
|
||||
err := l.UpdateTopic(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,11 +15,11 @@ import (
|
||||
func GetUserProfileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := userProfile.NewGetUserProfileLogic(r.Context(), svcCtx)
|
||||
err := l.GetUserProfile()
|
||||
resp, err := l.GetUserProfile()
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package userProfile
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/userProfile"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
func GetMyBadgesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := userProfile.NewGetMyBadgesLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetMyBadges()
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package userProfile
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/userProfile"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
func GetMyStarsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.PageReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
l := userProfile.NewGetMyStarsLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetMyStars(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/wiki"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 创建百科
|
||||
func CreateWikiHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CreateWikiReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := wiki.NewCreateWikiLogic(r.Context(), svcCtx)
|
||||
err := l.CreateWiki(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/wiki"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 删除百科分类
|
||||
func DeleteWikiClassHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := wiki.NewDeleteWikiClassLogic(r.Context(), svcCtx)
|
||||
err := l.DeleteWikiClass(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/wiki"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 删除百科
|
||||
func DeleteWikiHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := wiki.NewDeleteWikiLogic(r.Context(), svcCtx)
|
||||
err := l.DeleteWiki(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,11 +15,11 @@ import (
|
||||
func GetWikiClassListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := wiki.NewGetWikiClassListLogic(r.Context(), svcCtx)
|
||||
err := l.GetWikiClassList()
|
||||
resp, err := l.GetWikiClassList()
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,11 @@ func GetWikiDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
|
||||
l := wiki.NewGetWikiDetailLogic(r.Context(), svcCtx)
|
||||
err := l.GetWikiDetail(&req)
|
||||
resp, err := l.GetWikiDetail(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,11 @@ func GetWikiListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
|
||||
l := wiki.NewGetWikiListLogic(r.Context(), svcCtx)
|
||||
err := l.GetWikiList(&req)
|
||||
resp, err := l.GetWikiList(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/wiki"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 更新百科分类
|
||||
func UpdateWikiClassHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateWikiClassReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := wiki.NewUpdateWikiClassLogic(r.Context(), svcCtx)
|
||||
err := l.UpdateWikiClass(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/wiki"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 更新百科
|
||||
func UpdateWikiHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateWikiReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := wiki.NewUpdateWikiLogic(r.Context(), svcCtx)
|
||||
err := l.UpdateWiki(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user