-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
86 changed files
with
2,758 additions
and
74 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
29 changes: 29 additions & 0 deletions
29
backend/baton/src/docs/asciidoc/NotificationDeleteApi.adoc
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,29 @@ | ||
ifndef::snippets[] | ||
:snippets: ../../../build/generated-snippets | ||
endif::[] | ||
:doctype: book | ||
:icons: font | ||
:source-highlighter: highlight.js | ||
:toc: left | ||
:toclevels: 3 | ||
:sectlinks: | ||
:operation-http-request-title: Example Request | ||
:operation-http-response-title: Example Response | ||
|
||
==== *์๋ฆผ ์ญ์ API* | ||
|
||
===== *Http Request* | ||
|
||
include::{snippets}/../../build/generated-snippets/notification-delete-api-test/delete-notification-by-notification-id/http-request.adoc[] | ||
|
||
===== *Http Request Headers* | ||
|
||
include::{snippets}/../../build/generated-snippets/notification-delete-api-test/delete-notification-by-notification-id/request-headers.adoc[] | ||
|
||
===== *Http Request Path Parameters* | ||
|
||
include::{snippets}/../../build/generated-snippets/notification-delete-api-test/delete-notification-by-notification-id/path-parameters.adoc[] | ||
|
||
===== *Http Response* | ||
|
||
include::{snippets}/../../build/generated-snippets/notification-delete-api-test/delete-notification-by-notification-id/http-response.adoc[] |
29 changes: 29 additions & 0 deletions
29
backend/baton/src/docs/asciidoc/NotificationLoginReadApi.adoc
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,29 @@ | ||
ifndef::snippets[] | ||
:snippets: ../../../build/generated-snippets | ||
endif::[] | ||
:doctype: book | ||
:icons: font | ||
:source-highlighter: highlight.js | ||
:toc: left | ||
:toclevels: 3 | ||
:sectlinks: | ||
:operation-http-request-title: Example Request | ||
:operation-http-response-title: Example Response | ||
|
||
==== *๋ก๊ทธ์ธ๋ ์ฌ์ฉ์ ์๋ฆผ ๋ชฉ๋ก ์กฐํ API* | ||
|
||
===== *Http Request* | ||
|
||
include::{snippets}/../../build/generated-snippets/notification-read-with-logined-member-api-test/read-notifications-by-member-id/http-request.adoc[] | ||
|
||
===== *Http Request Headers* | ||
|
||
include::{snippets}/../../build/generated-snippets/notification-read-with-logined-member-api-test/read-notifications-by-member-id/request-headers.adoc[] | ||
|
||
===== *Http Response* | ||
|
||
include::{snippets}/../../build/generated-snippets/notification-read-with-logined-member-api-test/read-notifications-by-member-id/http-response.adoc[] | ||
|
||
===== *Http Response Fields* | ||
|
||
include::{snippets}/../../build/generated-snippets/notification-read-with-logined-member-api-test/read-notifications-by-member-id/response-fields.adoc[] |
29 changes: 29 additions & 0 deletions
29
backend/baton/src/docs/asciidoc/NotificationUpdateApi.adoc
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,29 @@ | ||
ifndef::snippets[] | ||
:snippets: ../../../build/generated-snippets | ||
endif::[] | ||
:doctype: book | ||
:icons: font | ||
:source-highlighter: highlight.js | ||
:toc: left | ||
:toclevels: 3 | ||
:sectlinks: | ||
:operation-http-request-title: Example Request | ||
:operation-http-response-title: Example Response | ||
|
||
==== *์๋ฆผ ์ฝ์ ์ฌ๋ถ ์ ๋ฐ์ดํธ API* | ||
|
||
===== *Http Request* | ||
|
||
include::{snippets}/../../build/generated-snippets/notification-update-api-test/update-notification-is-read-true-by-member/http-request.adoc[] | ||
|
||
===== *Http Request Headers* | ||
|
||
include::{snippets}/../../build/generated-snippets/notification-update-api-test/update-notification-is-read-true-by-member/request-headers.adoc[] | ||
|
||
===== *Http Request Path Parameters* | ||
|
||
include::{snippets}/../../build/generated-snippets/notification-update-api-test/update-notification-is-read-true-by-member/path-parameters.adoc[] | ||
|
||
===== *Http Response* | ||
|
||
include::{snippets}/../../build/generated-snippets/notification-update-api-test/update-notification-is-read-true-by-member/http-response.adoc[] |
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,25 @@ | ||
ifndef::snippets[] | ||
:snippets: ../../../build/generated-snippets | ||
endif::[] | ||
:doctype: book | ||
:icons: font | ||
:source-highlighter: highlight.js | ||
:toc: left | ||
:toclevels: 3 | ||
:sectlinks: | ||
:operation-http-request-title: Example Request | ||
:operation-http-response-title: Example Response | ||
|
||
==== *๋ก๊ทธ์์ API* | ||
|
||
===== *Http Request* | ||
|
||
include::{snippets}/../../build/generated-snippets/oauth-logout-api-test/logout/http-request.adoc[] | ||
|
||
===== *Http Request Headers* | ||
|
||
include::{snippets}/../../build/generated-snippets/oauth-logout-api-test/logout/request-headers.adoc[] | ||
|
||
===== *Http Response* | ||
|
||
include::{snippets}/../../build/generated-snippets/oauth-logout-api-test/logout/http-response.adoc[] |
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
22 changes: 22 additions & 0 deletions
22
backend/baton/src/main/java/touch/baton/domain/common/TruncatedBaseEntity.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,22 @@ | ||
package touch.baton.domain.common; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.temporal.ChronoUnit; | ||
|
||
public abstract class TruncatedBaseEntity extends BaseEntity { | ||
|
||
@Override | ||
public LocalDateTime getCreatedAt() { | ||
return super.getCreatedAt().truncatedTo(ChronoUnit.MINUTES); | ||
} | ||
|
||
@Override | ||
public LocalDateTime getDeletedAt() { | ||
return super.getDeletedAt().truncatedTo(ChronoUnit.MINUTES); | ||
} | ||
|
||
@Override | ||
public LocalDateTime getUpdatedAt() { | ||
return super.getUpdatedAt().truncatedTo(ChronoUnit.MINUTES); | ||
} | ||
} |
146 changes: 146 additions & 0 deletions
146
backend/baton/src/main/java/touch/baton/domain/notification/command/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,146 @@ | ||
package touch.baton.domain.notification.command; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embedded; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.ForeignKey; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.SQLDelete; | ||
import org.hibernate.annotations.Where; | ||
import touch.baton.domain.common.TruncatedBaseEntity; | ||
import touch.baton.domain.member.command.Member; | ||
import touch.baton.domain.notification.command.vo.IsRead; | ||
import touch.baton.domain.notification.command.vo.NotificationMessage; | ||
import touch.baton.domain.notification.command.vo.NotificationReferencedId; | ||
import touch.baton.domain.notification.command.vo.NotificationTitle; | ||
import touch.baton.domain.notification.command.vo.NotificationType; | ||
import touch.baton.domain.notification.exception.NotificationDomainException; | ||
|
||
import java.util.Objects; | ||
|
||
import static jakarta.persistence.EnumType.STRING; | ||
import static jakarta.persistence.FetchType.LAZY; | ||
import static jakarta.persistence.GenerationType.IDENTITY; | ||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = PROTECTED) | ||
@Where(clause = "deleted_at IS NULL") | ||
@SQLDelete(sql = "UPDATE notification SET deleted_at = now() WHERE id = ?") | ||
@Entity | ||
public class Notification extends TruncatedBaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = IDENTITY) | ||
private Long id; | ||
|
||
@Embedded | ||
private NotificationTitle notificationTitle; | ||
|
||
@Embedded | ||
private NotificationMessage notificationMessage; | ||
|
||
@Enumerated(STRING) | ||
@Column(nullable = false) | ||
private NotificationType notificationType; | ||
|
||
@Embedded | ||
private NotificationReferencedId notificationReferencedId; | ||
|
||
@Embedded | ||
private IsRead isRead; | ||
|
||
@ManyToOne(fetch = LAZY) | ||
@JoinColumn(name = "member_id", | ||
nullable = false, | ||
foreignKey = @ForeignKey(name = "fk_notification_to_member")) | ||
private Member member; | ||
|
||
@Builder | ||
private Notification(final NotificationTitle notificationTitle, | ||
final NotificationMessage notificationMessage, | ||
final NotificationType notificationType, | ||
final NotificationReferencedId notificationReferencedId, | ||
final IsRead isRead, | ||
final Member member | ||
) { | ||
this(null, notificationTitle, notificationMessage, notificationType, notificationReferencedId, isRead, member); | ||
} | ||
|
||
private Notification(final Long id, | ||
final NotificationTitle notificationTitle, | ||
final NotificationMessage notificationMessage, | ||
final NotificationType notificationType, | ||
final NotificationReferencedId notificationReferencedId, | ||
final IsRead isRead, | ||
final Member member | ||
) { | ||
validateNotNull(notificationTitle, notificationMessage, notificationType, notificationReferencedId, isRead, member); | ||
this.id = id; | ||
this.notificationTitle = notificationTitle; | ||
this.notificationMessage = notificationMessage; | ||
this.notificationType = notificationType; | ||
this.notificationReferencedId = notificationReferencedId; | ||
this.isRead = isRead; | ||
this.member = member; | ||
} | ||
|
||
private void validateNotNull(final NotificationTitle notificationTitle, | ||
final NotificationMessage notificationMessage, | ||
final NotificationType notificationType, | ||
final NotificationReferencedId notificationReferencedId, | ||
final IsRead isRead, | ||
final Member member | ||
) { | ||
if (notificationTitle == null) { | ||
throw new NotificationDomainException("NotificationTitle ์ notificationTitle ์ null ์ผ ์ ์์ต๋๋ค."); | ||
} | ||
if (notificationMessage == null) { | ||
throw new NotificationDomainException("NotificationMessage ์ notificationMessage ๋ null ์ผ ์ ์์ต๋๋ค."); | ||
} | ||
if (notificationType == null) { | ||
throw new NotificationDomainException("NotificationType ์ notificationType ๋ null ์ผ ์ ์์ต๋๋ค."); | ||
} | ||
if (notificationReferencedId == null) { | ||
throw new NotificationDomainException("NotificationReferencedId ์ notificationReferencedId ์ null ์ผ ์ ์์ต๋๋ค."); | ||
} | ||
if (isRead == null) { | ||
throw new NotificationDomainException("IsRead ์ isRead ๋ null ์ผ ์ ์์ต๋๋ค."); | ||
} | ||
if (member == null) { | ||
throw new NotificationDomainException("Member ์ member ๋ null ์ผ ์ ์์ต๋๋ค."); | ||
} | ||
} | ||
|
||
public void markAsRead(final Member currentMember) { | ||
if (!this.member.equals(currentMember)) { | ||
throw new NotificationDomainException("Notification ์ ์ฃผ์ธ(์ฌ์ฉ์)๊ฐ ์๋๋ฏ๋ก ์๋ฆผ์ ์ฝ์ ์ฌ๋ถ๋ฅผ ์์ ํ ์ ์์ต๋๋ค."); | ||
} | ||
|
||
this.isRead = IsRead.asRead(); | ||
} | ||
|
||
public boolean isNotOwner(final Member currentMember) { | ||
return !this.member.equals(currentMember); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
final Notification notification = (Notification) o; | ||
return Objects.equals(id, notification.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...ava/touch/baton/domain/notification/command/controller/NotificationCommandController.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,38 @@ | ||
package touch.baton.domain.notification.command.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import touch.baton.domain.notification.command.service.NotificationCommandService; | ||
import touch.baton.domain.member.command.Member; | ||
import touch.baton.domain.oauth.query.controller.resolver.AuthMemberPrincipal; | ||
|
||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/notifications") | ||
@RestController | ||
public class NotificationCommandController { | ||
|
||
private final NotificationCommandService notificationCommandService; | ||
|
||
@PatchMapping("/{notificationId}") | ||
public ResponseEntity<Void> updateNotificationIsReadTrueByNotificationId(@AuthMemberPrincipal final Member member, | ||
@PathVariable final Long notificationId | ||
) { | ||
notificationCommandService.updateNotificationIsReadTrueByMember(member, notificationId); | ||
|
||
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
@DeleteMapping("/{notificationId}") | ||
public ResponseEntity<Void> deleteNotificationByNotificationId(@AuthMemberPrincipal final Member member, | ||
@PathVariable final Long notificationId | ||
) { | ||
notificationCommandService.deleteNotificationByMember(member, notificationId); | ||
|
||
return ResponseEntity.noContent().build(); | ||
} | ||
} |
Oops, something went wrong.