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

v1.2.0 #156

Merged
merged 3 commits into from
Apr 3, 2024
Merged
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
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ services:
caddy.route_3.reverse_proxy: "{{ upstreams 4000 }}"
caddy.route_4: /meeting/v2/*
caddy.route_4.reverse_proxy: "{{ upstreams 4000 }}"
caddy.route_5: /post/v2/*
caddy.route_5: /post/v2
caddy.route_5.reverse_proxy: "{{ upstreams 4000 }}"
caddy.route_6: /comment/v2
caddy.route_6.reverse_proxy: "{{ upstreams 4000 }}"

nestjs:
build:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.sopt.makers.crew.main.comment.v2;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.security.Principal;
import lombok.RequiredArgsConstructor;
import org.sopt.makers.crew.main.comment.v2.dto.request.CommentV2CreateCommentBodyDto;
import org.sopt.makers.crew.main.comment.v2.dto.response.CommentV2CreateCommentResponseDto;
import org.sopt.makers.crew.main.comment.v2.service.CommentV2Service;
import org.sopt.makers.crew.main.common.util.UserUtil;
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.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/comment/v2")
@RequiredArgsConstructor
@Tag(name = "λŒ“κΈ€/λŒ€λŒ“κΈ€")
public class CommentV2Controller {

private final CommentV2Service commentV2Service;

@Operation(summary = "λͺ¨μž„ κ²Œμ‹œκΈ€ λŒ“κΈ€ μž‘μ„±")
@PostMapping()
@ResponseStatus(HttpStatus.CREATED)
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "성곡"),
})
public ResponseEntity<CommentV2CreateCommentResponseDto> createComment(
@Valid @RequestBody CommentV2CreateCommentBodyDto requestBody, Principal principal) {
Integer userId = UserUtil.getUserId(principal);
return ResponseEntity.ok(commentV2Service.createComment(requestBody, userId));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.sopt.makers.crew.main.comment.v2.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
@Schema(description = "λŒ“κΈ€ 생성 request body dto")
public class CommentV2CreateCommentBodyDto {

@Schema(example = "1", required = true, description = "κ²Œμ‹œκΈ€ ID")
@NotNull
private Integer postId;

@Schema(example = "μ•Œκ³ λ³΄λ©΄ μ“Έλ°μžˆλŠ” 개발 ν”„λ‘œμ„ΈμŠ€", required = true, description = "λŒ“κΈ€ λ‚΄μš©")
@NotEmpty
private String contents;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.sopt.makers.crew.main.comment.v2.dto.response;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor(staticName = "of")
public class CommentV2CreateCommentResponseDto {

/**
* μƒμ„±λœ λŒ“κΈ€ id
*/
private Integer commentId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.sopt.makers.crew.main.comment.v2.service;

import org.sopt.makers.crew.main.comment.v2.dto.request.CommentV2CreateCommentBodyDto;
import org.sopt.makers.crew.main.comment.v2.dto.response.CommentV2CreateCommentResponseDto;

public interface CommentV2Service {

CommentV2CreateCommentResponseDto createComment(CommentV2CreateCommentBodyDto requestBody,
Integer userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.sopt.makers.crew.main.comment.v2.service;

import static org.sopt.makers.crew.main.internal.notification.PushNotificationEnums.NEW_COMMENT_PUSH_NOTIFICATION_TITLE;
import static org.sopt.makers.crew.main.internal.notification.PushNotificationEnums.PUSH_NOTIFICATION_CATEGORY;

import lombok.RequiredArgsConstructor;
import org.sopt.makers.crew.main.comment.v2.dto.request.CommentV2CreateCommentBodyDto;
import org.sopt.makers.crew.main.comment.v2.dto.response.CommentV2CreateCommentResponseDto;
import org.sopt.makers.crew.main.entity.comment.Comment;
import org.sopt.makers.crew.main.entity.comment.CommentRepository;
import org.sopt.makers.crew.main.entity.post.Post;
import org.sopt.makers.crew.main.entity.post.PostRepository;
import org.sopt.makers.crew.main.entity.user.User;
import org.sopt.makers.crew.main.entity.user.UserRepository;
import org.sopt.makers.crew.main.internal.notification.PushNotificationService;
import org.sopt.makers.crew.main.internal.notification.dto.PushNotificationRequestDto;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class CommentV2ServiceImpl implements CommentV2Service {

private final PostRepository postRepository;
private final UserRepository userRepository;
private final CommentRepository commentRepository;
private final PushNotificationService pushNotificationService;

@Value("${push-notification.web-url}")
private String pushWebUrl;

/**
* λͺ¨μž„ κ²Œμ‹œκΈ€ λŒ“κΈ€ μž‘μ„±
*
* @throws 400 μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” κ²Œμ‹œκΈ€μΌ λ–„
* @apiNote λͺ¨μž„에 μ†ν•œ μœ μ €λ§Œ μž‘μ„± κ°€λŠ₯
*/
@Override
@Transactional

public CommentV2CreateCommentResponseDto createComment(CommentV2CreateCommentBodyDto requestBody,
Integer userId) {
Post post = postRepository.findByIdOrThrow(requestBody.getPostId());
User user = userRepository.findByIdOrThrow(userId);

Comment comment = Comment.builder()
.contents(requestBody.getContents())
.user(user)
.post(post)
.build();

Comment savedComment = commentRepository.save(comment);

User PostWriter = post.getUser();
String[] userIds = {String.valueOf(PostWriter.getOrgId())};

String pushNotificationContent = String.format("[%s의 λŒ“κΈ€] : \"%s\"",
user.getName(), requestBody.getContents());
String pushNotificationWeblink = pushWebUrl + "/post?id=" + post.getId();

PushNotificationRequestDto pushRequestDto = PushNotificationRequestDto.of(userIds,
NEW_COMMENT_PUSH_NOTIFICATION_TITLE.getValue(),
pushNotificationContent,
PUSH_NOTIFICATION_CATEGORY.getValue(), pushNotificationWeblink);

pushNotificationService.sendPushNotification(pushRequestDto);

return CommentV2CreateCommentResponseDto.of(savedComment.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ public enum ErrorStatus {
* 204 NO_CONTENT
*/
NO_CONTENT_EXCEPTION("μ°Έμ—¬ν•œ λͺ¨μž„이 μ—†μŠ΅λ‹ˆλ‹€."),

/**
* 400 BAD_REQUEST
*/
VALIDATION_EXCEPTION("CR-001"), // errorCodeλŠ” μ˜ˆμ‹œ, μΆ”ν›„ λ³€κ²½ μ˜ˆμ • -> 잘λͺ»λœ μš”μ²­μž…λ‹ˆλ‹€.
VALIDATION_REQUEST_MISSING_EXCEPTION("μš”μ²­κ°’μ΄ μž…λ ₯λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€."),
NOT_FOUND_MEETING("λͺ¨μž„이 μ—†μŠ΅λ‹ˆλ‹€."),
NOT_FOUND_POST("μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” κ²Œμ‹œκΈ€μž…λ‹ˆλ‹€."),

/**
* 401 UNAUTHORIZED
Expand Down
Loading
Loading