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

memoのタグのレスポンスにidを含めるように変更 #119

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion backend/app/views/memos/index.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ json.memos @memos[:memos] do |memo|
json.poster memo.poster
json.created_at memo.created_at
json.updated_at memo.updated_at
json.tag_names memo.tags.map(&:name)
json.tags memo.tags do |tag|
json.id tag.id
json.name tag.name
end
end
json.total_page @memos[:total_page]
5 changes: 4 additions & 1 deletion backend/app/views/memos/show.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ json.memo do
json.created_at @memo.created_at
json.updated_at @memo.updated_at

json.tag_names @memo.tags.map(&:name)
json.tags @memo.tags do |tag|
json.id tag.id
json.name tag.name
end

json.comments @comments do |comment|
json.id comment.id
Expand Down
13 changes: 8 additions & 5 deletions backend/doc/components/memoSchema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ components:
type: string
format: date-time
example: 2021-01-01T00:00:00.000Z
tag_names:
tags:
type: array
items:
type: string
example:
- タグ1
- タグ2
properties:
id:
type: integer
example: 1
name:
type: string
example: "タグの名前"
comments:
type: array
items:
Expand Down
12 changes: 8 additions & 4 deletions backend/spec/requests/memos_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@
expect(response.parsed_body['memos'].length).to eq(10)
result_memo_ids = response.parsed_body['memos'].map { _1['id'] } # rubocop:disable Rails/Pluck
expected_memo_ids = memos.reverse.map(&:id)
result_memo_tags = response.parsed_body['memos'].map { _1['tag_names'] } # rubocop:disable Rails/Pluck
expected_memo_tags = memos.reverse.map { |memo| memo.tags.map(&:name) }
result_memo_tags = response.parsed_body['memos'].map { _1['tags'] } # rubocop:disable Rails/Pluck
expected_memo_tags = memos.reverse.map do |memo|
memo.tags.map { |tag| { id: tag.id, name: tag.name } }
end.as_json
expect(result_memo_ids).to eq(expected_memo_ids[0..9])
expect(result_memo_tags).to eq(expected_memo_tags[0..9])
expect(response.parsed_body['total_page']).to eq(2)
Expand All @@ -81,8 +83,10 @@
expect(response.parsed_body['memos'].length).to eq(10)
result_memo_ids = response.parsed_body['memos'].pluck('id')
expected_memo_ids = memos.sort_by(&:id).reverse[10..19].map(&:id)
result_memo_tags = response.parsed_body['memos'].map { _1['tag_names'] } # rubocop:disable Rails/Pluck
expected_memo_tags = memos.reverse.map { |memo| memo.tags.map(&:name) }
result_memo_tags = response.parsed_body['memos'].map { _1['tags'] } # rubocop:disable Rails/Pluck
expected_memo_tags = memos.reverse.map do |memo|
memo.tags.map { |tag| { id: tag.id, name: tag.name } }
end.as_json
expect(result_memo_ids).to eq(expected_memo_ids)
expect(result_memo_tags).to eq(expected_memo_tags[10..19])
expect(response.parsed_body['total_page']).to eq(2)
Expand Down
Loading