Simple Managment webapp [LLM]

This commit is contained in:
2025-12-03 19:38:15 +01:00
parent 3ed323e056
commit 6090319b5f
10 changed files with 468 additions and 31 deletions

View File

@@ -135,10 +135,22 @@ export class ApiService {
if (params) {
if (params.after) httpParams = httpParams.set('after', params.after);
if (params.before) httpParams = httpParams.set('before', params.before);
if (params.channel) httpParams = httpParams.set('channel', params.channel);
if (params.priority !== undefined) httpParams = httpParams.set('priority', params.priority);
if (params.channel_id) {
for (const c of params.channel_id) {
httpParams = httpParams.append('channel_id', c);
}
}
if (params.priority) {
for (const p of params.priority) {
httpParams = httpParams.append('priority', p);
}
}
if (params.search) httpParams = httpParams.set('search', params.search);
if (params.sender) httpParams = httpParams.set('sender', params.sender);
if (params.sender) {
for (const s of params.sender) {
httpParams = httpParams.append('sender', s);
}
}
if (params.subscription_status) httpParams = httpParams.set('subscription_status', params.subscription_status);
if (params.trimmed !== undefined) httpParams = httpParams.set('trimmed', params.trimmed);
if (params.page_size) httpParams = httpParams.set('page_size', params.page_size);

View File

@@ -0,0 +1,88 @@
import { Injectable, inject } from '@angular/core';
import { Observable, of, map, shareReplay, catchError } from 'rxjs';
import { ApiService } from './api.service';
import { AuthService } from './auth.service';
import { ChannelWithSubscription } from '../models';
export interface ResolvedChannel {
channelId: string;
displayName: string;
internalName: string;
}
@Injectable({
providedIn: 'root'
})
export class ChannelCacheService {
private apiService = inject(ApiService);
private authService = inject(AuthService);
private channelsCache$: Observable<Map<string, ChannelWithSubscription>> | null = null;
getAllChannels(): Observable<ChannelWithSubscription[]> {
const userId = this.authService.getUserId();
if (!userId) {
return of([]);
}
return this.apiService.getChannels(userId, 'owned').pipe(
map(response => response.channels),
catchError(() => of([]))
);
}
resolveChannel(channelId: string): Observable<ResolvedChannel> {
return this.getChannelsMap().pipe(
map(channelsMap => {
const channel = channelsMap.get(channelId);
return {
channelId,
displayName: channel?.display_name || channel?.internal_name || channelId,
internalName: channel?.internal_name || channelId
};
})
);
}
resolveChannels(channelIds: string[]): Observable<Map<string, ResolvedChannel>> {
return this.getChannelsMap().pipe(
map(channelsMap => {
const resolved = new Map<string, ResolvedChannel>();
for (const channelId of channelIds) {
const channel = channelsMap.get(channelId);
resolved.set(channelId, {
channelId,
displayName: channel?.display_name || channel?.internal_name || channelId,
internalName: channel?.internal_name || channelId
});
}
return resolved;
})
);
}
private getChannelsMap(): Observable<Map<string, ChannelWithSubscription>> {
const userId = this.authService.getUserId();
if (!userId) {
return of(new Map());
}
if (!this.channelsCache$) {
this.channelsCache$ = this.apiService.getChannels(userId, 'owned').pipe(
map(response => {
const map = new Map<string, ChannelWithSubscription>();
for (const channel of response.channels) {
map.set(channel.channel_id, channel);
}
return map;
}),
catchError(() => of(new Map())),
shareReplay(1)
);
}
return this.channelsCache$;
}
clearCache(): void {
this.channelsCache$ = null;
}
}