Skip to content

Commit

Permalink
♻️ refactor(api): change name announcement -> notice (#490)
Browse files Browse the repository at this point in the history
* ♻️ refactor(api): change name announcement -> notice

* ♻️ refactor(admin): change name announcement -> notice

* ♻️ refactor(admin): do not change name announcement -> notice
  • Loading branch information
siyeonSon authored Jun 28, 2024
1 parent c819e13 commit 687ae99
Show file tree
Hide file tree
Showing 13 changed files with 315 additions and 316 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.depromeet.domains.notice.controller;

import com.depromeet.common.dto.PaginationResponseDto;
import com.depromeet.common.dto.ResponseDto;
import com.depromeet.domains.notice.dto.response.NoticeResponseDto;
import com.depromeet.domains.notice.dto.response.NewNoticeResponseDto;
import com.depromeet.domains.notice.service.NoticeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/notices")
@RequiredArgsConstructor
@Tag(name = "🔈Notice", description = "Notice API")
public class NoticeController {

private final NoticeService noticeService;

@Operation(summary = "공지사항 전체 조회")
@GetMapping
public ResponseEntity<PaginationResponseDto<?, ?>> getNotices() {
var response = noticeService.getNotices();
return ResponseDto.ok(response);
}

@Operation(summary = "공지사항 단건 조회")
@GetMapping("{noticeId}")
public ResponseEntity<NoticeResponseDto> getNotice(
@PathVariable(value = "noticeId") Long noticeId
) {
var response = noticeService.getNotice(noticeId);
return ResponseDto.ok(response);
}

@Operation(summary = "신규 공지사항 여부 조회")
@GetMapping("/new")
public ResponseEntity<NewNoticeResponseDto> hasNewNotice(
@Schema(description = "마지막으로 조회한 공지사항 아이디", example = "1")
@RequestParam(defaultValue = "-1") Long lastNoticeId
) {
var response = noticeService.hasNewNotice(lastNoticeId);
return ResponseDto.ok(response);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.depromeet.domains.notice.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;

public record NewNoticeResponseDto(
@Schema(description = "새로운 공지사항이 있는지 여부", example = "true")
boolean hasNewNotice
){
public NewNoticeResponseDto(boolean hasNewNotice) {
this.hasNewNotice = hasNewNotice;
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.depromeet.domains.announcement.dto.response;
package com.depromeet.domains.notice.dto.response;

import com.depromeet.announcement.Announcement;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDateTime;

public record AnnouncementListResponseDto(
public record NoticeListResponseDto(
@Schema(description = "공지사항 아이디", example = "1")
Long announcementId,
Long noticeId,

@Schema(description = "공지사항 제목", example = "사용성 개선")
String title,

@Schema(description = "생성시간", example = "yyyy-MM-dd HH:mm:ss")
LocalDateTime createdAt
) {
public AnnouncementListResponseDto(Announcement announcement) {
public NoticeListResponseDto(Announcement announcement) {
this(
announcement.getId(),
announcement.getTitle(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.depromeet.domains.announcement.dto.response;
package com.depromeet.domains.notice.dto.response;

import com.depromeet.announcement.Announcement;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;

public record AnnouncementResponseDto(
public record NoticeResponseDto(
@Schema(description = "공지사항 아이디", example = "1")
Long announcementId,
Long noticeId,

@Schema(description = "공지사항 제목", example = "사용성 개선")
String title,
Expand All @@ -17,7 +17,7 @@ public record AnnouncementResponseDto(
@Schema(description = "생성시간", example = "yyyy-MM-dd HH:mm:ss")
LocalDateTime createdAt
) {
public AnnouncementResponseDto(Announcement announcement) {
public NoticeResponseDto(Announcement announcement) {
this(
announcement.getId(),
announcement.getTitle(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.depromeet.domains.notice.repository;

import com.depromeet.announcement.Announcement;
import org.springframework.data.jpa.repository.JpaRepository;

public interface NoticeRepository extends JpaRepository<Announcement, Long> {

boolean existsByIdGreaterThan(Long lastNoticeId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.depromeet.domains.notice.service;

import com.depromeet.common.dto.MetaInterface;
import com.depromeet.common.dto.PageMetaResponseDto;
import com.depromeet.common.dto.PaginationResponseDto;
import com.depromeet.common.error.dto.CommonErrorCode;
import com.depromeet.common.error.exception.internal.NotFoundException;
import com.depromeet.domains.notice.dto.response.NoticeListResponseDto;
import com.depromeet.domains.notice.dto.response.NoticeResponseDto;
import com.depromeet.domains.notice.dto.response.NewNoticeResponseDto;
import com.depromeet.domains.notice.repository.NoticeRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Service
public class NoticeService {

private final NoticeRepository noticeRepository;

@Transactional(readOnly = true)
public PaginationResponseDto<NoticeListResponseDto, MetaInterface> getNotices() {
var notices = noticeRepository.findAll()
.stream()
.map(NoticeListResponseDto::new)
.toList();
var meta = PageMetaResponseDto.builder()
.page(1)
.size(notices.size())
.totalPage(1)
.firstPage(true)
.lastPage(true)
.build();
return new PaginationResponseDto<>(notices, meta);
}

@Transactional(readOnly = true)
public NoticeResponseDto getNotice(Long noticeId) {
return noticeRepository.findById(noticeId)
.map(NoticeResponseDto::new)
.orElseThrow(() -> new NotFoundException(CommonErrorCode.NOT_FOUND, noticeId));
}

@Transactional(readOnly = true)
public NewNoticeResponseDto hasNewNotice(Long lastNoticeId) {
var isExist = noticeRepository.existsByIdGreaterThan(lastNoticeId);
return new NewNoticeResponseDto(isExist);
}

}
Loading

0 comments on commit 687ae99

Please sign in to comment.