feat: add wechat pay

This commit is contained in:
Rogee
2025-01-14 14:42:08 +08:00
parent 52c17b63bb
commit 9cd7659d14
32 changed files with 1431 additions and 110 deletions

View File

@@ -1,6 +1,7 @@
package posts
import (
"backend/app/http/tenants"
"backend/app/requests"
"backend/database/models/qvyun_v2/public/model"
"backend/providers/jwt"
@@ -13,8 +14,9 @@ import (
// @provider
type Controller struct {
svc *Service
log *log.Entry `inject:"false"`
tenantSvc *tenants.Service
svc *Service
log *log.Entry `inject:"false"`
}
func (c *Controller) Prepare() error {
@@ -24,16 +26,22 @@ func (c *Controller) Prepare() error {
// List show posts list
// @Router /api/v1/posts [get]
// @Bind tenantSlug cookie key(tenant)
// @Bind claim local
// @Bind pagination query
// @Bind filter query
func (c *Controller) List(ctx fiber.Ctx, claim *jwt.Claims, pagination *requests.Pagination, filter *UserPostFilter) (*requests.Pager, error) {
func (c *Controller) List(ctx fiber.Ctx, tenantSlug string, claim *jwt.Claims, pagination *requests.Pagination, filter *UserPostFilter) (*requests.Pager, error) {
tenant, err := c.tenantSvc.GetTenantBySlug(ctx.Context(), tenantSlug)
if err != nil {
return nil, err
}
pagination.Format()
pager := &requests.Pager{
Pagination: *pagination,
}
filter.TenantID = *claim.TenantID
filter.TenantID = tenant.ID
filter.UserID = claim.UserID
orders, total, err := c.svc.GetPosts(ctx.Context(), pagination, filter)
if err != nil {
@@ -51,3 +59,64 @@ func (c *Controller) List(ctx fiber.Ctx, claim *jwt.Claims, pagination *requests
return pager, nil
}
// ListBought show user bought posts list
// @Router /api/v1/bought-posts [get]
// @Bind tenantSlug cookie key(tenant)
// @Bind claim local
// @Bind pagination query
// @Bind filter query
func (c *Controller) ListBought(ctx fiber.Ctx, tenantSlug string, claim *jwt.Claims, pagination *requests.Pagination, filter *UserPostFilter) (*requests.Pager, error) {
tenant, err := c.tenantSvc.GetTenantBySlug(ctx.Context(), tenantSlug)
if err != nil {
return nil, err
}
pagination.Format()
pager := &requests.Pager{
Pagination: *pagination,
}
filter.TenantID = tenant.ID
filter.UserID = claim.UserID
orders, total, err := c.svc.GetBoughtPosts(ctx.Context(), pagination, filter)
if err != nil {
return nil, err
}
pager.Total = total
pager.Items = lo.FilterMap(orders, func(item model.Posts, _ int) (UserPost, bool) {
var o UserPost
if err := copier.Copy(&o, item); err != nil {
return o, false
}
return o, true
})
return pager, nil
}
// Show show posts detail
// @Router /api/v1/show/:hash [get]
// @Bind claim local
// @Bind tenantSlug cookie key(tenant)
// @Bind hash path
func (c *Controller) Show(ctx fiber.Ctx, claim *jwt.Claims, tenantSlug, hash string) (*UserPost, error) {
userPost := &UserPost{}
tenant, err := c.tenantSvc.GetTenantBySlug(ctx.Context(), tenantSlug)
if err != nil {
return nil, err
}
post, err := c.svc.GetPostByHash(ctx.Context(), tenant.ID, hash)
if err != nil {
return nil, err
}
if err := copier.Copy(userPost, post); err != nil {
return nil, err
}
return userPost, nil
}