Skip to content

Commit

Permalink
feat/takumi0616/234-record-add-modal
Browse files Browse the repository at this point in the history
  • Loading branch information
takumi0616 committed May 2, 2024
1 parent dae3e8e commit b9a4835
Show file tree
Hide file tree
Showing 8 changed files with 816 additions and 288 deletions.
60 changes: 26 additions & 34 deletions api/app/models/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def self.with_curriculum_and_teacher(record_id)
"curriculum": record.chapter.nil? || record.chapter.curriculum.nil? ? nil: record.chapter.curriculum,
"curriculum_title": record.chapter.nil? || record.chapter.curriculum.nil? ? nil: record.chapter.curriculum.title,
"chapter": record.chapter.nil? ? nil: record.chapter,
"teacher": record.teacher.user.name,
"user": record.user.name,
"teacher": record.teacher&.user&.name,
"user": record.user&.name,
"skills": record.chapter.nil? || record.chapter.curriculum.nil? ? nil: record.chapter.curriculum.skills.map{
|skill|
{
Expand All @@ -24,62 +24,54 @@ def self.with_curriculum_and_teacher(record_id)

def self.with_teacher_and_skills
@records = Record.eager_load(:teacher, :chapter, :user)
.map{
|record|
.map do |record|
{
"id": record.id,
"title": record.title,
"user_id": record.user.id,
"user_name": record.user.name,
"teacher_id": record.teacher.nil? ? nil: record.teacher.user.id,
"teacher_name": record.teacher.nil? ? nil: record.teacher.user.name,
"chapter_id": record.chapter.nil? ? nil: record.chapter.id,
"chapter_title": record.chapter.nil? ? nil: record.chapter.title,
"curriculum_id": record.chapter.nil? ? nil: record.chapter.curriculum.id,
"curriculum_title": record.chapter.nil? ? nil: record.chapter.curriculum.title,
"skills": record.chapter.nil? || record.chapter.curriculum.nil? ? nil: record.chapter.curriculum.skills.map{
|skill|
{
"name": skill.name,
}
},
"user_id": record.user&.id,
"user_name": record.user&.name,
"teacher_id": record.teacher&.user&.id,
"teacher_name": record.teacher&.user&.name,
"chapter_id": record.chapter&.id,
"chapter_title": record.chapter&.title,
"curriculum_id": record.chapter&.curriculum&.id,
"curriculum_title": record.chapter&.curriculum&.title,
"skills": record.chapter&.curriculum&.skills&.map{ |skill| { "name": skill.name } } || [],
"created_at": record.created_at,
"updated_at": record.updated_at,
}
}
end
end


def self.with_teacher_and_skill(record_id)
@record = Record.eager_load(:teacher, :chapter, :user).where(records: {id: record_id})
.map{
|record|
.map do |record|
{
"id": record.id,
"title": record.title,
"user_id": record.user.id,
"user_name": record.user.name,
"teacher_id": record.teacher.nil? ? nil: record.teacher.user.id,
"teacher_name": record.teacher.nil? ? nil: record.teacher.user.name,
"chapter_id": record.chapter.nil? ? nil: record.chapter.id,
"chapter_title": record.chapter.nil? ? nil: record.chapter.title,
"skills": record.chapter.nil? || record.chapter.curriculum.nil? ? nil: record.chapter.curriculum.skills.map{
|skill|
{
"name": skill.name,
}
},
"user_id": record.user&.id,
"user_name": record.user&.name,
"teacher_id": record.teacher&.user&.id,
"teacher_name": record.teacher&.user&.name,
"chapter_id": record.chapter&.id,
"chapter_title": record.chapter&.title,
"skills": record.chapter&.curriculum&.skills&.map{ |skill| { "name": skill.name } } || [],
"created_at": record.created_at,
"updated_at": record.updated_at,
}
}
end
end

def self.get_teacher(record_id)
record = Record.find(record_id)
return nil unless record.teacher && record.teacher.user

{
"id": record.teacher.id,
"user_id": record.teacher.user.id,
"record_id": record.id,
}
end

end
56 changes: 28 additions & 28 deletions api/db/fixtures/record.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
Record.seed( :id,
{ id: 1, title: 'TypeScriptで二分木を反転', content: 'test_content', homework: 'test_homework', user_id: 1},
{ id: 2, title: 'GoでFizzBuzz', content: 'test_content', homework: 'test_homework', user_id: 2, chapter_id: 2 },
{ id: 3, title: 'Reactのルーティングについての記事を読んだ', content: 'test_content', homework: 'test_homework', user_id: 3, chapter_id: 3 },
{ id: 4, title: 'TypeScriptのインターフェースを書いた', content: 'test_content', homework: 'test_homework', user_id: 4, chapter_id: 4 },
{ id: 5, title: 'TypeScriptのバックエンドツールに関する記事を読んだ', content: 'test_content', homework: 'test_homework', user_id: 1, chapter_id: 1 },
{ id: 6, title: 'Goによるオニオンアーキテクチャを実装した', content: 'test_content', homework: 'test_homework', user_id: 2, chapter_id: 2 },
{ id: 7, title: 'Reactとnode-fetchによるAPI操作', content: 'test_content', homework: 'test_homework', user_id: 3, chapter_id: 3 },
{ id: 8, title: 'Goのインターフェースを書いた', content: 'test_content', homework: 'test_homework', user_id: 4, chapter_id: 4 },
{ id: 9, title: 'WSLの環境構築', content: 'test_content', homework: 'なし', user_id: 1, chapter_id: 1 },
{ id: 10, title: 'Linuxのコマンド学習', content: 'test_content', homework: 'なし', user_id: 2, chapter_id: 2 },
{ id: 11, title: 'GitとGitHubについて動画学習', content: 'test_content', homework: 'なし', user_id: 3, chapter_id: 3 },
{ id: 12, title: 'GitHub初期設定(SSH Keyの登録など)', content: 'test_content', homework: 'なし', user_id: 4, chapter_id: 4 },
{ id: 13, title: 'WSL上にRubyの環境構築', content: 'test_content', homework: 'なし', user_id: 1, chapter_id: 1 },
{ id: 14, title: 'Rubyでメソッドと配列について学習', content: 'test_content', homework: 'なし', user_id: 2, chapter_id: 2 },
{ id: 15, title: 'Rubyのif,for,while文について学習', content: 'test_content', homework: 'なし', user_id: 3, chapter_id: 3 },
{ id: 16, title: 'Dockerをつかってみる', content: 'test_content', homework: 'なし', user_id: 4, chapter_id: 4 },
{ id: 17, title: 'FastAPIでToDoリスト作成', content: 'test_content', homework: 'なし', user_id: 1, chapter_id: 1 },
{ id: 18, title: 'Azure for Student でインスタンス作成', content: 'test_content', homework: 'なし', user_id: 2, chapter_id: 2 },
{ id: 19, title: 'AzureにSSH接続', content: 'test_content', homework: 'なし', user_id: 3, chapter_id: 3 },
{ id: 20, title: 'お名前.comでドメイン取得とDNS設定', content: 'test_content', homework: 'なし', user_id: 4, chapter_id: 4 },
{ id: 21, title: 'Nginxを使ったリバースプロキシの設定', content: 'test_content', homework: 'なし', user_id: 1, chapter_id: 1 },
{ id: 22, title: 'AzureにStickeeをデプロイ', content: 'test_content', homework: 'なし', user_id: 2, chapter_id: 2 },
{ id: 23, title: 'Certbotを用いたSSLの設定', content: 'test_content', homework: 'なし', user_id: 3, chapter_id: 3 },
{ id: 24, title: 'Softether VPNをインストール(vpnserver)', content: 'test_content', homework: 'なし', user_id: 4, chapter_id: 4 },
{ id: 25, title: 'Softether VPNをインストール(vpnclient)', content: 'test_content', homework: 'なし', user_id: 1, chapter_id: 1 },
{ id: 26, title: 'NginxでVPN越しにリバースプロキシ', content: 'test_content', homework: 'なし', user_id: 2, chapter_id: 2},
{ id: 27, title: 'AWSでインスタンスを作成', content: 'test_content', homework: 'なし', user_id: 3, chapter_id: 3},
)
{ id: 1, title: 'TypeScriptで二分木を反転', content: 'test_content', homework: 'test_homework', user_id: 1, release: true },
{ id: 2, title: 'GoでFizzBuzz', content: 'test_content', homework: 'test_homework', user_id: 2, chapter_id: 2, release: true },
{ id: 3, title: 'Reactのルーティングについての記事を読んだ', content: 'test_content', homework: 'test_homework', user_id: 3, chapter_id: 3, release: true },
{ id: 4, title: 'TypeScriptのインターフェースを書いた', content: 'test_content', homework: 'test_homework', user_id: 4, chapter_id: 4, release: true },
{ id: 5, title: 'TypeScriptのバックエンドツールに関する記事を読んだ', content: 'test_content', homework: 'test_homework', user_id: 1, chapter_id: 1, release: true },
{ id: 6, title: 'Goによるオニオンアーキテクチャを実装した', content: 'test_content', homework: 'test_homework', user_id: 2, chapter_id: 2, release: true },
{ id: 7, title: 'Reactとnode-fetchによるAPI操作', content: 'test_content', homework: 'test_homework', user_id: 3, chapter_id: 3, release: true },
{ id: 8, title: 'Goのインターフェースを書いた', content: 'test_content', homework: 'test_homework', user_id: 4, chapter_id: 4, release: true },
{ id: 9, title: 'WSLの環境構築', content: 'test_content', homework: 'なし', user_id: 1, chapter_id: 1, release: true },
{ id: 10, title: 'Linuxのコマンド学習', content: 'test_content', homework: 'なし', user_id: 2, chapter_id: 2, release: true },
{ id: 11, title: 'GitとGitHubについて動画学習', content: 'test_content', homework: 'なし', user_id: 3, chapter_id: 3, release: true },
{ id: 12, title: 'GitHub初期設定(SSH Keyの登録など)', content: 'test_content', homework: 'なし', user_id: 4, chapter_id: 4, release: true },
{ id: 13, title: 'WSL上にRubyの環境構築', content: 'test_content', homework: 'なし', user_id: 1, chapter_id: 1, release: true },
{ id: 14, title: 'Rubyでメソッドと配列について学習', content: 'test_content', homework: 'なし', user_id: 2, chapter_id: 2, release: true },
{ id: 15, title: 'Rubyのif,for,while文について学習', content: 'test_content', homework: 'なし', user_id: 3, chapter_id: 3, release: true },
{ id: 16, title: 'Dockerをつかってみる', content: 'test_content', homework: 'なし', user_id: 4, chapter_id: 4, release: true },
{ id: 17, title: 'FastAPIでToDoリスト作成', content: 'test_content', homework: 'なし', user_id: 1, chapter_id: 1, release: true },
{ id: 18, title: 'Azure for Student でインスタンス作成', content: 'test_content', homework: 'なし', user_id: 2, chapter_id: 2, release: true },
{ id: 19, title: 'AzureにSSH接続', content: 'test_content', homework: 'なし', user_id: 3, chapter_id: 3, release: true },
{ id: 20, title: 'お名前.comでドメイン取得とDNS設定', content: 'test_content', homework: 'なし', user_id: 4, chapter_id: 4, release: true },
{ id: 21, title: 'Nginxを使ったリバースプロキシの設定', content: 'test_content', homework: 'なし', user_id: 1, chapter_id: 1, release: true },
{ id: 22, title: 'AzureにStickeeをデプロイ', content: 'test_content', homework: 'なし', user_id: 2, chapter_id: 2, release: true },
{ id: 23, title: 'Certbotを用いたSSLの設定', content: 'test_content', homework: 'なし', user_id: 3, chapter_id: 3, release: true },
{ id: 24, title: 'Softether VPNをインストール(vpnserver)', content: 'test_content', homework: 'なし', user_id: 4, chapter_id: 4, release: true },
{ id: 25, title: 'Softether VPNをインストール(vpnclient)', content: 'test_content', homework: 'なし', user_id: 1, chapter_id: 1, release: true },
{ id: 26, title: 'NginxでVPN越しにリバースプロキシ', content: 'test_content', homework: 'なし', user_id: 2, chapter_id: 2, release: true },
{ id: 27, title: 'AWSでインスタンスを作成', content: 'test_content', homework: 'なし', user_id: 3, chapter_id: 3, release: true },
)
6 changes: 5 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "3"
services:
seeds_db:
image: mysql:8.0
Expand All @@ -23,6 +22,11 @@ services:
- seeds_db
stdin_open: true
tty: true
environment:
DB_HOST: seeds_db
DB_USER: root
DB_PASSWORD: password
DB_NAME: myapp_development

seeds_view:
build: ./view
Expand Down
Loading

0 comments on commit b9a4835

Please sign in to comment.