-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from goormthon-Univ/develop
[develop] main merge
- Loading branch information
Showing
22 changed files
with
640 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/com/hatcher/haemo/comment/dto/CommentDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.hatcher.haemo.comment.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record CommentDto(Long commentIdx, | ||
String writer, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy/MM/dd HH:mm", timezone = "Asia/Seoul") | ||
LocalDateTime createdDate, | ||
String content) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/com/hatcher/haemo/notification/application/NotificationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.hatcher.haemo.notification.application; | ||
|
||
import com.hatcher.haemo.common.BaseResponse; | ||
import com.hatcher.haemo.common.exception.BaseException; | ||
import com.hatcher.haemo.notification.domain.Notification; | ||
import com.hatcher.haemo.notification.dto.NotificationDto; | ||
import com.hatcher.haemo.notification.dto.NotificationListResponse; | ||
import com.hatcher.haemo.notification.repository.NotificationRepository; | ||
import com.hatcher.haemo.user.application.UserService; | ||
import com.hatcher.haemo.user.domain.User; | ||
import com.hatcher.haemo.user.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
import static com.hatcher.haemo.common.constants.Constant.ACTIVE; | ||
import static com.hatcher.haemo.common.enums.BaseResponseStatus.*; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class NotificationService { | ||
|
||
private final UserRepository userRepository; | ||
private final UserService userService; | ||
private final NotificationRepository notificationRepository; | ||
|
||
// 알림 목록 조회 | ||
public BaseResponse<NotificationListResponse> getNotificationList() throws BaseException { | ||
try { | ||
User user = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); | ||
List<NotificationDto> notificationDtoList = notificationRepository.findByUserAndStatusEquals(user, ACTIVE).stream() | ||
.map(notification -> { | ||
long activeParticipantsCount = notification.getRecruitment().getParticipants().stream() | ||
.filter(participant -> participant.getStatus().equals(ACTIVE)).count(); | ||
return new NotificationDto(notification.getNotificationIdx(), notification.getRecruitment().getName(), notification.getRecruitment().getContactUrl(), | ||
notification.getRecruitment().getLeader().getNickname(), activeParticipantsCount+1, | ||
notification.getRecruitment().getParticipantLimit(), notification.getRecruitment().getDescription());}).toList(); | ||
return new BaseResponse<>(new NotificationListResponse(notificationDtoList)); | ||
} catch (BaseException e) { | ||
throw e; | ||
} catch (Exception e) { | ||
throw new BaseException(INTERNAL_SERVER_ERROR); | ||
} | ||
} | ||
|
||
// 알림 삭제 | ||
public BaseResponse<String> deleteNotification(Long notificationIdx) throws BaseException { | ||
try { | ||
User user = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); | ||
Notification notification = notificationRepository.findById(notificationIdx).orElseThrow(() -> new BaseException(INVALID_NOTIFICATION_IDX)); | ||
notificationRepository.delete(notification); | ||
notification.removeNotificationFromUser(user); | ||
return new BaseResponse<>(SUCCESS); | ||
} catch (BaseException e) { | ||
throw e; | ||
} catch (Exception e) { | ||
throw new BaseException(INTERNAL_SERVER_ERROR); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/hatcher/haemo/notification/domain/Notification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.hatcher.haemo.notification.domain; | ||
|
||
import com.hatcher.haemo.common.BaseEntity; | ||
import com.hatcher.haemo.recruitment.domain.Recruitment; | ||
import com.hatcher.haemo.user.domain.User; | ||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.DynamicInsert; | ||
|
||
@Entity | ||
@Getter | ||
@DynamicInsert | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Notification extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long notificationIdx; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(nullable = false, name = "user") | ||
private User user; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(nullable = false, name = "recruitment") | ||
private Recruitment recruitment; | ||
|
||
public void setUser(User user) { | ||
this.user = user; | ||
user.getNotifications().add(this); | ||
} | ||
|
||
public void removeNotificationFromUser(User user) { | ||
this.user = user; | ||
user.getNotifications().remove(this); | ||
} | ||
|
||
@Builder | ||
public Notification(User user, Recruitment recruitment) { | ||
this.user = user; | ||
this.recruitment = recruitment; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/hatcher/haemo/notification/dto/NotificationDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.hatcher.haemo.notification.dto; | ||
|
||
public record NotificationDto(Long notificationIdx, | ||
String name, | ||
String contactUrl, | ||
String leader, | ||
long participantNumber, | ||
Integer participantLimit, | ||
String description) {} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/hatcher/haemo/notification/dto/NotificationListResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.hatcher.haemo.notification.dto; | ||
|
||
import java.util.List; | ||
|
||
public record NotificationListResponse(List<NotificationDto> notificationList) {} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/hatcher/haemo/notification/presentation/NotificationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.hatcher.haemo.notification.presentation; | ||
|
||
import com.hatcher.haemo.common.BaseResponse; | ||
import com.hatcher.haemo.common.exception.BaseException; | ||
import com.hatcher.haemo.notification.application.NotificationService; | ||
import com.hatcher.haemo.notification.dto.NotificationListResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import static com.hatcher.haemo.common.constants.RequestURI.notification; | ||
|
||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping(notification) | ||
public class NotificationController { | ||
|
||
private final NotificationService notificationService; | ||
|
||
// 알림 목록 조회 | ||
@GetMapping("") | ||
public BaseResponse<NotificationListResponse> getNotificationList() { | ||
try { | ||
return notificationService.getNotificationList(); | ||
} catch (BaseException e) { | ||
return new BaseResponse<>(e.getStatus()); | ||
} | ||
} | ||
|
||
// 알림 삭제 | ||
@DeleteMapping("/{notificationIdx}") | ||
public BaseResponse<String> deleteNotification(@PathVariable Long notificationIdx) { | ||
try { | ||
return notificationService.deleteNotification(notificationIdx); | ||
} catch (BaseException e) { | ||
return new BaseResponse<>(e.getStatus()); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/hatcher/haemo/notification/repository/NotificationRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.hatcher.haemo.notification.repository; | ||
|
||
import com.hatcher.haemo.notification.domain.Notification; | ||
import com.hatcher.haemo.user.domain.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface NotificationRepository extends JpaRepository<Notification, Long> { | ||
List<Notification> findByUserAndStatusEquals(User user, String status); | ||
} |
Oops, something went wrong.