From 4e3b6d9baab73d8ae22f2be5a54cc69c5924c234 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Wed, 18 Oct 2023 15:34:15 +0200
Subject: [PATCH] post categories

---
 .../communication/websites/posts_controller.rb    | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/app/controllers/api/osuny/communication/websites/posts_controller.rb b/app/controllers/api/osuny/communication/websites/posts_controller.rb
index 218cc48da..350d41a51 100644
--- a/app/controllers/api/osuny/communication/websites/posts_controller.rb
+++ b/app/controllers/api/osuny/communication/websites/posts_controller.rb
@@ -35,8 +35,19 @@ class Api::Osuny::Communication::Websites::PostsController < Api::Osuny::Applica
   end
 
   def import_categories
-    categories.each do |category|
-      byebug
+    categories.each do |c|
+      data = c.to_unsafe_hash
+      if data.has_key? 'name'
+        category = website.categories.where(
+          university: current_university,
+          website: website,
+          name: data['name'],
+          language: website.default_language
+        ).first_or_create
+      end
+      next if category.nil?
+      next if category.in?(post.categories)
+      post.categories << category
     end
   end
 
-- 
GitLab