-
Notifications
You must be signed in to change notification settings - Fork 42
/
bookmark.go
46 lines (36 loc) · 1.18 KB
/
bookmark.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package dao
import (
"github.com/TUM-Dev/gocast/model"
"gorm.io/gorm"
)
//go:generate mockgen -source=bookmark.go -destination ../mock_dao/bookmark.go
type BookmarkDao interface {
Add(*model.Bookmark) error
GetByID(uint) (model.Bookmark, error)
GetByStreamID(uint, uint) ([]model.Bookmark, error)
Update(*model.Bookmark) error
Delete(uint) error
}
type bookmarkDao struct {
db *gorm.DB
}
func NewBookmarkDao() BookmarkDao {
return bookmarkDao{db: DB}
}
func (d bookmarkDao) Add(bookmark *model.Bookmark) error {
return d.db.Save(bookmark).Error
}
func (d bookmarkDao) GetByID(id uint) (bookmark model.Bookmark, err error) {
err = d.db.Where("id = ?", id).First(&bookmark).Error
return bookmark, err
}
func (d bookmarkDao) GetByStreamID(streamID uint, userID uint) (bookmarks []model.Bookmark, err error) {
err = d.db.Order("hours, minutes, seconds ASC").Where("stream_id = ? AND user_id = ?", streamID, userID).Find(&bookmarks).Error
return bookmarks, err
}
func (d bookmarkDao) Update(bookmark *model.Bookmark) error {
return d.db.Model(bookmark).Updates(bookmark).Error
}
func (d bookmarkDao) Delete(id uint) error {
return d.db.Delete(&model.Bookmark{}, "id = ?", id).Error
}