Skip to content

Commit

Permalink
[Merge] hyungjun#145-feat-refactor-email
Browse files Browse the repository at this point in the history
[Feat,Refactor] 로그인 이메일로, 이메일 인증 추가
  • Loading branch information
sukangpunch authored Sep 24, 2024
2 parents 4da068c + 5eab97f commit 4e963ab
Show file tree
Hide file tree
Showing 79 changed files with 748 additions and 518 deletions.
Empty file removed null0912191014511_99741401_profile
Empty file.
Empty file.
6 changes: 2 additions & 4 deletions src/main/generated/me/snaptime/user/domain/QUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public class QUser extends EntityPathBase<User> {

public final me.snaptime.common.QBaseTimeEntity _super = new me.snaptime.common.QBaseTimeEntity(this);

public final StringPath birthDay = createString("birthDay");

//inherited
public final DateTimePath<java.time.LocalDateTime> createdDate = _super.createdDate;

Expand All @@ -34,10 +32,10 @@ public class QUser extends EntityPathBase<User> {
//inherited
public final DateTimePath<java.time.LocalDateTime> lastModifiedDate = _super.lastModifiedDate;

public final StringPath loginId = createString("loginId");

public final StringPath name = createString("name");

public final StringPath nickName = createString("nickName");

public final StringPath password = createString("password");

public final me.snaptime.profilePhoto.domain.QProfilePhoto profilePhoto;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/me/snaptime/alarm/dto/res/AlarmInfoResDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public record AlarmInfoResDto(
String previewText,
AlarmType alarmType,
Long snapId,
String senderLoginId,
String senderEmail,
@Getter
LocalDateTime createdDate

Expand All @@ -36,7 +36,7 @@ public static AlarmInfoResDto toDtoByFollowAlarm(String senderProfilePhotoURL, S
.alarmType(followAlarm.getAlarmType())
.createdDate(followAlarm.getCreatedDate())
.snapId(null)
.senderLoginId(followAlarm.getSender().getLoginId())
.senderEmail(followAlarm.getSender().getEmail())
.build();
}

Expand All @@ -53,7 +53,7 @@ public static AlarmInfoResDto toDtoBySnapAlarm(String senderProfilePhotoURL, Str
.alarmType(snapAlarm.getAlarmType())
.createdDate(snapAlarm.getCreatedDate())
.snapId(snapAlarm.getSnap().getId())
.senderLoginId(snapAlarm.getSender().getLoginId())
.senderEmail(snapAlarm.getSender().getEmail())
.build();
}

Expand All @@ -70,7 +70,7 @@ public static AlarmInfoResDto toDtoByReplyAlarm(String senderProfilePhotoURL, St
.alarmType(replyAlarm.getAlarmType())
.createdDate(replyAlarm.getCreatedDate())
.snapId(replyAlarm.getSnap().getId())
.senderLoginId(replyAlarm.getSender().getLoginId())
.senderEmail(replyAlarm.getSender().getEmail())
.build();
}
}
12 changes: 6 additions & 6 deletions src/main/java/me/snaptime/alarm/service/AlarmService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ public interface AlarmService {
/*
snapAlarm을 읽음처리합니다.
*/
void readSnapAlarm(String reqLoginId, Long snapAlarmId);
void readSnapAlarm(String reqEmail, Long snapAlarmId);

//팔로우알림을 읽음처리합니다.
void readFollowAlarm(String reqLoginId, Long followAlarmId);
void readFollowAlarm(String reqEmail, Long followAlarmId);

/*
ReplyAlarm을 읽음처리합니다.
*/
void readReplyAlarm(String reqLoginId, Long replyAlarmId);
void readReplyAlarm(String reqEmail, Long replyAlarmId);

//유저의 모든 알림을 불러옵니다.
Object findAlarms(String reqLoginId);
Object findAlarms(String reqEmail);

// 읽지않은 알림이 몇개인지 조회합니다.
Long findNotReadAlarmCnt(String reqLoginId);
Long findNotReadAlarmCnt(String reqEmail);

/*
알림을 삭제합니다.
읽지않은 팔로우요청에 대한 알림의 경우 자동으로 요청거절이 됩니다.
*/
void deleteAlarm(String reqLoginId, Long alarmId, AlarmType alarmType);
void deleteAlarm(String reqEmail, Long alarmId, AlarmType alarmType);
}
32 changes: 16 additions & 16 deletions src/main/java/me/snaptime/alarm/service/impl/AlarmServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,26 @@ public class AlarmServiceImpl implements AlarmService {

@Override
@Transactional
public void readSnapAlarm(String reqLoginId, Long snapAlarmId) {
public void readSnapAlarm(String reqEmail, Long snapAlarmId) {

SnapAlarm snapAlarm = snapAlarmRepository.findById(snapAlarmId)
.orElseThrow(() -> new CustomException(ExceptionCode.ALARM_NOT_EXIST));

// 자신한테 온 알림인지 여부체크
isMyAlarm(reqLoginId,snapAlarm.getReceiver().getLoginId());
isMyAlarm(reqEmail,snapAlarm.getReceiver().getEmail());

snapAlarm.readAlarm();
snapAlarmRepository.save(snapAlarm);
}

@Override
@Transactional
public void readFollowAlarm(String reqLoginId, Long followAlarmId) {
public void readFollowAlarm(String reqEmail, Long followAlarmId) {
FollowAlarm followAlarm = followAlarmRepository.findById(followAlarmId)
.orElseThrow(() -> new CustomException(ExceptionCode.ALARM_NOT_EXIST));

// 자신한테 온 알림인지 여부체크
isMyAlarm(reqLoginId, followAlarm.getReceiver().getLoginId());
isMyAlarm(reqEmail, followAlarm.getReceiver().getEmail());


followAlarm.readAlarm();
Expand All @@ -66,28 +66,28 @@ public void readFollowAlarm(String reqLoginId, Long followAlarmId) {

@Override
@Transactional
public void readReplyAlarm(String reqLoginId, Long replyAlarmId) {
public void readReplyAlarm(String reqEmail, Long replyAlarmId) {
ReplyAlarm replyAlarm = replyAlarmRepository.findById(replyAlarmId)
.orElseThrow(() -> new CustomException(ExceptionCode.ALARM_NOT_EXIST));

// 자신한테 온 알림인지 여부체크
isMyAlarm(reqLoginId, replyAlarm.getReceiver().getLoginId());
isMyAlarm(reqEmail, replyAlarm.getReceiver().getEmail());

replyAlarm.readAlarm();
replyAlarmRepository.save(replyAlarm);
}

@Override
public AlarmFindAllResDto findAlarms(String reqLoginId) {
User reqUser = userRepository.findByLoginId(reqLoginId)
public AlarmFindAllResDto findAlarms(String reqEmail) {
User reqUser = userRepository.findByEmail(reqEmail)
.orElseThrow(() -> new CustomException(ExceptionCode.USER_NOT_EXIST));

return AlarmFindAllResDto.toDto(findSortedAlarms(reqUser,false), findSortedAlarms(reqUser,true));
}

@Override
public Long findNotReadAlarmCnt(String reqLoginId) {
User reqUser = userRepository.findByLoginId(reqLoginId)
public Long findNotReadAlarmCnt(String reqEmail) {
User reqUser = userRepository.findByEmail(reqEmail)
.orElseThrow(() -> new CustomException(ExceptionCode.USER_NOT_EXIST));

return followAlarmRepository.countByReceiverAndIsRead(reqUser,false)+
Expand All @@ -97,38 +97,38 @@ public Long findNotReadAlarmCnt(String reqLoginId) {

@Override
@Transactional
public void deleteAlarm(String reqLoginId, Long alarmId, AlarmType alarmType) {
public void deleteAlarm(String reqEmail, Long alarmId, AlarmType alarmType) {

// 팔로우 알림일 경우
if(alarmType == AlarmType.FOLLOW){
FollowAlarm followAlarm = followAlarmRepository.findById(alarmId)
.orElseThrow(() -> new CustomException(ExceptionCode.ALARM_NOT_EXIST));

isMyAlarm(reqLoginId, followAlarm.getReceiver().getLoginId());
isMyAlarm(reqEmail, followAlarm.getReceiver().getEmail());
followAlarmRepository.delete(followAlarm);
}
// 댓글알림일 경우
else if(alarmType == AlarmType.REPLY){
ReplyAlarm replyAlarm = replyAlarmRepository.findById(alarmId)
.orElseThrow(() -> new CustomException(ExceptionCode.ALARM_NOT_EXIST));

isMyAlarm(reqLoginId, replyAlarm.getReceiver().getLoginId());
isMyAlarm(reqEmail, replyAlarm.getReceiver().getEmail());
replyAlarmRepository.delete(replyAlarm);
}
// 스냅(스냅태그, 좋아요)에 대한 알림일 경우
else{
SnapAlarm snapAlarm = snapAlarmRepository.findById(alarmId)
.orElseThrow(() -> new CustomException(ExceptionCode.ALARM_NOT_EXIST));

isMyAlarm(reqLoginId, snapAlarm.getReceiver().getLoginId());
isMyAlarm(reqEmail, snapAlarm.getReceiver().getEmail());
snapAlarmRepository.delete(snapAlarm);
}
}

// 자신한테 온 알림인지 여부체크
private void isMyAlarm(String reqLoginId, String alarmReceiverLoginId){
private void isMyAlarm(String reqEmail, String alarmReceiverEmail){

if(!reqLoginId.equals(alarmReceiverLoginId))
if(!reqEmail.equals(alarmReceiverEmail))
throw new CustomException(ExceptionCode.ACCESS_FAIL_ALARM);

}
Expand Down
28 changes: 11 additions & 17 deletions src/main/java/me/snaptime/album/controller/AlbumController.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public class AlbumController {

@Operation(summary = "Album 목록(썸네일 포함) 조회", description = "사용자의 Album 목록(썸네일 포함)을 조회합니다.")
@GetMapping(path = "/albumListWithThumbnail")
public ResponseEntity<CommonResponseDto<List<FindAllAlbumsResDto>>> findAllAlbumsByLoginId(
public ResponseEntity<CommonResponseDto<List<FindAllAlbumsResDto>>> findAllAlbumsByEmail(
final @AuthenticationPrincipal UserDetails userDetails
) {
String uId = userDetails.getUsername();
String userEmail = userDetails.getUsername();
return ResponseEntity.status(HttpStatus.OK)
.body(
new CommonResponseDto<>(
"사용자의 앨범 목록(썸네일 포함)이 정상적으로 불러와졌습니다.",
albumService.findAllAlbumsByLoginId(uId)
albumService.findAllAlbumsByEmail(userEmail)
)
);
}
Expand All @@ -46,8 +46,8 @@ public ResponseEntity<CommonResponseDto<Void>> createAlbum(
final @RequestBody CreateAlbumReqDto createAlbumReqDto,
final @AuthenticationPrincipal UserDetails userDetails
) {
String uId = userDetails.getUsername();
albumService.createAlbum(createAlbumReqDto, uId);
String userEmail = userDetails.getUsername();
albumService.createAlbum(createAlbumReqDto, userEmail);
return ResponseEntity.status(HttpStatus.CREATED).body(
new CommonResponseDto<>(
"사용자의 앨범을 정상적으로 생성했습니다.",
Expand All @@ -61,11 +61,11 @@ public ResponseEntity<CommonResponseDto<Void>> createAlbum(
public ResponseEntity<CommonResponseDto<List<GetAllAlbumListResDto>>> findAlbumList(
final @AuthenticationPrincipal UserDetails userDetails
) {
String uId = userDetails.getUsername();
String userEmail = userDetails.getUsername();
return ResponseEntity.status(HttpStatus.OK).body(
new CommonResponseDto<>(
"사용자의 앨범 목록(앨범의 이름들)을 정상적으로 가져왔습니다.",
albumService.getAlbumListByLoginId(uId)
albumService.getAlbumListByEmail(userEmail)
)
);
}
Expand All @@ -76,11 +76,11 @@ public ResponseEntity<CommonResponseDto<FindAlbumResDto>> findAlbum(
final @PathVariable("album_id") Long album_id,
final @AuthenticationPrincipal UserDetails userDetails
) {
String uId = userDetails.getUsername();
String userEmail = userDetails.getUsername();
return ResponseEntity.status(HttpStatus.OK).body(
new CommonResponseDto<>(
album_id + "번 Album의 내용을 전부 가져오는데 성공했습니다.",
albumService.findAlbum(uId, album_id)
albumService.findAlbum(userEmail, album_id)
)
);
}
Expand All @@ -107,19 +107,13 @@ ResponseEntity<CommonResponseDto<Void>> deleteAlbum(
final @RequestParam Long albumId,
final @AuthenticationPrincipal UserDetails userDetails
) {
String uId = userDetails.getUsername();
albumService.removeAlbum(uId, albumId);
String userEmail = userDetails.getUsername();
albumService.removeAlbum(userEmail, albumId);
return ResponseEntity.status(HttpStatus.OK).body(
new CommonResponseDto<>(
albumId + "번 album을 정상적으로 삭제했습니다.",
null
)
);
}






}
8 changes: 4 additions & 4 deletions src/main/java/me/snaptime/album/service/AlbumService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import java.util.List;

public interface AlbumService {
List<FindAllAlbumsResDto> findAllAlbumsByLoginId(String uid);
FindAlbumResDto findAlbum(String uId, Long album_id);
List<GetAllAlbumListResDto> getAlbumListByLoginId(String uid);
void createAlbum(CreateAlbumReqDto createAlbumReqDto, String uid);
List<FindAllAlbumsResDto> findAllAlbumsByEmail(String userEmail);
FindAlbumResDto findAlbum(String userEmail, Long album_id);
List<GetAllAlbumListResDto> getAlbumListByEmail(String userEmail);
void createAlbum(CreateAlbumReqDto createAlbumReqDto, String userEmail);
/*
* 사용자 계정에 Non-Classification Album 을 생성하고 생성된 Album 의 Id를 반환한다.
* */
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/me/snaptime/album/service/impl/AlbumServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public class AlbumServiceImpl implements AlbumService {

@Override
@Transactional(readOnly = true)
public List<FindAllAlbumsResDto> findAllAlbumsByLoginId(String uid) {
User foundUser = userRepository.findByLoginId(uid).orElseThrow(() -> new CustomException(ExceptionCode.USER_NOT_EXIST));
public List<FindAllAlbumsResDto> findAllAlbumsByEmail(String userEmail) {
User foundUser = userRepository.findByEmail(userEmail).orElseThrow(() -> new CustomException(ExceptionCode.USER_NOT_EXIST));
List<Album> foundAlbums = albumRepository.findAlbumsByUser(foundUser);
return foundAlbums.stream().map(album -> {
int lastNumber = album.getSnap().size();
Expand All @@ -56,9 +56,9 @@ public List<FindAllAlbumsResDto> findAllAlbumsByLoginId(String uid) {

@Override
@Transactional(readOnly = true)
public FindAlbumResDto findAlbum(String uId, Long album_id) {
public FindAlbumResDto findAlbum(String userEmail, Long album_id) {
Album foundAlbum = albumRepository.findById(album_id).orElseThrow(() -> new CustomException(ExceptionCode.ALBUM_NOT_EXIST));
User foundUser = userRepository.findByLoginId(uId).orElseThrow(() -> new CustomException(ExceptionCode.USER_NOT_EXIST));
User foundUser = userRepository.findByEmail(userEmail).orElseThrow(() -> new CustomException(ExceptionCode.USER_NOT_EXIST));
try {
isUserHavePermission(foundUser, album_id);
} catch (CustomException e) {
Expand Down Expand Up @@ -119,15 +119,15 @@ public Long findUserNonClassificationId(User user) {

@Override
@Transactional(readOnly = true)
public List<GetAllAlbumListResDto> getAlbumListByLoginId(String uid) {
User foundUser = userRepository.findByLoginId(uid).orElseThrow(() -> new CustomException(ExceptionCode.USER_NOT_EXIST));
public List<GetAllAlbumListResDto> getAlbumListByEmail(String userEmail) {
User foundUser = userRepository.findByEmail(userEmail).orElseThrow(() -> new CustomException(ExceptionCode.USER_NOT_EXIST));
return albumRepository.findAlbumsByUser(foundUser).stream().map(album -> GetAllAlbumListResDto.builder().id(album.getId()).name(album.getName()).build()).toList();
}

@Override
@Transactional
public void createAlbum(CreateAlbumReqDto createAlbumReqDto, String uid) {
User foundUser = userRepository.findByLoginId(uid).orElseThrow(() -> new CustomException(ExceptionCode.USER_NOT_EXIST));
public void createAlbum(CreateAlbumReqDto createAlbumReqDto, String userEmail) {
User foundUser = userRepository.findByEmail(userEmail).orElseThrow(() -> new CustomException(ExceptionCode.USER_NOT_EXIST));
albumRepository.save(Album.builder().name(createAlbumReqDto.name()).user(foundUser).build());
}

Expand All @@ -146,8 +146,8 @@ public void modifyAlbumName(Long album_id, String album_name) {

@Override
@Transactional
public void removeAlbum(String uId, Long album_id) {
User foundUser = userRepository.findByLoginId(uId).orElseThrow(() -> new CustomException(ExceptionCode.USER_NOT_EXIST));
public void removeAlbum(String userEmail, Long album_id) {
User foundUser = userRepository.findByEmail(userEmail).orElseThrow(() -> new CustomException(ExceptionCode.USER_NOT_EXIST));
isUserHavePermission(foundUser, album_id);
Album foundAlbum = albumRepository.findById(album_id).orElseThrow(() -> new CustomException(ExceptionCode.ALBUM_NOT_EXIST));
// 사용자가 가지고 있는 non-classification id를 가져온다.
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/me/snaptime/component/email/EmailComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package me.snaptime.component.email;

import jakarta.mail.MessagingException;

public interface EmailComponent {

String sendVerificationCode(String toEmail, String verificationCode) throws MessagingException;
}
Loading

0 comments on commit 4e963ab

Please sign in to comment.