✨ update model
This commit is contained in:
3
api/comment_api/comment.go
Normal file
3
api/comment_api/comment.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package comment_api
|
||||
|
||||
type CommentAPI struct{}
|
1
api/comment_api/comment_api.go
Normal file
1
api/comment_api/comment_api.go
Normal file
@@ -0,0 +1 @@
|
||||
package comment_api
|
@@ -122,7 +122,6 @@ func HandelUserLogin(userId string) (bool, map[string]interface{}) {
|
||||
"data": data,
|
||||
"success": true,
|
||||
}
|
||||
global.DB.Set("user_id", userId)
|
||||
return true, responseData
|
||||
}
|
||||
|
||||
|
@@ -344,7 +344,6 @@ func handelUserLogin(user model.ScaAuthUser, autoLogin bool, c *gin.Context) {
|
||||
result.FailWithMessage(ginI18n.MustGetMessage(c, "LoginFailed"), c)
|
||||
return
|
||||
}
|
||||
global.DB.Set("user_id", user.UID)
|
||||
result.OkWithData(data, c)
|
||||
}
|
||||
|
||||
|
@@ -1,22 +1,18 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
ginI18n "github.com/gin-contrib/i18n"
|
||||
"github.com/gin-gonic/gin"
|
||||
"schisandra-cloud-album/common/result"
|
||||
"schisandra-cloud-album/global"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func SecurityHeaders() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
url := strings.TrimPrefix(global.CONFIG.System.Web, "https://")
|
||||
requestHost := c.Request.Host
|
||||
if requestHost != url {
|
||||
result.FailWithMessage(ginI18n.MustGetMessage(c, "IllegalRequests"), c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
//url := strings.TrimPrefix(global.CONFIG.System.Web, "https://")
|
||||
//requestHost := c.Request.Host
|
||||
//if requestHost != url {
|
||||
// result.FailWithMessage(ginI18n.MustGetMessage(c, "IllegalRequests"), c)
|
||||
// c.Abort()
|
||||
// return
|
||||
//}
|
||||
c.Header("X-Frame-Options", "DENY")
|
||||
c.Header("Content-Security-Policy", "default-src 'self'; connect-src *; font-src *; script-src-elem * 'unsafe-inline'; img-src * data:; style-src * 'unsafe-inline';")
|
||||
c.Header("X-XSS-Protection", "1; mode=block")
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package model
|
||||
|
||||
const ScaAuthCasbinRuleTableName = "sca_auth_casbin_rule"
|
||||
|
||||
// ScaAuthCasbinRule 角色/权限/用户关系表
|
||||
type ScaAuthCasbinRule struct {
|
||||
Id uint64 `gorm:"column:id;type:bigint(20) unsigned;primary_key;AUTO_INCREMENT" json:"id"`
|
||||
@@ -13,5 +15,5 @@ type ScaAuthCasbinRule struct {
|
||||
}
|
||||
|
||||
func (m *ScaAuthCasbinRule) TableName() string {
|
||||
return "sca_auth_casbin_rule"
|
||||
return ScaAuthCasbinRuleTableName
|
||||
}
|
||||
|
@@ -2,9 +2,6 @@ package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"schisandra-cloud-album/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -42,36 +39,3 @@ func (permission *ScaAuthPermission) MarshalBinary() ([]byte, error) {
|
||||
func (permission *ScaAuthPermission) UnmarshalBinary(data []byte) error {
|
||||
return json.Unmarshal(data, permission)
|
||||
}
|
||||
func (permission *ScaAuthPermission) BeforeCreate(tx *gorm.DB) (err error) {
|
||||
userId, b := tx.Get("user_id")
|
||||
if !b {
|
||||
global.LOG.Error("user_id is not in global.DB")
|
||||
return fmt.Errorf("user_id is not in global.DB")
|
||||
}
|
||||
|
||||
userIdStr, ok := userId.(*string)
|
||||
if !ok {
|
||||
global.LOG.Error("user_id is not of type *string")
|
||||
return fmt.Errorf("user_id is not of type *string")
|
||||
}
|
||||
|
||||
permission.CreatedBy = userIdStr
|
||||
return nil
|
||||
}
|
||||
|
||||
func (permission *ScaAuthPermission) BeforeUpdate(tx *gorm.DB) (err error) {
|
||||
userId, b := tx.Get("user_id")
|
||||
if !b {
|
||||
global.LOG.Error("user_id is not in global.DB")
|
||||
return fmt.Errorf("user_id is not in global.DB")
|
||||
}
|
||||
|
||||
userIdStr, ok := userId.(*string)
|
||||
if !ok {
|
||||
global.LOG.Error("user_id is not of type *string")
|
||||
return fmt.Errorf("user_id is not of type *string")
|
||||
}
|
||||
|
||||
permission.UpdateBy = userIdStr
|
||||
return nil
|
||||
}
|
||||
|
@@ -2,9 +2,6 @@ package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"schisandra-cloud-album/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -34,39 +31,3 @@ func (role *ScaAuthRole) MarshalBinary() ([]byte, error) {
|
||||
func (role *ScaAuthRole) UnmarshalBinary(data []byte) error {
|
||||
return json.Unmarshal(data, role)
|
||||
}
|
||||
|
||||
func (role *ScaAuthRole) BeforeCreate(tx *gorm.DB) (err error) {
|
||||
userId, b := tx.Get("user_id")
|
||||
if !b {
|
||||
creator := "system"
|
||||
role.CreatedBy = &creator
|
||||
return nil
|
||||
}
|
||||
|
||||
userIdStr, ok := userId.(*string)
|
||||
if !ok {
|
||||
global.LOG.Error("user_id is not of type *string")
|
||||
return fmt.Errorf("user_id is not of type *string")
|
||||
}
|
||||
|
||||
role.CreatedBy = userIdStr
|
||||
return nil
|
||||
}
|
||||
|
||||
func (role *ScaAuthRole) BeforeUpdate(tx *gorm.DB) (err error) {
|
||||
userId, b := tx.Get("user_id")
|
||||
if !b {
|
||||
creator := "system"
|
||||
role.CreatedBy = &creator
|
||||
return nil
|
||||
}
|
||||
|
||||
userIdStr, ok := userId.(*string)
|
||||
if !ok {
|
||||
global.LOG.Error("user_id is not of type *string")
|
||||
return fmt.Errorf("user_id is not of type *string")
|
||||
}
|
||||
|
||||
role.UpdateBy = userIdStr
|
||||
return nil
|
||||
}
|
||||
|
@@ -2,9 +2,6 @@ package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"schisandra-cloud-album/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -45,38 +42,3 @@ func (user *ScaAuthUser) MarshalBinary() ([]byte, error) {
|
||||
func (user *ScaAuthUser) UnmarshalBinary(data []byte) error {
|
||||
return json.Unmarshal(data, user)
|
||||
}
|
||||
func (user *ScaAuthUser) BeforeCreate(tx *gorm.DB) (err error) {
|
||||
userId, b := tx.Get("user_id")
|
||||
if !b {
|
||||
creator := "system"
|
||||
user.CreatedBy = &creator
|
||||
return nil
|
||||
}
|
||||
|
||||
userIdStr, ok := userId.(*string)
|
||||
if !ok {
|
||||
global.LOG.Error("user_id is not of type *string")
|
||||
return fmt.Errorf("user_id is not of type *string")
|
||||
}
|
||||
|
||||
user.CreatedBy = userIdStr
|
||||
return nil
|
||||
}
|
||||
|
||||
func (user *ScaAuthUser) BeforeUpdate(tx *gorm.DB) (err error) {
|
||||
userId, b := tx.Get("user_id")
|
||||
if !b {
|
||||
creator := "system"
|
||||
user.CreatedBy = &creator
|
||||
return nil
|
||||
}
|
||||
|
||||
userIdStr, ok := userId.(*string)
|
||||
if !ok {
|
||||
global.LOG.Error("user_id is not of type *string")
|
||||
return fmt.Errorf("user_id is not of type *string")
|
||||
}
|
||||
|
||||
user.UpdateBy = userIdStr
|
||||
return nil
|
||||
}
|
||||
|
@@ -1,9 +1,6 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"schisandra-cloud-album/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -36,19 +33,3 @@ type ScaAuthUserDevice struct {
|
||||
func (*ScaAuthUserDevice) TableName() string {
|
||||
return TableNameScaAuthUserDevice
|
||||
}
|
||||
|
||||
func (device *ScaAuthUserDevice) BeforeUpdate(tx *gorm.DB) (err error) {
|
||||
userId, b := tx.Get("user_id")
|
||||
if !b {
|
||||
global.LOG.Error("user_id is not found in global.DB")
|
||||
return fmt.Errorf("user_id is not found in global.DB")
|
||||
}
|
||||
userIdStr, ok := userId.(*string)
|
||||
if !ok {
|
||||
global.LOG.Error("user_id is not of type *string")
|
||||
return fmt.Errorf("user_id is not of type *string")
|
||||
}
|
||||
|
||||
device.UpdateBy = userIdStr
|
||||
return nil
|
||||
}
|
||||
|
@@ -1,9 +1,6 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"schisandra-cloud-album/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -27,18 +24,3 @@ type ScaAuthUserSocial struct {
|
||||
func (*ScaAuthUserSocial) TableName() string {
|
||||
return TableNameScaAuthUserSocial
|
||||
}
|
||||
|
||||
func (social *ScaAuthUserSocial) BeforeUpdate(tx *gorm.DB) (err error) {
|
||||
userId, b := tx.Get("user_id")
|
||||
if !b {
|
||||
global.LOG.Error("user_id is not found in global.DB")
|
||||
return fmt.Errorf("user_id is not found in global.DB")
|
||||
}
|
||||
userIdStr, ok := userId.(*string)
|
||||
if !ok {
|
||||
global.LOG.Error("user_id is not of type *string")
|
||||
return fmt.Errorf("user_id is not of type *string")
|
||||
}
|
||||
social.UpdateBy = userIdStr
|
||||
return nil
|
||||
}
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package model
|
||||
|
||||
const ScaCommentLikesTableName = "sca_comment_likes"
|
||||
|
||||
// ScaCommentLikes 评论点赞表
|
||||
type ScaCommentLikes struct {
|
||||
Id int64 `gorm:"column:id;type:bigint(20);primary_key" json:"id"`
|
||||
@@ -8,5 +10,5 @@ type ScaCommentLikes struct {
|
||||
}
|
||||
|
||||
func (like *ScaCommentLikes) TableName() string {
|
||||
return "sca_comment_likes"
|
||||
return ScaCommentLikesTableName
|
||||
}
|
||||
|
@@ -5,31 +5,37 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const ScaCommentReplyTable = "sca_comment_reply"
|
||||
|
||||
// ScaCommentReply 评论表
|
||||
type ScaCommentReply struct {
|
||||
Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT;comment:主键id" json:"id"`
|
||||
UserId string `gorm:"column:user_id;type:varchar(20);comment:评论用户id" json:"user_id"`
|
||||
TopicId string `gorm:"column:topic_id;type:varchar(20);comment:评论话题id" json:"topic_id"`
|
||||
TopicType int `gorm:"column:topic_type;type:int(11);comment:话题类型" json:"topic_type"`
|
||||
Content string `gorm:"column:content;type:longtext;comment:评论内容" json:"content"`
|
||||
CommentType int `gorm:"column:comment_type;type:int(11);comment:评论类型 0评论 1 回复" json:"comment_type"`
|
||||
ReplyId string `gorm:"column:reply_id;type:varchar(20);comment:回复目标id" json:"reply_id"`
|
||||
ReplyUser string `gorm:"column:reply_user;type:varchar(20);comment:回复人id" json:"reply_user"`
|
||||
Username string `gorm:"column:username;type:varchar(20);comment:评论用户昵称" json:"username"`
|
||||
Avatar string `gorm:"column:avatar;type:longtext;comment:评论用户头像" json:"avatar"`
|
||||
Author int `gorm:"column:author;type:int(11);comment:评论回复是否作者 0否 1是" json:"author"`
|
||||
Likes int64 `gorm:"column:likes;type:bigint(20);comment:点赞数" json:"likes"`
|
||||
ReplyCount int64 `gorm:"column:reply_count;type:bigint(20);comment:回复数量" json:"reply_count"`
|
||||
PicUrls string `gorm:"column:pic_urls;type:longtext;comment:图片链接" json:"pic_urls"`
|
||||
CreatedTime time.Time `gorm:"column:created_time;type:datetime;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_time"`
|
||||
UpdateTime time.Time `gorm:"column:update_time;type:datetime;default:CURRENT_TIMESTAMP;comment:更新时间" json:"update_time"`
|
||||
Deleted int `gorm:"column:deleted;type:int(11);default:0;comment:是否删除 0未删除 1 已删除" json:"deleted"`
|
||||
CreatedBy string `gorm:"column:created_by;type:varchar(32);comment:创建人" json:"created_by"`
|
||||
UpdateBy string `gorm:"column:update_by;type:varchar(32);comment:更新人" json:"update_by"`
|
||||
Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT;comment:主键id" json:"id"`
|
||||
UserId string `gorm:"column:user_id;type:varchar(20);comment:评论用户id" json:"user_id"`
|
||||
TopicId string `gorm:"column:topic_id;type:varchar(20);comment:评论话题id" json:"topic_id"`
|
||||
TopicType int `gorm:"column:topic_type;type:int(11);comment:话题类型" json:"topic_type"`
|
||||
Content string `gorm:"column:content;type:longtext;comment:评论内容" json:"content"`
|
||||
CommentType int `gorm:"column:comment_type;type:int(11);comment:评论类型 0评论 1 回复" json:"comment_type"`
|
||||
ReplyId string `gorm:"column:reply_id;type:varchar(20);comment:回复目标id" json:"reply_id"`
|
||||
ReplyUser string `gorm:"column:reply_user;type:varchar(20);comment:回复人id" json:"reply_user"`
|
||||
Author int `gorm:"column:author;type:int(11);comment:评论回复是否作者 0否 1是" json:"author"`
|
||||
Likes int64 `gorm:"column:likes;type:bigint(20);comment:点赞数" json:"likes"`
|
||||
ReplyCount int64 `gorm:"column:reply_count;type:bigint(20);comment:回复数量" json:"reply_count"`
|
||||
PicUrls string `gorm:"column:pic_urls;type:longtext;comment:图片链接" json:"pic_urls"`
|
||||
CreatedTime time.Time `gorm:"column:created_time;type:datetime;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_time"`
|
||||
UpdateTime time.Time `gorm:"column:update_time;type:datetime;default:CURRENT_TIMESTAMP;comment:更新时间" json:"update_time"`
|
||||
Deleted int `gorm:"column:deleted;type:int(11);default:0;comment:是否删除 0未删除 1 已删除" json:"deleted"`
|
||||
CreatedBy string `gorm:"column:created_by;type:varchar(32);comment:创建人" json:"created_by"`
|
||||
UpdateBy string `gorm:"column:update_by;type:varchar(32);comment:更新人" json:"update_by"`
|
||||
Dislikes int64 `gorm:"column:dislikes;type:bigint(20);comment:踩数" json:"dislikes"`
|
||||
CommentIp string `gorm:"column:comment_ip;type:varchar(20);comment:评论ip" json:"comment_ip"`
|
||||
Location string `gorm:"column:location;type:varchar(20);comment:评论地址" json:"location"`
|
||||
Browser string `gorm:"column:browser;type:varchar(20);comment:评论浏览器" json:"browser"`
|
||||
OperatingSystem string `gorm:"column:operating_system;type:varchar(20);comment:评论操作系统" json:"operating_system"`
|
||||
Order int64 `gorm:"column:order;type:bigint(20);comment:评论排序" json:"order"`
|
||||
}
|
||||
|
||||
func (comment *ScaCommentReply) TableName() string {
|
||||
return "sca_comment_reply"
|
||||
return ScaCommentReplyTable
|
||||
}
|
||||
|
||||
// BeforeCreate 创建前回调
|
||||
|
3
service/comment_likes/comment_likes.go
Normal file
3
service/comment_likes/comment_likes.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package comment_likes
|
||||
|
||||
type CommentLikes struct{}
|
1
service/comment_likes/comment_likes_service.go
Normal file
1
service/comment_likes/comment_likes_service.go
Normal file
@@ -0,0 +1 @@
|
||||
package comment_likes
|
3
service/comment_reply_service/comment_reply.go
Normal file
3
service/comment_reply_service/comment_reply.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package comment_reply_service
|
||||
|
||||
type CommentReplyService struct{}
|
1
service/comment_reply_service/comment_reply_service.go
Normal file
1
service/comment_reply_service/comment_reply_service.go
Normal file
@@ -0,0 +1 @@
|
||||
package comment_reply_service
|
Reference in New Issue
Block a user