refactor: flatten src/AKSRT → src (drop theme-identifier dir)
Move all domain folders from src/AKSRT/{Domain} to src/{Domain}; remap
Composer PSR-4 "AKSRT\\": "src/"; update audit script + README + ADR
paths; remove dead tools/build-psr4-map.php (scanned deleted inc/classes).
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
namespace AKSRT\Admin;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
trait UserControllerFollowOperations {
|
||||
|
||||
/**
|
||||
* POST /follow/toggle — 切换关注状态
|
||||
*/
|
||||
public function follow_toggle(\WP_REST_Request $request): \WP_REST_Response {
|
||||
if (!class_exists('\AKSRT\User\Follow')) {
|
||||
return $this->error('关注系统未启用', 500);
|
||||
}
|
||||
|
||||
$params = $this->get_json_params($request);
|
||||
$target_user_id = (int) ($params['target_user_id'] ?? 0);
|
||||
$current_user_id = get_current_user_id();
|
||||
|
||||
if ($target_user_id <= 0 || $target_user_id === $current_user_id) {
|
||||
return $this->error('参数无效');
|
||||
}
|
||||
|
||||
$target_user = get_userdata($target_user_id);
|
||||
if (!$target_user) {
|
||||
return $this->error('用户不存在', 404);
|
||||
}
|
||||
|
||||
$is_following = \AKSRT\User\Follow::get_instance()->toggle($current_user_id, $target_user_id);
|
||||
|
||||
return $this->success([
|
||||
'data' => [
|
||||
'is_following' => $is_following,
|
||||
'follower_count' => \AKSRT\User\Follow::get_instance()->get_follower_count($target_user_id),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /follow/status — 查询关注状态
|
||||
*/
|
||||
public function follow_status(\WP_REST_Request $request): \WP_REST_Response {
|
||||
if (!class_exists('\AKSRT\User\Follow')) {
|
||||
return $this->success(['data' => ['is_following' => false]]);
|
||||
}
|
||||
|
||||
$target_user_id = (int) $request->get_param('target_user_id');
|
||||
$current_user_id = get_current_user_id();
|
||||
|
||||
if ($target_user_id <= 0) {
|
||||
return $this->error('参数无效');
|
||||
}
|
||||
|
||||
$is_following = \AKSRT\User\Follow::get_instance()->is_following($current_user_id, $target_user_id);
|
||||
|
||||
return $this->success([
|
||||
'data' => [
|
||||
'is_following' => $is_following,
|
||||
'follower_count' => \AKSRT\User\Follow::get_instance()->get_follower_count($target_user_id),
|
||||
'following_count' => \AKSRT\User\Follow::get_instance()->get_following_count($target_user_id),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /follow/counts — 获取关注/粉丝数
|
||||
*/
|
||||
public function follow_counts(\WP_REST_Request $request): \WP_REST_Response {
|
||||
if (!class_exists('\AKSRT\User\Follow')) {
|
||||
return $this->success(['data' => ['followers' => 0, 'following' => 0]]);
|
||||
}
|
||||
|
||||
$user_id = (int) $request->get_param('user_id');
|
||||
if ($user_id <= 0) {
|
||||
return $this->error('参数无效');
|
||||
}
|
||||
|
||||
return $this->success([
|
||||
'data' => [
|
||||
'followers' => \AKSRT\User\Follow::get_instance()->get_follower_count($user_id),
|
||||
'following' => \AKSRT\User\Follow::get_instance()->get_following_count($user_id),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user