From c120fb3cf1ecd1b380b60e1c4f4632f2b2bc9a81 Mon Sep 17 00:00:00 2001 From: lyutvs Date: Wed, 22 Jun 2022 00:26:07 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=93=91::=20CreateFeedRequset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/CreateFeedRequest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/java/com/example/moizaspringserver/domain/feed/presenstation/dto/request/CreateFeedRequest.java diff --git a/src/main/java/com/example/moizaspringserver/domain/feed/presenstation/dto/request/CreateFeedRequest.java b/src/main/java/com/example/moizaspringserver/domain/feed/presenstation/dto/request/CreateFeedRequest.java new file mode 100644 index 00000000..5de75ef0 --- /dev/null +++ b/src/main/java/com/example/moizaspringserver/domain/feed/presenstation/dto/request/CreateFeedRequest.java @@ -0,0 +1,29 @@ +package com.example.moizaspringserver.domain.feed.presenstation.dto.request; + +import com.example.moizaspringserver.domain.feed.type.FeedType; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.util.List; + +@Getter +@NoArgsConstructor +public class CreateFeedRequest { + + @NotBlank(message = "title은 Null, 공백, 띄어쓰기를 허용하지 않습니다.") + private String title; + + @NotNull(message = "content은 Null, 공백, 띄어쓰기를 허용하지 않습니다.") + private String content; + + @NotNull(message = "feed_type은 Null일 수 없습니다.") + private FeedType feedType; + + @NotNull(message = "category은 Null일 수 없습니다.") + private String category; + + @NotNull(message = "image_urls은 Null일 수 없습니다.") + private List imageUrls; +} From 38cfa59fe51563e61a573623187603450a5a99de Mon Sep 17 00:00:00 2001 From: lyutvs Date: Wed, 22 Jun 2022 00:26:17 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=93=91=20::=20CreateFeedService?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feed/service/CreateFeedService.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/main/java/com/example/moizaspringserver/domain/feed/service/CreateFeedService.java diff --git a/src/main/java/com/example/moizaspringserver/domain/feed/service/CreateFeedService.java b/src/main/java/com/example/moizaspringserver/domain/feed/service/CreateFeedService.java new file mode 100644 index 00000000..4920c60a --- /dev/null +++ b/src/main/java/com/example/moizaspringserver/domain/feed/service/CreateFeedService.java @@ -0,0 +1,40 @@ +package com.example.moizaspringserver.domain.feed.service; + +import com.example.moizaspringserver.domain.feed.entity.Feed; +import com.example.moizaspringserver.domain.feed.entity.PublicFeed; +import com.example.moizaspringserver.domain.feed.presenstation.dto.request.CreateFeedRequest; +import com.example.moizaspringserver.domain.feed.respository.FeedAttachmentFileRepository; +import com.example.moizaspringserver.domain.feed.respository.PublicFeedRepository; +import com.example.moizaspringserver.domain.user.entity.User; +import com.example.moizaspringserver.domain.user.facade.UserFacade; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Service +public class CreateFeedService { + + private final PublicFeedRepository publicFeedRepository; + private final FeedAttachmentFileRepository feedAttachmentFileRepository; + private final UserFacade userFacade; + + @Transactional + public void execute(CreateFeedRequest request) { + User user = userFacade.queryCurrentUser(); + + Feed feed = Feed.builder() + .feedType(request.getFeedType()) + .user(user) + .build(); + + PublicFeed publicFeed = PublicFeed.builder() + .title(request.getTitle()) + .content(request.getContent()) + .feed(feed) + .build(); + + publicFeedRepository.save(publicFeed); + // TODO 이미지 저장 로직 + } +} From 6aeb8ba4ea6e65c1db00f79a6d5f7dfdfdb4f62b Mon Sep 17 00:00:00 2001 From: lyutvs Date: Wed, 22 Jun 2022 00:26:30 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20::=20FeedController?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/feed/presenstation/FeedController.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/com/example/moizaspringserver/domain/feed/presenstation/FeedController.java b/src/main/java/com/example/moizaspringserver/domain/feed/presenstation/FeedController.java index 82e57c68..250f93b2 100644 --- a/src/main/java/com/example/moizaspringserver/domain/feed/presenstation/FeedController.java +++ b/src/main/java/com/example/moizaspringserver/domain/feed/presenstation/FeedController.java @@ -1,16 +1,21 @@ package com.example.moizaspringserver.domain.feed.presenstation; +import com.example.moizaspringserver.domain.feed.presenstation.dto.request.CreateFeedRequest; +import com.example.moizaspringserver.domain.feed.service.CreateFeedService; import com.example.moizaspringserver.domain.feed.service.DeleteFeedService; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; +import javax.validation.Valid; + @RequiredArgsConstructor @RequestMapping("/feeds") @RestController public class FeedController { private final DeleteFeedService deleteFeedService; + private final CreateFeedService createFeedService; @ResponseStatus(HttpStatus.NO_CONTENT) @DeleteMapping("/{feed-id}") @@ -18,4 +23,10 @@ public void deleteFeed(@PathVariable("feed-id") Integer feedId) { deleteFeedService.execute(feedId); } + @ResponseStatus(HttpStatus.CREATED) + @PostMapping + public void createFeed(@Valid @RequestBody CreateFeedRequest request) { + createFeedService.execute(request); + } + } From bb9681f9a4a5f82ebe56fad317f5250e4904d07d Mon Sep 17 00:00:00 2001 From: lyutvs Date: Wed, 22 Jun 2022 00:26:38 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20=20::=20SecurirtConfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../moizaspringserver/global/security/SecurityConfig.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/moizaspringserver/global/security/SecurityConfig.java b/src/main/java/com/example/moizaspringserver/global/security/SecurityConfig.java index 7ee16e5b..c6635797 100644 --- a/src/main/java/com/example/moizaspringserver/global/security/SecurityConfig.java +++ b/src/main/java/com/example/moizaspringserver/global/security/SecurityConfig.java @@ -55,7 +55,7 @@ protected void configure(HttpSecurity http) throws Exception { .antMatchers(HttpMethod.POST, "/users/graduate-verifications").hasAuthority(UserType.ROLE_USER.name()) // notice - .antMatchers(HttpMethod.DELETE, "/notices/{notice-id}").hasAnyAuthority("ADMIN") + .antMatchers(HttpMethod.DELETE, "/notices/{notice-id}").hasAnyAuthority(UserType.ROLE_ADMIN.name()) // follow .antMatchers(HttpMethod.POST, "/follow/*").authenticated() @@ -63,6 +63,7 @@ protected void configure(HttpSecurity http) throws Exception { // feeds .antMatchers(HttpMethod.DELETE, "/feeds/{feed-id}").authenticated() + .antMatchers(HttpMethod.POST, "/feeds").hasAnyAuthority(UserType.ROLE_STUDENT.name(), UserType.ROLE_GRADUATE.name()) // notice .antMatchers(HttpMethod.GET, "/notices/{notice-id}").authenticated() From 95893aba83c0d164923a25fbfa83b0f94526cc4f Mon Sep 17 00:00:00 2001 From: lyutvs Date: Thu, 30 Jun 2022 15:09:21 +0900 Subject: [PATCH 5/5] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EC=82=AC=ED=95=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/feed/presenstation/FeedController.java | 2 +- .../feed/presenstation/dto/request/CreateFeedRequest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/moizaspringserver/domain/feed/presenstation/FeedController.java b/src/main/java/com/example/moizaspringserver/domain/feed/presenstation/FeedController.java index 250f93b2..a83248dc 100644 --- a/src/main/java/com/example/moizaspringserver/domain/feed/presenstation/FeedController.java +++ b/src/main/java/com/example/moizaspringserver/domain/feed/presenstation/FeedController.java @@ -25,7 +25,7 @@ public void deleteFeed(@PathVariable("feed-id") Integer feedId) { @ResponseStatus(HttpStatus.CREATED) @PostMapping - public void createFeed(@Valid @RequestBody CreateFeedRequest request) { + public void createFeed(@RequestBody @Valid CreateFeedRequest request) { createFeedService.execute(request); } diff --git a/src/main/java/com/example/moizaspringserver/domain/feed/presenstation/dto/request/CreateFeedRequest.java b/src/main/java/com/example/moizaspringserver/domain/feed/presenstation/dto/request/CreateFeedRequest.java index 5de75ef0..dd97ec02 100644 --- a/src/main/java/com/example/moizaspringserver/domain/feed/presenstation/dto/request/CreateFeedRequest.java +++ b/src/main/java/com/example/moizaspringserver/domain/feed/presenstation/dto/request/CreateFeedRequest.java @@ -15,13 +15,13 @@ public class CreateFeedRequest { @NotBlank(message = "title은 Null, 공백, 띄어쓰기를 허용하지 않습니다.") private String title; - @NotNull(message = "content은 Null, 공백, 띄어쓰기를 허용하지 않습니다.") + @NotNull(message = "content는 Null, 공백, 띄어쓰기를 허용하지 않습니다.") private String content; @NotNull(message = "feed_type은 Null일 수 없습니다.") private FeedType feedType; - @NotNull(message = "category은 Null일 수 없습니다.") + @NotBlank(message = "category은 Null일 수 없습니다.") private String category; @NotNull(message = "image_urls은 Null일 수 없습니다.")