Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: v0.0.6 #64

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/com/verby/indp/domain/contact/Contact.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Contact extends BaseTimeEntity {
@Getter
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "contact_id")
private long contactId;
private Long contactId;

@Embedded
private ContactUserName userName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.verby.indp.domain.contact.event;

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

public record ContactMailEvent(
ContactMail request
) {

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.verby.indp.domain.contact.service;

import com.verby.indp.domain.common.event.MailSendEvent;
import com.verby.indp.domain.notification.dto.Mail;
import com.verby.indp.domain.contact.event.ContactMailEvent;
import com.verby.indp.domain.contact.Contact;
import com.verby.indp.domain.contact.dto.request.RegisterContactRequest;
import com.verby.indp.domain.contact.repository.ContactRepository;
import com.verby.indp.domain.notification.dto.ContactMail;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
Expand All @@ -27,13 +27,15 @@ public long registerContact(RegisterContactRequest request) {
Contact contact = new Contact(request.userName(), request.content(), request.phoneNumber());
Contact persistContact = contactRepository.save(contact);

Mail mail = new Mail(to, "[버비] 문의가 들어왔어요!",
"문의 내용: " + request.content() + "\n" +
"문의자 성함: " + request.userName() + "\n" +
"문의자 연락처: " + request.phoneNumber() + "\n");
applicationEventPublisher.publishEvent(new MailSendEvent(mail));
sendMail(request);

return persistContact.getContactId();
}

private void sendMail(RegisterContactRequest request) {
ContactMail contactMailRequest = ContactMail.of(to, request.content(),
request.userName(), request.phoneNumber());
applicationEventPublisher.publishEvent(new ContactMailEvent(contactMailRequest));
}

}
21 changes: 21 additions & 0 deletions src/main/java/com/verby/indp/domain/mail/dto/Mail.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.verby.indp.domain.mail.dto;

import com.verby.indp.domain.notification.MailNotification;

