mirror of
https://github.com/thomiceli/opengist.git
synced 2025-01-03 16:22:40 +00:00
Create FileDTO
This commit is contained in:
parent
527be16183
commit
b56e02e3ed
3 changed files with 15 additions and 11 deletions
|
@ -8,9 +8,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
Filename string `validate:"excludes=\x2f,excludes=\x5c,max=50"`
|
Filename string
|
||||||
OldFilename string `validate:"excludes=\x2f,excludes=\x5c,max=50"`
|
OldFilename string
|
||||||
Content string `validate:"required"`
|
Content string
|
||||||
Truncated bool
|
Truncated bool
|
||||||
IsCreated bool
|
IsCreated bool
|
||||||
IsDeleted bool
|
IsDeleted bool
|
||||||
|
|
|
@ -226,7 +226,7 @@ func (gist *Gist) NbCommits() (string, error) {
|
||||||
return git.GetNumberOfCommitsOfRepository(gist.User.Username, gist.Uuid)
|
return git.GetNumberOfCommitsOfRepository(gist.User.Username, gist.Uuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gist *Gist) AddAndCommitFiles(files *[]git.File) error {
|
func (gist *Gist) AddAndCommitFiles(files *[]FileDTO) error {
|
||||||
if err := git.CloneTmp(gist.User.Username, gist.Uuid, gist.Uuid); err != nil {
|
if err := git.CloneTmp(gist.User.Username, gist.Uuid, gist.Uuid); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -263,10 +263,15 @@ func (gist *Gist) RPC(service string) ([]byte, error) {
|
||||||
// -- DTO -- //
|
// -- DTO -- //
|
||||||
|
|
||||||
type GistDTO struct {
|
type GistDTO struct {
|
||||||
Title string `validate:"max=50" form:"title"`
|
Title string `validate:"max=50" form:"title"`
|
||||||
Description string `validate:"max=150" form:"description"`
|
Description string `validate:"max=150" form:"description"`
|
||||||
Private bool `form:"private"`
|
Private bool `form:"private"`
|
||||||
Files []git.File `validate:"min=1,dive"`
|
Files []FileDTO `validate:"min=1,dive"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type FileDTO struct {
|
||||||
|
Filename string `validate:"excludes=\x2f,excludes=\x5c,max=50"`
|
||||||
|
Content string `validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dto *GistDTO) ToGist() *Gist {
|
func (dto *GistDTO) ToGist() *Gist {
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/url"
|
"net/url"
|
||||||
"opengist/internal/config"
|
"opengist/internal/config"
|
||||||
"opengist/internal/git"
|
|
||||||
"opengist/internal/models"
|
"opengist/internal/models"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -208,7 +207,7 @@ func processCreate(ctx echo.Context) error {
|
||||||
return errorRes(400, "Cannot bind data", err)
|
return errorRes(400, "Cannot bind data", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dto.Files = make([]git.File, 0)
|
dto.Files = make([]models.FileDTO, 0)
|
||||||
for i := 0; i < len(ctx.Request().PostForm["content"]); i++ {
|
for i := 0; i < len(ctx.Request().PostForm["content"]); i++ {
|
||||||
name := ctx.Request().PostForm["name"][i]
|
name := ctx.Request().PostForm["name"][i]
|
||||||
content := ctx.Request().PostForm["content"][i]
|
content := ctx.Request().PostForm["content"][i]
|
||||||
|
@ -222,7 +221,7 @@ func processCreate(ctx echo.Context) error {
|
||||||
return errorRes(400, "Invalid character unescaped", err)
|
return errorRes(400, "Invalid character unescaped", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dto.Files = append(dto.Files, git.File{
|
dto.Files = append(dto.Files, models.FileDTO{
|
||||||
Filename: name,
|
Filename: name,
|
||||||
Content: escapedValue,
|
Content: escapedValue,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue