• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

marscoin / martianrepublic / 23823524774

31 Mar 2026 11:03PM UTC coverage: 10.419%. Remained the same
23823524774

push

github

Martian Congress
refactor: A1 — split ApiController (1,147 lines) into 5 controllers

The god controller is dead. Long live focused controllers:

- FeedApiController (287 lines) — allPublic, allCitizen, allApplicants,
  allFeed, showCitizen, scitizen
- AuthApiController (260 lines) — marsAuth, checkAuth, wauth, token
- ForumApiController (205 lines) — threads, comments, categories
- ContentApiController (230 lines) — pinpic, pinvideo, pinjson (IPFS)
- UserManagementController (95 lines) — blockUser, deleteUser, eula

ApiController.php is now 18 lines (empty shell with migration notes).
All routes updated to array notation pointing to new controllers.
Zero method logic changed — pure structural refactor.

127 tests, 0 PHPStan errors, API endpoints verified.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

31 of 637 new or added lines in 5 files covered. (4.87%)

599 of 5749 relevant lines covered (10.42%)

1.47 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/Http/Controllers/UserManagementController.php
1
<?php
2

3
namespace App\Http\Controllers;
4

5
use App\Models\Profile;
6
use App\Models\User;
7
use Illuminate\Database\Eloquent\ModelNotFoundException;
8
use Illuminate\Http\Request;
9
use Illuminate\Support\Facades\Auth;
10
use Illuminate\Support\Facades\DB;
11
use Illuminate\Support\Facades\Log;
12

13
class UserManagementController extends Controller
14
{
NEW
15
    public function blockUser(Request $request, $id)
×
16
    {
NEW
17
        Log::debug('in function');
×
NEW
18
        $uid = Auth::user()->id;
×
NEW
19
        Log::debug('auth happened');
×
NEW
20
        $blockedUserId = $id;
×
21

22
        // Insert into `user_blocks` table if not already blocked
NEW
23
        DB::table('user_blocks')->updateOrInsert(
×
NEW
24
            ['user_id' => $uid, 'blocked_user_id' => $blockedUserId]
×
NEW
25
        );
×
26

NEW
27
        return response()->json(['message' => 'User blocked successfully'], 201);
×
28
    }
29

NEW
30
    public function deleteUser(Request $request, $id)
×
31
    {
32
        try {
33
            // Users can only deactivate their own account
NEW
34
            $authUser = Auth::user();
×
NEW
35
            if ((int) $authUser->id !== (int) $id) {
×
NEW
36
                return response()->json(['message' => 'Unauthorized: you can only delete your own account.'], 403);
×
37
            }
38

NEW
39
            $user = User::findOrFail($id);
×
40

NEW
41
            Log::debug('Deleting... '.$id);
×
42

NEW
43
            $user->update([
×
NEW
44
                'status' => 'inactive',
×
NEW
45
            ]);
×
NEW
46
            Log::debug('Status updated');
×
47

48
            // Revoke all tokens
NEW
49
            if (method_exists($user, 'tokens')) {
×
NEW
50
                $user->tokens()->delete();
×
51
            }
NEW
52
            Log::debug('Token wiped...');
×
53

NEW
54
            return response()->json([
×
NEW
55
                'message' => 'User deleted successfully',
×
NEW
56
            ], 200);
×
57

NEW
58
        } catch (ModelNotFoundException $e) {
×
NEW
59
            return response()->json([
×
NEW
60
                'message' => 'User not found',
×
NEW
61
            ], 404);
×
NEW
62
        } catch (\Exception $e) {
×
NEW
63
            \Log::error('Error deleting user: '.$e->getMessage());
×
64

NEW
65
            return response()->json([
×
NEW
66
                'message' => 'An error occurred while deleting the user',
×
NEW
67
            ], 500);
×
68
        }
69
    }
70

NEW
71
    public function handleEula(Request $request)
×
72
    {
NEW
73
        $uid = Auth::user()->id;
×
NEW
74
        $profile = Profile::where('userid', $uid)->firstOrFail();
×
75

NEW
76
        return response()->json([
×
NEW
77
            'is_signed' => (bool) $profile->signed_eula,
×
NEW
78
        ]);
×
79
    }
80

NEW
81
    public function setEula(Request $request)
×
82
    {
NEW
83
        $uid = Auth::user()->id;
×
NEW
84
        $profile = Profile::where('userid', $uid)->firstOrFail();
×
NEW
85
        if (! $profile->signed_eula) {
×
NEW
86
            $profile->signed_eula = 1;
×
NEW
87
            $profile->save();
×
88
        }
89

NEW
90
        return response()->json([
×
NEW
91
            'message' => 'EULA signed successfully',
×
NEW
92
            'is_signed' => true,
×
NEW
93
        ]);
×
94
    }
95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc