Skip to content

Commit

Permalink
A segment can be active or inactive #23
Browse files Browse the repository at this point in the history
- Segment can be made active / inactive
- migrations are added to support this
- covered through test
  • Loading branch information
amitavroy committed Jan 4, 2025
1 parent f240291 commit b825ba0
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 78 deletions.
8 changes: 8 additions & 0 deletions app/Domain/Segment/Models/Segment.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Domain\Segment\Models;

use Database\Factories\SegmentFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
Expand All @@ -21,12 +22,19 @@ protected static function newFactory(): SegmentFactory
'name',
'description',
'rules',
'is_active',
];

protected function casts(): array
{
return [
'rules' => 'json',
'is_active' => 'boolean',
];
}

public function scopeActive(Builder $query): void
{
$this->where('is_active', true);
}
}
9 changes: 4 additions & 5 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
class HomeController extends Controller
{
public function __invoke(
HomePageData $homePageData,
CustomerService $customerService,
ProductService $productService,
HomePageData $homePageData,
CustomerService $customerService,
ProductService $productService,
ChartDataService $chartDataService,
): Response|ResponseFactory
{
): Response|ResponseFactory {
$data = $homePageData->handle();

return inertia('Home/Index', [
Expand Down
10 changes: 4 additions & 6 deletions app/Http/Controllers/SegmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ public function store(SegmentRequest $request): RedirectResponse
}

public function show(
Segment $segment,
Segment $segment,
SegmentRuleService $segmentRuleService
): Response|ResponseFactory
{
): Response|ResponseFactory {
$rules = $segmentRuleService->getRuleNames();

return inertia('Segment/Show', [
Expand All @@ -66,6 +65,7 @@ public function update(Request $request, Segment $segment): RedirectResponse
'name' => 'required|string',
'description' => 'required|string',
'rules' => 'sometimes|array',
'is_active' => 'required|boolean',
]);

Segment::where('id', $segment->id)
Expand All @@ -74,7 +74,5 @@ public function update(Request $request, Segment $segment): RedirectResponse
return redirect()->route('segment.show', ['segment' => $segment->id]);
}

public function destroy(Segment $segment): void
{
}
public function destroy(Segment $segment): void {}
}
8 changes: 8 additions & 0 deletions database/factories/SegmentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ public function definition(): array
'name' => $this->faker->name(),
'description' => $this->faker->text(),
'rules' => $this->faker->words(),
'is_active' => true,
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
];
}

public function inactive(): static
{
return $this->state(fn (array $attributes) => [
'is_active' => false,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function up(): void
$table->string('name');
$table->text('description');
$table->json('rules');
$table->boolean('is_active')->default(true);
$table->timestamps();
$table->softDeletes();
});
Expand Down
62 changes: 31 additions & 31 deletions resources/js/Components/Charts/NewCustomers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
const { recentCustomerCount } = defineProps({
recentCustomerCount: {
type: Object,
required: true
}
required: true,
},
})
const total = Object.values(recentCustomerCount).reduce(
(acc, curr) => acc + curr,
0
0,
)
const signupsChartColors = {
Expand All @@ -19,8 +19,8 @@ const signupsChartColors = {
'#E5E7EB',
'#E5E7EB',
'#E5E7EB',
'#E5E7EB'
]
'#E5E7EB',
],
}
const options = {
Expand All @@ -31,77 +31,77 @@ const options = {
foreColor: '#4B5563',
fontFamily: 'Inter, sans-serif',
toolbar: {
show: false
}
show: false,
},
},
theme: {
monochrome: {
enabled: true,
color: '#1A56DB'
}
color: '#1A56DB',
},
},
plotOptions: {
bar: {
columnWidth: '25%',
borderRadius: 3,
colors: {
backgroundBarColors: signupsChartColors.backgroundBarColors,
backgroundBarRadius: 3
}
backgroundBarRadius: 3,
},
},
dataLabels: {
hideOverflowingLabels: false
}
hideOverflowingLabels: false,
},
},
xaxis: {
floating: false,
labels: {
show: false
show: false,
},
axisBorder: {
show: false
show: false,
},
axisTicks: {
show: false
}
show: false,
},
},
tooltip: {
shared: true,
intersect: false,
style: {
fontSize: '14px',
fontFamily: 'Inter, sans-serif'
}
fontFamily: 'Inter, sans-serif',
},
},
states: {
hover: {
filter: {
type: 'darken',
value: 0.8
}
}
value: 0.8,
},
},
},
fill: {
opacity: 1
opacity: 1,
},
yaxis: {
show: false
show: false,
},
grid: {
show: false
show: false,
},
dataLabels: {
enabled: false
enabled: false,
},
legend: {
show: false
}
show: false,
},
}
const series = [
{
name: 'Users',
data: Object.values(recentCustomerCount)
}
data: Object.values(recentCustomerCount),
},
]
</script>

Expand All @@ -113,7 +113,7 @@ const series = [
<h3 class="text-base font-normal text-gray-500">New customers</h3>
<span
class="text-2xl font-bold leading-none text-gray-900 sm:text-3xl dark:text-white"
>{{ total }}</span
>{{ total }}</span
>
<p
class="flex items-center text-base font-normal text-gray-500 dark:text-gray-400"
Expand Down
52 changes: 26 additions & 26 deletions resources/js/Components/Charts/NewOrders.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
const { recentOrderData } = defineProps({
recentOrderData: {
type: Object,
required: true
required: true,
},
recentOrderCount: {
type: Number,
required: true
}
required: true,
},
})
const options = {
Expand All @@ -18,70 +18,70 @@ const options = {
fontFamily: 'Inter, sans-serif',
foreColor: '#4B5563',
toolbar: {
show: false
}
show: false,
},
},
plotOptions: {
bar: {
columnWidth: '90%',
borderRadius: 3
}
borderRadius: 3,
},
},
tooltip: {
shared: false,
intersect: false,
style: {
fontSize: '14px',
fontFamily: 'Inter, sans-serif'
}
fontFamily: 'Inter, sans-serif',
},
},
states: {
hover: {
filter: {
type: 'darken',
value: 1
}
}
value: 1,
},
},
},
stroke: {
show: true,
width: 5,
colors: ['transparent']
colors: ['transparent'],
},
grid: {
show: false
show: false,
},
dataLabels: {
enabled: false
enabled: false,
},
legend: {
show: false
show: false,
},
xaxis: {
floating: false,
labels: {
show: false
show: false,
},
axisBorder: {
show: false
show: false,
},
axisTicks: {
show: false
}
show: false,
},
},
yaxis: {
show: false
show: false,
},
fill: {
opacity: 1
}
opacity: 1,
},
}
const series = [
{
name: 'Quantity',
color: '#1A56DB',
data: recentOrderData
}
data: recentOrderData,
},
]
</script>

Expand All @@ -93,7 +93,7 @@ const series = [
<h3 class="text-base font-normal text-gray-500">New orders</h3>
<span
class="text-2xl font-bold leading-none text-gray-900 sm:text-3xl dark:text-white"
>{{ recentOrderCount }}</span
>{{ recentOrderCount }}</span
>
<p
class="flex items-center text-base font-normal text-gray-500 dark:text-gray-400"
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/Home/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PageContainer from '../../Components/PageContainer.vue'
import Breadcrumb from '../../Components/Breadcrumb.vue'
import PageTitle from '../../Components/PageTitle.vue'
import StatsCard from '../../Components/StatsCard.vue'
import { usePage, usePoll } from '@inertiajs/vue3'
import { usePoll } from '@inertiajs/vue3'
import TopProdAndCustomer from './TopProdAndCustomer.vue'
import NewOrders from '../../Components/Charts/NewOrders.vue'
import NewCustomers from '../../Components/Charts/NewCustomers.vue'
Expand Down
Loading

0 comments on commit b825ba0

Please sign in to comment.