Skip to content

Commit c300e64

Browse files
authored
Merge pull request #202 from Dugout-Developers/fix/#201
[FIX] 직관신청 취소시, 발생하는 오류 수정
2 parents b238499 + 0206fd3 commit c300e64

File tree

8 files changed

+32
-29
lines changed

8 files changed

+32
-29
lines changed

src/main/java/com/back/catchmate/domain/admin/controller/AdminController.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.back.catchmate.domain.admin.dto.AdminRequest;
44
import com.back.catchmate.domain.admin.dto.AdminRequest.AnswerInquiryRequest;
5-
import com.back.catchmate.domain.admin.dto.AdminResponse;
65
import com.back.catchmate.domain.admin.dto.AdminResponse.*;
76
import com.back.catchmate.domain.admin.service.AdminService;
87
import com.back.catchmate.global.dto.StateResponse;
@@ -107,7 +106,7 @@ public StateResponse answerInquiry(@JwtValidation Long userId,
107106
@GetMapping("/report")
108107
@Operation(summary = "신고 내역 조회", description = "신고 내역을 페이징하여 조회하는 API 입니다.")
109108
public PagedReportInfo getReportList(@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC)
110-
@Parameter(hidden = true) Pageable pageable) {
109+
@Parameter(hidden = true) Pageable pageable) {
111110
return adminService.getReportList(pageable);
112111
}
113112

@@ -126,16 +125,16 @@ public StateResponse processReport(@PathVariable Long reportId) {
126125
@PostMapping("/notice")
127126
@Operation(summary = "공지글 등록 API", description = "공지글을 등록하는 API 입니다.")
128127
public NoticeInfo createNotice(@JwtValidation Long userId,
129-
@Valid @RequestBody AdminRequest.CreateNoticeRequest request) {
128+
@Valid @RequestBody AdminRequest.CreateNoticeRequest request) {
130129
return adminService.createNotice(userId, request);
131130
}
132131

133132
@GetMapping("/notice/list")
134133
@Operation(summary = "공지사항 목록 조회 API", description = "공지사항 목록을 페이징하여 조회하는 API 입니다.")
135134
public PagedNoticeInfo getNoticeList(@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate startDate,
136-
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate endDate,
137-
@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC)
138-
@Parameter(hidden = true) Pageable pageable) {
135+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate endDate,
136+
@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC)
137+
@Parameter(hidden = true) Pageable pageable) {
139138
return adminService.getNoticeList(startDate, endDate, pageable);
140139
}
141140

