✨ 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,
|
"data": data,
|
||||||
"success": true,
|
"success": true,
|
||||||
}
|
}
|
||||||
global.DB.Set("user_id", userId)
|
|
||||||
return true, responseData
|
return true, responseData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -344,7 +344,6 @@ func handelUserLogin(user model.ScaAuthUser, autoLogin bool, c *gin.Context) {
|
|||||||
result.FailWithMessage(ginI18n.MustGetMessage(c, "LoginFailed"), c)
|
result.FailWithMessage(ginI18n.MustGetMessage(c, "LoginFailed"), c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
global.DB.Set("user_id", user.UID)
|
|
||||||
result.OkWithData(data, c)
|
result.OkWithData(data, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,22 +1,18 @@
|
|||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ginI18n "github.com/gin-contrib/i18n"
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"schisandra-cloud-album/common/result"
|
|
||||||
"schisandra-cloud-album/global"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func SecurityHeaders() gin.HandlerFunc {
|
func SecurityHeaders() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
url := strings.TrimPrefix(global.CONFIG.System.Web, "https://")
|
//url := strings.TrimPrefix(global.CONFIG.System.Web, "https://")
|
||||||
requestHost := c.Request.Host
|
//requestHost := c.Request.Host
|
||||||
if requestHost != url {
|
//if requestHost != url {
|
||||||
result.FailWithMessage(ginI18n.MustGetMessage(c, "IllegalRequests"), c)
|
// result.FailWithMessage(ginI18n.MustGetMessage(c, "IllegalRequests"), c)
|
||||||
c.Abort()
|
// c.Abort()
|
||||||
return
|
// return
|
||||||
}
|
//}
|
||||||
c.Header("X-Frame-Options", "DENY")
|
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("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")
|
c.Header("X-XSS-Protection", "1; mode=block")
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
|
const ScaAuthCasbinRuleTableName = "sca_auth_casbin_rule"
|
||||||
|
|
||||||
// ScaAuthCasbinRule 角色/权限/用户关系表
|
// ScaAuthCasbinRule 角色/权限/用户关系表
|
||||||
type ScaAuthCasbinRule struct {
|
type ScaAuthCasbinRule struct {
|
||||||
Id uint64 `gorm:"column:id;type:bigint(20) unsigned;primary_key;AUTO_INCREMENT" json:"id"`
|
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 {
|
func (m *ScaAuthCasbinRule) TableName() string {
|
||||||
return "sca_auth_casbin_rule"
|
return ScaAuthCasbinRuleTableName
|
||||||
}
|
}
|
||||||
|
@@ -2,9 +2,6 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"schisandra-cloud-album/global"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -42,36 +39,3 @@ func (permission *ScaAuthPermission) MarshalBinary() ([]byte, error) {
|
|||||||
func (permission *ScaAuthPermission) UnmarshalBinary(data []byte) error {
|
func (permission *ScaAuthPermission) UnmarshalBinary(data []byte) error {
|
||||||
return json.Unmarshal(data, permission)
|
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 (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"schisandra-cloud-album/global"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -34,39 +31,3 @@ func (role *ScaAuthRole) MarshalBinary() ([]byte, error) {
|
|||||||
func (role *ScaAuthRole) UnmarshalBinary(data []byte) error {
|
func (role *ScaAuthRole) UnmarshalBinary(data []byte) error {
|
||||||
return json.Unmarshal(data, role)
|
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 (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"schisandra-cloud-album/global"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -45,38 +42,3 @@ func (user *ScaAuthUser) MarshalBinary() ([]byte, error) {
|
|||||||
func (user *ScaAuthUser) UnmarshalBinary(data []byte) error {
|
func (user *ScaAuthUser) UnmarshalBinary(data []byte) error {
|
||||||
return json.Unmarshal(data, user)
|
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
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"schisandra-cloud-album/global"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -36,19 +33,3 @@ type ScaAuthUserDevice struct {
|
|||||||
func (*ScaAuthUserDevice) TableName() string {
|
func (*ScaAuthUserDevice) TableName() string {
|
||||||
return TableNameScaAuthUserDevice
|
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
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"schisandra-cloud-album/global"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -27,18 +24,3 @@ type ScaAuthUserSocial struct {
|
|||||||
func (*ScaAuthUserSocial) TableName() string {
|
func (*ScaAuthUserSocial) TableName() string {
|
||||||
return TableNameScaAuthUserSocial
|
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
|
package model
|
||||||
|
|
||||||
|
const ScaCommentLikesTableName = "sca_comment_likes"
|
||||||
|
|
||||||
// ScaCommentLikes 评论点赞表
|
// ScaCommentLikes 评论点赞表
|
||||||
type ScaCommentLikes struct {
|
type ScaCommentLikes struct {
|
||||||
Id int64 `gorm:"column:id;type:bigint(20);primary_key" json:"id"`
|
Id int64 `gorm:"column:id;type:bigint(20);primary_key" json:"id"`
|
||||||
@@ -8,5 +10,5 @@ type ScaCommentLikes struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (like *ScaCommentLikes) TableName() string {
|
func (like *ScaCommentLikes) TableName() string {
|
||||||
return "sca_comment_likes"
|
return ScaCommentLikesTableName
|
||||||
}
|
}
|
||||||
|
@@ -5,31 +5,37 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const ScaCommentReplyTable = "sca_comment_reply"
|
||||||
|
|
||||||
// ScaCommentReply 评论表
|
// ScaCommentReply 评论表
|
||||||
type ScaCommentReply struct {
|
type ScaCommentReply struct {
|
||||||
Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT;comment:主键id" json:"id"`
|
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"`
|
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"`
|
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"`
|
TopicType int `gorm:"column:topic_type;type:int(11);comment:话题类型" json:"topic_type"`
|
||||||
Content string `gorm:"column:content;type:longtext;comment:评论内容" json:"content"`
|
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"`
|
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"`
|
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"`
|
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"`
|
Author int `gorm:"column:author;type:int(11);comment:评论回复是否作者 0否 1是" json:"author"`
|
||||||
Avatar string `gorm:"column:avatar;type:longtext;comment:评论用户头像" json:"avatar"`
|
Likes int64 `gorm:"column:likes;type:bigint(20);comment:点赞数" json:"likes"`
|
||||||
Author int `gorm:"column:author;type:int(11);comment:评论回复是否作者 0否 1是" json:"author"`
|
ReplyCount int64 `gorm:"column:reply_count;type:bigint(20);comment:回复数量" json:"reply_count"`
|
||||||
Likes int64 `gorm:"column:likes;type:bigint(20);comment:点赞数" json:"likes"`
|
PicUrls string `gorm:"column:pic_urls;type:longtext;comment:图片链接" json:"pic_urls"`
|
||||||
ReplyCount int64 `gorm:"column:reply_count;type:bigint(20);comment:回复数量" json:"reply_count"`
|
CreatedTime time.Time `gorm:"column:created_time;type:datetime;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_time"`
|
||||||
PicUrls string `gorm:"column:pic_urls;type:longtext;comment:图片链接" json:"pic_urls"`
|
UpdateTime time.Time `gorm:"column:update_time;type:datetime;default:CURRENT_TIMESTAMP;comment:更新时间" json:"update_time"`
|
||||||
CreatedTime time.Time `gorm:"column:created_time;type:datetime;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_time"`
|
Deleted int `gorm:"column:deleted;type:int(11);default:0;comment:是否删除 0未删除 1 已删除" json:"deleted"`
|
||||||
UpdateTime time.Time `gorm:"column:update_time;type:datetime;default:CURRENT_TIMESTAMP;comment:更新时间" json:"update_time"`
|
CreatedBy string `gorm:"column:created_by;type:varchar(32);comment:创建人" json:"created_by"`
|
||||||
Deleted int `gorm:"column:deleted;type:int(11);default:0;comment:是否删除 0未删除 1 已删除" json:"deleted"`
|
UpdateBy string `gorm:"column:update_by;type:varchar(32);comment:更新人" json:"update_by"`
|
||||||
CreatedBy string `gorm:"column:created_by;type:varchar(32);comment:创建人" json:"created_by"`
|
Dislikes int64 `gorm:"column:dislikes;type:bigint(20);comment:踩数" json:"dislikes"`
|
||||||
UpdateBy string `gorm:"column:update_by;type:varchar(32);comment:更新人" json:"update_by"`
|
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 {
|
func (comment *ScaCommentReply) TableName() string {
|
||||||
return "sca_comment_reply"
|
return ScaCommentReplyTable
|
||||||
}
|
}
|
||||||
|
|
||||||
// BeforeCreate 创建前回调
|
// 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