-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12cd899
commit 660dd6e
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/java/com/example/parking/api/announcement/AnnouncementController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Page<Announcement>> findAnnouncements(@RequestParam String type, Pageable pageable) { | ||
AnnouncementType announcementType = AnnouncementType.findType(type); | ||
Page<Announcement> announcements = announcementRepository.findAllByAnnouncementType(announcementType, pageable); | ||
return ResponseEntity.ok(announcements); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/example/parking/domain/announcement/Announcement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/example/parking/domain/announcement/AnnouncementRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Announcement, Long> { | ||
|
||
Page<Announcement> findAllByAnnouncementType(AnnouncementType announcementType, Pageable pageable); | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/example/parking/domain/announcement/AnnouncementType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |