Skip to content
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

๐Ÿ”€ :: (#120) ๊ฒŒ์‹œ๊ธ€ ์ž‘์„ฑ API #123

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
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}")
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);
}

}
Original file line number Diff line number Diff line change
@@ -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<String> imageUrls;
}
Original file line number Diff line number Diff line change
@@ -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 ์ด๋ฏธ์ง€ ์ €์žฅ ๋กœ์ง
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ 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()
.antMatchers(HttpMethod.GET, "/following/*").authenticated()

// 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()
Expand Down