
Features: - Complete project management system with Epic/Story/Task hierarchy - Vue.js 3 + Element Plus frontend with kanban board - Go backend with Gin framework and GORM - OAuth2 integration with Gitea - Docker containerization with MySQL - RESTful API for project, task, and user management - JWT authentication and authorization - Responsive web interface with dashboard
152 lines
4.0 KiB
Go
152 lines
4.0 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type Comment struct {
|
|
ID uint `json:"id" gorm:"primaryKey"`
|
|
EntityType string `json:"entity_type" gorm:"type:varchar(50)"`
|
|
EntityID uint `json:"entity_id"`
|
|
UserID uint `json:"user_id"`
|
|
Content string `json:"content"`
|
|
User User `json:"user" gorm:"foreignKey:UserID"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
type EntityType string
|
|
|
|
const (
|
|
EntityTypeProject EntityType = "project"
|
|
EntityTypeEpic EntityType = "epic"
|
|
EntityTypeStory EntityType = "story"
|
|
EntityTypeTask EntityType = "task"
|
|
)
|
|
|
|
type Tag struct {
|
|
ID uint `json:"id" gorm:"primaryKey"`
|
|
Name string `json:"name" gorm:"unique;not null"`
|
|
Color string `json:"color" gorm:"default:'#1890ff'"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
type EntityTag struct {
|
|
ID uint `json:"id" gorm:"primaryKey"`
|
|
EntityType EntityType `json:"entity_type" gorm:"type:varchar(50)"`
|
|
EntityID uint `json:"entity_id"`
|
|
TagID uint `json:"tag_id"`
|
|
Tag Tag `json:"tag" gorm:"foreignKey:TagID"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
type TimeLog struct {
|
|
ID uint `json:"id" gorm:"primaryKey"`
|
|
TaskID uint `json:"task_id"`
|
|
UserID uint `json:"user_id"`
|
|
Hours float64 `json:"hours"`
|
|
Description string `json:"description"`
|
|
LogDate time.Time `json:"log_date"`
|
|
Task Task `json:"task" gorm:"foreignKey:TaskID"`
|
|
User User `json:"user" gorm:"foreignKey:UserID"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
func CreateComment(comment *Comment) error {
|
|
return DB.Create(comment).Error
|
|
}
|
|
|
|
func GetCommentsByEntity(entityType string, entityID uint) ([]Comment, error) {
|
|
var comments []Comment
|
|
err := DB.Where("entity_type = ? AND entity_id = ?", entityType, entityID).
|
|
Preload("User").
|
|
Order("created_at DESC").
|
|
Find(&comments).Error
|
|
return comments, err
|
|
}
|
|
|
|
func UpdateComment(comment *Comment) error {
|
|
return DB.Save(comment).Error
|
|
}
|
|
|
|
func DeleteComment(id uint) error {
|
|
return DB.Delete(&Comment{}, id).Error
|
|
}
|
|
|
|
func CreateTag(tag *Tag) error {
|
|
return DB.Create(tag).Error
|
|
}
|
|
|
|
func GetAllTags() ([]Tag, error) {
|
|
var tags []Tag
|
|
err := DB.Find(&tags).Error
|
|
return tags, err
|
|
}
|
|
|
|
func GetTagByName(name string) (*Tag, error) {
|
|
var tag Tag
|
|
err := DB.Where("name = ?", name).First(&tag).Error
|
|
return &tag, err
|
|
}
|
|
|
|
func UpdateTag(tag *Tag) error {
|
|
return DB.Save(tag).Error
|
|
}
|
|
|
|
func DeleteTag(id uint) error {
|
|
return DB.Delete(&Tag{}, id).Error
|
|
}
|
|
|
|
func AddTagToEntity(entityType EntityType, entityID, tagID uint) error {
|
|
entityTag := EntityTag{
|
|
EntityType: entityType,
|
|
EntityID: entityID,
|
|
TagID: tagID,
|
|
}
|
|
return DB.Create(&entityTag).Error
|
|
}
|
|
|
|
func RemoveTagFromEntity(entityType EntityType, entityID, tagID uint) error {
|
|
return DB.Where("entity_type = ? AND entity_id = ? AND tag_id = ?",
|
|
entityType, entityID, tagID).Delete(&EntityTag{}).Error
|
|
}
|
|
|
|
func GetTagsByEntity(entityType EntityType, entityID uint) ([]Tag, error) {
|
|
var tags []Tag
|
|
err := DB.Joins("JOIN entity_tags ON tags.id = entity_tags.tag_id").
|
|
Where("entity_tags.entity_type = ? AND entity_tags.entity_id = ?",
|
|
entityType, entityID).
|
|
Find(&tags).Error
|
|
return tags, err
|
|
}
|
|
|
|
func CreateTimeLog(timeLog *TimeLog) error {
|
|
return DB.Create(timeLog).Error
|
|
}
|
|
|
|
func GetTimeLogsByTask(taskID uint) ([]TimeLog, error) {
|
|
var timeLogs []TimeLog
|
|
err := DB.Where("task_id = ?", taskID).
|
|
Preload("User").
|
|
Order("log_date DESC").
|
|
Find(&timeLogs).Error
|
|
return timeLogs, err
|
|
}
|
|
|
|
func GetTimeLogsByUser(userID uint, startDate, endDate time.Time) ([]TimeLog, error) {
|
|
var timeLogs []TimeLog
|
|
err := DB.Where("user_id = ? AND log_date BETWEEN ? AND ?",
|
|
userID, startDate, endDate).
|
|
Preload("Task.Project").
|
|
Order("log_date DESC").
|
|
Find(&timeLogs).Error
|
|
return timeLogs, err
|
|
}
|
|
|
|
func UpdateTimeLog(timeLog *TimeLog) error {
|
|
return DB.Save(timeLog).Error
|
|
}
|
|
|
|
func DeleteTimeLog(id uint) error {
|
|
return DB.Delete(&TimeLog{}, id).Error
|
|
} |