72 lines
1.3 KiB
Go
72 lines
1.3 KiB
Go
package models
|
|
|
|
import (
|
|
"github.com/jackc/pgtype"
|
|
pb "go.unistack.org/unistack-org/pkgdash/proto"
|
|
"time"
|
|
)
|
|
|
|
type ListPackage []*Package
|
|
|
|
func (l ListPackage) Decode() []*pb.Package {
|
|
result := make([]*pb.Package, 0, len(l))
|
|
|
|
for i := range l {
|
|
temp := &pb.Package{
|
|
Id: l[i].ID,
|
|
Name: l[i].Name,
|
|
Url: l[i].URL,
|
|
Modules: l[i].Modules,
|
|
Issues: l[i].Issues,
|
|
Comments: l[i].Comments,
|
|
}
|
|
|
|
result = append(result, temp)
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
type ListModule []*Module
|
|
|
|
func (l ListModule) Decode() []*pb.Module {
|
|
result := make([]*pb.Module, 0, len(l))
|
|
for i := range l {
|
|
temp := &pb.Module{
|
|
Id: l[i].ID,
|
|
Name: l[i].Name,
|
|
Version: l[i].Version,
|
|
LastVersion: l[i].LastVersion,
|
|
}
|
|
|
|
result = append(result, temp)
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
type ListComment []*Comment
|
|
|
|
func (l ListComment) Decode() []*pb.Comment {
|
|
result := make([]*pb.Comment, 0, len(l))
|
|
for i := range l {
|
|
temp := &pb.Comment{
|
|
Id: l[i].ID,
|
|
//Package: l[i].,
|
|
Text: l[i].Text,
|
|
}
|
|
|
|
if l[i].Created.Status == pgtype.Present {
|
|
temp.Created = l[i].Created.Time.Format(time.DateTime)
|
|
}
|
|
|
|
if l[i].Updated.Status == pgtype.Present {
|
|
temp.Updated = l[i].Updated.Time.Format(time.DateTime)
|
|
}
|
|
|
|
result = append(result, temp)
|
|
}
|
|
|
|
return result
|
|
}
|