mirror of
https://github.com/thomiceli/opengist.git
synced 2025-07-08 17:08:04 +02:00
Save content form on gist create error (#420)
This commit is contained in:
@ -567,6 +567,32 @@ func (gist *Gist) TopicsSlice() []string {
|
||||
return topics
|
||||
}
|
||||
|
||||
func (gist *Gist) ToDTO() (*GistDTO, error) {
|
||||
files, err := gist.Files("HEAD", false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fileDTOs := make([]FileDTO, 0, len(files))
|
||||
for _, file := range files {
|
||||
fileDTOs = append(fileDTOs, FileDTO{
|
||||
Filename: file.Filename,
|
||||
Content: file.Content,
|
||||
})
|
||||
}
|
||||
|
||||
return &GistDTO{
|
||||
Title: gist.Title,
|
||||
Description: gist.Description,
|
||||
URL: gist.URL,
|
||||
Files: fileDTOs,
|
||||
VisibilityDTO: VisibilityDTO{
|
||||
Private: gist.Private,
|
||||
},
|
||||
Topics: strings.Join(gist.TopicsSlice(), " "),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// -- DTO -- //
|
||||
|
||||
type GistDTO struct {
|
||||
@ -580,6 +606,10 @@ type GistDTO struct {
|
||||
VisibilityDTO
|
||||
}
|
||||
|
||||
func (dto *GistDTO) HasMetadata() bool {
|
||||
return dto.Title != "" || dto.Description != "" || dto.URL != "" || dto.Topics != ""
|
||||
}
|
||||
|
||||
type VisibilityDTO struct {
|
||||
Private Visibility `validate:"number,min=0,max=2" form:"private"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user