Skip to content

Commit

Permalink
[#127] feat: 실패 내역과 카테고리가 존재하지 않는지 확인 (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdomo authored Oct 19, 2023
1 parent 727a360 commit 496c5db
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.todaysfail.domains.failure.domain.Failure;
import com.todaysfail.domains.failure.port.FailureQueryPort;
import com.todaysfail.domains.failure.repository.FailureRepository;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
Expand All @@ -19,4 +20,9 @@ public class FailureQueryAdapter implements FailureQueryPort {
public Slice<Failure> queryFeed(Pageable pageable) {
return failureRepository.findAllBySecretFalseOrderByFailureDateDesc(pageable);
}

@Override
public List<Failure> queryFailureByUserId(Long userId) {
return failureRepository.findAllByUserId(userId);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.todaysfail.domains.failure.port;

import com.todaysfail.domains.failure.domain.Failure;
import java.util.List;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;

public interface FailureQueryPort {
Slice<Failure> queryFeed(Pageable pageable);

List<Failure> queryFailureByUserId(Long userId);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.todaysfail.domains.failure.repository;

import com.todaysfail.domains.failure.domain.Failure;
import java.util.List;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.JpaRepository;

public interface FailureRepository extends JpaRepository<Failure, Long> {
Slice<Failure> findAllBySecretFalseOrderByFailureDateDesc(Pageable pageable);

List<Failure> findAllByUserId(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.todaysfail.api.web.user.dto.response.RandomNicknameResponse;
import com.todaysfail.api.web.user.usecase.RandomNicknameUseCase;
import com.todaysfail.api.web.user.usecase.UserFirstTimeCheckUseCase;
import com.todaysfail.api.web.user.usecase.UserQueryUseCase;
import com.todaysfail.api.web.user.usecase.UserWithDrawUseCase;
import com.todaysfail.common.annotation.DisableSwaggerSecurity;
Expand All @@ -24,6 +25,7 @@ public class UserController {
private final UserQueryUseCase userQueryUseCase;
private final RandomNicknameUseCase randomNicknameUseCase;
private final UserWithDrawUseCase userWithDrawUseCase;
private final UserFirstTimeCheckUseCase userFirstTimeCheckUseCase;

@SecurityRequirement(name = "access-token")
@Operation(summary = "내 정보를 조회합니다.")
Expand All @@ -45,4 +47,10 @@ public void withdrawal() {
public RandomNicknameResponse generateRandomNickname() {
return randomNicknameUseCase.execute();
}

@Operation(summary = "생성 된 카테고리와 실패기록이 없는지 확인합니다.")
@GetMapping("/check-first")
public boolean checkIfFirstTimeUser() {
return userFirstTimeCheckUseCase.execute();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.todaysfail.api.web.user.usecase;

import com.todaysfail.common.annotation.UseCase;
import com.todaysfail.config.security.SecurityUtils;
import com.todaysfail.domains.category.domain.Category;
import com.todaysfail.domains.category.port.CategoryQueryPort;
import com.todaysfail.domains.failure.domain.Failure;
import com.todaysfail.domains.failure.port.FailureQueryPort;
import java.util.List;
import lombok.RequiredArgsConstructor;

@UseCase
@RequiredArgsConstructor
public class UserFirstTimeCheckUseCase {
private final CategoryQueryPort categoryQueryPort;
private final FailureQueryPort failureQueryPort;

public boolean execute() {
final Long userId = SecurityUtils.getCurrentUserId();
List<Category> categories = categoryQueryPort.queryCategoryByUserId(userId);
if (!categories.isEmpty()) {
return false;
}

List<Failure> failures = failureQueryPort.queryFailureByUserId(userId);
if (!failures.isEmpty()) {
return false;
}

return true;
}
}

0 comments on commit 496c5db

Please sign in to comment.