-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomment.go
More file actions
43 lines (34 loc) · 858 Bytes
/
comment.go
File metadata and controls
43 lines (34 loc) · 858 Bytes
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
package repository
import (
"time"
"github.com/traPtitech/booQ-v3/domain"
"gorm.io/gorm"
)
type comment struct {
GormModel // ID, CreatedAt, UpdatedAt
ItemID int `gorm:"not null"`
UserID string `gorm:"type:varchar(32);not null"`
Text string `gorm:"column:comment;type:text;not null"`
DeletedAt *time.Time
}
type commentRepository struct {
db *gorm.DB
}
func NewCommentRepository(db *gorm.DB) domain.CommentRepository {
return &commentRepository{db: db}
}
func (r *commentRepository) Create(c *domain.Comment) error {
newComment := &comment{
ItemID: c.ItemID,
UserID: c.UserID,
Text: c.Text,
}
if err := r.db.Create(newComment).Error; err != nil {
return err
}
c.ID = newComment.ID
c.CreatedAt = newComment.CreatedAt
c.UpdatedAt = newComment.UpdatedAt
c.DeletedAt = newComment.DeletedAt
return nil
}