import { makeAutoObservable } from 'mobx'; import api from '../services/api'; class InteractionStore { comments = []; ratings = []; likes = []; favorites = []; loading = false; error = null; constructor() { makeAutoObservable(this); } // Comments async createComment(targetType, targetId, content) { try { const response = await api.post('/api/comments/', { target_type: targetType, target_id: targetId, content, }); return { success: true, comment: response.data }; } catch (error) { return { success: false, error: error.response?.data || 'Failed to create comment', }; } } async fetchComments(targetType, targetId) { try { const response = await api.get('/api/comments/', { params: { target_type: targetType, target_id: targetId }, }); this.comments = response.data.results || response.data; } catch (error) { this.error = error.response?.data || 'Failed to fetch comments'; } } async approveComment(commentId) { try { await api.post(`/api/comments/${commentId}/approve_ai/`); return { success: true }; } catch (error) { return { success: false, error: error.response?.data || 'Failed to approve comment', }; } } async rejectComment(commentId, reason) { try { await api.post(`/api/comments/${commentId}/reject_ai/`, { reason }); return { success: true }; } catch (error) { return { success: false, error: error.response?.data || 'Failed to reject comment', }; } } // Ratings async createRating(targetType, targetId, score) { try { const response = await api.post('/api/ratings/', { target_type: targetType, target_id: targetId, score, }); return { success: true, rating: response.data }; } catch (error) { return { success: false, error: error.response?.data || 'Failed to create rating', }; } } async fetchRatings(params = {}) { try { const response = await api.get('/api/ratings/', { params }); this.ratings = response.data.results || response.data; } catch (error) { this.error = error.response?.data || 'Failed to fetch ratings'; } } async fetchMyRatings() { try { const response = await api.get('/api/ratings/my_ratings/'); this.ratings = response.data; } catch (error) { this.error = error.response?.data || 'Failed to fetch my ratings'; } } // Likes async toggleLike(targetType, targetId) { try { const response = await api.post('/api/likes/toggle/', { target_type: targetType, target_id: targetId, }); return response.data; } catch (error) { return null; } } async fetchMyLikes() { try { const response = await api.get('/api/likes/my_likes/'); this.likes = response.data; } catch (error) { this.error = error.response?.data || 'Failed to fetch my likes'; } } // Favorites async toggleFavorite(targetType, targetId) { try { const response = await api.post('/api/favorites/toggle/', { target_type: targetType, target_id: targetId, }); return response.data; } catch (error) { return null; } } async fetchMyFavorites() { try { const response = await api.get('/api/favorites/my_favorites/'); this.favorites = response.data; } catch (error) { this.error = error.response?.data || 'Failed to fetch my favorites'; } } clearComments() { this.comments = []; } clearRatings() { this.ratings = []; } clearLikes() { this.likes = []; } clearFavorites() { this.favorites = []; } } export default InteractionStore;