-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] 공지사항 작성 API 구현
- Loading branch information
Showing
10 changed files
with
98 additions
and
15 deletions.
There are no files selected for viewing
Empty file.
27 changes: 27 additions & 0 deletions
27
src/main/java/com/pickple/server/api/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,27 @@ | ||
package com.pickple.server.api.notice.controller; | ||
|
||
import com.pickple.server.api.notice.dto.request.NoticeCreateRequest; | ||
import com.pickple.server.api.notice.service.NoticeCommandService; | ||
import com.pickple.server.global.response.ApiResponseDto; | ||
import com.pickple.server.global.response.enums.SuccessCode; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api") | ||
@RequiredArgsConstructor | ||
public class NoticeController { | ||
|
||
private final NoticeCommandService noticeCommandService; | ||
|
||
@PostMapping("/v1/moim/{moimId}/notice") | ||
public ApiResponseDto createNotice(@PathVariable Long moimId, | ||
@RequestBody NoticeCreateRequest noticeCreateRequest) { | ||
noticeCommandService.createNotice(moimId, noticeCreateRequest); | ||
return ApiResponseDto.success(SuccessCode.HOST_POST_SUCCESS); | ||
} | ||
} |
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
Empty file.
18 changes: 18 additions & 0 deletions
18
src/main/java/com/pickple/server/api/notice/dto/request/NoticeCreateRequest.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,18 @@ | ||
package com.pickple.server.api.notice.dto.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Size; | ||
|
||
public record NoticeCreateRequest( | ||
@Size(max = 25, message = "제목은 최대 25자 이내로 작성해주세요.") | ||
@NotBlank(message = "제목 비어 있습니다.") | ||
String noticeTitle,//공지사항 제목 | ||
|
||
@Size(max = 500, message = "내용은 최대 500자 이내로 작성해주세요.") | ||
@NotBlank(message = "내용이 비어 있습니다.") | ||
String noticeContent, //공지사항 내용 | ||
|
||
String imageUrl //공지사항 이미지 | ||
) { | ||
|
||
} |
Empty file.
7 changes: 7 additions & 0 deletions
7
src/main/java/com/pickple/server/api/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,7 @@ | ||
package com.pickple.server.api.notice.repository; | ||
|
||
import com.pickple.server.api.notice.domain.Notice; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface NoticeRepository extends JpaRepository<Notice, Long> { | ||
} |
Empty file.
32 changes: 32 additions & 0 deletions
32
src/main/java/com/pickple/server/api/notice/service/NoticeCommandService.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,32 @@ | ||
package com.pickple.server.api.notice.service; | ||
|
||
import com.pickple.server.api.moim.domain.Moim; | ||
import com.pickple.server.api.moim.repository.MoimRepository; | ||
import com.pickple.server.api.notice.domain.Notice; | ||
import com.pickple.server.api.notice.dto.request.NoticeCreateRequest; | ||
import com.pickple.server.api.notice.repository.NoticeRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class NoticeCommandService { | ||
|
||
private final MoimRepository moimRepository; | ||
private final NoticeRepository noticeRepository; | ||
|
||
public void createNotice(Long moimId, NoticeCreateRequest request) { | ||
Moim moim = moimRepository.findMoimByIdOrThrow(moimId); | ||
|
||
Notice notice = Notice.builder() | ||
.title(request.noticeTitle()) | ||
.content(request.noticeContent()) | ||
.imageUrl(request.imageUrl()) | ||
.moim(moim) | ||
.build(); | ||
|
||
noticeRepository.save(notice); | ||
} | ||
} |
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