SPMS_API/SPMS.Application/Services/BannerService.cs
2026-02-10 13:41:19 +09:00

44 lines
1.4 KiB
C#

using SPMS.Application.DTOs.Banner;
using SPMS.Application.Interfaces;
using SPMS.Domain.Common;
using SPMS.Domain.Exceptions;
using SPMS.Domain.Interfaces;
namespace SPMS.Application.Services;
public class BannerService : IBannerService
{
private readonly IBannerRepository _bannerRepository;
private readonly IServiceRepository _serviceRepository;
public BannerService(IBannerRepository bannerRepository, IServiceRepository serviceRepository)
{
_bannerRepository = bannerRepository;
_serviceRepository = serviceRepository;
}
public async Task<BannerListResponseDto> GetListAsync(string serviceCode, BannerListRequestDto request)
{
var service = await _serviceRepository.GetByServiceCodeAsync(serviceCode);
if (service == null)
throw new SpmsException(ErrorCodes.NotFound, "존재하지 않는 서비스입니다.", 404);
var items = await _bannerRepository.GetActiveListAsync(service.Id, request.Position);
return new BannerListResponseDto
{
Items = items.Select(b => new BannerItemDto
{
BannerId = b.Id,
Title = b.Title,
ImageUrl = b.ImageUrl,
LinkUrl = b.LinkUrl,
LinkType = b.LinkType,
Position = b.Position,
SortOrder = b.SortOrder
}).ToList(),
TotalCount = items.Count
};
}
}