@@ -148,8 +147,8 @@ public NoticeInfo getNotice(@PathVariable Long noticeId) {
148147
@PutMapping("/notice/{noticeId}")
149148
@Operation(summary = "공지사항 수정 API", description = "공지사항을 수정하는 API 입니다.")
150149
public NoticeInfo updateNotice(@JwtValidation Long userId,
151-
@PathVariable Long noticeId,
152-
@Valid @RequestBody AdminRequest.UpdateNoticeRequest request) {
150+
@PathVariable Long noticeId,
151+
@Valid @RequestBody AdminRequest.UpdateNoticeRequest request) {
153152
return adminService.updateNotice(userId, noticeId, request);
154153
}
155154

src/main/java/com/back/catchmate/domain/enroll/service/EnrollServiceImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public CreateEnrollInfo requestEnroll(CreateEnrollRequest request, Long boardId,
8686
fcmService.sendMessageByToken(boardWriter.getFcmToken(), title, body, boardId, AcceptStatus.PENDING, null);
8787

8888
// 데이터베이스에 저장
89-
notificationService.createNotification(title, body, enroll.getUser().getProfileImageUrl(), boardId, boardWriter.getId(), AcceptStatus.PENDING);
89+
notificationService.createNotification(title, body, enroll.getUser().getId(), boardId, boardWriter.getId(), AcceptStatus.PENDING);
9090
return enrollConverter.toCreateEnrollInfo(enroll);
9191
}
9292

@@ -106,7 +106,7 @@ public CancelEnrollInfo cancelEnroll(Long enrollId, Long userId) {
106106

107107
enroll.delete();
108108

109-
Notification notification = notificationRepository.findByBoardIdAndUserIdAndDeletedAtIsNull(enroll.getBoard().getId(), enroll.getBoard().getUser().getId())
109+
Notification notification = notificationRepository.findByBoardIdAndUserIdAndSenderIdAndDeletedAtIsNull(enroll.getBoard().getId(), enroll.getBoard().getUser().getId(), userId)
110110
.orElseThrow(() -> new BaseException(ErrorCode.NOTIFICATION_NOT_FOUND));
111111
notification.delete();
112112

@@ -206,7 +206,7 @@ public UpdateEnrollInfo acceptEnroll(Long enrollId, Long userId) throws IOExcept
206206
String body = ENROLLMENT_ACCEPT_BODY;
207207

208208
fcmService.sendMessageByToken(enrollApplicant.getFcmToken(), title, body, enroll.getBoard().getId(), AcceptStatus.ACCEPTED, board.getChatRoom().getId());
209-
notificationService.createNotification(title, body, boardWriter.getProfileImageUrl(), enroll.getBoard().getId(), enrollApplicant.getId(), AcceptStatus.ACCEPTED);
209+
notificationService.createNotification(title, body, boardWriter.getId(), enroll.getBoard().getId(), enrollApplicant.getId(), AcceptStatus.ACCEPTED);
210210

211211
enroll.respondToEnroll(AcceptStatus.REJECTED);
212212
enroll.delete();
@@ -251,7 +251,7 @@ public UpdateEnrollInfo rejectEnroll(Long enrollId, Long userId) throws IOExcept
251251
String body = ENROLLMENT_REJECT_BODY;
252252

253253
fcmService.sendMessageByToken(enrollApplicant.getFcmToken(), title, body, enroll.getBoard().getId(), AcceptStatus.REJECTED, null);
254-
notificationService.createNotification(title, body, boardWriter.getProfileImageUrl(), enroll.getBoard().getId(), enrollApplicant.getId(), AcceptStatus.REJECTED);
254+
notificationService.createNotification(title, body, boardWriter.getId(), enroll.getBoard().getId(), enrollApplicant.getId(), AcceptStatus.REJECTED);
255255

256256
enroll.respondToEnroll(AcceptStatus.REJECTED);
257257
enroll.delete();

src/main/java/com/back/catchmate/domain/notification/converter/NotificationConverter.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.back.catchmate.domain.board.entity.Board;
66
import com.back.catchmate.domain.enroll.entity.AcceptStatus;
77
import com.back.catchmate.domain.inquiry.converter.InquiryConverter;
8-
import com.back.catchmate.domain.inquiry.dto.InquiryResponse;
98
import com.back.catchmate.domain.inquiry.dto.InquiryResponse.InquiryInfo;
109
import com.back.catchmate.domain.inquiry.entity.Inquiry;
1110
import com.back.catchmate.domain.notification.dto.NotificationResponse.NotificationInfo;
@@ -25,25 +24,25 @@ public class NotificationConverter {
2524
private final BoardConverter boardConverter;
2625
private final InquiryConverter inquiryConverter;
2726

28-
public Notification toEntity(User user, Board board, String senderProfileImageUrl, String title, String body, AcceptStatus acceptStatus) {
27+
public Notification toEntityEnroll(User user, Board board, User sender, String title, String body, AcceptStatus acceptStatus) {
2928
return Notification.builder()
3029
.user(user)
3130
.board(board)
3231
.title(title)
3332
.body(body)
34-
.senderProfileImageUrl(senderProfileImageUrl)
33+
.sender(sender)
3534
.isRead(false)
3635
.acceptStatus(acceptStatus)
3736
.build();
3837
}
3938

40-
public Notification toEntity(User user, Inquiry inquiry, String senderProfileImageUrl, String title, String body) {
39+
public Notification toEntityInquiry(User user, Inquiry inquiry, String title, String body) {
4140
return Notification.builder()
4241
.user(user)
4342
.inquiry(inquiry)
4443
.title(title)
4544
.body(body)
46-
.senderProfileImageUrl(senderProfileImageUrl)
45+
.sender(null)
4746
.isRead(false)
4847
.build();
4948
}
@@ -77,7 +76,7 @@ public NotificationInfo toNotificationInfo(Notification notification, Board boar
7776
.notificationId(notification.getId())
7877
.title(notification.getTitle())
7978
.body(notification.getBody())
80-
.senderProfileImageUrl(notification.getSenderProfileImageUrl())
79+
.senderProfileImageUrl(notification.getSender().getProfileImageUrl())
8180
.isRead(notification.isRead())
8281
.acceptStatus(notification.getAcceptStatus())
8382
.boardInfo(boardInfo)
@@ -92,7 +91,7 @@ public NotificationInfo toNotificationInfo(Notification notification, Inquiry in
9291
.notificationId(notification.getId())
9392
.title(notification.getTitle())
9493
.body(notification.getBody())
95-
.senderProfileImageUrl(notification.getSenderProfileImageUrl())
94+
.senderProfileImageUrl(notification.getSender().getProfileImageUrl())
9695
.isRead(notification.isRead())
9796
.acceptStatus(notification.getAcceptStatus())
9897
.inquiryInfo(inquiryInfo)

src/main/java/com/back/catchmate/domain/notification/entity/Notification.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public class Notification extends BaseTimeEntity {
3838
@JoinColumn(name = "user_id", nullable = false)
3939
private User user;
4040

41+
@ManyToOne(fetch = FetchType.LAZY)
42+
@JoinColumn(name = "sender_id", nullable = false)
43+
private User sender;
44+
4145
@ManyToOne(fetch = FetchType.LAZY)
4246
@JoinColumn(name = "board_id")
4347
private Board board;
@@ -46,8 +50,6 @@ public class Notification extends BaseTimeEntity {
4650
@JoinColumn(name = "inquiry_id")
4751
private Inquiry inquiry;
4852

49-
private String senderProfileImageUrl;
50-
5153
@Column(nullable = false)
5254
private String title;
5355

src/main/java/com/back/catchmate/domain/notification/repository/NotificationRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public interface NotificationRepository extends JpaRepository<Notification, Long
1313

1414
Optional<Notification> findByIdAndUserIdAndDeletedAtIsNull(Long notificationId, Long userId);
1515

16-
Optional<Notification> findByBoardIdAndUserIdAndDeletedAtIsNull(Long boardId, Long userId);
16+
Optional<Notification> findByBoardIdAndUserIdAndSenderIdAndDeletedAtIsNull(Long boardId, Long userId, Long senderId);
1717

1818
Optional<Notification> findByUserIdAndBoardIdAndAcceptStatusAndDeletedAtIsNull(Long userId, Long boardId, AcceptStatus acceptStatus);
1919

src/main/java/com/back/catchmate/domain/notification/service/NotificationService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import org.springframework.data.domain.Pageable;
88

99
public interface NotificationService {
10-
void createNotification(String title, String body, String senderProfileImageUrl, Long boardId, Long userId, AcceptStatus acceptStatus);
10+
void createNotification(String title, String body, Long senderId, Long boardId, Long receiverId, AcceptStatus acceptStatus);
1111

12-
void createNotification(String title, String body, String senderProfileImageUrl, Long inquiryId, Long userId);
12+
void createNotification(String title, String body, Long senderId, Long inquiryId, Long receiverId);
1313

1414
PagedNotificationInfo getNotificationList(Long userId, Pageable pageable);
1515

src/main/java/com/back/catchmate/domain/notification/service/NotificationServiceImpl.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,30 @@ public class NotificationServiceImpl implements NotificationService {
3232

3333
@Override
3434
@Transactional
35-
public void createNotification(String title, String body, String senderProfileImageUrl, Long boardId, Long userId, AcceptStatus acceptStatus) {
35+
public void createNotification(String title, String body, Long senderId, Long boardId, Long userId, AcceptStatus acceptStatus) {
3636
User user = userRepository.findById(userId)
3737
.orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_FOUND));
3838

39+
User sender = userRepository.findByIdAndDeletedAtIsNull(senderId)
40+
.orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_FOUND));
41+
3942
Board board = boardRepository.findByIdAndDeletedAtIsNullAndIsCompleted(boardId)
4043
.orElseThrow(() -> new BaseException(ErrorCode.BOARD_NOT_FOUND));
4144

42-
Notification notification = notificationConverter.toEntity(user, board, senderProfileImageUrl, title, body, acceptStatus);
45+
Notification notification = notificationConverter.toEntityEnroll(user, board, sender, title, body, acceptStatus);
4346
notificationRepository.save(notification);
4447
}
4548

4649
@Override
4750
@Transactional
48-
public void createNotification(String title, String body, String senderProfileImageUrl, Long inquiryId, Long userId) {
51+
public void createNotification(String title, String body, Long senderId, Long inquiryId, Long userId) {
4952
User user = userRepository.findByIdAndDeletedAtIsNull(userId)
5053
.orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_FOUND));
5154

5255
Inquiry inquiry = inquiryRepository.findByIdAndDeletedAtIsNull(inquiryId)
5356
.orElseThrow(() -> new BaseException(ErrorCode.BOARD_NOT_FOUND));
5457

55-
Notification notification = notificationConverter.toEntity(user, inquiry, senderProfileImageUrl, title, body);
58+
Notification notification = notificationConverter.toEntityInquiry(user, inquiry, title, body);
5659
notificationRepository.save(notification);
5760
}
5861

src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
spring:
22
profiles:
3-
active: prod
3+
active: local

0 commit comments

Comments
 (0)