Source: Router/listSync/controller.js

// @ts-check
/**
 * @import {ExpressRequestAuthorized, ExpressResponse} from '../../types.js'
 */

/**
 * List Sync Controllers - HTTP Request/Response Handling
 *
 * Handles the HTTP layer for list synchronisation endpoints,
 * extracting path parameters from `req` and delegating to the service layer.
 */

import { UUID2hex } from '@commtool/sql-query';
import { errorLoggerRead } from '../../utils/requestLogger.js';
import * as listSyncService from './service.js';


/**
 * GET /list/added/:UID/:timestamp — entries added to a static list since timestamp
 * GET /dlist/added/:UID/:timestamp — entries added to a dynamic list since timestamp
 *
 * @param {ExpressRequestAuthorized} req
 * @param {ExpressResponse} res
 */
export const getAddedListingController = async (req, res) => {
    try {
        const UID = UUID2hex(req.params.UID);
        const result = await listSyncService.getAddedListing(UID, req.params.timestamp, req.session);
        res.json({ success: true, result });
    } catch (e) {
        errorLoggerRead(e);
        res.status(500).json({ success: false, message: e.message });
    }
};


/**
 * GET /list/removed/:UID/:timestamp — entries removed from a static list since timestamp
 * GET /dlist/removed/:UID/:timestamp — entries removed from a dynamic list since timestamp
 *
 * @param {ExpressRequestAuthorized} req
 * @param {ExpressResponse} res
 */
export const getRemovedListingController = async (req, res) => {
    try {
        const UID = UUID2hex(req.params.UID);
        const result = await listSyncService.getRemovedListing(UID, req.params.timestamp, req.session);
        res.json({ success: true, result });
    } catch (e) {
        errorLoggerRead(e);
        res.status(500).json({ success: false, message: e.message });
    }
};