From 660dd6eeaf38192be6a8d020a283a29e78075381 Mon Sep 17 00:00:00 2001 From: JunDonghyuk Date: Thu, 7 Mar 2024 17:54:04 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B3=B5=EC=A7=80=EC=82=AC=ED=95=AD,?= =?UTF-8?q?=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=A0=84=EC=B2=B4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../announcement/AnnouncementController.java | 28 ++++++++++++++ .../domain/announcement/Announcement.java | 37 +++++++++++++++++++ .../announcement/AnnouncementRepository.java | 10 +++++ .../domain/announcement/AnnouncementType.java | 28 ++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 src/main/java/com/example/parking/api/announcement/AnnouncementController.java create mode 100644 src/main/java/com/example/parking/domain/announcement/Announcement.java create mode 100644 src/main/java/com/example/parking/domain/announcement/AnnouncementRepository.java create mode 100644 src/main/java/com/example/parking/domain/announcement/AnnouncementType.java diff --git a/src/main/java/com/example/parking/api/announcement/AnnouncementController.java b/src/main/java/com/example/parking/api/announcement/AnnouncementController.java new file mode 100644 index 00000000..19f1db26 --- /dev/null +++ b/src/main/java/com/example/parking/api/announcement/AnnouncementController.java @@ -0,0 +1,28 @@ +package com.example.parking.api.announcement; + +import com.example.parking.domain.announcement.Announcement; +import com.example.parking.domain.announcement.AnnouncementRepository; +import com.example.parking.domain.announcement.AnnouncementType; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class AnnouncementController { + + private final AnnouncementRepository announcementRepository; + + public AnnouncementController(AnnouncementRepository announcementRepository) { + this.announcementRepository = announcementRepository; + } + + @GetMapping("/announcements") + public ResponseEntity> findAnnouncements(@RequestParam String type, Pageable pageable) { + AnnouncementType announcementType = AnnouncementType.findType(type); + Page announcements = announcementRepository.findAllByAnnouncementType(announcementType, pageable); + return ResponseEntity.ok(announcements); + } +} diff --git a/src/main/java/com/example/parking/domain/announcement/Announcement.java b/src/main/java/com/example/parking/domain/announcement/Announcement.java new file mode 100644 index 00000000..9f4ece97 --- /dev/null +++ b/src/main/java/com/example/parking/domain/announcement/Announcement.java @@ -0,0 +1,37 @@ +package com.example.parking.domain.announcement; + +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 lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Announcement { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String title; + private String fileName; + private LocalDateTime createdAt; + + @Enumerated(EnumType.STRING) + private AnnouncementType announcementType; + + public Announcement(String title, String fileName, LocalDateTime createdAt, AnnouncementType announcementType) { + this.title = title; + this.fileName = fileName; + this.createdAt = createdAt; + this.announcementType = announcementType; + } +} diff --git a/src/main/java/com/example/parking/domain/announcement/AnnouncementRepository.java b/src/main/java/com/example/parking/domain/announcement/AnnouncementRepository.java new file mode 100644 index 00000000..4191cf9e --- /dev/null +++ b/src/main/java/com/example/parking/domain/announcement/AnnouncementRepository.java @@ -0,0 +1,10 @@ +package com.example.parking.domain.announcement; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface AnnouncementRepository extends JpaRepository { + + Page findAllByAnnouncementType(AnnouncementType announcementType, Pageable pageable); +} diff --git a/src/main/java/com/example/parking/domain/announcement/AnnouncementType.java b/src/main/java/com/example/parking/domain/announcement/AnnouncementType.java new file mode 100644 index 00000000..a466a510 --- /dev/null +++ b/src/main/java/com/example/parking/domain/announcement/AnnouncementType.java @@ -0,0 +1,28 @@ +package com.example.parking.domain.announcement; + +import com.example.parking.application.member.dto.MemberNotFoundException; + +import java.util.Arrays; + +public enum AnnouncementType { + + NOTICE("notice"), + EVENT("event"); + + private final String type; + + AnnouncementType(String type) { + this.type = type; + } + + public static AnnouncementType findType(String type) { + return Arrays.stream(AnnouncementType.values()) + .filter(announcementType -> announcementType.getType().equals(type)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("찾을 수 없는 타입")); + } + + public String getType() { + return type; + } +}