Skip to content
47 changes: 21 additions & 26 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
@if (keycloakService.isLoading()) {
@if (keycloakService.isAuthenticated()) {
<router-outlet />
} @else {
<main class="flex flex-col items-center justify-center h-screen w-screen">
<div class="card bg-neutral text-primary-content w-96 m-4">
<div class="card-body">
<h2 class="card-title font-bold w-1/2 skeleton h-8"></h2>
<p class="text-md h-4 skeleton"></p>
<p class="text-md h-4 skeleton w-1/2"></p>
<div class="card-actions flex-col *:w-full mt-2">
<div class="btn btn-primary">
<span class="loading loading-spinner"></span>
</div>
<app-theme-controller />

<div class="card bg-primary text-primary-content m-4 px-12">
<div class="card-body items-center text-center">
<i class="material-symbols-outlined !text-8xl max-w-36 overflow-hidden">network_intelligence</i>
<h2 class="card-title text-3xl font-semibold">KJO Mind Care</h2>
<p class="text-xl">
Bienestar mental está a su alcance.
</p>
<div class="card-actions flex-col w-full mt-3 gap-1">
@if (keycloakService.isLoading()) {
<button (click)="login()" class="btn w-full btn-primary">
<span class="loading loading-spinner"></span>
</button>
} @else {
<button (click)="login()" class="btn w-full btn-primary">Iniciar sesión</button>
<button (click)="register()" class="btn w-full btn-primary btn-link py-0">Registrarme</button>
}
</div>
</div>
</div>
</main>
} @else {
@if (keycloakService.isAuthenticated()) {
<router-outlet />
} @else {
<main class="flex flex-col items-center justify-center h-screen w-screen">
<div class="card bg-neutral text-primary-content max-w-96 m-4">
<div class="card-body">
<h2 class="card-title text-2xl font-bold">KJO Mind Care</h2>
<p class="text-md">Welcome to the dashboard of the KJO Mind Care application.</p>
<div class="card-actions flex-col *:w-full mt-2">
<button (click)="login()" class="btn btn-primary">Login</button>
</div>
</div>
</div>
</main>
}
}

<app-toast></app-toast>
7 changes: 6 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { Component, inject } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { KeycloakService } from './modules/auth/services/keycloak.service';
import { ToastComponent } from './shared/components/layout/toast/toast.component';
import { ThemeControllerComponent } from './shared/components/layout/theme-controller/theme-controller.component';

@Component({
selector: 'app-root',
imports: [RouterOutlet, ToastComponent],
imports: [RouterOutlet, ToastComponent, ThemeControllerComponent],
templateUrl: './app.component.html',
styleUrl: './app.component.css'
})
Expand All @@ -16,6 +17,10 @@ export class AppComponent {
this.keycloakService.login();
}

register() {
this.keycloakService.register();
}

ngOnInit() {
this.keycloakService.init();
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const routes: Routes = [
{ path: 'blog-management', loadComponent: () => import('./modules/blog/blog-page.component') },
{ path: 'moods', loadChildren: () => import('./modules/mood-analytics/mood-analytics.routes') },
{ path: 'settings', loadChildren: () => import('./modules/settings/settings.routes') },
{ path: 'health-centers', loadComponent: () => import('./modules/health-center/health-center.component') },
// { path: 'health-centers', loadComponent: () => import('./modules/health-center/health-center.component') },
{ path: 'map', loadComponent: () => import('./modules/health-center-map/health-center-map.component') }
],
canActivate: [authGuard]
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/interfaces/blog-http.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface BlogDetailResponse {
}

export interface CommentSummary {
id: number;
id: string;
userId: UserInfo;
content: string;
date: string;
Expand Down
8 changes: 4 additions & 4 deletions src/app/core/interfaces/comment-http.interface.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export interface CommentRequest {
id: number;
id: string;
content: string;
blogId: number;
commentParentId: number | null;
blogId: string;
commentParentId: string | null;
}

export interface CommentResponse {
id: number;
id: string;
blogId: number;
userId: number;
content: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface EmergencyResourceRequest {
}

export interface EmergencyResourceResponse {
id: number;
id: string;
user: UserInfo;
name: string;
description: string;
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/interfaces/health-center-http.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface HealthCenterRequest {
}

export interface HealthCenterResponse extends HealthCenterRequest {
id: number;
id: string;
user: UserInfo;
status: string;
createdDate: string;
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/interfaces/mood-http.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface MoodStateRequest {
}

export interface MoodStateResponse {
id: number,
id: string,
name: string,
description: string,
image: string,
Expand Down
6 changes: 3 additions & 3 deletions src/app/core/models/blog.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { UserProfile } from './user-profile';

export interface Blog {
id: number;
id: string;
title: string;
content: string;
image?: string;
Expand All @@ -20,7 +20,7 @@ export enum Status {
}

export interface Category {
id: number;
id: string;
name: string;
}

Expand All @@ -34,6 +34,6 @@ export interface Reaction {

export interface FilterDTO {
search: string;
category: number;
category: string;
status: string;
}
2 changes: 1 addition & 1 deletion src/app/core/models/mood.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface Mood {
}

export interface Content {
id: number;
id: string;
name: string;
description: string;
state: string;
Expand Down
10 changes: 6 additions & 4 deletions src/app/core/services/analytics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ import { HttpClient } from '@angular/common/http';
import { environment } from '../../../environments/environment';
import { catchError, Observable, tap, throwError } from 'rxjs';
import { MoodAnalyticsResponse, MoodTrendsAnalysis } from '../interfaces/mood-analytics.response';
import { ApiResponse } from '../../shared/interfaces/api-response';

@Injectable({
providedIn: 'root',
})
export class AnalyticsService {
private http = inject(HttpClient);
private readonly baseUrl = `${environment.apiUrl}/api/mind/mood-tracking`;
getMoodAnalytics(months: number = 3): Observable<MoodAnalyticsResponse> {

getMoodAnalytics(months: number = 3): Observable<ApiResponse<MoodAnalyticsResponse>> {
return this.http
.get<MoodAnalyticsResponse>(
.get<ApiResponse<MoodAnalyticsResponse>>(
`${this.baseUrl}/user-mood/statistics?month=${months}`,
)
.pipe(
Expand All @@ -31,8 +33,8 @@ export class AnalyticsService {
);
}

getMoodTrendsAnalysis(month: number = 3): Observable<MoodTrendsAnalysis> {
return this.http.get<MoodTrendsAnalysis>(`${this.baseUrl}/user-mood/trends-analysis?months=${month}`
getMoodTrendsAnalysis(month: number = 3): Observable<ApiResponse<MoodTrendsAnalysis>> {
return this.http.get<ApiResponse<MoodTrendsAnalysis>>(`${this.baseUrl}/user-mood/trends-analysis?months=${month}`
).pipe(
tap((response) => console.log("Mood Trend Anlysis", response)),
catchError((error) => {
Expand Down
21 changes: 11 additions & 10 deletions src/app/core/services/blog.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { environment } from '../../../environments/environment';
import { Blog } from '../models/blog';
import { blogs } from '../../shared/utils/local-data';
import { BlogDetailResponse, BlogResponse } from '../interfaces/blog-http.interface';
import { ApiResponse } from '../../shared/interfaces/api-response';

@Injectable({
providedIn: 'root'
Expand All @@ -27,8 +28,8 @@ export class BlogService {
this._selectedBlog.set(blog);
}

findAll(): Observable<BlogResponse[]> {
return this.http.get<BlogResponse[]>(`${this.baseUrl}/all`);
findAll(): Observable<ApiResponse<BlogResponse[]>> {
return this.http.get<ApiResponse<BlogResponse[]>>(`${this.baseUrl}/all`);
}

// findAll(): Observable<Blog[]> {
Expand All @@ -41,19 +42,19 @@ export class BlogService {
// );
// }

getById(id: number): Observable<BlogDetailResponse> {
return this.http.get<BlogDetailResponse>(`${this.baseUrl}/${id}`);
getById(id: string): Observable<ApiResponse<BlogDetailResponse>> {
return this.http.get<ApiResponse<BlogDetailResponse>>(`${this.baseUrl}/${id}`);
}

create(request: FormData): Observable<Blog> {
return this.http.post<Blog>(`${this.baseUrl}`, request);
create(request: FormData): Observable<ApiResponse<Blog>> {
return this.http.post<ApiResponse<Blog>>(`${this.baseUrl}`, request);
}

update(request: FormData, id: number): Observable<Blog> {
return this.http.put<Blog>(`${this.baseUrl}/${id}`, request);
update(request: FormData, id: string): Observable<ApiResponse<Blog>> {
return this.http.put<ApiResponse<Blog>>(`${this.baseUrl}/${id}`, request);
}

delete(id: number): Observable<void> {
return this.http.delete<void>(`${this.baseUrl}/${id}`);
delete(id: string): Observable<ApiResponse<void>> {
return this.http.delete<ApiResponse<void>>(`${this.baseUrl}/${id}`);
}
}
23 changes: 12 additions & 11 deletions src/app/core/services/category.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { environment } from '../../../environments/environment';
import { Observable } from 'rxjs';

import { Category } from '../models/blog';
import { ApiResponse } from '../../shared/interfaces/api-response';

@Injectable({
providedIn: 'root'
Expand All @@ -16,27 +17,27 @@ export class CategoryService {
private http = inject(HttpClient);

selectedCategory = signal<Category>({
id: 0,
id: '',
name: ''
});

findAll(): Observable<Category[]> {
return this.http.get<Category[]>(`${this.baseUrl}`);
findAll(): Observable<ApiResponse<Category[]>> {
return this.http.get<ApiResponse<Category[]>>(`${this.baseUrl}`);
}

getById(id: number): Observable<Category> {
return this.http.get<Category>(`${this.baseUrl}/${id}`);
getById(id: string): Observable<ApiResponse<Category>> {
return this.http.get<ApiResponse<Category>>(`${this.baseUrl}/${id}`);
}

create(request: Category): Observable<Category> {
return this.http.post<Category>(`${this.baseUrl}`, request);
create(request: Category): Observable<ApiResponse<Category>> {
return this.http.post<ApiResponse<Category>>(`${this.baseUrl}`, request);
}

update(request: Category, id: number): Observable<Category> {
return this.http.patch<Category>(`${this.baseUrl}/${id}`, request);
update(request: Category, id: string): Observable<ApiResponse<Category>> {
return this.http.patch<ApiResponse<Category>>(`${this.baseUrl}/${id}`, request);
}

delete(id: number): Observable<void> {
return this.http.delete<void>(`${this.baseUrl}/${id}`);
delete(id: string): Observable<ApiResponse<void>> {
return this.http.delete<ApiResponse<void>>(`${this.baseUrl}/${id}`);
}
}
19 changes: 10 additions & 9 deletions src/app/core/services/comment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Observable } from 'rxjs';

import { Category } from '../models/blog';
import { CommentRequest, CommentResponse } from '../interfaces/comment-http.interface';
import { ApiResponse } from '../../shared/interfaces/api-response';

@Injectable({
providedIn: 'root'
Expand All @@ -17,9 +18,9 @@ export class CommentService {
private http = inject(HttpClient);

readonly _selectedComment = signal<CommentRequest>({
id: 0,
id: '',
content: '',
blogId: 0,
blogId: '',
commentParentId: null
});

Expand All @@ -31,21 +32,21 @@ export class CommentService {
this._selectedComment.set(comment);
}

create(request: CommentRequest): Observable<CommentResponse> {
create(request: CommentRequest): Observable<ApiResponse<CommentResponse>> {
if (!request.commentParentId) {
return this.http.post<CommentResponse>(`${this.baseUrl}?blogId=${request.blogId}&content=${request.content}`, null);
return this.http.post<ApiResponse<CommentResponse>>(`${this.baseUrl}?blogId=${request.blogId}&content=${request.content}`, null);
}
return this.http.post<CommentResponse>(`${this.baseUrl}?blogId=${request.blogId}&commentParentId=${request.commentParentId}&content=${request.content}`, request);
return this.http.post<ApiResponse<CommentResponse>>(`${this.baseUrl}?blogId=${request.blogId}&commentParentId=${request.commentParentId}&content=${request.content}`, request);
}

update(request: CommentRequest, id: number): Observable<CommentResponse> {
update(request: CommentRequest, id: string): Observable<ApiResponse<CommentResponse>> {
if (!request.commentParentId) {
return this.http.put<CommentResponse>(`${this.baseUrl}/${id}?blogId=${request.blogId}&content=${request.content}`, null);
return this.http.put<ApiResponse<CommentResponse>>(`${this.baseUrl}/${id}?blogId=${request.blogId}&content=${request.content}`, null);
}
return this.http.put<CommentResponse>(`${this.baseUrl}/${id}?blogId=${request.blogId}&commentParentId=${request.commentParentId}&content=${request.content}`, request);
return this.http.put<ApiResponse<CommentResponse>>(`${this.baseUrl}/${id}?blogId=${request.blogId}&commentParentId=${request.commentParentId}&content=${request.content}`, request);
}

delete(id: number): Observable<void> {
delete(id: string): Observable<void> {
return this.http.delete<void>(`${this.baseUrl}/${id}`);
}
}
10 changes: 7 additions & 3 deletions src/app/core/services/dashboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { environment } from '../../../environments/environment';
import { DailyBlogsStats, DashboardStats, UserMoodStats } from '../interfaces/dashboard-http.interface';
import { toSignal } from '@angular/core/rxjs-interop';
import { catchError, map, of } from 'rxjs';
import { ApiResponse } from '../../shared/interfaces/api-response';

@Injectable({
providedIn: 'root'
Expand All @@ -14,8 +15,9 @@ export class DashboardService {

// Use toSignal to create signals from observables
dashboardStats = toSignal(
this.http.get<DashboardStats>(`${this.baseUrl}/dashboard-stats`)
this.http.get<ApiResponse<DashboardStats>>(`${this.baseUrl}/dashboard-stats`)
.pipe(
map(response => response.result),
catchError(error => {
console.error('Error fetching dashboard stats:', error);
return of(null);
Expand All @@ -24,8 +26,9 @@ export class DashboardService {
);

userMoodStats = toSignal(
this.http.get<UserMoodStats[]>(`${this.baseUrl}/moods/daily-users-last-month`)
this.http.get<ApiResponse<UserMoodStats[]>>(`${this.baseUrl}/moods/daily-users-last-month`)
.pipe(
map(response => response.result),
catchError(error => {
console.error('Error fetching mood stats:', error);
return of([]);
Expand All @@ -34,8 +37,9 @@ export class DashboardService {
);

blogStats = toSignal(
this.http.get<DailyBlogsStats[]>(`${this.baseUrl}/blogs/daily-current-month`)
this.http.get<ApiResponse<DailyBlogsStats[]>>(`${this.baseUrl}/blogs/daily-current-month`)
.pipe(
map(response => response.result),
catchError(error => {
console.error('Error fetching blog stats:', error);
return of([]);
Expand Down
Loading