-
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 #78 from Team-MindWay/76-admin-notice-add-api
🔀 :: 어드민 공지 등록 api
- Loading branch information
Showing
10 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
src/main/java/com/mindway/server/v2/domain/notice/converter/NoticeConverter.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.mindway.server.v2.domain.notice.converter; | ||
|
||
|
||
import com.mindway.server.v2.domain.notice.entity.Notice; | ||
import com.mindway.server.v2.domain.notice.presentation.dto.request.NoticeAddRequestDto; | ||
import com.mindway.server.v2.domain.user.entity.User; | ||
|
||
public interface NoticeConverter { | ||
Notice toEntity(NoticeAddRequestDto noticeAddRequestDto, User user); | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/mindway/server/v2/domain/notice/converter/impl/NoticeConverterImpl.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.mindway.server.v2.domain.notice.converter.impl; | ||
|
||
import com.mindway.server.v2.domain.notice.converter.NoticeConverter; | ||
import com.mindway.server.v2.domain.notice.entity.Notice; | ||
import com.mindway.server.v2.domain.notice.presentation.dto.request.NoticeAddRequestDto; | ||
import com.mindway.server.v2.domain.user.entity.User; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class NoticeConverterImpl implements NoticeConverter { | ||
|
||
public Notice toEntity(NoticeAddRequestDto noticeAddRequestDto, User user) { | ||
return Notice.builder() | ||
.title(noticeAddRequestDto.getTitle()) | ||
.content(noticeAddRequestDto.getContent()) | ||
.user(user) | ||
.build(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/mindway/server/v2/domain/notice/entity/Notice.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.mindway.server.v2.domain.notice.entity; | ||
|
||
import com.mindway.server.v2.domain.user.entity.User; | ||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Entity | ||
@Builder | ||
public class Notice { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private String title; | ||
|
||
private String content; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "user_id") | ||
private User user; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/mindway/server/v2/domain/notice/exception/NotAccessStudentException.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.mindway.server.v2.domain.notice.exception; | ||
|
||
import com.mindway.server.v2.global.exception.ErrorCode; | ||
import com.mindway.server.v2.global.exception.MindWayException; | ||
|
||
public class NotAccessStudentException extends MindWayException { | ||
public NotAccessStudentException() { | ||
super(ErrorCode.NOT_ACCESS_STUDENT); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/mindway/server/v2/domain/notice/presentation/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.mindway.server.v2.domain.notice.presentation; | ||
|
||
import com.mindway.server.v2.domain.notice.presentation.dto.request.NoticeAddRequestDto; | ||
import com.mindway.server.v2.domain.notice.service.NoticeAddService; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
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("/api/v2/notice") | ||
public class NoticeController { | ||
|
||
private final NoticeAddService noticeAddService; | ||
|
||
@PostMapping | ||
public ResponseEntity<Void> addNotice(@Valid @RequestBody NoticeAddRequestDto noticeAddRequestDto) { | ||
noticeAddService.execute(noticeAddRequestDto); | ||
return ResponseEntity.status(HttpStatus.CREATED).build(); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...ava/com/mindway/server/v2/domain/notice/presentation/dto/request/NoticeAddRequestDto.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,16 @@ | ||
package com.mindway.server.v2.domain.notice.presentation.dto.request; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class NoticeAddRequestDto { | ||
|
||
@NotNull | ||
private String title; | ||
@NotNull | ||
private String content; | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/mindway/server/v2/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,8 @@ | ||
package com.mindway.server.v2.domain.notice.repository; | ||
|
||
|
||
import com.mindway.server.v2.domain.notice.entity.Notice; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface NoticeRepository extends JpaRepository<Notice, Long> { | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/mindway/server/v2/domain/notice/service/NoticeAddService.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.mindway.server.v2.domain.notice.service; | ||
|
||
import com.mindway.server.v2.domain.notice.presentation.dto.request.NoticeAddRequestDto; | ||
|
||
public interface NoticeAddService { | ||
void execute(NoticeAddRequestDto noticeAddRequestDto); | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/mindway/server/v2/domain/notice/service/impl/NoticeAddServiceImpl.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,33 @@ | ||
package com.mindway.server.v2.domain.notice.service.impl; | ||
|
||
import com.mindway.server.v2.domain.notice.converter.NoticeConverter; | ||
import com.mindway.server.v2.domain.notice.entity.Notice; | ||
import com.mindway.server.v2.domain.notice.exception.NotAccessStudentException; | ||
import com.mindway.server.v2.domain.notice.presentation.dto.request.NoticeAddRequestDto; | ||
import com.mindway.server.v2.domain.notice.repository.NoticeRepository; | ||
import com.mindway.server.v2.domain.notice.service.NoticeAddService; | ||
import com.mindway.server.v2.domain.user.entity.Authority; | ||
import com.mindway.server.v2.domain.user.entity.User; | ||
import com.mindway.server.v2.domain.user.util.UserUtil; | ||
import com.mindway.server.v2.global.annotation.ServiceWithTransaction; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@ServiceWithTransaction | ||
@RequiredArgsConstructor | ||
public class NoticeAddServiceImpl implements NoticeAddService { | ||
|
||
private final NoticeConverter noticeConverter; | ||
private final NoticeRepository noticeRepository; | ||
private final UserUtil userUtil; | ||
|
||
public void execute(NoticeAddRequestDto noticeAddRequestDto) { | ||
User user = userUtil.getCurrentUser(); | ||
|
||
if (user.getAuthority() == Authority.ROLE_STUDENT) | ||
throw new NotAccessStudentException(); | ||
|
||
Notice notice = noticeConverter.toEntity(noticeAddRequestDto, user); | ||
|
||
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