Skip to content

Commit 6769adf

Browse files
authored
Merge pull request #554 from abdielbytes/abdiel
fix: update user profile
2 parents 0ad7145 + b33328c commit 6769adf

File tree

4 files changed

+188
-234
lines changed

4 files changed

+188
-234
lines changed

Diff for: app/Http/Controllers/Api/V1/User/UserController.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,8 @@ public function show(User $user)
9595
'username' => '',
9696
'jobTitle' => $user->profile->job_title ?? null,
9797
'pronouns' => $user->profile->pronoun ?? null,
98-
'department' => null,
9998
'email' => $user->email,
10099
'bio' => $user->profile->bio ?? null,
101-
'social_links' => null,
102-
'language' => null,
103-
'region' => null,
104-
'timezones' => null,
105100
'profile_pic_url' => $user->profile->avatar_url ?? null,
106101
'deletedAt' => $user->profile->deleted_at ?? null
107102
],
@@ -138,7 +133,14 @@ public function update(Request $request, string $id)
138133
'first_name' => 'nullable|string|max:255',
139134
'last_name' => 'nullable|string|max:255',
140135
"email" => 'nullable|string|email|max:255|unique:users,email,' . $id,
141-
"phone" => 'nullable|string'
136+
"phone" => 'nullable|string',
137+
'pronouns' => 'nullable|string|max:255',
138+
'job_title' => 'nullable|string|max:255',
139+
'social' => 'nullable|string|max:255',
140+
'bio' => 'nullable|string|max:500',
141+
'phone_number' => 'nullable|string|max:20',
142+
'avatar_url' => 'nullable|string|url',
143+
'recovery_email' => 'nullable|string|email|max:255'
142144
]);
143145

144146
if ($validator->fails()) {

Diff for: app/Http/Controllers/UserNotificationController.php

+23-19
Original file line numberDiff line numberDiff line change
@@ -182,36 +182,40 @@ public function update(Request $request, $notificationId)
182182
/**
183183
* Remove the specified resource from storage.
184184
*/
185-
public function destroy()
185+
public function destroy(Request $request)
186186
{
187187
try {
188-
189-
UserNotification::query()->where([
190-
['user_id', auth()->id()],
191-
['status', 'unread']
192-
])->update([
193-
'status' => 'read'
194-
]);
195-
188+
// Check if the user is authenticated
189+
$user = Auth::user();
190+
191+
// Update the status of all notifications (read or unread) for the authenticated user to 'read'
192+
UserNotification::query()
193+
->where('user_id', $user->id)
194+
->update(['status' => 'read']);
195+
196+
// Return a success response
196197
return response()->json([
197-
'status' => 'success',
198-
'message' => 'notifications cleared successfully',
199-
'status_code' => Response::HTTP_OK,
200-
'data' => UserNotification::query()->where('user_id', auth()->id())->get(),
198+
'data' => 'All notifications have been cleared.',
199+
'message' => 'All notifications cleared successfully',
200+
'status_code' => Response::HTTP_OK
201201
], Response::HTTP_OK);
202202
} catch (ModelNotFoundException $exception) {
203+
// Handle case where notifications are not found
203204
return response()->json([
204-
'status' => 'error',
205-
'message' => 'notifications not found',
206-
'status_code' => Response::HTTP_NOT_FOUND,
205+
'data' => null,
206+
'error' => 'Notifications not found',
207+
'message' => 'No notifications found to clear',
208+
'status_code' => Response::HTTP_NOT_FOUND
207209
], Response::HTTP_NOT_FOUND);
208210
} catch (\Exception $exception) {
209211
Log::error($exception->getMessage());
210212
return response()->json([
211-
'status' => 'error',
212-
'message' => 'something went wrong',
213-
'status_code' => Response::HTTP_INTERNAL_SERVER_ERROR,
213+
'data' => null,
214+
'error' => 'Internal Server Error',
215+
'message' => 'Something went wrong while clearing notifications',
216+
'status_code' => Response::HTTP_INTERNAL_SERVER_ERROR
214217
], Response::HTTP_INTERNAL_SERVER_ERROR);
215218
}
216219
}
220+
217221
}

0 commit comments

Comments
 (0)