Create FileDTO

This commit is contained in:
Thomas Miceli 2023-03-18 23:23:23 +01:00
parent 527be16183
commit b56e02e3ed
No known key found for this signature in database
GPG key ID: D86C6F6390AF050F
3 changed files with 15 additions and 11 deletions

View file

@ -8,9 +8,9 @@ import (
)
type File struct {
Filename string `validate:"excludes=\x2f,excludes=\x5c,max=50"`
OldFilename string `validate:"excludes=\x2f,excludes=\x5c,max=50"`
Content string `validate:"required"`
Filename string
OldFilename string
Content string
Truncated bool
IsCreated bool
IsDeleted bool

View file

@ -226,7 +226,7 @@ func (gist *Gist) NbCommits() (string, error) {
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 {
return err
}
@ -263,10 +263,15 @@ func (gist *Gist) RPC(service string) ([]byte, error) {
// -- DTO -- //
type GistDTO struct {
Title string `validate:"max=50" form:"title"`
Description string `validate:"max=150" form:"description"`
Private bool `form:"private"`
Files []git.File `validate:"min=1,dive"`
Title string `validate:"max=50" form:"title"`
Description string `validate:"max=150" form:"description"`
Private bool `form:"private"`
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 {

View file

@ -10,7 +10,6 @@ import (
"html/template"
"net/url"
"opengist/internal/config"
"opengist/internal/git"
"opengist/internal/models"
"strconv"
"strings"
@ -208,7 +207,7 @@ func processCreate(ctx echo.Context) error {
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++ {
name := ctx.Request().PostForm["name"][i]
content := ctx.Request().PostForm["content"][i]
@ -222,7 +221,7 @@ func processCreate(ctx echo.Context) error {
return errorRes(400, "Invalid character unescaped", err)
}
dto.Files = append(dto.Files, git.File{
dto.Files = append(dto.Files, models.FileDTO{
Filename: name,
Content: escapedValue,
})