Skip to content

Commit

Permalink
Fix: 찾을 수 없는 깃허브 아이디 유저 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
wonyongChoi05 committed Apr 25, 2023
1 parent e693944 commit 3d294ed
Show file tree
Hide file tree
Showing 29 changed files with 32 additions and 4 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/java/bssm/db/bssmgit/domain/user/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class User {
@Column(length = 8)
private Integer commits;

@Column(length = 128)
@Column(length = 1024)
private String githubMsg;

@Column
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ public interface UserRepository extends JpaRepository<User, Long> {
"bssm.db.bssmgit.domain.user.domain.type.Imaginary.IMAGINARY_NUMBER")
List<User> findByUserImaginaryUser();

}
void deleteByGithubId(String githubId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URLConnection;
import java.util.List;

import static bssm.db.bssmgit.global.exception.ErrorCode.GIT_CONNECTION_REFUSED;
import static bssm.db.bssmgit.global.util.Constants.EVERY_10MINUTES;
import static bssm.db.bssmgit.global.util.Constants.EVERY_5MINUTES;
import static bssm.db.bssmgit.global.util.Constants.REGEX_FOR_COMMIT;

Expand All @@ -39,15 +42,16 @@ private void connectToGithub(String token) throws IOException {
github.checkApiUrlValidity();
}

@Scheduled(cron = EVERY_5MINUTES)
@Scheduled(cron = EVERY_10MINUTES)
@Transactional
public void updateUserGithubInfo() throws IOException {
connectGithub();
List<User> users = userRepository.findAll();

for (int i = 0, userSize = users.size(); i < userSize; i++) {
User user = users.get(i);
if (user.hasNotGithubId()) {
return;
continue;
}
Integer commit = getCommit(user.getGithubId());
String bio = github.getUser(user.getGithubId()).getBio();
Expand All @@ -67,6 +71,22 @@ private Integer getCommit(String githubId) throws IOException {
return Integer.parseInt(commitSymbol);
}

@Scheduled(cron = EVERY_5MINUTES)
@Transactional
public void deleteNotFoundGithubIdUser() throws IOException {
List<User> users = userRepository.findAll();
for (int i = 0, userSize = users.size(); i < userSize; i++) {
User user = users.get(i);
try {
URLConnection connection = GithubUtil.getGithubUrlConnection(user.getGithubId());
connection.getInputStream();
} catch (FileNotFoundException e) {
log.info("{}를 찾을 수 없음 -> 해당 유저 깃허브 아이디 자동 삭제 처리", e.getMessage());
userRepository.deleteByGithubId(user.getGithubId());
}
}
}

private static String getCommitSymbol(BufferedReader br) throws IOException {
boolean isMatchRegexForCommit = false;
String inputLine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import bssm.db.bssmgit.domain.user.web.dto.response.UserResponseDto;
import bssm.db.bssmgit.global.generic.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -45,4 +46,8 @@ public void test() throws IOException {
githubService.updateUserGithubInfo();
}

@DeleteMapping("/test")
public void deleteTest() throws IOException {
githubService.deleteNotFoundGithubIdUser();
}
}
1 change: 1 addition & 0 deletions src/main/java/bssm/db/bssmgit/global/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class Constants {
public static final String BOJ_URL = "https://solved.ac/api/v3/user/show?handle=";

public static final String REGEX_FOR_COMMIT = "<h2 class=\"f4 text-normal mb-2\">";
public static final String EVERY_10MINUTES = "0 0/5 * * * ?";
public static final String EVERY_5MINUTES = "0 0/5 * * * ?";
public static final String EVERY_50MINUTES = "0 0/50 * * * ?";
}

0 comments on commit 3d294ed

Please sign in to comment.