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 @@ -42,7 +42,11 @@ public GithubRepositoryResult register(Long userId, RegisterRepositoryCommand co
User user = userRepository.findByIdAndDeletedFalse(userId)
.orElseThrow(() -> new DomainException(ApiErrorCode.USER_NOT_FOUND));

if (repositoryRepository.findByUser_IdAndGithubRepoIdAndDeletedFalse(userId, command.githubRepoId()).isPresent()) {
// soft delete 된 행이 있으면 새 INSERT 대신 그 행을 복구한다
GithubRepository existing = repositoryRepository
.findByUser_IdAndGithubRepoId(userId, command.githubRepoId())
.orElse(null);
if (existing != null && !existing.isDeleted()) {
throw new DomainException(ApiErrorCode.REPO_ALREADY_REGISTERED);
}

Expand All @@ -55,14 +59,20 @@ public GithubRepositoryResult register(Long userId, RegisterRepositoryCommand co
throw new DomainException(ApiErrorCode.VALIDATION_ERROR);
}

GithubRepository repo = repositoryRepository.save(GithubRepository.create(
user,
meta.id(),
meta.name(),
meta.fullName(),
meta.htmlUrl(),
meta.defaultBranch()
));
GithubRepository repo;
if (existing != null) {
existing.reactivate(meta.name(), meta.fullName(), meta.htmlUrl(), meta.defaultBranch());
repo = existing;
} else {
repo = repositoryRepository.save(GithubRepository.create(
user,
meta.id(),
meta.name(),
meta.fullName(),
meta.htmlUrl(),
meta.defaultBranch()
));
}

events.publishEvent(new RepositoryRegisteredEvent(userId, repo.getId()));
return GithubRepositoryResult.of(repo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,11 @@ public void markFailed() {
public void markDeleted() {
this.deleted = true;
}

// 이전에 soft delete 된 레포를 다시 등록할 때 같은 행을 복구한다.
public void reactivate(String repoName, String repoFullName, String repoUrl, String defaultBranch) {
this.deleted = false;
this.status = RepositoryStatus.PENDING;
updateMetadata(repoName, repoFullName, repoUrl, defaultBranch);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ public interface GithubRepositoryRepository extends JpaRepository<GithubReposito

Optional<GithubRepository> findByUser_IdAndGithubRepoIdAndDeletedFalse(Long userId, Long githubRepoId);

Optional<GithubRepository> findByUser_IdAndGithubRepoId(Long userId, Long githubRepoId);

List<GithubRepository> findByUser_IdAndGithubRepoIdInAndDeletedFalse(Long userId, Set<Long> githubRepoIds);
}
2 changes: 1 addition & 1 deletion frontend/src/features/analysis/model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type AnalyzedDocument = {
updatedAt: string
}

// /api/stream/me 의 DOC_STATE / REPO_STATE 이벤트 data 의 payload 필드.
// /realtime/stream/me 의 DOC_STATE / REPO_STATE 이벤트 data 의 payload 필드.
export type AnalysisEventPayload = {
targetType: AnalysisSourceType
targetId: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { repoKeys } from '@/features/repo'
import { documentKeys } from '@/features/analysis'
import { useEventStream } from '@/shared/hooks'

// /api/stream/me 를 구독해 분석 상태(DOC_STATE/REPO_STATE) 가 오면
// 이력서·레포·문서 쿼리를 무효화 → 화면이 자동으로 최신 상태로 갱신된다.
export function useWorkspaceAnalysisStream() {
const queryClient = useQueryClient()
Expand All @@ -20,7 +19,7 @@ export function useWorkspaceAnalysisStream() {
}, [queryClient])

useEventStream({
path: '/api/stream/me',
path: '/realtime/stream/me',
getToken,
handlers: {
DOC_STATE: invalidateAll,
Expand Down