Skip to content

Commit

Permalink
Merge pull request #2 from mijin0721/devepole
Browse files Browse the repository at this point in the history
공지사항 조회하는 기능 추가
  • Loading branch information
mijin0721 authored Mar 24, 2023
2 parents bdfc301 + c9d5f5f commit 45bd41b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
Expand All @@ -19,4 +20,14 @@ public Map<String, String> create(@RequestBody NoticeDto noticeDto) {
return Map.of("result", "create success");
}

@GetMapping
public List<NoticeDto> getNoticeList() {
return noticeService.getNoticeList();
}

@GetMapping("/{id}")
public NoticeDto getNotice(@PathVariable("id") Long id) {
return noticeService.getNotice(id);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import com.hallym.festival.domain.notice.dto.NoticeDto;
import com.hallym.festival.domain.notice.entity.Notice;
import com.hallym.festival.domain.notice.repository.NoticeRepository;
import com.hallym.festival.global.exception.WrongBoothId;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@RequiredArgsConstructor
@Transactional
Expand All @@ -21,4 +25,21 @@ public NoticeDto create(NoticeDto noticeDto) {
return noticeDto1;
}

public List<NoticeDto> getNoticeList() {
List<Notice> noticeList = noticeRepository.findAll();
return noticeList.stream()
.map(notice -> notice.toDto())
.collect(Collectors.toList());
}

public NoticeDto getNotice(Long id) {
Notice notice = findByNotice(id);
NoticeDto noticeDto = notice.toDto();
return noticeDto;
}

public Notice findByNotice(Long id) {
return noticeRepository.findById(id).orElseThrow(() -> new WrongBoothId());
}

}
17 changes: 17 additions & 0 deletions src/test/java/com/hallym/festival/service/NoticeServiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;
import java.util.stream.IntStream;

@SpringBootTest
Expand All @@ -29,4 +30,20 @@ public class NoticeServiceTests {
});
System.out.println("----------작성완료!----------");
}

@Test
public void 게시물_목록_조회() {
List<NoticeDto> noticeDtoList = noticeService.getNoticeList();
System.out.println(noticeDtoList.size());
for (NoticeDto notice : noticeDtoList) {
System.out.println(notice);
}
}

@Test
public void 게시물_한개_조회() {
Long id = 1L;
NoticeDto noticeDto = noticeService.getNotice(id);
System.out.println(noticeDto);
}
}

0 comments on commit 45bd41b

Please sign in to comment.