Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

レスポンスにサムネイル情報追加 #1929

Merged
merged 25 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e4494ee
レスポンスにサムネイル情報追加
azbcww Aug 13, 2023
bf16962
Revert "レスポンスにサムネイル情報追加"
azbcww Oct 2, 2023
59201bd
サムネイル情報を一度で取得
azbcww Oct 4, 2023
6407e0e
fix error
azbcww Oct 4, 2023
0c87c4a
Delete tree.txt
azbcww Oct 4, 2023
6fde0ca
StampWithThumbnail修正
azbcww Oct 18, 2023
e3d6c7c
test追加
azbcww Oct 18, 2023
ad78889
fix lint and change HasThumbnail to hasThumbnail
azbcww Oct 18, 2023
9efe74c
fix test
azbcww Oct 18, 2023
d87efdd
Revert "fix test"
azbcww Nov 27, 2023
f35c172
Revert "fix lint and change HasThumbnail to hasThumbnail"
azbcww Nov 27, 2023
5cff7cb
Revert "test追加"
azbcww Nov 27, 2023
d2b5d5c
Revert "StampWithThumbnail修正"
azbcww Nov 27, 2023
fd669b5
Revert "Delete tree.txt"
azbcww Nov 27, 2023
d65701a
Revert "fix error"
azbcww Nov 27, 2023
93faae0
Revert "サムネイル情報を一度で取得"
azbcww Nov 27, 2023
9069946
Revert "Revert "レスポンスにサムネイル情報追加""
azbcww Nov 27, 2023
96ed273
Revert "レスポンスにサムネイル情報追加"
azbcww Nov 27, 2023
634342d
convert GetAllStamps into GetAllStampsWithThumbnail
azbcww Nov 27, 2023
c70583c
put StampThumbnailExists into loadFilteredStamps
azbcww Nov 27, 2023
b2d6939
use make([]uuid.UUID, 0, len(stamps)) to define ts
azbcww Nov 27, 2023
b7a434d
correction of the part pointed out
azbcww Nov 28, 2023
c84387f
add test
azbcww Dec 1, 2023
d62fa79
edit swagger and fix nesting depth
azbcww Dec 3, 2023
47df0e8
edit OpenAPI schema
azbcww Dec 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
logica0419 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return herror.InternalServerError(err)
}
thumbs[i] = ts.Thumbnails
}
return extension.ServeJSONWithETag(c, formatStampInfos(stamps, thumbs))
}

// CreateStamp POST /stamps
Expand Down