-
Notifications
You must be signed in to change notification settings - Fork 2
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 #240 from haedoang/feature/contact
[feature/contact] 알림 기능 추가
- Loading branch information
Showing
43 changed files
with
558 additions
and
75 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
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 |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
import static com.koliving.api.location.domain.LocationType.GU; | ||
|
||
import com.google.common.collect.Sets; | ||
import com.koliving.api.email.IEmailService; | ||
import com.koliving.api.email.MailType; | ||
import com.koliving.api.file.domain.ImageFile; | ||
import com.koliving.api.file.infra.ImageFileRepository; | ||
import com.koliving.api.i18n.Language; | ||
|
@@ -21,9 +23,11 @@ | |
import com.koliving.api.room.infra.FurnishingRepository; | ||
import com.koliving.api.room.infra.LikeRepository; | ||
import com.koliving.api.room.infra.RoomRepository; | ||
import com.koliving.api.user.User; | ||
import com.koliving.api.user.UserRepository; | ||
import com.koliving.api.user.UserRole; | ||
import com.koliving.api.user.domain.Notification; | ||
import com.koliving.api.user.domain.User; | ||
import com.koliving.api.user.infra.NotificationRepository; | ||
import com.koliving.api.user.infra.UserRepository; | ||
import com.koliving.api.user.domain.UserRole; | ||
import jakarta.annotation.PostConstruct; | ||
import java.time.LocalDate; | ||
import java.util.Arrays; | ||
|
@@ -38,9 +42,6 @@ | |
import org.springframework.context.annotation.Profile; | ||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@EnableJpaAuditing | ||
@SpringBootApplication | ||
|
@@ -69,25 +70,33 @@ CommandLineRunner commandLineRunner( | |
ImageFileRepository imageFileRepository, | ||
LikeRepository likeRepository, | ||
UserRepository userRepository, | ||
PasswordEncoder encoder | ||
PasswordEncoder encoder, | ||
NotificationRepository notificationRepository | ||
) { | ||
return args -> { | ||
initImageFiles(imageFileRepository); | ||
initFurnishings(furnishingRepository); | ||
initLocations(locationRepository); | ||
initLanguages(languageRepository); | ||
User user = initUser(userRepository, encoder); | ||
User user = initUser(userRepository, encoder, notificationRepository); | ||
initRooms(roomRepository, locationRepository, furnishingRepository, imageFileRepository, likeRepository, user); | ||
}; | ||
} | ||
|
||
private User initUser(UserRepository userRepository, PasswordEncoder encoder) { | ||
private User initUser(UserRepository userRepository, PasswordEncoder encoder, NotificationRepository notificationRepository) { | ||
final User user = User.valueOf("[email protected]", encoder.encode("test1234!@"), UserRole.USER); | ||
final User user2 = User.valueOf("[email protected]", encoder.encode("test1234!@"), UserRole.USER); | ||
final User manager = User.valueOf("[email protected]", encoder.encode("test1234!@"), UserRole.ADMIN); | ||
|
||
userRepository.saveAll(List.of(user2, manager)); | ||
return userRepository.save(user); | ||
userRepository.saveAll(List.of(user, manager)); | ||
userRepository.save(user2); | ||
|
||
// 알림 | ||
notificationRepository.save(Notification.of(user, user2)); | ||
notificationRepository.save(Notification.of(manager, user)); | ||
notificationRepository.save(Notification.of(user2, user)); | ||
|
||
return user2; | ||
} | ||
|
||
private void initImageFiles(ImageFileRepository imageFileRepository) { | ||
|
@@ -171,8 +180,12 @@ private void initLanguages(LanguageRepository languageRepository) { | |
Language.valueOf("ko", "email_duplication", "이미 존재하는 이메일입니다 : {0}"), | ||
Language.valueOf("en", "auth_email_subject", "Confirm your email"), | ||
Language.valueOf("ko", "auth_email_subject", "이메일 인증을 완료하세요"), | ||
Language.valueOf("en", "contact_email_subject", "Someone is interested in your posts."), | ||
Language.valueOf("ko", "contact_email_subject", "누군가 당신의 게시글에 관심이 있어요."), | ||
Language.valueOf("en", "auth_email_subtitle", "Click the link below to proceed with authentication"), | ||
Language.valueOf("ko", "auth_email_subtitle", "아래 링크를 클릭하셔서 인증을 진행하세요"), | ||
Language.valueOf("en", "contact_email_subtitle", "Possible roommate has shown interest in your room!"), | ||
Language.valueOf("ko", "contact_email_subtitle", "룸메이트가 당신의 방에 관심을 보였습니다!"), | ||
Language.valueOf("en", "auth_email_link_guidance", | ||
"If the button doesn't work, copy and paste the link below into url"), | ||
Language.valueOf("ko", "auth_email_link_guidance", "버튼이 동작하지 않다면, 아래 링크를 url에 붙여 인증을 시도하세요"), | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.koliving.api.base; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import org.springframework.core.annotation.AliasFor; | ||
|
||
/** | ||
* author : haedoang date : 2023/11/05 description : | ||
*/ | ||
@Retention(RetentionPolicy.SOURCE) | ||
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD}) | ||
public @interface KLDescription { | ||
String value() default ""; | ||
|
||
String example() default ""; | ||
} |
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
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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
package com.koliving.api.email; | ||
|
||
import com.koliving.api.user.domain.User; | ||
|
||
public interface IEmailService { | ||
|
||
void send(MailType type, String to, String url); | ||
|
||
void sendRoomContact(String to, String contactInfo, String message, User sender, String link); | ||
} |
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
4 changes: 2 additions & 2 deletions
4
src/main/java/com/koliving/api/my/application/dto/UserProfileUpdateRequest.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,30 +2,37 @@ | |
|
||
import static com.koliving.api.base.ServiceError.FORBIDDEN; | ||
import static com.koliving.api.base.ServiceError.RECORD_NOT_EXIST; | ||
import static com.koliving.api.base.ServiceError.UNAUTHORIZED; | ||
|
||
import com.google.common.collect.Sets; | ||
import com.koliving.api.base.ServiceError; | ||
import com.koliving.api.base.exception.KolivingServiceException; | ||
import com.koliving.api.email.IEmailService; | ||
import com.koliving.api.file.domain.ImageFile; | ||
import com.koliving.api.file.infra.ImageFileRepository; | ||
import com.koliving.api.location.domain.Location; | ||
import com.koliving.api.location.infra.LocationRepository; | ||
import com.koliving.api.properties.FrontProperties; | ||
import com.koliving.api.room.application.dto.RoomContactRequest; | ||
import com.koliving.api.room.application.dto.RoomResponse; | ||
import com.koliving.api.room.application.dto.RoomSaveRequest; | ||
import com.koliving.api.room.application.dto.RoomSearchCondition; | ||
import com.koliving.api.room.domain.Furnishing; | ||
import com.koliving.api.room.domain.Like; | ||
import com.koliving.api.room.domain.Room; | ||
import com.koliving.api.room.infra.RoomContactEvent; | ||
import com.koliving.api.room.infra.FurnishingRepository; | ||
import com.koliving.api.room.infra.LikeRepository; | ||
import com.koliving.api.room.infra.RoomRepository; | ||
import com.koliving.api.user.User; | ||
import com.koliving.api.user.domain.Notification; | ||
import com.koliving.api.user.domain.User; | ||
import com.koliving.api.user.infra.UserRepository; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
|
@@ -45,6 +52,8 @@ public class RoomService { | |
private final RoomRepository roomRepository; | ||
private final ImageFileRepository imageFileRepository; | ||
private final LikeRepository likeRepository; | ||
private final IEmailService emailService; | ||
private final FrontProperties frontProperties; | ||
|
||
public List<RoomResponse> list() { | ||
return roomRepository.findAllWithUser() | ||
|
@@ -144,4 +153,17 @@ private Room getRoom(Long id) { | |
return roomRepository.findByIdWithUser(id) | ||
.orElseThrow(() -> new KolivingServiceException(RECORD_NOT_EXIST)); | ||
} | ||
|
||
@Transactional | ||
public void contact(RoomContactRequest request, User user) { | ||
final Room room = getRoom(request.roomId()); | ||
final Notification notification = Notification.of(user, room.getUser()); | ||
room.getUser().addReceivedNotification(notification); | ||
emailService.sendRoomContact("[email protected]", request.contactInfo(), request.message(), user, getRoomDetailUrl(room.getId())); | ||
} | ||
|
||
|
||
public String getRoomDetailUrl(Long roomId) { | ||
return String.format("%s/room/%d", frontProperties.getOrigin(), roomId); | ||
} | ||
} |
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
Oops, something went wrong.