feat: add breath colors
This commit is contained in:
@@ -19,7 +19,9 @@ public function createTemplate(Request $request)
|
||||
'duration' => 'sometimes|integer|min:0',
|
||||
'description' => 'sometimes|string|nullable',
|
||||
'image_id' => 'nullable|exists:images,id',
|
||||
'source' => 'nullable|string'
|
||||
'source' => 'nullable|string',
|
||||
// The chosen color from the /breathing-colors palette.
|
||||
'breathing_color_id' => 'nullable|exists:breathing_colors,id',
|
||||
]);
|
||||
|
||||
$template = BreathingTemplate::create([
|
||||
@@ -31,10 +33,11 @@ public function createTemplate(Request $request)
|
||||
'duration'=> $data['duration'] ?? 60,
|
||||
'description' => $data['description'] ?? null,
|
||||
'image_id' => $data['image_id'] ?? null,
|
||||
'source' => 'nullable|string'
|
||||
'source' => $data['source'] ?? null,
|
||||
'breathing_color_id' => $data['breathing_color_id'] ?? null,
|
||||
]);
|
||||
|
||||
return response()->json(['message' => 'Template created', 'template' => $template->load('image')]);
|
||||
return response()->json(['message' => 'Template created', 'template' => $template->load('image', 'breathingColor')]);
|
||||
}
|
||||
|
||||
public function updateTemplate(Request $request, $id)
|
||||
@@ -51,12 +54,13 @@ public function updateTemplate(Request $request, $id)
|
||||
'duration' => 'sometimes|integer|min:0',
|
||||
'description' => 'sometimes|string|nullable',
|
||||
'image_id' => 'nullable|exists:images,id',
|
||||
'source' => 'nullable|string'
|
||||
'source' => 'nullable|string',
|
||||
'breathing_color_id' => 'nullable|exists:breathing_colors,id',
|
||||
]);
|
||||
|
||||
$template->update($data);
|
||||
|
||||
return response()->json(['message' => 'Template updated', 'template' => $template->load('image')]);
|
||||
return response()->json(['message' => 'Template updated', 'template' => $template->load('image', 'breathingColor')]);
|
||||
}
|
||||
public function deleteTemplate($id)
|
||||
{
|
||||
@@ -75,7 +79,7 @@ public function getTemplates()
|
||||
|
||||
$templates = BreathingTemplate::whereNull('user_id')
|
||||
->orWhere('user_id', $userId)
|
||||
->with('image') // eager load image
|
||||
->with(['image', 'breathingColor']) // eager load image + color
|
||||
->get()
|
||||
->map(function ($template) {
|
||||
if ($template->image) {
|
||||
@@ -92,7 +96,7 @@ public function getTemplates()
|
||||
public function getUserTemplates()
|
||||
{
|
||||
$templates = BreathingTemplate::where('user_id', auth()->id())
|
||||
->with('image') // eager load image
|
||||
->with(['image', 'breathingColor']) // eager load image + color
|
||||
->get()
|
||||
->map(function ($template) {
|
||||
if ($template->image) {
|
||||
|
||||
Reference in New Issue
Block a user