-
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.
Browse files
Browse the repository at this point in the history
feat : notice api 구현
- Loading branch information
Showing
8 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
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
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
28 changes: 28 additions & 0 deletions
28
src/main/java/com/clubber/ClubberServer/domain/notice/controller/NoticeController.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.clubber.ClubberServer.domain.notice.controller; | ||
|
||
import com.clubber.ClubberServer.domain.notice.domain.Notice; | ||
import com.clubber.ClubberServer.domain.notice.dto.NoticesDto; | ||
import com.clubber.ClubberServer.domain.notice.repository.NoticeRepository; | ||
import com.clubber.ClubberServer.domain.notice.service.NoticeService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class NoticeController { | ||
private final NoticeService noticeService; | ||
private final NoticeRepository noticeRepository; | ||
|
||
|
||
@GetMapping("/v1/notice") | ||
public ResponseEntity<List<NoticesDto>> getNotices(){ | ||
List<NoticesDto> notices=noticeService.getSortedNotices(); | ||
return ResponseEntity.ok(notices); | ||
} | ||
|
||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/clubber/ClubberServer/domain/notice/dto/NoticesDto.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,24 @@ | ||
package com.clubber.ClubberServer.domain.notice.dto; | ||
|
||
import com.clubber.ClubberServer.domain.club.dto.SimpleCenterDto; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Data | ||
public class NoticesDto { | ||
private Long noticeId; | ||
private String content; | ||
private LocalDateTime createdAt; | ||
|
||
|
||
@Builder | ||
public NoticesDto(Long noticeId, String content,LocalDateTime createdAt){ | ||
this.noticeId=noticeId; | ||
this.content=content; | ||
this.createdAt=createdAt; | ||
|
||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/clubber/ClubberServer/domain/notice/dto/OneNoticeDto.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,22 @@ | ||
package com.clubber.ClubberServer.domain.notice.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Data | ||
public class OneNoticeDto { | ||
private Long id; | ||
private String content; | ||
private LocalDateTime createdAt; | ||
|
||
|
||
@Builder | ||
public OneNoticeDto(Long id, String content,LocalDateTime createdAt){ | ||
this.id=id; | ||
this.content=content; | ||
this.createdAt=createdAt; | ||
|
||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/clubber/ClubberServer/domain/notice/repository/NoticeRepository.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,12 @@ | ||
package com.clubber.ClubberServer.domain.notice.repository; | ||
|
||
import com.clubber.ClubberServer.domain.notice.domain.Notice; | ||
import com.clubber.ClubberServer.domain.notice.dto.NoticesDto; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface NoticeRepository extends JpaRepository<Notice,Long> { | ||
List<Notice> findAll(Sort sort); | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/clubber/ClubberServer/domain/notice/service/NoticeService.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,29 @@ | ||
package com.clubber.ClubberServer.domain.notice.service; | ||
|
||
import com.clubber.ClubberServer.domain.club.dto.DivisionCenterDto; | ||
import com.clubber.ClubberServer.domain.club.dto.SimpleCenterDto; | ||
import com.clubber.ClubberServer.domain.common.BaseEntity; | ||
import com.clubber.ClubberServer.domain.notice.domain.Notice; | ||
import com.clubber.ClubberServer.domain.notice.dto.NoticesDto; | ||
import com.clubber.ClubberServer.domain.notice.repository.NoticeRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class NoticeService { | ||
|
||
private final NoticeRepository noticeRepository; | ||
public List<NoticesDto> getSortedNotices(){ | ||
Sort sort =Sort.by(Sort.Direction.DESC,"createdAt"); | ||
List <Notice> notices=noticeRepository.findAll(sort); | ||
List <NoticesDto> noticeDto = notices.stream() | ||
.map(notice -> new NoticesDto(notice.getId(), notice.getContent(), notice.getCreatedAt())) | ||
.collect(Collectors.toList()); | ||
return noticeDto; | ||
} | ||
} |
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