-
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.
Merge pull request #98 from DSM-Repo/notice
공지 작성, 삭제, 수정 api 추가
- Loading branch information
Showing
15 changed files
with
237 additions
and
3 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/main/java/com/repo/whopper/application/notice/impl/DeleteNoticeService.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,19 @@ | ||
package com.repo.whopper.application.notice.impl; | ||
|
||
import com.repo.whopper.application.notice.usecase.DeleteNoticeUseCase; | ||
import com.repo.whopper.domain.notice.NoticeRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class DeleteNoticeService implements DeleteNoticeUseCase { | ||
private final NoticeRepository noticeRepository; | ||
|
||
@Override | ||
@Transactional | ||
public void deleteNotice(String noticeId) { | ||
noticeRepository.deleteById(noticeId); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/repo/whopper/application/notice/impl/EditNoticeService.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.repo.whopper.application.notice.impl; | ||
|
||
import com.repo.whopper.application.notice.usecase.EditNoticeUseCase; | ||
import com.repo.whopper.common.exception.notice.NoticeNotFoundException; | ||
import com.repo.whopper.domain.notice.NoticeRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class EditNoticeService implements EditNoticeUseCase { | ||
private final NoticeRepository noticeRepository; | ||
|
||
@Override | ||
@Transactional | ||
public void editNotice(String noticeId, String title, String content) { | ||
final var notice = noticeRepository.findById(noticeId) | ||
.orElseThrow(()-> NoticeNotFoundException.EXCEPTION); | ||
|
||
var newNotice = notice.editNotice(title, content); | ||
noticeRepository.save(newNotice); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/repo/whopper/application/notice/impl/WriteNoticeService.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.repo.whopper.application.notice.impl; | ||
|
||
import com.repo.whopper.application.notice.usecase.WriteNoticeUseCase; | ||
import com.repo.whopper.application.teacher.component.CurrentTeacher; | ||
import com.repo.whopper.domain.notice.NoticeModel; | ||
import com.repo.whopper.domain.notice.NoticeRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class WriteNoticeService implements WriteNoticeUseCase { | ||
private final NoticeRepository noticeRepository; | ||
private final CurrentTeacher currentTeacher; | ||
|
||
@Override | ||
@Transactional | ||
public void writeNotice(String title, String content) { | ||
LocalDateTime now = LocalDateTime.now(); | ||
|
||
final var teacher = currentTeacher.getTeacher(); | ||
|
||
noticeRepository.save(new NoticeModel(null, title, content, teacher.name(), now, false)); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/repo/whopper/application/notice/usecase/DeleteNoticeUseCase.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,5 @@ | ||
package com.repo.whopper.application.notice.usecase; | ||
|
||
public interface DeleteNoticeUseCase { | ||
void deleteNotice(String noticeId); | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/repo/whopper/application/notice/usecase/EditNoticeUseCase.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,5 @@ | ||
package com.repo.whopper.application.notice.usecase; | ||
|
||
public interface EditNoticeUseCase { | ||
void editNotice(String noticeId, String title, String content); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/repo/whopper/common/swagger/notice/DeleteNoticeApiDocumentation.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,21 @@ | ||
package com.repo.whopper.common.swagger.notice; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
|
||
@Tag(name = "Delete_notice", description = "공지 삭제 API") | ||
public interface DeleteNoticeApiDocumentation { | ||
@ApiResponses({ | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "OK, 성공!" | ||
) | ||
}) | ||
@Operation( | ||
summary = "공지 삭제 API", | ||
description = "클라이언트에서 받은 id로 공지를 삭제합니다." | ||
) | ||
void deleteNotice(String noticeId); | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/repo/whopper/common/swagger/notice/EditNoticeApiDocumentation.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.repo.whopper.common.swagger.notice; | ||
|
||
import com.repo.whopper.interfaces.notice.dto.request.NoticeRequest; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
|
||
@Tag(name = "Edit_notice", description = "공지 수정 API") | ||
public interface EditNoticeApiDocumentation { | ||
@ApiResponses({ | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "OK, 성공!" | ||
) | ||
}) | ||
@Operation( | ||
summary = "공지 수정 API", | ||
description = "클라이언트에서 받은 id로 공지를 검색하고, 검색한 공지의 제목과 내용을 수정합니다." | ||
) | ||
void editNotice(String noticeId, NoticeRequest request); | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/repo/whopper/common/swagger/notice/WriteNoticeApiDocumentation.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.repo.whopper.common.swagger.notice; | ||
|
||
import com.repo.whopper.interfaces.notice.dto.request.NoticeRequest; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
|
||
@Tag(name = "Write_notice", description = "공지 작성 API") | ||
public interface WriteNoticeApiDocumentation { | ||
@ApiResponses({ | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "OK, 성공!" | ||
) | ||
}) | ||
@Operation( | ||
summary = "공지 작성 API", | ||
description = "제목과 내용을 받아서 데이터베이스에 저장합니다." | ||
) | ||
void writeNotice(NoticeRequest request); | ||
} |
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
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
23 changes: 23 additions & 0 deletions
23
src/main/java/com/repo/whopper/interfaces/notice/DeleteNoticeController.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,23 @@ | ||
package com.repo.whopper.interfaces.notice; | ||
|
||
import com.repo.whopper.application.notice.usecase.DeleteNoticeUseCase; | ||
import com.repo.whopper.common.annotation.OnlyTeacher; | ||
import com.repo.whopper.common.swagger.notice.DeleteNoticeApiDocumentation; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/notice") | ||
public class DeleteNoticeController implements DeleteNoticeApiDocumentation { | ||
private final DeleteNoticeUseCase deleteNoticeUseCase; | ||
|
||
@OnlyTeacher | ||
@DeleteMapping("/{noticeId}") | ||
public void deleteNotice(@PathVariable String noticeId) { | ||
deleteNoticeUseCase.deleteNotice(noticeId); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/repo/whopper/interfaces/notice/EditNoticeController.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,25 @@ | ||
package com.repo.whopper.interfaces.notice; | ||
|
||
import com.repo.whopper.application.notice.usecase.EditNoticeUseCase; | ||
import com.repo.whopper.common.annotation.OnlyTeacher; | ||
import com.repo.whopper.common.swagger.notice.EditNoticeApiDocumentation; | ||
import com.repo.whopper.interfaces.notice.dto.request.NoticeRequest; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/notice") | ||
public class EditNoticeController implements EditNoticeApiDocumentation { | ||
private final EditNoticeUseCase editNoticeUseCase; | ||
|
||
@OnlyTeacher | ||
@PatchMapping("/{noticeId}") | ||
public void editNotice(@PathVariable String noticeId, @RequestBody NoticeRequest request) { | ||
editNoticeUseCase.editNotice(noticeId, request.title(), request.content()); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/repo/whopper/interfaces/notice/WriteNoticeController.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.repo.whopper.interfaces.notice; | ||
|
||
import com.repo.whopper.application.notice.usecase.WriteNoticeUseCase; | ||
import com.repo.whopper.common.annotation.OnlyTeacher; | ||
import com.repo.whopper.common.swagger.notice.WriteNoticeApiDocumentation; | ||
import com.repo.whopper.interfaces.notice.dto.request.NoticeRequest; | ||
import lombok.RequiredArgsConstructor; | ||
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 | ||
@RequiredArgsConstructor | ||
@RequestMapping("/notice") | ||
public class WriteNoticeController implements WriteNoticeApiDocumentation { | ||
private final WriteNoticeUseCase writeNoticeUseCase; | ||
|
||
@OnlyTeacher | ||
@PostMapping | ||
public void writeNotice(@RequestBody NoticeRequest request) { | ||
writeNoticeUseCase.writeNotice(request.title(), request.content()); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/repo/whopper/interfaces/notice/dto/request/NoticeRequest.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,6 @@ | ||
package com.repo.whopper.interfaces.notice.dto.request; | ||
|
||
public record NoticeRequest( | ||
String title, | ||
String content | ||
) {} |