import type { Request, Response } from 'express';
import { paramStr } from '@/api/http/request';
import FrameEntriesService from '@/services/frame_entries';

export async function list(req: Request, res: Response): Promise<void> {
  const payload = await FrameEntriesService.list(req.query, req.currentUser);
  res.status(200).send(payload);
}

export async function create(req: Request, res: Response): Promise<void> {
  const payload = await FrameEntriesService.create(
    req.body.data,
    req.currentUser,
  );
  res.status(201).send(payload);
}

export async function update(req: Request, res: Response): Promise<void> {
  const payload = await FrameEntriesService.update(
    paramStr(req.params.id),
    req.body.data,
    req.currentUser,
  );
  res.status(200).send(payload);
}

export async function destroy(req: Request, res: Response): Promise<void> {
  await FrameEntriesService.destroy(paramStr(req.params.id), req.currentUser);
  res.status(204).send();
}
