Put project modules under pkg directory
This commit is contained in:
parent
f4684be37d
commit
e1516e450b
13 changed files with 7 additions and 7 deletions
50
pkg/cgnolink/link/dto.go
Normal file
50
pkg/cgnolink/link/dto.go
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
package link
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CreationModel struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
RedirectURL string `json:"redirectUrl"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type ResourceModel struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
RedirectURL string `json:"redirectUrl"`
|
||||
CreationTime int64 `json:"creationTime"`
|
||||
}
|
||||
|
||||
type UpdateModel struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
RedirectURL string `json:"redirectUrl,omitempty"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
func (m *CreationModel) MapModelToEntity() (*Link, error) {
|
||||
u, err := url.Parse(m.RedirectURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Link{
|
||||
Id: m.Id,
|
||||
Name: m.Name,
|
||||
RedirectURL: *u,
|
||||
Password: m.Password,
|
||||
CreationTime: time.Now().UTC(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func MapEntityToModel(entity *Link) ResourceModel {
|
||||
return ResourceModel{
|
||||
Id: entity.Id,
|
||||
Name: entity.Name,
|
||||
RedirectURL: entity.RedirectURL.String(),
|
||||
CreationTime: entity.CreationTime.Unix(),
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue