Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ docs/k8s/secrets.local.yaml

# generated api clients
internal/guest/gateway/business/client/
pkg/gateway/admin/client/

.agent

Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: build build-guest build-business build-auth build-migrator build-notifications build-outbox build-lambda
.PHONY: run-all run-guest run-business run-auth migrate-up
.PHONY: run-all run-guest run-business run-auth run-notifications run-outbox migrate-up
.PHONY: test test-cover tidy clean
.PHONY: docs docs-guest docs-business docs-admin-auth
.PHONY: generate generate-guest-business-client
Expand Down Expand Up @@ -43,6 +43,12 @@ run-business: build-business
run-auth: build-auth
./bin/admin-auth-api

run-notifications: build-notifications
./bin/notifications-service

run-outbox: build-outbox
./bin/outbox-worker

migrate-up: build-migrator
./bin/migrator

Expand Down
20 changes: 20 additions & 0 deletions build/compose.infra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,29 @@ services:
timeout: 5s
retries: 5

localstack:
image: localstack/localstack:3
container_name: share-bite-localstack
ports:
- "4566:4566"
environment:
SERVICES: sns,sqs
DEFAULT_REGION: us-east-2
AWS_DEFAULT_REGION: us-east-2
volumes:
- localstack-data:/var/lib/localstack
networks:
- share-bite-net
healthcheck:
test: ["CMD-SHELL", "awslocal sns list-topics >/dev/null 2>&1 && awslocal sqs list-queues >/dev/null 2>&1"]
interval: 5s
timeout: 5s
retries: 10

volumes:
pg_data:
pgadmin_data:
localstack-data:
redis-data:
driver: local

Expand Down
62 changes: 1 addition & 61 deletions cmd/admin-auth-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import (
"context"
"errors"
"net/http"
"time"

"github.com/gin-gonic/gin"
"github.com/sony/gobreaker"
businessclient "github.com/ua-academy-projects/share-bite/internal/admin-auth/adapter/business"
guestclient "github.com/ua-academy-projects/share-bite/internal/admin-auth/adapter/guest"
apperr "github.com/ua-academy-projects/share-bite/internal/admin-auth/error"
Expand All @@ -17,9 +15,6 @@ import (
mcphttp "github.com/ua-academy-projects/share-bite/internal/admin-auth/handler/mcp"
"github.com/ua-academy-projects/share-bite/internal/admin-auth/worker"
"github.com/ua-academy-projects/share-bite/internal/config/env"
"github.com/ua-academy-projects/share-bite/pkg/notification"
"github.com/ua-academy-projects/share-bite/pkg/redis"
"github.com/ua-academy-projects/share-bite/pkg/resilience"
"go.uber.org/zap"

authhttp "github.com/ua-academy-projects/share-bite/internal/admin-auth/handler/auth"
Expand Down Expand Up @@ -62,11 +57,6 @@ func main() {
logger.Fatal(ctx, "load google oauth config: ", err)
}

redisCfg, err := env.NewRedisConfig()
if err != nil {
logger.Fatal(ctx, "load redis config: ", err)
}

router := gin.New()
router.Use(gin.Recovery())
router.Use(pkgmw.RequestID())
Expand Down Expand Up @@ -95,56 +85,6 @@ func main() {
return nil
})

rdb, err := redis.NewClient(
redisCfg.Addr(),
redisCfg.Password(),
redisCfg.DB(),
redisCfg.TLS(),
)
if err != nil {
logger.Fatal(ctx, "new redis client: ", err)
}
closer.Add(func(ctx context.Context) error {
return rdb.Close()
})

notificationResiliencePolicy := resilience.Policy{
RetryConfig: resilience.RetryConfig{
InitialInterval: 10 * time.Millisecond,
RandomizationFactor: 0.2,
Multiplier: 2.0,
MaxInterval: 200 * time.Millisecond,
MaxElapsedTime: 1500 * time.Millisecond,
},
Breaker: resilience.NewCircuitBreaker(resilience.CircuitBreakerConfig{
Name: "admin-redis-pub",
MaxRequests: 1,
Interval: 10 * time.Second,
Timeout: 5 * time.Second,
ReadyToTrip: func(counts gobreaker.Counts) bool {
return counts.ConsecutiveFailures >= 20
},
OnStateChange: func(name string, from gobreaker.State, to gobreaker.State) {
logger.WarnKV(ctx, "redis circuit breaker state changed",
"name", name,
"from", from.String(),
"to", to.String(),
)
},
IsSuccessful: func(err error) bool {
if err == nil || errors.Is(err, context.Canceled) {
return true
}
return redis.IsPermanentRedisError(err)
},
}),
RetryNotify: func(err error, nextRetryIn time.Duration) {
logger.Debugf(ctx, "redis publish retry scheduled in %v: %v", nextRetryIn, err)
},
}

broker := notification.NewBroker(rdb, notification.WithPublishPolicy(notificationResiliencePolicy))

tokenManager := jwt.NewTokenManager(
cfg.JwtToken.AccessTokenSecretKey(),
cfg.JwtToken.RefreshTokenSecretKey(),
Expand Down Expand Up @@ -176,7 +116,7 @@ func main() {
customerClient := guestclient.NewClient(client)
businessClient := businessclient.NewClient(client)

adminSvc := adminsvc.NewService(adminRepo, userRepo, customerClient, businessClient, broker, txManager)
adminSvc := adminsvc.NewService(adminRepo, userRepo, customerClient, businessClient, outboxWriter, txManager)
adminHandler := adminhttp.NewHandler(adminSvc)

mcpSvc := mcpsvc.NewMCPPermissionService(adminRepo)
Expand Down
5 changes: 4 additions & 1 deletion cmd/outbox-worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ func main() {
logger.Fatal(ctx, "OUTBOX_SNS_TOPIC_ARN is required")
}

snsPub, err := outboxpkg.NewSNSPublisher(ctx, topicArn)
// Optional: point SNS at a custom endpoint (e.g. LocalStack) for local dev.
snsEndpoint := config.GetSecret("OUTBOX_SNS_ENDPOINT_URL")

snsPub, err := outboxpkg.NewSNSPublisher(ctx, topicArn, snsEndpoint)
if err != nil {
logger.Fatal(ctx, "new sns publisher:", err)
}
Expand Down
30 changes: 30 additions & 0 deletions frontend/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,36 @@

@custom-variant dark (&:is(.dark *));

/*
* Map the design tokens below into Tailwind's color namespace so shadcn
* utilities (bg-popover, bg-muted, text-muted-foreground, border-border, …)
* are generated. Uses `inline` + var() so the .dark overrides keep working.
*/
@theme inline {
Comment thread
MihuNt3r marked this conversation as resolved.
--color-background: var(--background);
--color-foreground: var(--foreground);
--color-card: var(--card);
--color-card-foreground: var(--card-foreground);
--color-popover: var(--popover);
--color-popover-foreground: var(--popover-foreground);
--color-primary: var(--primary);
--color-primary-foreground: var(--primary-foreground);
--color-secondary: var(--secondary);
--color-secondary-foreground: var(--secondary-foreground);
--color-muted: var(--muted);
--color-muted-foreground: var(--muted-foreground);
--color-accent: var(--accent);
--color-accent-foreground: var(--accent-foreground);
--color-destructive: var(--destructive);
--color-border: var(--border);
--color-input: var(--input);
--color-ring: var(--ring);
--radius-sm: calc(var(--radius) - 4px);
--radius-md: calc(var(--radius) - 2px);
--radius-lg: var(--radius);
--radius-xl: calc(var(--radius) + 4px);
}


:root {
--background: #F9F7F2;
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import { ProfileCreatePage } from "@/pages/guest/UserProfile/ProfileCreatePage";
import { CreatePost } from "@/pages/guest/CreatePost/CreatePost";
import { AdminUsersPage } from "@/pages/guest/Admin/AdminUsersPage";
import { AdminUserDetailPage } from "@/pages/guest/Admin/AdminUserDetailPage";
import { AdminStatisticsPage } from "@/pages/guest/Admin/AdminStatisticsPage";
import { AdminPendingBusinessesPage } from "@/pages/guest/Admin/AdminPendingBusinessesPage";
import { ForbiddenPage } from "@/pages/guest/Forbidden/ForbiddenPage";
import { isUserRole } from "@/utils/auth";

Expand Down Expand Up @@ -166,6 +168,22 @@ function App() {
</RequireAdmin>
}
/>
<Route
path="/admin/statistics"
element={
<RequireAdmin>
<AdminStatisticsPage />
</RequireAdmin>
}
/>
<Route
path="/admin/businesses"
element={
<RequireAdmin>
<AdminPendingBusinessesPage />
</RequireAdmin>
}
/>

<Route path="/feed/users" element={<HomeFeed />} />
<Route path="/feed/business" element={<HomeFeedPage />} />
Expand Down
29 changes: 29 additions & 0 deletions frontend/src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import type {
FullUserDetails,
AdminUsersParams,
CollectionItem,
PlatformStatistics,
PaginatedPendingBusinesses,
ReviewBusinessStatus,
PaginationParams,
} from "@/types/api";

const API_BASE = import.meta.env.VITE_API_BASE_URL || "";
Expand Down Expand Up @@ -552,6 +556,31 @@ export const apiClient = {
return res.data;
},

adminGetStatistics: async () => {
const res = await apiRoot.get<PlatformStatistics>("/admin/statistics");
return res.data;
},

adminGetPendingBusinesses: async (params: PaginationParams = {}) => {
const res = await apiRoot.get<PaginatedPendingBusinesses>(
"/admin/businesses/pending",
{ params }
);
return res.data;
},

adminReviewBusiness: async (
orgUnitId: number,
status: ReviewBusinessStatus,
comment?: string
) => {
const res = await apiRoot.patch<{ message: string }>(
`/admin/businesses/${orgUnitId}/review`,
{ status, ...(comment ? { comment } : {}) }
);
return res.data;
},

updateUserStatus: async (userId: string, status: string) => {
const res = await apiRoot.put<{ message: string }>(
`/users/${userId}/status`,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function mapNotification(raw: Record<string, unknown>): NotificationItem {
entityID: String(raw.entityID ?? raw.entity_id ?? ""),
metadata,
createdAt: String(raw.createdAt ?? raw.created_at ?? new Date().toISOString()),
read: Boolean(raw.read),
read: Boolean(raw.isRead ?? raw.is_read ?? raw.read),
message,
};
}
Expand Down
36 changes: 29 additions & 7 deletions frontend/src/components/Notifications/NotificationBell.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Link } from "react-router-dom";
import { useQuery } from "@tanstack/react-query";
import { Bell } from "lucide-react";
import { fetchNotifications } from "@/api/notifications";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { Bell, CheckCheck } from "lucide-react";
import { fetchNotifications, markNotificationsRead } from "@/api/notifications";
import { Button } from "@/components/ui/button";
import {
Popover,
Expand All @@ -20,6 +20,8 @@ type NotificationBellProps = {
export function NotificationBell({ variant = "default" }: NotificationBellProps) {
const token = localStorage.getItem("token");

const queryClient = useQueryClient();

const { data: notifications = [] } = useQuery({
queryKey: ["notifications"],
queryFn: () => fetchNotifications(token!, 20),
Expand All @@ -28,7 +30,13 @@ export function NotificationBell({ variant = "default" }: NotificationBellProps)
enabled: !!token,
});

const unreadCount = notifications.filter((n) => !n.read).length;
const markRead = useMutation({
mutationFn: (ids: string[]) => markNotificationsRead(token!, ids),
onSuccess: () => queryClient.invalidateQueries({ queryKey: ["notifications"] }),
});

const unreadIds = notifications.filter((n) => !n.read).map((n) => n.id);
const unreadCount = unreadIds.length;

const formatMessage = (n: (typeof notifications)[0]) =>
n.message ||
Expand Down Expand Up @@ -78,9 +86,23 @@ export function NotificationBell({ variant = "default" }: NotificationBellProps)
Notifications
</PopoverTitle>
</div>
<span className="rounded-full border border-emerald-500/40 bg-emerald-500/10 px-2.5 py-0.5 text-xs font-medium text-emerald-600 dark:text-emerald-300">
{unreadCount} new
</span>
<div className="flex items-center gap-2">
<span className="rounded-full border border-emerald-500/40 bg-emerald-500/10 px-2.5 py-0.5 text-xs font-medium text-emerald-600 dark:text-emerald-300">
{unreadCount} new
</span>
{unreadCount > 0 && (
<button
type="button"
onClick={() => markRead.mutate(unreadIds)}
disabled={markRead.isPending}
aria-label="Mark all as read"
title="Mark all as read"
className="inline-flex items-center gap-1 text-xs font-medium text-emerald-600 transition-colors hover:text-emerald-700 disabled:opacity-50 dark:text-emerald-300 dark:hover:text-emerald-200"
>
<CheckCheck className="h-4 w-4" />
</button>
)}
</div>
</PopoverHeader>

<div className="max-h-80 overflow-y-auto border-t border-gray-200 dark:border-[#2f5e50]">
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/components/ui/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { NotificationBell } from "@/components/Notifications/NotificationBell";
import { LogoutDialog } from "@/components/LogoutDialog";
import { useCurrentCustomer } from "@/hooks/useCurrentCustomer";
import { useOnboardingStatus } from "@/hooks/useOnboardingStatus";
import { useRealtimeNotifications } from "@/hooks/useRealtimeNotifications";
import {
getBusinessOrgId,
getTokenRole,
Expand All @@ -30,6 +31,7 @@ export function Sidebar() {
const token = localStorage.getItem("token");
const { data: customer } = useCurrentCustomer();
useOnboardingStatus(!!token);
useRealtimeNotifications();
const [logoutOpen, setLogoutOpen] = useState(false);
const businessOrgId = getBusinessOrgId();

Expand Down Expand Up @@ -183,9 +185,15 @@ export function Sidebar() {
{isAdminOrModerator() ? (
<>
<NavSection label="Admin" />
<NavLink to="/admin" className={linkClass}>
<NavLink to="/admin" end className={linkClass}>
Admin Users
</NavLink>
<NavLink to="/admin/statistics" className={linkClass}>
Statistics
</NavLink>
<NavLink to="/admin/businesses" className={linkClass}>
Verify Businesses
</NavLink>
</>
) : null}
</nav>
Expand Down
Loading
Loading