Spaces:
Sleeping
Sleeping
| package models | |
| import ( | |
| "time" | |
| "github.com/google/uuid" | |
| "gorm.io/gorm" | |
| ) | |
| type Bookmark struct { | |
| ID uuid.UUID `json:"id" gorm:"type:char(36);primaryKey"` | |
| UserID uuid.UUID `json:"user_id" gorm:"type:char(36);index"` | |
| JournalID uuid.UUID `json:"journal_id" gorm:"type:char(36);index"` | |
| CreatedAt time.Time `json:"created_at"` | |
| // Relations | |
| // Journal models.MoodEntry `json:"journal" gorm:"foreignKey:JournalID"` | |
| Journal MoodEntry `json:"journal" gorm:"foreignKey:JournalID"` // <-- UBAH BARIS INI | |
| } | |
| func (b *Bookmark) BeforeCreate(tx *gorm.DB) error { | |
| if b.ID == uuid.Nil { | |
| b.ID = uuid.New() | |
| } | |
| return nil | |
| } | |
| type BookmarkRequest struct { | |
| JournalID string `json:"journal_id" validate:"required,uuid"` | |
| } | |