@@ -33,11 +33,25 @@ func (r *commentRepository) GetCommentsByCursorTime(db *gorm.DB, articleID int64
3333 return comments , err
3434}
3535
36+ func (r * commentRepository ) GetCommentsByCommentID (db * gorm.DB , id int64 ) (* model.Comment , error ) {
37+ return r .takeOne (db , "id = ?" , id )
38+ }
39+
3640func (r * commentRepository ) GetCommentsByArticleID (db * gorm.DB , articleID int64 ) ([]model.Comment , error ) {
37- return r .take (db , "article_id = ?" , articleID )
41+ return r .takeList (db , "article_id = ?" , articleID )
42+ }
43+
44+ func (r * commentRepository ) takeOne (db * gorm.DB , column string , value interface {}) (* model.Comment , error ) {
45+ comment := & model.Comment {}
46+ err := db .Where (column , value ).Find (& comment ).Error
47+ if err != nil {
48+ logs .Logger .Errorf ("query db error:" , err )
49+ return nil , err
50+ }
51+ return comment , nil
3852}
3953
40- func (r * commentRepository ) take (db * gorm.DB , column string , value interface {}) ([]model.Comment , error ) {
54+ func (r * commentRepository ) takeList (db * gorm.DB , column string , value interface {}) ([]model.Comment , error ) {
4155 var comments []model.Comment
4256 err := db .Where (column , value ).Find (& comments ).Error
4357 if err != nil {
0 commit comments