|
| 1 | +package com.example.FixLog.service; |
| 2 | + |
| 3 | +import com.example.FixLog.domain.member.Member; |
| 4 | +import com.example.FixLog.domain.tag.Tag; |
| 5 | +import com.example.FixLog.dto.UserIdDto; |
| 6 | +import com.example.FixLog.dto.tag.TagDto; |
| 7 | +import com.example.FixLog.dto.tag.TagResponseDto; |
| 8 | +import com.example.FixLog.exception.CustomException; |
| 9 | +import com.example.FixLog.exception.ErrorCode; |
| 10 | +import com.example.FixLog.repository.MemberRepository; |
| 11 | +import com.example.FixLog.repository.tag.TagRepository; |
| 12 | +import org.springframework.data.domain.Page; |
| 13 | +import org.springframework.data.domain.PageRequest; |
| 14 | +import org.springframework.data.domain.Pageable; |
| 15 | +import org.springframework.stereotype.Service; |
| 16 | + |
| 17 | +import java.util.List; |
| 18 | +import java.util.stream.Collectors; |
| 19 | + |
| 20 | +@Service |
| 21 | +public class TagService { |
| 22 | + private final TagRepository tagRepository; |
| 23 | + |
| 24 | + public TagService(TagRepository tagRepository){ |
| 25 | + this.tagRepository = tagRepository; |
| 26 | + } |
| 27 | + |
| 28 | + // 태그 모음 보기 |
| 29 | + public TagResponseDto viewTags(int page){ |
| 30 | + Pageable pageable = PageRequest.of(page - 1, 12); |
| 31 | + |
| 32 | + Page<Tag> tags = tagRepository.findAll(pageable); |
| 33 | + |
| 34 | + List<TagDto> tagList = tags.stream() |
| 35 | + .map(tag -> new TagDto( |
| 36 | + tag.getTagName(), |
| 37 | + tag.getTagInfo() |
| 38 | + )) |
| 39 | + .collect(Collectors.toList()); |
| 40 | + |
| 41 | + int totalPages = tags.getTotalPages(); |
| 42 | + |
| 43 | + return new TagResponseDto(tagList, totalPages); |
| 44 | + } |
| 45 | +} |
0 commit comments