public record Mail(
long id,
String to,
String subject,
String text
) {

public static Mail from(MailNotification notification) {
return new Mail(
notification.getMailNotificationId(),
notification.getReceiverEmail(),
notification.getSubject(),
notification.getText()
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.verby.indp.domain.mail.service;

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

public interface MailService {

void sendMail(Mail mail);

}
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package com.verby.indp.domain.notification.service;
package com.verby.indp.domain.mail.service;

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

import com.verby.indp.domain.common.event.MailSendEvent;
import com.verby.indp.domain.notification.event.SendMailEvent;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.event.TransactionalEventListener;

@Service
@RequiredArgsConstructor
public class MailSendListener {
public class SendMailListener {

private final MailService mailService;

@Async
@TransactionalEventListener(phase = AFTER_COMMIT)
public void handleMailSendEvent(MailSendEvent event) {
public void handleSendMailEvent(SendMailEvent event) {
mailService.sendMail(event.mail());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
import lombok.NoArgsConstructor;

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

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

@Column(name = "subject")
private String subject;
Expand All @@ -30,7 +30,7 @@ public class Notification extends BaseTimeEntity {
@Column(name = "receiver_email")
private String receiverEmail;

public Notification(String subject, String text, String receiverEmail) {
public MailNotification(String subject, String text, String receiverEmail) {
this.subject = subject;
this.text = text;
this.receiverEmail = receiverEmail;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.verby.indp.domain.notification.dto;

public record ContactMail(
String to,
String content,
String userName,
String phoneNumber
) {

public static ContactMail of(
String to,
String content,
String userName,
String phoneNumber
) {
return new ContactMail(to, content, userName, phoneNumber);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.verby.indp.domain.notification.dto;

public record RecommendationMail(
String to,
String information,
String phoneNumber,
String storeName,
String storeAddress
) {
public static RecommendationMail of(
String to,
String information,
String phoneNumber,
String storeName,
String storeAddress
) {
return new RecommendationMail(to, information, phoneNumber, storeName, storeAddress);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.verby.indp.domain.notification.event;

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

public record SendMailEvent(Mail mail) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.verby.indp.domain.notification.repository;

import com.verby.indp.domain.notification.MailNotification;
import org.springframework.data.jpa.repository.JpaRepository;

public interface NotificationRepository extends JpaRepository<MailNotification, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.verby.indp.domain.notification.service;

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

import com.verby.indp.domain.contact.event.ContactMailEvent;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.event.TransactionalEventListener;

@Service
@RequiredArgsConstructor
public class ContactMailListener {

private final NotificationService notificationService;

@Async
@TransactionalEventListener(phase = AFTER_COMMIT)
public void handleContactMailEvent(ContactMailEvent event) {
notificationService.sendContactMail(event.request());
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.verby.indp.domain.notification.service;

import com.verby.indp.domain.notification.MailNotification;
import com.verby.indp.domain.mail.dto.Mail;
import com.verby.indp.domain.notification.dto.ContactMail;
import com.verby.indp.domain.notification.dto.RecommendationMail;
import com.verby.indp.domain.notification.event.SendMailEvent;
import com.verby.indp.domain.notification.repository.NotificationRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class NotificationService {

private final NotificationRepository notificationRepository;
private final ApplicationEventPublisher applicationEventPublisher;

@Transactional
public void sendContactMail(ContactMail request) {
MailNotification mailNotification = new MailNotification("[버비] 문의가 들어왔어요!",
"문의 내용: " + request.content() + "\n" +
"문의자 성함: " + request.userName() + "\n" +
"문의자 연락처: " + request.phoneNumber() + "\n", request.to());
MailNotification persistMailNotification = notificationRepository.save(mailNotification);
sendMail(persistMailNotification);
}

@Transactional
public void sendRecommendationMail(RecommendationMail request) {
MailNotification mailNotification = new MailNotification("[버비] 인디피 서비스에 음악이 추천되었어요!",
"추천 음악 정보: " + request.information() + "\n" +
"추천인 연락처: " + request.phoneNumber() + "\n" +
"매장 이름: " + request.storeName() + "\n" +
"매장 주소: " + request.storeAddress() + "\n", request.to());
MailNotification persistMailNotification = notificationRepository.save(mailNotification);
sendMail(persistMailNotification);
}

private void sendMail(MailNotification persistMailNotification) {
Mail mail = Mail.from(persistMailNotification);
applicationEventPublisher.publishEvent(new SendMailEvent(mail));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.verby.indp.domain.notification.service;

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

import com.verby.indp.domain.recommendation.event.RecommendationMailEvent;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.event.TransactionalEventListener;

@Service
@RequiredArgsConstructor
public class RecommendationMailListener {

private final NotificationService notificationService;

@Async
@TransactionalEventListener(phase = AFTER_COMMIT)
public void handleRecommendationMailEvent(RecommendationMailEvent event) {
notificationService.sendRecommendationMail(event.request());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Recommendation extends BaseTimeEntity {
@Getter
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "recommendation_id")
private long recommendationId;
private Long recommendationId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "store_id")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.verby.indp.domain.recommendation.event;

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

public record RecommendationMailEvent(
RecommendationMail request
) {
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.verby.indp.domain.recommendation.service;

import com.verby.indp.domain.common.event.MailSendEvent;
import com.verby.indp.domain.recommendation.event.RecommendationMailEvent;
import com.verby.indp.domain.common.exception.NotFoundException;
import com.verby.indp.domain.notification.dto.Mail;
import com.verby.indp.domain.notification.dto.RecommendationMail;
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 All @@ -29,17 +29,14 @@ public class RecommendationService {
@Transactional
public long registerRecommendation(RegisterRecommendationRequest request) {
Store store = getStore(request);

Recommendation recommendation = new Recommendation(store, request.information(),
request.phoneNumber());

Recommendation persistRecommendation = recommendationRepository.save(recommendation);

Mail mail = new Mail(to, "[버비] 인디피 서비스에 음악이 추천되었어요!",
"추천 음악 정보: " + request.information() + "\n" +
"추천인 연락처: " + request.phoneNumber() + "\n" +
"매장 이름: " + store.getName() + "\n" +
"매장 주소: " + store.getAddress() + "\n");
applicationEventPublisher.publishEvent(new MailSendEvent(mail));
RecommendationMail recommendationMail = RecommendationMail.of(to,
request.information(), request.phoneNumber(), store.getName(), store.getAddress());
applicationEventPublisher.publishEvent(new RecommendationMailEvent(recommendationMail));

return persistRecommendation.getRecommendationId();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/verby/indp/domain/song/SongForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class SongForm {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "song_form_id")
private long songFormId;
private Long songFormId;

@Embedded
private SongFormName name;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/verby/indp/domain/store/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Store extends BaseTimeEntity {
@Getter
@Column(name = "store_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long storeId;
private Long storeId;

@Embedded
private StoreName name;
Expand Down
Loading