Skip to content

Commit

Permalink
レスポンスにサムネイル情報追加
Browse files Browse the repository at this point in the history
  • Loading branch information
azbcww committed Aug 13, 2023
1 parent 69170f6 commit e4494ee
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
35 changes: 35 additions & 0 deletions router/v3/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,3 +623,38 @@ func formatStampPalettes(cfs []*model.StampPalette) []*StampPalette {
sort.Slice(res, func(i, j int) bool { return res[i].ID.String() < res[j].ID.String() })
return res
}

type StampInfo struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
CreatorID uuid.UUID `json:"creatorId"`
FileID uuid.UUID `json:"fileId"`
IsUnicode bool `json:"isUnicode"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt time.Time `json:"-"`
Thumbnails []model.FileThumbnail `json:"thumbnails"`
}

func formatStampInfo(stamp *model.Stamp, thumb []model.FileThumbnail) *StampInfo {
si := &StampInfo{
ID: stamp.ID,
Name: stamp.Name,
CreatorID: stamp.CreatorID,
FileID: stamp.FileID,
IsUnicode: stamp.IsUnicode,
CreatedAt: stamp.CreatedAt,
UpdatedAt: stamp.UpdatedAt,
DeletedAt: stamp.DeletedAt.Time,
Thumbnails: thumb,
}
return si
}

func formatStampInfos(stamps []*model.Stamp, thumbs [][]model.FileThumbnail) []*StampInfo {
result := make([]*StampInfo, len(stamps))
for i, stamp := range stamps {
result[i] = formatStampInfo(stamp, thumbs[i])
}
return result
}
11 changes: 10 additions & 1 deletion router/v3/stamps.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/gofrs/uuid"
"github.com/labstack/echo/v4"

"github.com/traPtitech/traQ/model"
"github.com/traPtitech/traQ/repository"
"github.com/traPtitech/traQ/router/consts"
"github.com/traPtitech/traQ/router/extension"
Expand Down Expand Up @@ -71,7 +72,15 @@ func (h *Handlers) GetStamps(c echo.Context) error {
return herror.InternalServerError(err)
}

return extension.ServeJSONWithETag(c, stamps)
thumbs := make([][]model.FileThumbnail, len(stamps))
for i, stamp := range stamps {
ts, err := h.Repo.GetFileMeta(stamp.FileID)
if err != nil {
return herror.InternalServerError(err)
}
thumbs[i] = ts.Thumbnails
}
return extension.ServeJSONWithETag(c, formatStampInfos(stamps, thumbs))
}

// CreateStamp POST /stamps
Expand Down

0 comments on commit e4494ee

Please sign in to comment.