pkgdash/internal/models/models.go

79 lines
2.0 KiB
Go
Raw Normal View History

package models
import (
"time"
pb "git.unistack.org/unistack-org/pkgdash/proto"
"google.golang.org/protobuf/types/known/timestamppb"
)
type Package struct {
Name string `db:"name" json:"name"`
URL string `db:"url" json:"url"`
Modules []uint64 `db:"modules" json:"modules"`
Issues []uint64 `db:"issues" json:"issues,omitempty"`
Comments []uint64 `db:"comments" json:"comments,omitempty"`
ID uint64 `db:"id" json:"id"`
Created time.Time `db:"created" json:"created"`
Updated time.Time `db:"updated" json:"updated,omitempty"`
}
func NewPackage(pkg *Package) *pb.Package {
return &pb.Package{
Name: pkg.Name,
Url: pkg.URL,
Modules: pkg.Modules,
Issues: pkg.Issues,
Comments: pkg.Comments,
Id: pkg.ID,
Created: timestamppb.New(pkg.Created),
Updated: timestamppb.New(pkg.Updated),
}
}
type Module struct {
Name string `db:"name"`
Version string `db:"version"`
LastVersion string `db:"last_version"`
ID uint64 `db:"id"`
Package uint64 `db:"package"`
Created time.Time `db:"created" json:"created"`
Updated time.Time `db:"updated" json:"updated,omitempty"`
}
func NewModule(mod *Module) *pb.Module {
return &pb.Module{
Name: mod.Name,
Version: mod.Version,
LastVersion: mod.LastVersion,
Package: mod.Package,
Id: mod.ID,
Created: timestamppb.New(mod.Created),
Updated: timestamppb.New(mod.Updated),
}
}
type Issue struct {
Desc string `db:"desc"`
Modules []int64 `db:"modules"`
ID uint64 `db:"id"`
Status uint64 `db:"status"`
Package int64 `db:"package"`
}
type Comment struct {
Created time.Time `db:"created" json:"created"`
Updated time.Time `db:"updated" json:"updated,omitempty"`
Text string `db:"value" json:"text"`
ID uint64 `db:"id" json:"id"`
}
func NewComment(com *Comment) *pb.Comment {
return &pb.Comment{
Id: com.ID,
Text: com.Text,
Created: timestamppb.New(com.Created),
Updated: timestamppb.New(com.Updated),
}
}