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

Feat/#173 #174

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
13 changes: 9 additions & 4 deletions src/main/java/org/winey/server/controller/FeedController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@
import org.winey.server.common.dto.ApiResponse;
import org.winey.server.config.resolver.UserId;
import org.winey.server.controller.request.CreateFeedRequestDto;
import org.winey.server.controller.response.feed.CreateFeedResponseDto;
import org.winey.server.controller.response.feed.DeleteFeedResponseDto;
import org.winey.server.controller.response.feed.GetAllFeedResponseDto;
import org.winey.server.controller.response.feed.GetFeedDetailResponseDto;
import org.winey.server.controller.response.feed.*;
import org.winey.server.exception.Error;
import org.winey.server.exception.Success;
import org.winey.server.external.client.aws.S3Service;
import org.winey.server.service.FeedService;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import java.io.IOException;

@RestController
@RequiredArgsConstructor
Expand Down Expand Up @@ -83,4 +81,11 @@ public ApiResponse<GetAllFeedResponseDto> getMyFeed(@RequestParam int page, @Use
public ApiResponse<GetFeedDetailResponseDto> getFeedDetail(@UserId Long userId, @PathVariable Long feedId) {
return ApiResponse.success(Success.GET_DETAIL_SUCCESS, feedService.getFeedDetail(feedId, userId));
}

@PostMapping(value = "/report/{feedId}")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "ν”Όλ“œ μ‹ κ³  API", description = "ν”Όλ“œλ₯Ό μ‹ κ³ ν•©λ‹ˆλ‹€.")
public ApiResponse<ReportFeedResponseDto> reportFeed(@UserId Long userId, @PathVariable Long feedId) throws IOException {
return ApiResponse.success(Success.REPORT_FEED_SUCCESS, feedService.reportFeed(feedId, userId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.winey.server.controller.response.feed;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class ReportFeedResponseDto {
private Long reporterId;
private Long reportFeedId;

private String reportMessage;

public static ReportFeedResponseDto of(Long reporterId, Long reportFeedId, String reportMessage){
return new ReportFeedResponseDto(reporterId, reportFeedId, reportMessage);
}

}
1 change: 1 addition & 0 deletions src/main/java/org/winey/server/exception/Success.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public enum Success {
UPDATE_NICKNAME_SUCCESS(HttpStatus.OK, "λ‹‰λ„€μž„ λ³€κ²½ 성곡"),
CHECK_NICKNAME_DUPLICATE_SUCCESS(HttpStatus.OK, "λ‹‰λ„€μž„ 쀑볡 확인 성곡"),
CHECK_NEW_NOTIFICATION_SUCCESS(HttpStatus.OK, "μƒˆ μ•Œλ¦Ό μ—¬λΆ€ 쑰회 성곡"),
REPORT_FEED_SUCCESS(HttpStatus.OK, "ν”Όλ“œ μ‹ κ³  μ™„λ£Œ"),

/**
* 201 CREATED
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/org/winey/server/service/FeedService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.winey.server.common.dto.ApiResponse;
import org.winey.server.controller.request.CreateFeedRequestDto;
import org.winey.server.controller.response.PageResponseDto;
import org.winey.server.controller.response.comment.CommentResponseDto;
Expand All @@ -20,7 +21,9 @@
import org.winey.server.exception.model.NotFoundException;
import org.winey.server.exception.model.UnauthorizedException;
import org.winey.server.infrastructure.*;
import org.winey.server.slack.SlackApi;

import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
Expand All @@ -36,8 +39,8 @@ public class FeedService {
private final GoalRepository goalRepository;
private final FeedLikeRepository feedLikeRepository;
private final CommentRepository commentRepository;

private final NotiRepository notiRepository;
private final SlackApi slackApi;

@Transactional
public CreateFeedResponseDto createFeed(CreateFeedRequestDto request, Long userId, String imageUrl) {
Expand Down Expand Up @@ -292,4 +295,12 @@ private String getTimeAgo(LocalDateTime createdAt) {
}
return "μ§€κΈˆ";
}
@Transactional
public ReportFeedResponseDto reportFeed(Long userId, Long feedId) throws IOException {
Feed reportFeed = feedRepository.findByFeedId(feedId)
.orElseThrow(()-> new NotFoundException(Error.NOT_FOUND_FEED_EXCEPTION, Error.NOT_FOUND_FEED_EXCEPTION.getMessage()));
User reporter = userRepository.findByUserId(userId)
.orElseThrow(()-> new NotFoundException(Error.NOT_FOUND_USER_EXCEPTION, Error.NOT_FOUND_USER_EXCEPTION.getMessage()));
return ReportFeedResponseDto.of(userId,feedId,slackApi.sendReport(reporter, reportFeed));
}
}
30 changes: 30 additions & 0 deletions src/main/java/org/winey/server/slack/SlackApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.winey.server.domain.feed.Feed;
import org.winey.server.domain.user.User;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
Expand Down Expand Up @@ -69,6 +71,15 @@ private String generateErrorPointMessage(HttpServletRequest request) {

return sb.toString();
}
private String generateReportMessage(Feed feed){
sb.setLength(0);
sb.append("*[πŸ”₯ feed id]*" + NEW_LINE + feed.getFeedId() + DOUBLE_NEW_LINE);
sb.append("*[πŸ“© feed content]*" + NEW_LINE + feed.getFeedTitle() + DOUBLE_NEW_LINE);
sb.append("*[🚨 feed image]*" + NEW_LINE + feed.getFeedImage() + DOUBLE_NEW_LINE);
return sb.toString();
}



private String readRootStackTrace(Exception error) {
return error.getStackTrace()[0].toString();
Expand All @@ -84,4 +95,23 @@ private LayoutBlock getSection(String message) {
return Blocks.section(s ->
s.text(BlockCompositions.markdownText(message)));
}
public String sendReport(User user, Feed feed) throws IOException{
List<LayoutBlock> layoutBlocks = generateReportBlock(feed);
Slack.getInstance().send(webhookUrl, WebhookPayloads
.payload(p ->
p.username("μ‹ κ³ κ°€ μ ‘μˆ˜λ˜μ—ˆμŠ΅λ‹ˆλ‹€. 🚨")
.iconUrl("https://yt3.googleusercontent.com/ytc/AGIKgqMVUzRrhoo1gDQcqvPo0PxaJz7e0gqDXT0D78R5VQ=s900-c-k-c0x00ffffff-no-rj")
.blocks(layoutBlocks)));
return "μ‹ κ³ κ°€ μ •μƒμ μœΌλ‘œ μ ‘μˆ˜λ˜μ—ˆμŠ΅λ‹ˆλ‹€.";
}

private List<LayoutBlock> generateReportBlock(Feed feed) {
return Blocks.asBlocks(
getHeader("μ‹ κ³ κ°€ λ“€μ–΄μ˜¨ κ²Œμ‹œλ¬Όμ΄ μžˆμŠ΅λ‹ˆλ‹€.🚨"+NEW_LINE+"μ •μ‹ μ μœΌλ‘œ ν•΄λ‘œμš΄ 사진일 수 μžˆμœΌλ‹ˆ μ£Όμ˜ν•˜μ„Έμš”."),
Blocks.divider(),
getSection(generateReportMessage(feed)),
Blocks.divider(),
getSection("<https://github.com/team-winey/Winey-Server/issues|이슈 μƒμ„±ν•˜λŸ¬ κ°€κΈ°>")
);
}
}