mirror of https://github.com/rocboss/paopao-ce
commit
8921655de5
@ -1,24 +1,36 @@
|
|||||||
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/rocboss/paopao-ce/internal/model"
|
"github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
Comment = dbr.Comment
|
||||||
|
CommentFormated = dbr.CommentFormated
|
||||||
|
CommentReply = dbr.CommentReply
|
||||||
|
CommentContent = dbr.CommentContent
|
||||||
|
CommentReplyFormated = dbr.CommentReplyFormated
|
||||||
)
|
)
|
||||||
|
|
||||||
// CommentService 评论检索服务
|
// CommentService 评论检索服务
|
||||||
type CommentService interface {
|
type CommentService interface {
|
||||||
GetComments(conditions *model.ConditionsT, offset, limit int) ([]*model.Comment, error)
|
GetComments(conditions *ConditionsT, offset, limit int) ([]*Comment, error)
|
||||||
GetCommentByID(id int64) (*model.Comment, error)
|
GetCommentByID(id int64) (*Comment, error)
|
||||||
GetCommentCount(conditions *model.ConditionsT) (int64, error)
|
GetCommentCount(conditions *ConditionsT) (int64, error)
|
||||||
GetCommentReplyByID(id int64) (*model.CommentReply, error)
|
GetCommentReplyByID(id int64) (*CommentReply, error)
|
||||||
GetCommentContentsByIDs(ids []int64) ([]*model.CommentContent, error)
|
GetCommentContentsByIDs(ids []int64) ([]*CommentContent, error)
|
||||||
GetCommentRepliesByID(ids []int64) ([]*model.CommentReplyFormated, error)
|
GetCommentRepliesByID(ids []int64) ([]*CommentReplyFormated, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommentManageService 评论管理服务
|
// CommentManageService 评论管理服务
|
||||||
type CommentManageService interface {
|
type CommentManageService interface {
|
||||||
DeleteComment(comment *model.Comment) error
|
DeleteComment(comment *Comment) error
|
||||||
CreateComment(comment *model.Comment) (*model.Comment, error)
|
CreateComment(comment *Comment) (*Comment, error)
|
||||||
CreateCommentReply(reply *model.CommentReply) (*model.CommentReply, error)
|
CreateCommentReply(reply *CommentReply) (*CommentReply, error)
|
||||||
DeleteCommentReply(reply *model.CommentReply) error
|
DeleteCommentReply(reply *CommentReply) error
|
||||||
CreateCommentContent(content *model.CommentContent) (*model.CommentContent, error)
|
CreateCommentContent(content *CommentContent) (*CommentContent, error)
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,36 @@
|
|||||||
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/rocboss/paopao-ce/internal/model"
|
"github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
MsgTypePost = dbr.MsgTypePost
|
||||||
|
MsgtypeComment = dbr.MsgtypeComment
|
||||||
|
MsgTypeReply = dbr.MsgTypeReply
|
||||||
|
MsgTypeWhisper = dbr.MsgTypeWhisper
|
||||||
|
MsgTypeRequestingFriend = dbr.MsgTypeRequestingFriend
|
||||||
|
MsgTypeSystem = dbr.MsgTypeSystem
|
||||||
|
|
||||||
|
MsgStatusUnread = dbr.MsgStatusUnread
|
||||||
|
MsgStatusReaded = dbr.MsgStatusReaded
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
Message = dbr.Message
|
||||||
|
MessageFormated = dbr.MessageFormated
|
||||||
)
|
)
|
||||||
|
|
||||||
// MessageService 消息服务
|
// MessageService 消息服务
|
||||||
type MessageService interface {
|
type MessageService interface {
|
||||||
CreateMessage(msg *model.Message) (*model.Message, error)
|
CreateMessage(msg *Message) (*Message, error)
|
||||||
GetUnreadCount(userID int64) (int64, error)
|
GetUnreadCount(userID int64) (int64, error)
|
||||||
GetMessageByID(id int64) (*model.Message, error)
|
GetMessageByID(id int64) (*Message, error)
|
||||||
ReadMessage(message *model.Message) error
|
ReadMessage(message *Message) error
|
||||||
GetMessages(conditions *model.ConditionsT, offset, limit int) ([]*model.MessageFormated, error)
|
GetMessages(conditions *ConditionsT, offset, limit int) ([]*MessageFormated, error)
|
||||||
GetMessageCount(conditions *model.ConditionsT) (int64, error)
|
GetMessageCount(conditions *ConditionsT) (int64, error)
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,22 @@
|
|||||||
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/rocboss/paopao-ce/internal/model"
|
"github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
Tag = dbr.Tag
|
||||||
|
TagFormated = dbr.TagFormated
|
||||||
)
|
)
|
||||||
|
|
||||||
// TopicService 话题服务
|
// TopicService 话题服务
|
||||||
type TopicService interface {
|
type TopicService interface {
|
||||||
CreateTag(tag *model.Tag) (*model.Tag, error)
|
CreateTag(tag *Tag) (*Tag, error)
|
||||||
DeleteTag(tag *model.Tag) error
|
DeleteTag(tag *Tag) error
|
||||||
GetTags(conditions *model.ConditionsT, offset, limit int) ([]*model.Tag, error)
|
GetTags(conditions *ConditionsT, offset, limit int) ([]*Tag, error)
|
||||||
GetTagsByKeyword(keyword string) ([]*model.Tag, error)
|
GetTagsByKeyword(keyword string) ([]*Tag, error)
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
UserStatusNormal = dbr.UserStatusNormal
|
||||||
|
UserStatusClosed = dbr.UserStatusClosed
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
User = dbr.User
|
||||||
|
Post = dbr.Post
|
||||||
|
ConditionsT = dbr.ConditionsT
|
||||||
|
PostFormated = dbr.PostFormated
|
||||||
|
UserFormated = dbr.UserFormated
|
||||||
|
PostContentFormated = dbr.PostContentFormated
|
||||||
|
Model = dbr.Model
|
||||||
|
)
|
@ -1,15 +1,24 @@
|
|||||||
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/rocboss/paopao-ce/internal/model"
|
"github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
WalletStatement = dbr.WalletStatement
|
||||||
|
WalletRecharge = dbr.WalletRecharge
|
||||||
)
|
)
|
||||||
|
|
||||||
// WalletService wallet service interface
|
// WalletService wallet service interface
|
||||||
type WalletService interface {
|
type WalletService interface {
|
||||||
GetUserWalletBills(userID int64, offset, limit int) ([]*model.WalletStatement, error)
|
GetUserWalletBills(userID int64, offset, limit int) ([]*WalletStatement, error)
|
||||||
GetUserWalletBillCount(userID int64) (int64, error)
|
GetUserWalletBillCount(userID int64) (int64, error)
|
||||||
GetRechargeByID(id int64) (*model.WalletRecharge, error)
|
GetRechargeByID(id int64) (*WalletRecharge, error)
|
||||||
CreateRecharge(userId, amount int64) (*model.WalletRecharge, error)
|
CreateRecharge(userId, amount int64) (*WalletRecharge, error)
|
||||||
HandleRechargeSuccess(recharge *model.WalletRecharge, tradeNo string) error
|
HandleRechargeSuccess(recharge *WalletRecharge, tradeNo string) error
|
||||||
HandlePostAttachmentBought(post *model.Post, user *model.User) error
|
HandlePostAttachmentBought(post *Post, user *User) error
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import "gorm.io/gorm"
|
import "gorm.io/gorm"
|
||||||
|
|
||||||
type AttachmentType int
|
type AttachmentType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ATTACHMENT_TYPE_IMAGE AttachmentType = iota + 1
|
AttachmentTypeImage AttachmentType = iota + 1
|
||||||
ATTACHMENT_TYPE_VIDEO
|
AttachmentTypeVideo
|
||||||
ATTACHMENT_TYPE_OTHER
|
AttachmentTypeOther
|
||||||
)
|
)
|
||||||
|
|
||||||
type Attachment struct {
|
type Attachment struct {
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import "gorm.io/gorm"
|
import "gorm.io/gorm"
|
||||||
|
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import "gorm.io/gorm"
|
import "gorm.io/gorm"
|
||||||
|
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import "gorm.io/gorm"
|
import "gorm.io/gorm"
|
||||||
|
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import "gorm.io/gorm"
|
import "gorm.io/gorm"
|
||||||
|
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import "gorm.io/gorm"
|
import "gorm.io/gorm"
|
||||||
|
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import "gorm.io/gorm"
|
import "gorm.io/gorm"
|
||||||
|
|
@ -0,0 +1 @@
|
|||||||
|
### RESTful API for paopao-ce use [go-mir](https://github.com/alimy/mir) to generate service interface code automatic.
|
@ -0,0 +1,159 @@
|
|||||||
|
// Code generated by go-mir. DO NOT EDIT.
|
||||||
|
|
||||||
|
package v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/alimy/mir/v3"
|
||||||
|
gin "github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LoginReq struct {
|
||||||
|
AgentInfo AgentInfo `json:"agent_info"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Passwd string `json:"passwd"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AgentInfo struct {
|
||||||
|
Platform string `json:"platform"`
|
||||||
|
UserAgent string `json:"user_agent"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LoginResp struct {
|
||||||
|
UserInfo
|
||||||
|
ServerInfo ServerInfo `json:"server_info"`
|
||||||
|
JwtToken string `json:"jwt_token"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServerInfo struct {
|
||||||
|
ApiVer string `json:"api_ver"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserInfo struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WebCore interface {
|
||||||
|
// Chain provide handlers chain for gin
|
||||||
|
Chain() gin.HandlersChain
|
||||||
|
|
||||||
|
Logout(c *gin.Context) mir.Error
|
||||||
|
Login(c *gin.Context, req *LoginReq) (*LoginResp, mir.Error)
|
||||||
|
Articles(c *gin.Context) mir.Error
|
||||||
|
Index(c *gin.Context) mir.Error
|
||||||
|
|
||||||
|
mustEmbedUnimplementedWebCoreServant()
|
||||||
|
}
|
||||||
|
|
||||||
|
type WebCoreBinding interface {
|
||||||
|
BindLogin(c *gin.Context) (*LoginReq, mir.Error)
|
||||||
|
|
||||||
|
mustEmbedUnimplementedWebCoreBinding()
|
||||||
|
}
|
||||||
|
|
||||||
|
type WebCoreRender interface {
|
||||||
|
RenderLogout(c *gin.Context, err mir.Error)
|
||||||
|
RenderLogin(c *gin.Context, data *LoginResp, err mir.Error)
|
||||||
|
RenderArticles(c *gin.Context, err mir.Error)
|
||||||
|
RenderIndex(c *gin.Context, err mir.Error)
|
||||||
|
|
||||||
|
mustEmbedUnimplementedWebCoreRender()
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterWebCoreServant register WebCore servant to gin
|
||||||
|
func RegisterWebCoreServant(e *gin.Engine, s WebCore, b WebCoreBinding, r WebCoreRender) {
|
||||||
|
router := e.Group("v1")
|
||||||
|
// use chain for router
|
||||||
|
middlewares := s.Chain()
|
||||||
|
router.Use(middlewares...)
|
||||||
|
|
||||||
|
// register routes info to router
|
||||||
|
router.Handle("POST", "/user/logout/", func(c *gin.Context) {
|
||||||
|
r.RenderLogout(c, s.Logout(c))
|
||||||
|
})
|
||||||
|
|
||||||
|
router.Handle("POST", "/user/login/", func(c *gin.Context) {
|
||||||
|
req, err := b.BindLogin(c)
|
||||||
|
if err != nil {
|
||||||
|
r.RenderLogin(c, nil, err)
|
||||||
|
}
|
||||||
|
resp, err := s.Login(c, req)
|
||||||
|
r.RenderLogin(c, resp, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
{
|
||||||
|
h := func(c *gin.Context) {
|
||||||
|
r.RenderArticles(c, s.Articles(c))
|
||||||
|
}
|
||||||
|
router.Handle("HEAD", "/articles/:category/", h)
|
||||||
|
router.Handle("GET", "/articles/:category/", h)
|
||||||
|
}
|
||||||
|
|
||||||
|
router.Handle("GET", "/index/", func(c *gin.Context) {
|
||||||
|
r.RenderIndex(c, s.Index(c))
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnimplementedWebCoreServant can be embedded to have forward compatible implementations.
|
||||||
|
type UnimplementedWebCoreServant struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UnimplementedWebCoreServant) Chain() gin.HandlersChain {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UnimplementedWebCoreServant) Logout(c *gin.Context) mir.Error {
|
||||||
|
return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UnimplementedWebCoreServant) Login(c *gin.Context, req *LoginReq) (*LoginResp, mir.Error) {
|
||||||
|
return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UnimplementedWebCoreServant) Articles(c *gin.Context) mir.Error {
|
||||||
|
return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UnimplementedWebCoreServant) Index(c *gin.Context) mir.Error {
|
||||||
|
return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UnimplementedWebCoreServant) mustEmbedUnimplementedWebCoreServant() {}
|
||||||
|
|
||||||
|
// UnimplementedWebCoreRender can be embedded to have forward compatible implementations.
|
||||||
|
type UnimplementedWebCoreRender struct {
|
||||||
|
RenderAny func(*gin.Context, any, mir.Error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *UnimplementedWebCoreRender) RenderLogout(c *gin.Context, err mir.Error) {
|
||||||
|
r.RenderAny(c, nil, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *UnimplementedWebCoreRender) RenderLogin(c *gin.Context, data *LoginResp, err mir.Error) {
|
||||||
|
r.RenderAny(c, data, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *UnimplementedWebCoreRender) RenderArticles(c *gin.Context, err mir.Error) {
|
||||||
|
r.RenderAny(c, nil, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *UnimplementedWebCoreRender) RenderIndex(c *gin.Context, err mir.Error) {
|
||||||
|
r.RenderAny(c, nil, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *UnimplementedWebCoreRender) mustEmbedUnimplementedWebCoreRender() {}
|
||||||
|
|
||||||
|
// UnimplementedWebCoreBinding can be embedded to have forward compatible implementations.
|
||||||
|
type UnimplementedWebCoreBinding struct {
|
||||||
|
BindAny func(*gin.Context, any) mir.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *UnimplementedWebCoreBinding) BindLogin(c *gin.Context) (*LoginReq, mir.Error) {
|
||||||
|
obj := new(LoginReq)
|
||||||
|
err := b.BindAny(c, obj)
|
||||||
|
return obj, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *UnimplementedWebCoreBinding) mustEmbedUnimplementedWebCoreBinding() {}
|
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
. "github.com/alimy/mir/v3/core"
|
||||||
|
. "github.com/alimy/mir/v3/engine"
|
||||||
|
|
||||||
|
_ "github.com/rocboss/paopao-ce/internal/mirc/routes/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:generate go run main.go
|
||||||
|
func main() {
|
||||||
|
log.Println("generate code start")
|
||||||
|
opts := Options{
|
||||||
|
RunMode(InSerialDebugMode),
|
||||||
|
GeneratorName(GeneratorGin),
|
||||||
|
SinkPath("auto"),
|
||||||
|
}
|
||||||
|
if err := Generate(opts); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
log.Println("generate code finish")
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
### RESTful API for paopao-ce
|
@ -0,0 +1,15 @@
|
|||||||
|
package v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/alimy/mir/v3"
|
||||||
|
. "github.com/alimy/mir/v3/engine"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
AddEntry(new(LocalOSS))
|
||||||
|
}
|
||||||
|
|
||||||
|
type LocalOSS struct {
|
||||||
|
Chain Chain `mir:"-"`
|
||||||
|
Group Group `mir:"v1"`
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/alimy/mir/v3"
|
||||||
|
. "github.com/alimy/mir/v3/engine"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
AddEntry(new(WebAdmin))
|
||||||
|
}
|
||||||
|
|
||||||
|
type WebAdmin struct {
|
||||||
|
Chain Chain `mir:"-"`
|
||||||
|
Group Group `mir:"v1"`
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/alimy/mir/v3"
|
||||||
|
. "github.com/alimy/mir/v3/engine"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
AddEntry(new(WebAlipay))
|
||||||
|
}
|
||||||
|
|
||||||
|
type WebAlipay struct {
|
||||||
|
Chain Chain `mir:"-"`
|
||||||
|
Group Group `mir:"v1"`
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
package v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/alimy/mir/v3"
|
||||||
|
. "github.com/alimy/mir/v3/engine"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
AddEntry(new(WebCore))
|
||||||
|
}
|
||||||
|
|
||||||
|
type AgentInfo struct {
|
||||||
|
Platform string `json:"platform"`
|
||||||
|
UserAgent string `json:"user_agent"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServerInfo struct {
|
||||||
|
ApiVer string `json:"api_ver"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserInfo struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LoginReq struct {
|
||||||
|
AgentInfo AgentInfo `json:"agent_info"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Passwd string `json:"passwd"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LoginResp struct {
|
||||||
|
UserInfo
|
||||||
|
ServerInfo ServerInfo `json:"server_info"`
|
||||||
|
JwtToken string `json:"jwt_token"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WebCore struct {
|
||||||
|
Chain Chain `mir:"-"`
|
||||||
|
Group Group `mir:"v1"`
|
||||||
|
Index func(Get) `mir:"/index/"`
|
||||||
|
Articles func(Get, Head) `mir:"/articles/:category/"`
|
||||||
|
Login func(Post, LoginReq) LoginResp `mir:"/user/login/"`
|
||||||
|
Logout func(Post) `mir:"/user/logout/"`
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/alimy/mir/v3"
|
||||||
|
. "github.com/alimy/mir/v3/engine"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
AddEntry(new(WebFollowship))
|
||||||
|
}
|
||||||
|
|
||||||
|
type WebFollowship struct {
|
||||||
|
Chain Chain `mir:"-"`
|
||||||
|
Group Group `mir:"v1"`
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/alimy/mir/v3"
|
||||||
|
. "github.com/alimy/mir/v3/engine"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
AddEntry(new(WebFriendship))
|
||||||
|
}
|
||||||
|
|
||||||
|
type WebFriendship struct {
|
||||||
|
Chain Chain `mir:"-"`
|
||||||
|
Group Group `mir:"v1"`
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/alimy/mir/v3"
|
||||||
|
. "github.com/alimy/mir/v3/engine"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
AddEntry(new(WebLoose))
|
||||||
|
}
|
||||||
|
|
||||||
|
type WebLoose struct {
|
||||||
|
Chain Chain `mir:"-"`
|
||||||
|
Group Group `mir:"v1"`
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/alimy/mir/v3"
|
||||||
|
. "github.com/alimy/mir/v3/engine"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
AddEntry(new(WebPriv))
|
||||||
|
}
|
||||||
|
|
||||||
|
type WebPriv struct {
|
||||||
|
Chain Chain `mir:"-"`
|
||||||
|
Group Group `mir:"v1"`
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/alimy/mir/v3"
|
||||||
|
. "github.com/alimy/mir/v3/engine"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
AddEntry(new(WebPub))
|
||||||
|
}
|
||||||
|
|
||||||
|
type WebPub struct {
|
||||||
|
Chain Chain `mir:"-"`
|
||||||
|
Group Group `mir:"v1"`
|
||||||
|
}
|
@ -1,31 +0,0 @@
|
|||||||
package rest
|
|
||||||
|
|
||||||
type RequestingFriendReq struct {
|
|
||||||
UserId int64 `json:"user_id" binding:"required"`
|
|
||||||
Greetings string `json:"greetings" binding:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AddFriendReq struct {
|
|
||||||
UserId int64 `json:"user_id" binding:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type RejectFriendReq struct {
|
|
||||||
UserId int64 `json:"user_id" binding:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DeleteFriendReq struct {
|
|
||||||
UserId int64 `json:"user_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ContactItem struct {
|
|
||||||
UserId int64 `json:"user_id"`
|
|
||||||
UserName string `json:"username"`
|
|
||||||
Nickname string `json:"nickname"`
|
|
||||||
Avatar string `json:"avatar"`
|
|
||||||
Phone string `json:"phone"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ContactsResp struct {
|
|
||||||
Contacts []ContactItem `json:"contacts"`
|
|
||||||
Total int64 `json:"total"`
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package rest
|
|
||||||
|
|
||||||
import "github.com/rocboss/paopao-ce/internal/model"
|
|
||||||
|
|
||||||
type IndexTweetsResp struct {
|
|
||||||
Tweets []*model.PostFormated
|
|
||||||
Total int64
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package rest
|
|
||||||
|
|
||||||
type UserProfileResp struct {
|
|
||||||
ID int64 `json:"id"`
|
|
||||||
Nickname string `json:"nickname"`
|
|
||||||
Username string `json:"username"`
|
|
||||||
Status int `json:"status"`
|
|
||||||
Avatar string `json:"avatar"`
|
|
||||||
IsAdmin bool `json:"is_admin"`
|
|
||||||
IsFriend bool `json:"is_friend"`
|
|
||||||
}
|
|
@ -0,0 +1,2 @@
|
|||||||
|
### gRPC API
|
||||||
|
This directory contain some gRPC API define files.
|
@ -0,0 +1,5 @@
|
|||||||
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package proto
|
@ -0,0 +1,10 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package paopao;
|
||||||
|
|
||||||
|
option go_package = "proto";
|
||||||
|
|
||||||
|
message Tag {
|
||||||
|
string name = 1;
|
||||||
|
int32 type = 2;
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package base
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/alimy/mir/v3"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/rocboss/paopao-ce/internal/core"
|
||||||
|
"github.com/rocboss/paopao-ce/pkg/xerror"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BaseServant struct {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
type BaseBinding struct {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
type BaseRender struct {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
func (BaseServant) userFrom(c *gin.Context) (*core.User, bool) {
|
||||||
|
if u, exists := c.Get("USER"); exists {
|
||||||
|
user, ok := u.(*core.User)
|
||||||
|
return user, ok
|
||||||
|
}
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func BindAny(c *gin.Context, obj any) mir.Error {
|
||||||
|
var errs xerror.ValidErrors
|
||||||
|
err := c.ShouldBind(obj)
|
||||||
|
if err != nil {
|
||||||
|
return mir.NewError(xerror.InvalidParams.Code(), xerror.InvalidParams.WithDetails(errs.Error()))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func RenderAny(c *gin.Context, data any, err mir.Error) {
|
||||||
|
if err == nil {
|
||||||
|
hostname, _ := os.Hostname()
|
||||||
|
if data == nil {
|
||||||
|
data = gin.H{
|
||||||
|
"code": 0,
|
||||||
|
"msg": "success",
|
||||||
|
"tracehost": hostname,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
data = gin.H{
|
||||||
|
"code": 0,
|
||||||
|
"msg": "success",
|
||||||
|
"data": data,
|
||||||
|
"tracehost": hostname,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, data)
|
||||||
|
} else {
|
||||||
|
// TODO: error process logic
|
||||||
|
resp := gin.H{"code": err.StatusCode(), "msg": err.Error()}
|
||||||
|
// xerr := &xerror.Error{}
|
||||||
|
// if errors.As(err, xerr) {
|
||||||
|
// resp["code"], resp["msg"] = xerr.Code(), xerr.Msg()
|
||||||
|
// details := xerr.Details()
|
||||||
|
// if len(details) > 0 {
|
||||||
|
// resp["details"] = details
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
c.JSON(http.StatusInternalServerError, resp)
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue