Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,38 @@ public interface CommentRepository extends JpaRepository<Comment, Long> {
@Query(value = """
select comments.comment_id, comments.lesson_id, comments.user_id, comments.content,
comments.parent_comment_id, comments.deleted, comments.created_at, comments.updated_at
from ( select comment_id from comments where lesson_id = :lessonId order by parent_comment_id asc, comment_id asc limit :limit offset :offset
from (
select comment_id
from comments c
join users u on c.user_id = u.id and u.deleted_at IS NULL
where lesson_id = :lessonId
order by parent_comment_id asc, comment_id asc
limit :limit offset :offset
) t left join comments on t.comment_id = comments.comment_id
""", nativeQuery = true)
List<Comment> findAll(@Param("lessonId") Long lessonId, @Param("offset") int offset, @Param("limit") int limit);

@Query(value = """
select count(*) from ( select comment_id from comments where lesson_id = :lessonId limit :limit) t
select count(*) from (
select comment_id
from comments c
join users u on c.user_id = u.id and u.deleted_at IS NULL
where lesson_id = :lessonId
limit :limit
) t
""", nativeQuery = true)
Integer count(@Param("lessonId") Long lessonId, @Param("limit") int limit);

@Query(value = """
select count(*) from (select comment_id from comments where lesson_id = :lessonId and parent_comment_id = :parentCommentId limit :limit) t
select count(*) from (
select comment_id
from comments c
join users u on c.user_id = u.id and u.deleted_at IS NULL
where lesson_id = :lessonId and parent_comment_id = :parentCommentId
limit :limit
) t
""", nativeQuery = true)
Long countBy(@Param("lessonId") Long lessonId, @Param("parentCommentId") Long parentCommentId,
@Param("limit") int limit);
Long countBy(@Param("lessonId") Long lessonId, @Param("parentCommentId") Long parentCommentId, @Param("limit") int limit);

Optional<Comment> findByCommentIdAndUserId(Long commentId, Long userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ public interface ReviewRepository extends JpaRepository<Review, Long> {
boolean existsByReviewer_IdAndLessonId(Long reviewerId, Long lessonId);

@Query(value = """
select count(*) from (select review_id from reviews where reviewee_id = :userId limit :limit ) t
SELECT COUNT(*) FROM (
SELECT r.review_id
FROM reviews r
JOIN users u1 ON r.reviewee_id = u1.id AND u1.deleted_at IS NULL
JOIN users u2 ON r.reviewer_id = u2.id AND u2.deleted_at IS NULL
WHERE r.reviewee_id = :userId
LIMIT :limit
) t
""", nativeQuery = true)
Integer count(
@Param("userId") Long userId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -18,7 +17,6 @@
import com.threestar.trainus.domain.user.dto.PasswordUpdateDto;
import com.threestar.trainus.domain.user.dto.SignupRequestDto;
import com.threestar.trainus.domain.user.dto.SignupResponseDto;
import com.threestar.trainus.domain.user.dto.UserInfoResponseDto;
import com.threestar.trainus.domain.user.service.EmailVerificationService;
import com.threestar.trainus.domain.user.service.UserService;
import com.threestar.trainus.global.annotation.LoginUser;
Expand Down Expand Up @@ -111,4 +109,13 @@ public ResponseEntity<BaseResponse<UserInfoResponseDto>> getCurrentUser(
UserInfoResponseDto response = userService.getCurrentUserInfo(loginUserId);
return BaseResponse.ok("사용자 정보 조회가 완료되었습니다.", response, HttpStatus.OK);
}

@DeleteMapping("/withdraw")
@Operation(summary = "회원탈퇴 api")
public ResponseEntity<BaseResponse<Void>> withdraw(
@LoginUser Long loginUserId
) {
userService.withdraw(loginUserId);
return BaseResponse.okOnlyStatus(HttpStatus.NO_CONTENT);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 기능 참고하겠습니다!

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.ArrayList;
import java.util.List;

import org.hibernate.annotations.SQLRestriction;

import com.threestar.trainus.domain.coupon.user.entity.UserCoupon;
import com.threestar.trainus.domain.metadata.entity.ProfileMetadata;
import com.threestar.trainus.domain.profile.entity.Profile;
Expand Down Expand Up @@ -32,6 +34,7 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@SQLRestriction("deleted_at IS NULL") //삭제되지 않은 데이터만 기본적으로 조회하는 필터
public class User extends BaseDateEntity {

@Id
Expand Down Expand Up @@ -65,4 +68,8 @@ public class User extends BaseDateEntity {
public void updatePassword(String newPassword) {
this.password = newPassword;
}

public void withdraw() {
this.deletedAt = LocalDateTime.now();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,4 @@ public interface UserRepository extends JpaRepository<User, Long> {
boolean existsByNickname(String nickname);

Optional<User> findByEmail(String email);

// 닉네임으로 사용자 찾기
Optional<User> findByNickname(String nickname);

// 삭제되지 않은 사용자만 조회
Optional<User> findByIdAndDeletedAtIsNull(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.threestar.trainus.domain.user.dto.PasswordUpdateDto;
import com.threestar.trainus.domain.user.dto.SignupRequestDto;
import com.threestar.trainus.domain.user.dto.SignupResponseDto;
import com.threestar.trainus.domain.user.dto.UserInfoResponseDto;
import com.threestar.trainus.domain.user.entity.User;
import com.threestar.trainus.domain.user.entity.UserRole;
import com.threestar.trainus.domain.user.mapper.UserMapper;
Expand Down Expand Up @@ -140,6 +139,13 @@ public void updatePassword(PasswordUpdateDto request, Long userId) {
userRepository.save(user);
}

@Transactional
public void withdraw(Long userId) {
User user = getUserById(userId);

user.withdraw();
}

@Transactional(readOnly = true)
public UserInfoResponseDto getCurrentUserInfo(Long userId) {
User user = getUserById(userId);
Expand Down
Loading