Skip to content

Commit

Permalink
Merge pull request #51 from GOAT-WAAAM/dev/encJ/auth-register
Browse files Browse the repository at this point in the history
[FIX] 일반 회원가입시 쓰레기통, 복습창고, 알림설정이 생성되지 않던 문제 수정
  • Loading branch information
encoreJeong authored Jul 25, 2024
2 parents 1543b9f + 706bbee commit cecbfc0
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 8 deletions.
11 changes: 4 additions & 7 deletions src/main/java/com/goat/server/auth/application/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.goat.server.global.application.S3Uploader;
import com.goat.server.global.util.jwt.JwtUserDetails;
import com.goat.server.global.util.jwt.JwtTokenProvider;
import com.goat.server.mypage.application.UserService;
import com.goat.server.mypage.domain.User;
import com.goat.server.mypage.domain.type.Role;
import com.goat.server.mypage.exception.UserNotFoundException;
Expand All @@ -25,6 +26,7 @@
public class AuthService {

private final JwtTokenProvider jwtTokenProvider;
private final UserService userService;
private final UserRepository userRepository;
private final S3Uploader s3Uploader;

Expand Down Expand Up @@ -82,14 +84,9 @@ public void withdraw(Long userId) {
*/
public SignUpSuccessResponse signUp() {

log.info("[AuthService.signUp]");
User user = userService.createUser();

User user = User.builder()
.nickname("temporaryUser")
.role(Role.GUEST)
.build();

userRepository.save(user);
log.info("[AuthService.signUp] userId: {}", user.getUserId());

return SignUpSuccessResponse.of(jwtTokenProvider.generateToken(getJwtUserDetails(user.getUserId())), user, 0L);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class UserService {
private final ReviewRepository reviewRepository;

/**
* 유저 회원가입
* 소셜 유저 회원가입
*/
@Transactional
public User createUser(final OAuthInfoResponse userResponse) {
Expand Down Expand Up @@ -76,6 +76,43 @@ public User findUser(final Long userId) {
.orElseThrow(() -> new UserNotFoundException(MypageErrorCode.USER_NOT_FOUND));
}

/**
* 일반 회원 가입
*/
@Transactional
public User createUser() {
User user = User.builder()
.nickname("temporalUser")
.role(Role.GUEST)
.build();

Directory trashDirectory = Directory.builder()
.user(user)
.title("trash_directory")
.depth(1L)
.build();

Directory storageDirectory = Directory.builder()
.user(user)
.title("storage_directory")
.depth(1L)
.build();

NotificationSetting notificationSetting = NotificationSetting.builder()
.user(user)
.isCommentNoti(false)
.isPostNoti(false)
.isReviewNoti(false)
.build();


notificationSettingRepository.save(notificationSetting);
directoryRepository.save(trashDirectory);
directoryRepository.save(storageDirectory);

return userRepository.save(user);
}

/**
* 프로필 이미지 업데이트
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.goat.server.notification.domain.Notification;
import lombok.Builder;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.List;

@Builder
Expand All @@ -14,21 +16,47 @@ public record NotificationComponentResponse(
Long notificationId,
Long reviewId,
String reviewBody,
String whenItPushed,
Boolean isRead
){
public static NotificationComponentResponse from(Notification notification) {

String whenItPushed = calculateWhenItPushed(notification);

return NotificationComponentResponse.builder()
.notificationId(notification.getNoti_id())
.reviewId(notification.getReview().getId())
.reviewBody(notification.getContent())
.whenItPushed(whenItPushed)
.isRead(notification.getIsRead())
.build();
}

private static String calculateWhenItPushed(Notification notification) {
LocalDate currentDate = LocalDate.now();
LocalDate createdDate = notification.getCreatedDate().toLocalDate();
long daysBetween = ChronoUnit.DAYS.between(createdDate, currentDate);
long hoursBetween = ChronoUnit.HOURS.between(createdDate, currentDate);

String whenItPushed = null;
if (daysBetween == 0) {
if(hoursBetween == 0) {
whenItPushed = "방금 전";
} else {
whenItPushed = hoursBetween + "시간 전";
}
} else {
whenItPushed = daysBetween + "일 전";
}
return whenItPushed;
}
}

public static NotificationResponse from(List<NotificationComponentResponse> notifications) {
return NotificationResponse.builder()
.notifications(notifications)
.build();
}


}

0 comments on commit cecbfc0

Please sign in to comment.