Skip to content

Commit

Permalink
feat(wechat): add get media material list
Browse files Browse the repository at this point in the history
  • Loading branch information
Matrix-X committed Oct 18, 2023
1 parent 744e741 commit d73208b
Show file tree
Hide file tree
Showing 16 changed files with 478 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/admin.wechat.offiaccount.api
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"

89 changes: 89 additions & 0 deletions api/admin/wechat/officialaccount/media.api
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"`
}
)
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)
}
}
}
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)
}
}
}
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)
}
}
}
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)
}
}
}
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)
}
}
}
35 changes: 35 additions & 0 deletions internal/handler/routes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
}
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
}
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
}
Loading

0 comments on commit d73208b

Please sign in to comment.