2023-08-16 13:17:42 +03:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
2023-08-18 23:59:15 +03:00
|
|
|
"database/sql"
|
2023-08-16 13:17:42 +03:00
|
|
|
"time"
|
|
|
|
|
|
|
|
pb "git.unistack.org/unistack-org/pkgdash/proto"
|
|
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
|
|
)
|
|
|
|
|
2023-09-23 21:16:26 +03:00
|
|
|
type Handler struct {
|
|
|
|
ID uint64 `db:"id"`
|
|
|
|
Package uint64 `db:"package"`
|
|
|
|
Name string `db:"name"`
|
|
|
|
Coverage sql.NullFloat64 `db:"coverage"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHandler(hdlr *Handler) *pb.Handler {
|
|
|
|
if hdlr == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
rsp := &pb.Handler{
|
|
|
|
Id: hdlr.ID,
|
|
|
|
Package: hdlr.Package,
|
|
|
|
Name: hdlr.Name,
|
|
|
|
}
|
|
|
|
if hdlr.Coverage.Valid {
|
|
|
|
rsp.Coverage = hdlr.Coverage.Float64
|
|
|
|
}
|
|
|
|
return rsp
|
|
|
|
}
|
|
|
|
|
2023-08-16 13:17:42 +03:00
|
|
|
type Package struct {
|
2023-09-23 21:16:26 +03:00
|
|
|
Created time.Time `db:"created"`
|
|
|
|
Updated time.Time `db:"updated"`
|
|
|
|
LastCheck sql.NullTime `db:"last_check"`
|
|
|
|
Type string `db:"type"`
|
|
|
|
Name string `db:"name"`
|
|
|
|
URL string `db:"url"`
|
|
|
|
Description sql.NullString `db:"description"`
|
|
|
|
Coverage sql.NullFloat64 `db:"coverage"`
|
|
|
|
Modules uint64 `db:"modules"`
|
|
|
|
ID uint64 `db:"id"`
|
|
|
|
Status uint64 `db:"status"`
|
|
|
|
Comments uint64 `db:"comments"`
|
|
|
|
Issues uint64 `db:"issues"`
|
2023-08-16 13:17:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewPackage(pkg *Package) *pb.Package {
|
2023-09-23 21:16:26 +03:00
|
|
|
if pkg == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2023-08-18 23:59:15 +03:00
|
|
|
rsp := &pb.Package{
|
2023-08-16 13:17:42 +03:00
|
|
|
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),
|
2023-09-23 21:16:26 +03:00
|
|
|
Type: pkg.Type,
|
|
|
|
}
|
|
|
|
if rsp.Type == "" {
|
|
|
|
rsp.Type = "package"
|
|
|
|
}
|
|
|
|
if pkg.Description.Valid {
|
|
|
|
rsp.Description = pkg.Description.String
|
2023-08-16 13:17:42 +03:00
|
|
|
}
|
2023-08-18 23:59:15 +03:00
|
|
|
if pkg.LastCheck.Valid {
|
|
|
|
rsp.LastCheck = timestamppb.New(pkg.LastCheck.Time)
|
|
|
|
}
|
2023-09-23 21:16:26 +03:00
|
|
|
if pkg.Coverage.Valid {
|
|
|
|
rsp.Coverage = pkg.Coverage.Float64
|
|
|
|
}
|
2023-08-18 23:59:15 +03:00
|
|
|
return rsp
|
2023-08-16 13:17:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type Module struct {
|
2023-08-19 16:55:52 +03:00
|
|
|
LastCheck sql.NullTime `db:"last_check"`
|
|
|
|
Name string `db:"name"`
|
|
|
|
Version string `db:"version"`
|
|
|
|
ID uint64 `db:"id"`
|
2023-08-16 13:17:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewModule(mod *Module) *pb.Module {
|
2023-09-23 21:16:26 +03:00
|
|
|
if mod == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2023-08-19 16:55:52 +03:00
|
|
|
rsp := &pb.Module{
|
|
|
|
Name: mod.Name,
|
|
|
|
Version: mod.Version,
|
|
|
|
Id: mod.ID,
|
|
|
|
}
|
|
|
|
if mod.LastCheck.Valid {
|
|
|
|
rsp.LastCheck = timestamppb.New(mod.LastCheck.Time)
|
2023-08-16 13:17:42 +03:00
|
|
|
}
|
2023-08-19 16:55:52 +03:00
|
|
|
return rsp
|
2023-08-16 13:17:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type Issue struct {
|
2023-08-18 23:59:15 +03:00
|
|
|
Comment string `db:"comment"`
|
2023-08-16 13:17:42 +03:00
|
|
|
Modules []int64 `db:"modules"`
|
|
|
|
ID uint64 `db:"id"`
|
|
|
|
Status uint64 `db:"status"`
|
2023-08-18 23:59:15 +03:00
|
|
|
Package uint64 `db:"package"`
|
2023-08-16 13:17:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type Comment struct {
|
2023-08-18 23:59:15 +03:00
|
|
|
Created time.Time `db:"created"`
|
|
|
|
Updated time.Time `db:"updated"`
|
|
|
|
Comment string `db:"comment"`
|
|
|
|
ID uint64 `db:"id"`
|
2023-08-16 13:17:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewComment(com *Comment) *pb.Comment {
|
2023-09-23 21:16:26 +03:00
|
|
|
if com == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2023-08-16 13:17:42 +03:00
|
|
|
return &pb.Comment{
|
|
|
|
Id: com.ID,
|
2023-08-18 23:59:15 +03:00
|
|
|
Comment: com.Comment,
|
2023-08-16 13:17:42 +03:00
|
|
|
Created: timestamppb.New(com.Created),
|
|
|
|
Updated: timestamppb.New(com.Updated),
|
|
|
|
}
|
|
|
|
}
|