forked from CSID-DGU/2024-2-OSSProj-Running-Machines-04
-
Notifications
You must be signed in to change notification settings - Fork 0
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
8e4ca42
commit 1fb43c5
Showing
4 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
14 changes: 13 additions & 1 deletion
14
...ain/java/RunningMachines/R2R/domain/crew/post/notice/controller/NoticePostController.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 |
---|---|---|
@@ -1,25 +1,37 @@ | ||
package RunningMachines.R2R.domain.crew.post.notice.controller; | ||
|
||
import RunningMachines.R2R.domain.crew.post.entity.CrewPost; | ||
import RunningMachines.R2R.domain.crew.post.notice.dto.NoticePostCreateRequestDto; | ||
import RunningMachines.R2R.domain.crew.post.notice.dto.NoticePostResponseDto; | ||
import RunningMachines.R2R.domain.crew.post.notice.service.NoticePostCommandService; | ||
import RunningMachines.R2R.domain.crew.post.notice.service.NoticePostQueryService; | ||
import RunningMachines.R2R.domain.user.entity.User; | ||
import RunningMachines.R2R.domain.user.service.AuthCommandService; | ||
import RunningMachines.R2R.domain.user.service.UserCommandService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/crew/{crewId}/notice") | ||
@RequiredArgsConstructor | ||
public class NoticePostController { | ||
private final NoticePostCommandService noticePostCommandService; | ||
private final NoticePostQueryService noticePostQueryService; | ||
private final AuthCommandService authCommandService; | ||
|
||
@PostMapping() | ||
@PostMapping | ||
public ResponseEntity<Long> createNoticePost(@PathVariable Long crewId, @RequestBody NoticePostCreateRequestDto requestDto) { | ||
User currentUser = authCommandService.getCurrentUser(); | ||
noticePostCommandService.createNoticePost(crewId, currentUser, requestDto); | ||
return ResponseEntity.ok(crewId); | ||
} | ||
|
||
@GetMapping("/{crewPostId}") | ||
public ResponseEntity<NoticePostResponseDto> getNoticePostDetail(@PathVariable Long crewId, @PathVariable Long crewPostId) { | ||
return ResponseEntity.ok(noticePostQueryService.getPostDetail(crewId, crewPostId)); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
.../src/main/java/RunningMachines/R2R/domain/crew/post/notice/dto/NoticePostResponseDto.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,27 @@ | ||
package RunningMachines.R2R.domain.crew.post.notice.dto; | ||
|
||
import RunningMachines.R2R.domain.crew.post.entity.CrewPost; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Builder | ||
public class NoticePostResponseDto { | ||
private String title; | ||
private String content; | ||
private String author; | ||
private String crewName; | ||
private LocalDateTime createdDate; | ||
|
||
public static NoticePostResponseDto fromEntity(CrewPost crewPost) { | ||
return NoticePostResponseDto.builder() | ||
.title(crewPost.getTitle()) | ||
.content(crewPost.getContent()) | ||
.author(crewPost.getUser().getNickname()) | ||
.crewName(crewPost.getCrew().getTitle()) | ||
.createdDate(crewPost.getCreatedAt()) | ||
.build(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...main/java/RunningMachines/R2R/domain/crew/post/notice/service/NoticePostQueryService.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 RunningMachines.R2R.domain.crew.post.notice.service; | ||
|
||
import RunningMachines.R2R.domain.crew.board.entity.CrewBoard; | ||
import RunningMachines.R2R.domain.crew.common.entity.Crew; | ||
import RunningMachines.R2R.domain.crew.post.entity.CrewPost; | ||
import RunningMachines.R2R.domain.crew.post.notice.dto.NoticePostResponseDto; | ||
import RunningMachines.R2R.domain.crew.post.repository.CrewPostRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class NoticePostQueryService { | ||
private final CrewPostRepository crewPostRepository; | ||
|
||
public NoticePostResponseDto getPostDetail(Long crewId, Long crewpostId) { | ||
CrewPost noticePost = crewPostRepository.findByIdAndCrewIdAndBoard(crewpostId, crewId, CrewBoard.NOTICE) | ||
.orElseThrow(() -> new IllegalArgumentException("공지글을 찾을 수 없습니다.")); | ||
return NoticePostResponseDto.fromEntity(noticePost); | ||
} | ||
} |
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