From a162615b051069d703ae24e94c9f7a13f7752672 Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Wed, 18 Oct 2023 15:21:09 +0200 Subject: [PATCH] wip --- .../api/osuny/application_controller.rb | 6 ++++ .../websites/posts_controller.rb | 31 ++++++++++++------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/app/controllers/api/osuny/application_controller.rb b/app/controllers/api/osuny/application_controller.rb index 0ed98e140..e5c8aab42 100644 --- a/app/controllers/api/osuny/application_controller.rb +++ b/app/controllers/api/osuny/application_controller.rb @@ -1,4 +1,5 @@ class Api::Osuny::ApplicationController < Api::ApplicationController + protected def verify_app_token @@ -6,4 +7,9 @@ class Api::Osuny::ApplicationController < Api::ApplicationController secret_key: params[:secret_key]) raise_403_unless app end + + def website + @website ||= current_university.websites.find params[:website_id] + end + end \ No newline at end of file diff --git a/app/controllers/api/osuny/communication/websites/posts_controller.rb b/app/controllers/api/osuny/communication/websites/posts_controller.rb index 4f617e3ac..785795440 100644 --- a/app/controllers/api/osuny/communication/websites/posts_controller.rb +++ b/app/controllers/api/osuny/communication/websites/posts_controller.rb @@ -5,6 +5,7 @@ class Api::Osuny::Communication::Websites::PostsController < Api::Osuny::Applica verify_app_token create_post import_blocks + import_categories render json: :ok end @@ -16,16 +17,6 @@ class Api::Osuny::Communication::Websites::PostsController < Api::Osuny::Applica post.save end - def post - @post ||= website.posts - .where( - university: current_university, - website: website, - migration_identifier: migration_identifier - ) - .first_or_initialize - end - def import_blocks blocks.each do |b| migration_identifier = b[:migration_identifier] @@ -43,13 +34,29 @@ class Api::Osuny::Communication::Websites::PostsController < Api::Osuny::Applica end end + def import_categories + categories.each do |category| + byebug + end + end + + def post + @post ||= website.posts.where( + university: current_university, + website: website, + migration_identifier: migration_identifier + ) + .first_or_initialize + end + def blocks return [] unless params[:post].has_key?(:blocks) @blocks ||= params[:post][:blocks] end - def website - @website ||= current_university.websites.find params[:website_id] + def categories + return [] unless params[:post].has_key?(:categories) + @categories ||= params[:post][:categories] end def migration_identifier -- GitLab