mirror of https://github.com/rocboss/paopao-ce
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.1 KiB
44 lines
1.1 KiB
// 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 jinzhu
|
|
|
|
import (
|
|
"github.com/rocboss/paopao-ce/internal/core"
|
|
"github.com/rocboss/paopao-ce/internal/core/cs"
|
|
"github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type tweetMetricSrvA struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func (s *tweetMetricSrvA) UpdateRankScore(metric *cs.TweetMetric) error {
|
|
return s.db.Transaction(func(tx *gorm.DB) (err error) {
|
|
postMetric := &dbr.PostMetric{PostId: metric.PostId}
|
|
db := s.db.Model(postMetric).Where("post_id=?", metric.PostId)
|
|
db.First(postMetric)
|
|
postMetric.RankScore = metric.RankScore(postMetric.MotivationFactor)
|
|
err = db.Save(postMetric).Error
|
|
return
|
|
})
|
|
|
|
}
|
|
|
|
func (s *tweetMetricSrvA) AddTweetMetric(postId int64) (err error) {
|
|
_, err = (&dbr.PostMetric{PostId: postId}).Create(s.db)
|
|
return
|
|
}
|
|
|
|
func (s *tweetMetricSrvA) DeleteTweetMetric(postId int64) (err error) {
|
|
return (&dbr.PostMetric{PostId: postId}).Delete(s.db)
|
|
}
|
|
|
|
func NewTweetMetricServentA(db *gorm.DB) core.TweetMetricServantA {
|
|
return &tweetMetricSrvA{
|
|
db: db,
|
|
}
|
|
}
|