Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import plango.notice.domain.entity.NoticeType;

@Schema(description = "공지사항 생성 요청")
public record NoticeCreateRequest(
@Schema(description = "공지 제목", example = "서비스 점검 안내")
String title,

@Schema(description = "공지 내용", example = "금일 23시부터 서버 점검이 진행됩니다.")
String content
String content,

@Schema(
description = "공지 타입",
example = "UPDATE",
allowableValues = {"ERROR", "UPDATE", "EMERGENCY"}
)
NoticeType type
) {
@Builder
public NoticeCreateRequest { }
public NoticeCreateRequest {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import plango.notice.domain.entity.NoticeType;

@Schema(description = "공지사항 수정 요청")
public record NoticeUpdateRequest(
@Schema(description = "공지 제목", example = "서비스 점검 시간 변경 안내")
String title,

@Schema(description = "공지 내용", example = "점검 시간이 23시에서 24시로 변경되었습니다.")
String content
String content,

@Schema(
description = "공지 타입",
example = "UPDATE",
allowableValues = {"ERROR", "UPDATE", "EMERGENCY"}
)
NoticeType type
) {
@Builder
public NoticeUpdateRequest { }
public NoticeUpdateRequest {
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
package plango.notice.application.dto.response;

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

import java.time.LocalDateTime;
import lombok.Builder;
import plango.notice.domain.entity.NoticeType;

@Schema(description = "공지사항 리스트 응답")
public record NoticeListResponse(
@Schema(description = "공지 ID", example = "1")
Long id,

@Schema(description = "공지 제목", example = "서비스 점검 안내")
String title,

@Schema(
description = "공지 타입",
example = "UPDATE",
allowableValues = {"ERROR", "UPDATE", "EMERGENCY"}
)
NoticeType type,

@Schema(description = "생성 일시", example = "2025-12-08T12:34:56")
LocalDateTime createdAt
) {
@Builder
public NoticeListResponse { }
public NoticeListResponse {
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
package plango.notice.application.dto.response;

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

import java.time.LocalDateTime;
import lombok.Builder;
import plango.notice.domain.entity.NoticeType;

@Schema(description = "공지사항 상세 응답")
public record NoticeResponse(
@Schema(description = "공지 ID", example = "1")
Long id,

@Schema(description = "공지 제목", example = "서비스 점검 안내")
String title,

@Schema(description = "공지 내용", example = "금일 23시부터 서버 점검이 진행됩니다.")
String content,

@Schema(description = "작성 관리자 ID", example = "1")
Long adminId,

@Schema(
description = "공지 타입",
example = "UPDATE",
allowableValues = {"ERROR", "UPDATE", "EMERGENCY"}
)
NoticeType type,

@Schema(description = "생성 일시", example = "2025-12-08T12:34:56")
LocalDateTime createdAt,

@Schema(description = "수정 일시", example = "2025-12-08T13:00:00")
LocalDateTime updatedAt
) {
@Builder
public NoticeResponse { }
public NoticeResponse {
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package plango.notice.application.mapper;

import java.util.List;
import plango.notice.application.dto.request.NoticeCreateRequest;
import plango.notice.application.dto.response.NoticeListResponse;
import plango.notice.application.dto.response.NoticeResponse;
import plango.notice.domain.entity.Notice;

import java.util.List;

public class NoticeMapper {

public static Notice toEntity(NoticeCreateRequest request, Long adminId) {
return Notice.builder()
.title(request.title())
.content(request.content())
.adminId(adminId)
.type(request.type())
.build();
}

Expand All @@ -23,6 +23,7 @@ public static NoticeResponse toResponse(Notice notice) {
.title(notice.getTitle())
.content(notice.getContent())
.adminId(notice.getAdminId())
.type(notice.getType())
.createdAt(notice.getCreatedAt())
.updatedAt(notice.getUpdatedAt())
.build();
Expand All @@ -32,6 +33,7 @@ public static NoticeListResponse toListResponse(Notice notice) {
return NoticeListResponse.builder()
.id(notice.getId())
.title(notice.getTitle())
.type(notice.getType())
.createdAt(notice.getCreatedAt())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public void execute(Long noticeId, NoticeUpdateRequest request) {
noticeService.update(
noticeId,
request.title(),
request.content()
request.content(),
request.type()
);
}
}
22 changes: 19 additions & 3 deletions src/main/java/plango/notice/domain/entity/Notice.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -14,10 +17,12 @@
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "notice")
public class Notice extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;

@Column(nullable = false, length = 255)
Expand All @@ -29,19 +34,30 @@ public class Notice extends BaseTimeEntity {
@Column(name = "admin_id", nullable = false)
private Long adminId;

@Enumerated(EnumType.STRING)
@Column(name = "type", nullable = false, length = 20)
private NoticeType type;

@Builder
public Notice(
String title,
String content,
Long adminId
Long adminId,
NoticeType type
) {
this.title = title;
this.content = content;
this.adminId = adminId;
this.type = type;
}

public void update(String title, String content) {
public void update(
String title,
String content,
NoticeType type
) {
this.title = title;
this.content = content;
this.type = type;
}
}
}
7 changes: 7 additions & 0 deletions src/main/java/plango/notice/domain/entity/NoticeType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package plango.notice.domain.entity;

public enum NoticeType {
ERROR,
UPDATE,
EMERGENCY
}
18 changes: 9 additions & 9 deletions src/main/java/plango/notice/domain/service/NoticeService.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package plango.notice.domain.service;

import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import plango.global.common.exception.BusinessException;
import plango.global.common.exception.ErrorCode;
import plango.notice.domain.entity.Notice;
import plango.notice.domain.entity.NoticeType;
import plango.notice.domain.repository.NoticeRepository;

import java.util.List;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
Expand All @@ -26,20 +26,20 @@ public List<Notice> getAll() {
return noticeRepository.findAllByOrderByIdDesc();
}

@Transactional
public Notice save(Notice notice) {
return noticeRepository.save(notice);
}

@Transactional
public void delete(Long noticeId) {
Notice notice = getById(noticeId);
noticeRepository.delete(notice);
}

@Transactional
public void update(Long noticeId, String title, String content) {
public void update(
Long noticeId,
String title,
String content,
NoticeType type
) {
Notice notice = getById(noticeId);
notice.update(title, content);
notice.update(title, content, type);
}
}
2 changes: 2 additions & 0 deletions src/main/resources/db/migration/V28__add_type_to_notice.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE notice
ADD COLUMN type ENUM('ERROR', 'UPDATE', 'EMERGENCY') NOT NULL DEFAULT 'UPDATE';