|
6 | 6 | "fmt" |
7 | 7 | "time" |
8 | 8 |
|
9 | | - "github.com/PythonHacker24/linux-acl-management-backend/internal/postgresql" |
10 | 9 | "github.com/PythonHacker24/linux-acl-management-backend/internal/types" |
11 | 10 | "github.com/gorilla/websocket" |
12 | 11 | "github.com/redis/go-redis/v9" |
@@ -333,117 +332,3 @@ func (m *Manager) handleTransactionChangeEventPending(conn *websocket.Conn, sess |
333 | 332 | /* send the message to the client */ |
334 | 333 | return conn.WriteJSON(message) |
335 | 334 | } |
336 | | - |
337 | | -/* ==== User Archived Session ==== */ |
338 | | - |
339 | | -/* send list of archived session of a user */ |
340 | | -func (m *Manager) sendCurrentArchivedSessions(conn *websocket.Conn, username string, page int, pageSize int) error { |
341 | | - ctx := context.Background() |
342 | | - |
343 | | - /* calculate LIMIT and OFFSET */ |
344 | | - limit := int32(pageSize) |
345 | | - offset := int32((page - 1) * pageSize) |
346 | | - |
347 | | - pqParams := &postgresql.GetSessionByUsernamePaginatedPQParams{ |
348 | | - Username: username, |
349 | | - Limit: limit, |
350 | | - Offset: offset, |
351 | | - } |
352 | | - |
353 | | - /* query sessions */ |
354 | | - sessions, err := m.archivalPQ.GetSessionByUsernamePaginatedPQ(ctx, *pqParams) |
355 | | - if err != nil { |
356 | | - return fmt.Errorf("failed to get sessions for username %s: %w", username, err) |
357 | | - } |
358 | | - |
359 | | - exists := len(sessions) > 0 |
360 | | - |
361 | | - /* convert to plain JSON-compatible slices */ |
362 | | - var outgoing []map[string]any |
363 | | - for _, session := range sessions { |
364 | | - outgoing = append(outgoing, map[string]any{ |
365 | | - "id": session.ID, |
366 | | - "username": session.Username, |
367 | | - "ip": session.Ip.String, |
368 | | - "user_agent": session.UserAgent.String, |
369 | | - "status": session.Status, |
370 | | - "created_at": session.CreatedAt, |
371 | | - "last_active_at": session.LastActiveAt, |
372 | | - "expiry": session.Expiry, |
373 | | - "completed_count": session.CompletedCount, |
374 | | - "failed_count": session.FailedCount, |
375 | | - "archived_at": session.ArchivedAt, |
376 | | - }) |
377 | | - } |
378 | | - |
379 | | - message := StreamMessage{ |
380 | | - Type: "session_state", |
381 | | - Data: map[string]any{ |
382 | | - "username": username, |
383 | | - "exists": exists, |
384 | | - "sessions": outgoing, |
385 | | - "page": page, |
386 | | - "pageSize": pageSize, |
387 | | - }, |
388 | | - Timestamp: time.Now(), |
389 | | - } |
390 | | - |
391 | | - return conn.WriteJSON(message) |
392 | | -} |
393 | | - |
394 | | -/* ==== User Archived Transactions ==== */ |
395 | | - |
396 | | -/* send list of archived pending transactions */ |
397 | | -func (m *Manager) sendCurrentArchivedPendingTransactions(conn *websocket.Conn, username string, page int, pageSize int) error { |
398 | | - ctx := context.Background() |
399 | | - |
400 | | - limit := int32(pageSize) |
401 | | - offset := int32((page - 1) * pageSize) |
402 | | - |
403 | | - pqParams := &postgresql.GetPendingTransactionsByUserPaginatedPQParams{ |
404 | | - ExecutedBy: username, |
405 | | - Limit: limit, |
406 | | - Offset: offset, |
407 | | - } |
408 | | - |
409 | | - /* query transactions by executed_by */ |
410 | | - transactions, err := m.archivalPQ.GetPendingTransactionsByUserPaginatedPQ(ctx, *pqParams) |
411 | | - if err != nil { |
412 | | - return fmt.Errorf("failed to get transactions for user %s: %w", username, err) |
413 | | - } |
414 | | - |
415 | | - exists := len(transactions) > 0 |
416 | | - |
417 | | - var outgoing []map[string]any |
418 | | - for _, tx := range transactions { |
419 | | - outgoing = append(outgoing, map[string]any{ |
420 | | - "id": tx.ID, |
421 | | - "session_id": tx.SessionID, |
422 | | - "timestamp": tx.Timestamp, |
423 | | - "operation": tx.Operation, |
424 | | - "target_path": tx.TargetPath, |
425 | | - "entries": tx.Entries, // JSONB will decode as []byte, so decode if needed |
426 | | - "status": tx.Status, |
427 | | - "error_msg": tx.ErrorMsg, |
428 | | - "output": tx.Output, |
429 | | - "executed_by": tx.ExecutedBy, |
430 | | - "duration_ms": tx.DurationMs, |
431 | | - "ExecStatus": tx.Execstatus, |
432 | | - "created_at": tx.CreatedAt, |
433 | | - }) |
434 | | - } |
435 | | - |
436 | | - message := StreamMessage{ |
437 | | - Type: "transactions_state", |
438 | | - Data: map[string]any{ |
439 | | - "username": username, |
440 | | - "exists": exists, |
441 | | - "transactions": outgoing, |
442 | | - "page": page, |
443 | | - "pageSize": pageSize, |
444 | | - }, |
445 | | - Timestamp: time.Now(), |
446 | | - } |
447 | | - |
448 | | - return conn.WriteJSON(message) |
449 | | -} |
0 commit comments