pkgdash/internal/models/models.go
Vasiliy Tolstov 59e28e5a86 updates
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-08-19 16:55:52 +03:00

83 lines
1.8 KiB
Go

package models
import (
"database/sql"
"time"
pb "git.unistack.org/unistack-org/pkgdash/proto"
"google.golang.org/protobuf/types/known/timestamppb"
)
type Package struct {
LastCheck sql.NullTime `db:"last_check"`
Created time.Time `db:"created"`
Updated time.Time `db:"updated"`
Name string `db:"name"`
URL string `db:"url"`
Modules uint64 `db:"modules"`
Issues uint64 `db:"issues"`
Comments uint64 `db:"comments"`
ID uint64 `db:"id"`
Status uint64 `db:"status"`
}
func NewPackage(pkg *Package) *pb.Package {
rsp := &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),
}
if pkg.LastCheck.Valid {
rsp.LastCheck = timestamppb.New(pkg.LastCheck.Time)
}
return rsp
}
type Module struct {
LastCheck sql.NullTime `db:"last_check"`
Name string `db:"name"`
Version string `db:"version"`
ID uint64 `db:"id"`
}
func NewModule(mod *Module) *pb.Module {
rsp := &pb.Module{
Name: mod.Name,
Version: mod.Version,
Id: mod.ID,
}
if mod.LastCheck.Valid {
rsp.LastCheck = timestamppb.New(mod.LastCheck.Time)
}
return rsp
}
type Issue struct {
Comment string `db:"comment"`
Modules []int64 `db:"modules"`
ID uint64 `db:"id"`
Status uint64 `db:"status"`
Package uint64 `db:"package"`
}
type Comment struct {
Created time.Time `db:"created"`
Updated time.Time `db:"updated"`
Comment string `db:"comment"`
ID uint64 `db:"id"`
}
func NewComment(com *Comment) *pb.Comment {
return &pb.Comment{
Id: com.ID,
Comment: com.Comment,
Created: timestamppb.New(com.Created),
Updated: timestamppb.New(com.Updated),
}
}