-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
๐ :: ์ด๋๋ฏผ ๊ณต์ง ๋ฑ๋ก api #78
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
def2e50
add :: Notice ์ถ๊ฐ
Umjiseung 332f8cf
add :: NoticeAddRequestDto ์ถ๊ฐ
Umjiseung af71082
add :: NoticeAddService ์ถ๊ฐ
Umjiseung 6337afc
add :: NoticeController ์ถ๊ฐ
Umjiseung aa5dcfa
add :: NoticeConverter ์ถ๊ฐ
Umjiseung 271b5f1
add :: NoticeRepository ์ถ๊ฐ
Umjiseung efd9d77
add :: url ์ถ๊ฐ
Umjiseung 0464d2c
add :: ์ด๋๋ฏผ ๊ฒ์ฆ ๋ก์ง ์ถ๊ฐ
Umjiseung e3193c3
add :: NotAccessStudentException ์ถ๊ฐ
Umjiseung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ์๋๋ง ์ธ ์ ์๋๋ก ์์ธ์ฒ๋ฆฌ ํด์ผํ ๊ฑฐ๊ฐ์์
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0464d2c
์์ ํ์ด์ฉ