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 bfad8f4d..3ad87bfd 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,5 +1,7 @@ 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.presenstation.dto.request.LocalFeedRequest; import com.example.moizaspringserver.domain.feed.service.DeleteFeedService; import com.example.moizaspringserver.domain.feed.service.UpdateLocalFeedService; @@ -15,6 +17,7 @@ public class FeedController { private final DeleteFeedService deleteFeedService; + private final CreateFeedService createFeedService; private final UpdateLocalFeedService updateLocalFeedService; @ResponseStatus(HttpStatus.NO_CONTENT) @@ -23,6 +26,12 @@ public void deleteFeed(@PathVariable("feed-id") Integer feedId) { deleteFeedService.execute(feedId); } + @ResponseStatus(HttpStatus.CREATED) + @PostMapping + public void createFeed(@RequestBody @Valid CreateFeedRequest request) { + createFeedService.execute(request); + } + @ResponseStatus(HttpStatus.NO_CONTENT) @PatchMapping("/temporaries/{feed-id}") public void updateLocalFeed(@RequestBody @Valid LocalFeedRequest request, @PathVariable("feed-id") Integer feedId) { 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..dd97ec02 --- /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; + + @NotBlank(message = "category은 Null일 수 없습니다.") + private String category; + + @NotNull(message = "image_urls은 Null일 수 없습니다.") + private List imageUrls; +} 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 이미지 저장 로직 + } +} 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 b01f7396..059c25e1 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() @@ -64,6 +64,8 @@ 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()) + .antMatchers(HttpMethod.PATCH, "/feeds/temporaries/{feed-id}").hasAnyAuthority(UserType.ROLE_STUDENT.name(), UserType.ROLE_GRADUATE.name()) // notice