package dev.awesomedev.mirim.web;

import dev.awesomedev.mirim.repository.AssignmentRepository;
import dev.awesomedev.mirim.web.dto.AssignmentResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 이 파일이 하는 일:
 * 주차별 과제 조회 API를 제공하는 컨트롤러다.
 */
@RestController
@RequestMapping("/api/assignments")
public class AssignmentController {

    private final AssignmentRepository assignmentRepository;

    public AssignmentController(AssignmentRepository assignmentRepository) {
        this.assignmentRepository = assignmentRepository;
    }

    /** GET /api/assignments?week=N — 해당 주차의 과제 목록 (일차순) */
    @GetMapping
    public List<AssignmentResponse> list(@RequestParam("week") Integer week) {
        return assignmentRepository.findByWeekOrderByDayAsc(week).stream()
                .map(AssignmentResponse::from)
                .toList();
    }
}
