Spaces:
Sleeping
Sleeping
| package models | |
| import ( | |
| "time" | |
| "github.com/google/uuid" | |
| "gorm.io/gorm" | |
| ) | |
| type JournalComment struct { | |
| ID uuid.UUID `json:"id" gorm:"type:char(36);primaryKey"` | |
| JournalID uuid.UUID `json:"journal_id" gorm:"type:char(36);index"` | |
| UserID uuid.UUID `json:"user_id" gorm:"type:char(36);index"` | |
| Comment string `json:"comment" gorm:"type:text"` | |
| IsFlagged bool `json:"is_flagged" gorm:"default:false"` | |
| CreatedAt time.Time `json:"created_at"` | |
| } | |
| func (c *JournalComment) BeforeCreate(tx *gorm.DB) error { | |
| if c.ID == uuid.Nil { | |
| c.ID = uuid.New() | |
| } | |
| return nil | |
| } | |
| type CommentRequest struct { | |
| JournalID string `json:"journal_id" validate:"required,uuid"` | |
| Comment string `json:"comment" validate:"required,min=1,max=500"` | |
| } | |
| type CommentResponse struct { | |
| ID uuid.UUID `json:"id"` | |
| JournalID uuid.UUID `json:"journal_id"` | |
| Comment string `json:"comment"` | |
| CreatedAt time.Time `json:"created_at"` | |
| IsFlagged bool `json:"is_flagged"` | |
| } |