using SPMS.Application.DTOs.Notice; using SPMS.Application.Interfaces; using SPMS.Domain.Common; using SPMS.Domain.Exceptions; using SPMS.Domain.Interfaces; namespace SPMS.Application.Services; public class NoticeService : INoticeService { private readonly INoticeRepository _noticeRepository; public NoticeService(INoticeRepository noticeRepository) { _noticeRepository = noticeRepository; } public async Task GetListAsync(NoticeListRequestDto request) { var (items, totalCount) = await _noticeRepository.GetActivePagedAsync(request.Page, request.Size); var totalPages = (int)Math.Ceiling((double)totalCount / request.Size); return new NoticeListResponseDto { Items = items.Select(n => new NoticeSummaryDto { NoticeId = n.Id, Title = n.Title, IsImportant = n.IsPinned, CreatedAt = n.CreatedAt }).ToList(), Pagination = new PaginationDto { Page = request.Page, Size = request.Size, TotalCount = totalCount, TotalPages = totalPages } }; } public async Task GetInfoAsync(NoticeInfoRequestDto request) { var notice = await _noticeRepository.GetActiveByIdAsync(request.NoticeId); if (notice == null) throw new SpmsException(ErrorCodes.NotFound, "존재하지 않는 공지사항입니다.", 404); return new NoticeInfoResponseDto { NoticeId = notice.Id, Title = notice.Title, Content = notice.Content, IsImportant = notice.IsPinned, CreatedAt = notice.CreatedAt }; } }