Skip to content

Commit

Permalink
[feat] #17 단일 공지사항 조회 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jj0526 authored and seokjun01 committed Jan 16, 2025
1 parent b2b8d70 commit 63844a5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.eatmate.app.domain.notice.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.eatmate.app.domain.notice.dto.NoticeResponseDto;
import com.example.eatmate.app.domain.notice.service.NoticeService;
import com.example.eatmate.global.response.GlobalResponseDto;

import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;

@RestController
@RequestMapping("/api/notices")
@RequiredArgsConstructor
public class NoticeController {

private final NoticeService noticeService;

@GetMapping("/{noticeId}")
@Operation(summary = "단일 공지사항 조회", description = "단일 공지사항을 조회합니다.")
public ResponseEntity<GlobalResponseDto<NoticeResponseDto>> getNotice(@PathVariable Long noticeId) {
return ResponseEntity.status(HttpStatus.OK)
.body(GlobalResponseDto.success(noticeService.findNotice(noticeId)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import com.example.eatmate.app.domain.notice.domain.Notice;
import com.example.eatmate.app.domain.notice.domain.repository.NoticeRepository;
import com.example.eatmate.app.domain.notice.dto.NoticeAdminRequestDto;
import com.example.eatmate.app.domain.notice.dto.NoticeResponseDto;
import com.example.eatmate.global.config.error.ErrorCode;
import com.example.eatmate.global.config.error.exception.CommonException;

import lombok.RequiredArgsConstructor;

Expand All @@ -18,4 +21,11 @@ public void createNotice(NoticeAdminRequestDto noticeAdminRequestDto) {
Notice notice = Notice.createNotice(noticeAdminRequestDto);
noticeRepository.save(notice);
}

public NoticeResponseDto findNotice(Long noticeId) {
Notice notice = noticeRepository.findById(noticeId)
.orElseThrow(() -> new CommonException(ErrorCode.NOTICE_NOT_FOUND));

return NoticeResponseDto.createNoticeResponseDto(notice);
}
}

0 comments on commit 63844a5

Please sign in to comment.