-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wechat): add get media material list
- Loading branch information
Showing
16 changed files
with
478 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
import "admin/wechat/officialaccount/menu.api" | ||
import "admin/wechat/officialaccount/media.api" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
syntax = "v1" | ||
|
||
info( | ||
title: "菜单管理" | ||
desc: "菜单管理" | ||
author: "MichaelHu" | ||
email: "[email protected]" | ||
version: "v1" | ||
) | ||
|
||
@server( | ||
group: admin/wechat/officialaccount/media | ||
prefix: /api/v1/admin/wechat/official-account | ||
middleware: EmployeeJWTAuth | ||
) | ||
|
||
service PowerX { | ||
@doc "查询菜单列表" | ||
@handler GetMediaList | ||
post /medias/page-list (GetOAMediaListRequest) returns (GetOAMediaListReply) | ||
|
||
@doc "查询菜单列表" | ||
@handler GetOAMediaNewsList | ||
get /media/news/list returns (GetOAMediaNewsListReply) | ||
|
||
@doc "请求菜单上传链接" | ||
@handler GetOAMedia | ||
post /medias/:mediaId (GetOAMediaRequest) returns (GetOAMediaReply) | ||
|
||
|
||
@doc "创建菜单" | ||
@handler CreateOAMedia | ||
post /medias (CreateOAMediaRequest) returns (CreateOAMediaReply) | ||
|
||
@doc "删除菜单" | ||
@handler DeleteOAMedia | ||
delete /medias/:mediaId (DeleteOAMediaRequest) returns (DeleteOAMediaReply) | ||
} | ||
|
||
|
||
type ( | ||
GetOAMediaListRequest struct { | ||
Offset int64 `json:"offset,optional"` | ||
Count int64 `json:"count,optional"` | ||
MediaType string `json:"type"` | ||
} | ||
GetOAMediaListReply struct { | ||
TotalCount interface{} `json:"total_count"` | ||
ItemCount interface{} `json:"item_count"` | ||
Item interface{} `json:"item"` | ||
} | ||
|
||
GetOAMediaNewsListReply struct { | ||
NewsItem interface{} `json:"news_item"` | ||
} | ||
) | ||
|
||
type ( | ||
CreateOAMediaRequest struct { | ||
OAMedia interface{} `json:"media"` | ||
} | ||
|
||
CreateOAMediaReply struct { | ||
Success bool `json:"success,optional"` | ||
Data interface{} `json:"data"` | ||
} | ||
) | ||
|
||
type ( | ||
GetOAMediaRequest struct { | ||
MediaId string `path:"mediaId"` | ||
} | ||
|
||
GetOAMediaReply struct { | ||
OAMedia interface{} `json:"media"` | ||
} | ||
) | ||
|
||
|
||
type ( | ||
DeleteOAMediaRequest struct { | ||
MediaId string `path:"mediaId"` | ||
} | ||
|
||
DeleteOAMediaReply struct { | ||
Success bool `json:"success"` | ||
Data interface{} `json:"data"` | ||
} | ||
) |
28 changes: 28 additions & 0 deletions
28
internal/handler/admin/wechat/officialaccount/media/createoamediahandler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package media | ||
|
||
import ( | ||
"net/http" | ||
|
||
"PowerX/internal/logic/admin/wechat/officialaccount/media" | ||
"PowerX/internal/svc" | ||
"PowerX/internal/types" | ||
"github.com/zeromicro/go-zero/rest/httpx" | ||
) | ||
|
||
func CreateOAMediaHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
var req types.CreateOAMediaRequest | ||
if err := httpx.Parse(r, &req); err != nil { | ||
httpx.ErrorCtx(r.Context(), w, err) | ||
return | ||
} | ||
|
||
l := media.NewCreateOAMediaLogic(r.Context(), svcCtx) | ||
resp, err := l.CreateOAMedia(&req) | ||
if err != nil { | ||
httpx.ErrorCtx(r.Context(), w, err) | ||
} else { | ||
httpx.OkJsonCtx(r.Context(), w, resp) | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
internal/handler/admin/wechat/officialaccount/media/deleteoamediahandler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package media | ||
|
||
import ( | ||
"net/http" | ||
|
||
"PowerX/internal/logic/admin/wechat/officialaccount/media" | ||
"PowerX/internal/svc" | ||
"PowerX/internal/types" | ||
"github.com/zeromicro/go-zero/rest/httpx" | ||
) | ||
|
||
func DeleteOAMediaHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
var req types.DeleteOAMediaRequest | ||
if err := httpx.Parse(r, &req); err != nil { | ||
httpx.ErrorCtx(r.Context(), w, err) | ||
return | ||
} | ||
|
||
l := media.NewDeleteOAMediaLogic(r.Context(), svcCtx) | ||
resp, err := l.DeleteOAMedia(&req) | ||
if err != nil { | ||
httpx.ErrorCtx(r.Context(), w, err) | ||
} else { | ||
httpx.OkJsonCtx(r.Context(), w, resp) | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
internal/handler/admin/wechat/officialaccount/media/getmedialisthandler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package media | ||
|
||
import ( | ||
"net/http" | ||
|
||
"PowerX/internal/logic/admin/wechat/officialaccount/media" | ||
"PowerX/internal/svc" | ||
"PowerX/internal/types" | ||
"github.com/zeromicro/go-zero/rest/httpx" | ||
) | ||
|
||
func GetMediaListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
var req types.GetOAMediaListRequest | ||
if err := httpx.Parse(r, &req); err != nil { | ||
httpx.ErrorCtx(r.Context(), w, err) | ||
return | ||
} | ||
|
||
l := media.NewGetMediaListLogic(r.Context(), svcCtx) | ||
resp, err := l.GetMediaList(&req) | ||
if err != nil { | ||
httpx.ErrorCtx(r.Context(), w, err) | ||
} else { | ||
httpx.OkJsonCtx(r.Context(), w, resp) | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
internal/handler/admin/wechat/officialaccount/media/getoamediahandler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package media | ||
|
||
import ( | ||
"net/http" | ||
|
||
"PowerX/internal/logic/admin/wechat/officialaccount/media" | ||
"PowerX/internal/svc" | ||
"PowerX/internal/types" | ||
"github.com/zeromicro/go-zero/rest/httpx" | ||
) | ||
|
||
func GetOAMediaHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
var req types.GetOAMediaRequest | ||
if err := httpx.Parse(r, &req); err != nil { | ||
httpx.ErrorCtx(r.Context(), w, err) | ||
return | ||
} | ||
|
||
l := media.NewGetOAMediaLogic(r.Context(), svcCtx) | ||
resp, err := l.GetOAMedia(&req) | ||
if err != nil { | ||
httpx.ErrorCtx(r.Context(), w, err) | ||
} else { | ||
httpx.OkJsonCtx(r.Context(), w, resp) | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
internal/handler/admin/wechat/officialaccount/media/getoamedianewslisthandler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package media | ||
|
||
import ( | ||
"net/http" | ||
|
||
"PowerX/internal/logic/admin/wechat/officialaccount/media" | ||
"PowerX/internal/svc" | ||
"github.com/zeromicro/go-zero/rest/httpx" | ||
) | ||
|
||
func GetOAMediaNewsListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
l := media.NewGetOAMediaNewsListLogic(r.Context(), svcCtx) | ||
resp, err := l.GetOAMediaNewsList() | ||
if err != nil { | ||
httpx.ErrorCtx(r.Context(), w, err) | ||
} else { | ||
httpx.OkJsonCtx(r.Context(), w, resp) | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
internal/logic/admin/wechat/officialaccount/media/createoamedialogic.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package media | ||
|
||
import ( | ||
"context" | ||
|
||
"PowerX/internal/svc" | ||
"PowerX/internal/types" | ||
|
||
"github.com/zeromicro/go-zero/core/logx" | ||
) | ||
|
||
type CreateOAMediaLogic struct { | ||
logx.Logger | ||
ctx context.Context | ||
svcCtx *svc.ServiceContext | ||
} | ||
|
||
func NewCreateOAMediaLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOAMediaLogic { | ||
return &CreateOAMediaLogic{ | ||
Logger: logx.WithContext(ctx), | ||
ctx: ctx, | ||
svcCtx: svcCtx, | ||
} | ||
} | ||
|
||
func (l *CreateOAMediaLogic) CreateOAMedia(req *types.CreateOAMediaRequest) (resp *types.CreateOAMediaReply, err error) { | ||
// todo: add your logic here and delete this line | ||
|
||
return | ||
} |
30 changes: 30 additions & 0 deletions
30
internal/logic/admin/wechat/officialaccount/media/deleteoamedialogic.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package media | ||
|
||
import ( | ||
"context" | ||
|
||
"PowerX/internal/svc" | ||
"PowerX/internal/types" | ||
|
||
"github.com/zeromicro/go-zero/core/logx" | ||
) | ||
|
||
type DeleteOAMediaLogic struct { | ||
logx.Logger | ||
ctx context.Context | ||
svcCtx *svc.ServiceContext | ||
} | ||
|
||
func NewDeleteOAMediaLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteOAMediaLogic { | ||
return &DeleteOAMediaLogic{ | ||
Logger: logx.WithContext(ctx), | ||
ctx: ctx, | ||
svcCtx: svcCtx, | ||
} | ||
} | ||
|
||
func (l *DeleteOAMediaLogic) DeleteOAMedia(req *types.DeleteOAMediaRequest) (resp *types.DeleteOAMediaReply, err error) { | ||
// todo: add your logic here and delete this line | ||
|
||
return | ||
} |
49 changes: 49 additions & 0 deletions
49
internal/logic/admin/wechat/officialaccount/media/getmedialistlogic.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package media | ||
|
||
import ( | ||
"PowerX/internal/svc" | ||
"PowerX/internal/types" | ||
"PowerX/internal/types/errorx" | ||
"context" | ||
"github.com/ArtisanCloud/PowerWeChat/v3/src/officialAccount/material/request" | ||
|
||
"github.com/zeromicro/go-zero/core/logx" | ||
) | ||
|
||
type GetMediaListLogic struct { | ||
logx.Logger | ||
ctx context.Context | ||
svcCtx *svc.ServiceContext | ||
} | ||
|
||
func NewGetMediaListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMediaListLogic { | ||
return &GetMediaListLogic{ | ||
Logger: logx.WithContext(ctx), | ||
ctx: ctx, | ||
svcCtx: svcCtx, | ||
} | ||
} | ||
|
||
func (l *GetMediaListLogic) GetMediaList(req *types.GetOAMediaListRequest) (resp *types.GetOAMediaListReply, err error) { | ||
|
||
if req.Count <= 0 { | ||
req.Count = 10 | ||
} | ||
res, err := l.svcCtx.PowerX.WechatOA.App.Material.List(l.ctx, &request.RequestMaterialBatchGetMaterial{ | ||
Type: req.MediaType, | ||
Offset: req.Offset, | ||
Count: req.Count, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if res.ErrCode != 0 { | ||
return nil, errorx.WithCause(errorx.ErrNotFoundObject, res.ErrMsg) | ||
} | ||
|
||
return &types.GetOAMediaListReply{ | ||
TotalCount: res.TotalCount, | ||
ItemCount: res.ItemCount, | ||
Item: res.Item, | ||
}, nil | ||
} |
Oops, something went wrong.