Skip to content

Commit

Permalink
feat: 알림(Notification) 엔티티 생성 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
pushedrumex authored Feb 22, 2024
1 parent 46ee5cb commit 57cd23b
Show file tree
Hide file tree
Showing 19 changed files with 111 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.verby.indp.domain.common.event;

import com.verby.indp.domain.notification.dto.Mail;

public record MailSendEvent(
Mail mail
) {
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import java.net.URI;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
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.RestController;

@Controller
@RestController
@RequiredArgsConstructor
@RequestMapping("/api")
public class ContactController {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.verby.indp.domain.contact.service;

import com.verby.indp.domain.common.event.mail.MailSendEvent;
import com.verby.indp.domain.common.notification.mail.Mail;
import com.verby.indp.domain.common.notification.mail.MailService;
import com.verby.indp.domain.common.event.MailSendEvent;
import com.verby.indp.domain.notification.dto.Mail;
import com.verby.indp.domain.contact.Contact;
import com.verby.indp.domain.contact.dto.request.RegisterContactRequest;
import com.verby.indp.domain.contact.repository.ContactRepository;
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/com/verby/indp/domain/notification/Notification.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.verby.indp.domain.notification;

import com.verby.indp.domain.common.entity.BaseTimeEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "notification")
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
public class Notification extends BaseTimeEntity {

@Id
@Getter
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "notification_id")
private long notificationId;

@Column(name = "subject")
private String subject;

@Column(name = "text")
private String text;

@Column(name = "receiver_email")
private String receiverEmail;

public Notification(String subject, String text, String receiverEmail) {
this.subject = subject;
this.text = text;
this.receiverEmail = receiverEmail;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.verby.indp.domain.common.notification.mail;
package com.verby.indp.domain.notification.dto;

public record Mail(
String to,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.verby.indp.domain.common.event.mail;
package com.verby.indp.domain.notification.service;

import static org.springframework.transaction.event.TransactionPhase.AFTER_COMMIT;

import com.verby.indp.domain.common.notification.mail.MailService;
import com.verby.indp.domain.common.event.MailSendEvent;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.event.TransactionalEventListener;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.verby.indp.domain.notification.service;

import com.verby.indp.domain.notification.dto.Mail;

public interface MailService {

void sendMail(Mail mail);

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import java.net.URI;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
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.RestController;

@Controller
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class RecommendationController {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.verby.indp.domain.recommendation.service;

import com.verby.indp.domain.common.event.mail.MailSendEvent;
import com.verby.indp.domain.common.notification.mail.Mail;
import com.verby.indp.domain.common.notification.mail.MailService;
import com.verby.indp.domain.common.event.MailSendEvent;
import com.verby.indp.domain.notification.dto.Mail;
import com.verby.indp.domain.recommendation.Recommendation;
import com.verby.indp.domain.recommendation.dto.request.RegisterRecommendationRequest;
import com.verby.indp.domain.recommendation.repository.RecommendationRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Controller
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class StoreController {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.verby.indp.global.mail;

import com.verby.indp.domain.common.notification.mail.Mail;
import com.verby.indp.domain.common.notification.mail.MailService;
import com.verby.indp.domain.notification.dto.Mail;
import com.verby.indp.domain.notification.service.MailService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.mail.MailAuthenticationException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import static org.mockito.Mockito.verify;

import com.verby.indp.acceptance.support.ContactSupporter;
import com.verby.indp.domain.common.notification.mail.Mail;
import com.verby.indp.domain.common.notification.mail.MailService;
import com.verby.indp.domain.notification.dto.Mail;
import com.verby.indp.domain.notification.service.MailService;
import com.verby.indp.domain.contact.Contact;
import com.verby.indp.domain.contact.dto.request.RegisterContactRequest;
import io.restassured.response.ExtractableResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import static org.mockito.Mockito.verify;

import com.verby.indp.acceptance.support.RecommendationSupporter;
import com.verby.indp.domain.common.notification.mail.Mail;
import com.verby.indp.domain.common.notification.mail.MailService;
import com.verby.indp.domain.notification.dto.Mail;
import com.verby.indp.domain.notification.service.MailService;
import com.verby.indp.domain.recommendation.dto.request.RegisterRecommendationRequest;
import com.verby.indp.domain.store.Store;
import com.verby.indp.domain.store.repository.StoreRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import com.verby.indp.domain.notification.dto.Mail;
import com.verby.indp.global.mail.SpringMailService;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import com.verby.indp.domain.common.event.mail.MailSendEvent;
import com.verby.indp.domain.common.event.MailSendEvent;
import com.verby.indp.domain.contact.Contact;
import com.verby.indp.domain.contact.dto.request.RegisterContactRequest;
import com.verby.indp.domain.contact.repository.ContactRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.verby.indp.domain.notification;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchException;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

class NotificationTest {

@Nested
@DisplayName("Notification 생성 시")
class NewNotification {

@Test
@DisplayName("성공: Notification 을 생성한다.")
void newNotification() {
// given
String to = "[email protected]";
String subject = "subject";
String text = "text";

// when
Exception exception = catchException(
() -> new Notification(to, subject, text));

// then
assertThat(exception).isNull();
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import com.verby.indp.domain.common.event.mail.MailSendEvent;
import com.verby.indp.domain.common.event.MailSendEvent;
import com.verby.indp.domain.recommendation.Recommendation;
import com.verby.indp.domain.recommendation.dto.request.RegisterRecommendationRequest;
import com.verby.indp.domain.recommendation.repository.RecommendationRepository;
Expand Down

0 comments on commit 57cd23b

Please sign in to comment.