Skip to content

Commit 4a770d6

Browse files
committed
Merge remote-tracking branch 'origin/dev' into refactor/257
2 parents 8761b03 + c257696 commit 4a770d6

File tree

21 files changed

+530
-281
lines changed

21 files changed

+530
-281
lines changed

src/main/java/com/back/domain/board/comment/service/CommentLikeService.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
import com.back.domain.board.comment.entity.CommentLike;
66
import com.back.domain.board.comment.repository.CommentLikeRepository;
77
import com.back.domain.board.comment.repository.CommentRepository;
8+
import com.back.domain.notification.event.community.CommentLikedEvent;
89
import com.back.domain.user.entity.User;
910
import com.back.domain.user.repository.UserRepository;
1011
import com.back.global.exception.CustomException;
1112
import com.back.global.exception.ErrorCode;
1213
import lombok.RequiredArgsConstructor;
14+
import org.springframework.context.ApplicationEventPublisher;
1315
import org.springframework.stereotype.Service;
1416
import org.springframework.transaction.annotation.Transactional;
1517

@@ -20,13 +22,15 @@ public class CommentLikeService {
2022
private final CommentRepository commentRepository;
2123
private final CommentLikeRepository commentLikeRepository;
2224
private final UserRepository userRepository;
25+
private final ApplicationEventPublisher eventPublisher;
2326

2427
/**
2528
* 댓글 좋아요 서비스
2629
* 1. User 조회
2730
* 2. Comment 조회
2831
* 3. 이미 존재하는 경우 예외 처리
2932
* 4. CommentLike 저장 및 likeCount 증가
33+
* 5. 알림 이벤트 발행 (자기 글이 아닐 경우)
3034
*/
3135
public CommentLikeResponse likeComment(Long commentId, Long userId) {
3236
// User 조회
@@ -47,6 +51,19 @@ public CommentLikeResponse likeComment(Long commentId, Long userId) {
4751

4852
// CommentLike 저장 및 응답 반환
4953
commentLikeRepository.save(new CommentLike(comment, user));
54+
55+
if (!comment.getUser().getId().equals(userId)) {
56+
eventPublisher.publishEvent(
57+
new CommentLikedEvent(
58+
userId, // 좋아요 누른 사람
59+
comment.getUser().getId(), // 댓글 작성자
60+
comment.getPost().getId(), // 게시글 ID
61+
comment.getId(),
62+
comment.getContent()
63+
)
64+
);
65+
}
66+
5067
return CommentLikeResponse.from(comment);
5168
}
5269

src/main/java/com/back/domain/board/post/service/PostLikeService.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
import com.back.domain.board.post.entity.PostLike;
66
import com.back.domain.board.post.repository.PostLikeRepository;
77
import com.back.domain.board.post.repository.PostRepository;
8+
import com.back.domain.notification.event.community.PostLikedEvent;
89
import com.back.domain.user.entity.User;
910
import com.back.domain.user.repository.UserRepository;
1011
import com.back.global.exception.CustomException;
1112
import com.back.global.exception.ErrorCode;
1213
import lombok.RequiredArgsConstructor;
14+
import org.springframework.context.ApplicationEventPublisher;
1315
import org.springframework.stereotype.Service;
1416
import org.springframework.transaction.annotation.Transactional;
1517

@@ -20,14 +22,16 @@ public class PostLikeService {
2022
private final PostRepository postRepository;
2123
private final PostLikeRepository postLikeRepository;
2224
private final UserRepository userRepository;
25+
private final ApplicationEventPublisher eventPublisher;
2326

2427
/**
2528
* 게시글 좋아요 서비스
2629
* 1. User 조회
2730
* 2. Post 조회
2831
* 3. 이미 존재하는 경우 예외 처리
2932
* 4. PostLike 저장 및 likeCount 증가
30-
* 5. PostLikeResponse 반환
33+
* 5. 알림 이벤트 발행 (자기 글이 아닐 경우)
34+
* 6. PostLikeResponse 반환
3135
*/
3236
public PostLikeResponse likePost(Long postId, Long userId) {
3337
// User 조회
@@ -48,6 +52,19 @@ public PostLikeResponse likePost(Long postId, Long userId) {
4852

4953
// PostLike 저장 및 응답 반환
5054
postLikeRepository.save(new PostLike(post, user));
55+
56+
// 알림 이벤트 발행 (자기 자신의 글이 아닐 때만)
57+
if (!post.getUser().getId().equals(userId)) {
58+
eventPublisher.publishEvent(
59+
new PostLikedEvent(
60+
userId, // 좋아요 누른 사람
61+
post.getUser().getId(), // 게시글 작성자
62+
post.getId(),
63+
post.getTitle()
64+
)
65+
);
66+
}
67+
5168
return PostLikeResponse.from(post);
5269
}
5370

src/main/java/com/back/domain/file/controller/FileController.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ public ResponseEntity<RsData<FileUploadResponseDto>> uploadFile(
2929
) {
3030
FileUploadResponseDto res = fileService.uploadFile(
3131
req.getMultipartFile(),
32-
req.getEntityType(),
33-
req.getEntityId(),
3432
user.getUserId()
3533
);
3634

@@ -39,44 +37,41 @@ public ResponseEntity<RsData<FileUploadResponseDto>> uploadFile(
3937
.body(RsData.success("파일 업로드 성공", res));
4038
}
4139

42-
@GetMapping(value = "/read")
40+
@GetMapping(value = "/read/{attachmentId}")
4341
public ResponseEntity<RsData<FileReadResponseDto>> getFile(
44-
@RequestParam("entityType") @NotBlank(message = "entityType은 필수입니다.") EntityType entityType,
45-
@RequestParam("entityId") @NotBlank(message = "entityId는 필수입니다.") Long entityId
42+
@PathVariable("attachmentId") Long attachmentId
4643
) {
47-
FileReadResponseDto res = fileService.getFile(entityType, entityId);
44+
FileReadResponseDto res = fileService.getFile(attachmentId);
4845

4946
return ResponseEntity
5047
.status(HttpStatus.OK)
5148
.body(RsData.success("파일 조회 성공", res));
5249
}
5350

54-
@PutMapping(value = "/update", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
55-
public ResponseEntity<RsData<Void>> updateFile(
51+
@PutMapping(value = "/update/{attachmentId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
52+
public ResponseEntity<RsData<FileUpdateResponseDto>> updateFile(
53+
@PathVariable("attachmentId") Long attachmentId,
5654
@ModelAttribute @Valid FileUpdateRequestDto req,
5755
@AuthenticationPrincipal CustomUserDetails user
5856
) {
59-
fileService.updateFile(
57+
FileUpdateResponseDto res = fileService.updateFile(
58+
attachmentId,
6059
req.getMultipartFile(),
61-
req.getEntityType(),
62-
req.getEntityId(),
6360
user.getUserId()
6461
);
6562

6663
return ResponseEntity
6764
.status(HttpStatus.OK)
68-
.body(RsData.success("파일 업데이트 성공"));
65+
.body(RsData.success("파일 업데이트 성공", res));
6966
}
7067

71-
@DeleteMapping(value = "/delete")
68+
@DeleteMapping(value = "/delete/{attachmentId}")
7269
public ResponseEntity<RsData<Void>> deleteFile(
73-
@RequestParam("entityType") @NotBlank(message = "entityType은 필수입니다.") EntityType entityType,
74-
@RequestParam("entityId") @NotBlank(message = "entityId는 필수입니다.") Long entityId,
70+
@PathVariable("attachmentId") Long attachmentId,
7571
@AuthenticationPrincipal CustomUserDetails user
7672
) {
7773
fileService.deleteFile(
78-
entityType,
79-
entityId,
74+
attachmentId,
8075
user.getUserId()
8176
);
8277

src/main/java/com/back/domain/file/dto/FileReadResponseDto.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
@Data
66
public class FileReadResponseDto {
7-
private String imageUrl;
7+
private String publicURL;
88

9-
public FileReadResponseDto(String imageUrl) {
10-
this.imageUrl = imageUrl;
9+
public FileReadResponseDto(String publicURL) {
10+
this.publicURL = publicURL;
1111
}
1212
}

src/main/java/com/back/domain/file/dto/FileUpdateRequestDto.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,4 @@
1010
public class FileUpdateRequestDto {
1111
@NotNull(message = "파일 입력은 필수입니다.")
1212
private MultipartFile multipartFile;
13-
14-
private EntityType entityType;
15-
16-
private Long entityId;
1713
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.back.domain.file.dto;
2+
3+
import lombok.Data;
4+
5+
@Data
6+
public class FileUpdateResponseDto {
7+
private String publicURL;
8+
9+
public FileUpdateResponseDto(String publicURL) {
10+
this.publicURL = publicURL;
11+
}
12+
}

src/main/java/com/back/domain/file/dto/FileUploadRequestDto.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,4 @@
1010
public class FileUploadRequestDto {
1111
@NotNull(message = "파일 입력은 필수입니다.")
1212
private MultipartFile multipartFile;
13-
14-
private EntityType entityType;
15-
16-
private Long entityId;
1713
}

src/main/java/com/back/domain/file/dto/FileUploadResponseDto.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
@Data
66
public class FileUploadResponseDto {
7-
private String imageUrl;
7+
private Long attachmentId;
8+
private String publicURL;
89

9-
public FileUploadResponseDto(String imageUrl) {
10-
this.imageUrl = imageUrl;
10+
public FileUploadResponseDto(Long attachmentId, String publicURL) {
11+
this.attachmentId = attachmentId;
12+
this.publicURL = publicURL;
1113
}
1214
}

src/main/java/com/back/domain/file/entity/FileAttachment.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class FileAttachment extends BaseEntity {
1818

1919
private String originalName;
2020

21-
private String filePath;
21+
private String publicURL;
2222

2323
private long fileSize;
2424

@@ -36,25 +36,21 @@ public FileAttachment(
3636
String storedName,
3737
MultipartFile multipartFile,
3838
User user,
39-
EntityType entityType,
40-
Long entityId,
41-
String filePath
39+
String publicURL
4240
) {
4341
this.storedName = storedName;
44-
originalName = multipartFile.getOriginalFilename();
45-
this.filePath = filePath;
46-
fileSize = multipartFile.getSize();
42+
this.originalName = multipartFile.getOriginalFilename();
43+
this.publicURL = publicURL;
44+
this.fileSize = multipartFile.getSize();
4745
this.contentType = multipartFile.getContentType();
4846
this.user = user;
49-
50-
attachmentMappings.add(new AttachmentMapping(this ,entityType, entityId));
5147
}
5248

53-
public void update(String storedName, MultipartFile multipartFile, String filePath) {
49+
public void update(String storedName, MultipartFile multipartFile, String publicURL) {
5450
this.storedName = storedName;
55-
originalName = multipartFile.getOriginalFilename();
56-
this.filePath = filePath;
57-
fileSize = multipartFile.getSize();
51+
this.originalName = multipartFile.getOriginalFilename();
52+
this.publicURL = publicURL;
53+
this.fileSize = multipartFile.getSize();
5854
this.contentType = multipartFile.getContentType();
5955
}
6056
}

0 commit comments

Comments
 (0)