Skip to content

Commit

Permalink
Merge pull request #5 from UniD3-Hackathon-Team12/feat/#1
Browse files Browse the repository at this point in the history
Feat/#1
  • Loading branch information
born2slayy authored Nov 11, 2023
2 parents 91f49ab + bbd835b commit 9ad169b
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 14 deletions.
Binary file not shown.
8 changes: 8 additions & 0 deletions src/main/java/com/example/SeaReaUrl_back/FraudAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ public class FraudAccount {
private Long view;

private Long report;

public FraudAccount(String accountName, Boolean isFraud, Long view, Long report) {
this.accountName = accountName;
this.IsFraud = isFraud;
this.view = view;
this.report = report;

}
}
8 changes: 4 additions & 4 deletions src/main/java/com/example/SeaReaUrl_back/FraudController.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public Top5Response getTop5UrlView(){
// return fraudService.reportUrl();
// }
//
// @GetMapping("/checkUrl")
// public IsFraudUrlResponse checkUrlValidation(@RequestParam String url){
// return fraudService.checkUrlValidation(url);
// }
@GetMapping("/checkUrl")
public IsFraudUrlResponse checkUrlValidation(@RequestParam String url){
return fraudService.checkUrlValidation(url);
}
//
// @GetMapping("/checkAccount")
// public IsFraudAccountResponse checkAccountValidation(@RequestParam String accountName){
Expand Down
32 changes: 27 additions & 5 deletions src/main/java/com/example/SeaReaUrl_back/FraudService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
Expand Down Expand Up @@ -81,11 +87,27 @@ public Top5Response getTop5AccountAndView() {
// return new StringResponse();
// }
//
// @Transactional
// public IsFraudUrlResponse checkUrlValidation(String url){
// List<String> responseList = new ArrayList<>();
// return new IsFraudUrlResponse(responseList);
// }
private RestTemplate restTemplate = new RestTemplate();

public IsFraudUrlResponse checkUrlValidation(String url){
String pythonServerUrl = "http://localhost:5000/fraud";

Map<String, String> params = new HashMap<>();
params.put("url", url);

HttpEntity<Map<String, String>> requestEntity = new HttpEntity<>(params);
ResponseEntity<String> responseEntity = restTemplate.exchange(pythonServerUrl, HttpMethod.POST, requestEntity, String.class);

String result = responseEntity.getBody();
// double percentage = Double.parseDouble(result.split("%")[0]);

IsFraudUrlResponse isFraudUrlResponse = new IsFraudUrlResponse();
// isFraudUrlResponse.setPercentage(percentage);
// isFraudUrlResponse.setIsSafe(result.contains("safe"));
isFraudUrlResponse.setFraudPossibility(result);

return isFraudUrlResponse;
}
// @Transactional
// public IsFraudAccountResponse checkAccountValidation(String accountName){
// return new IsFraudAccountResponse(accountName);
Expand Down
62 changes: 62 additions & 0 deletions src/main/java/com/example/SeaReaUrl_back/InitFraudAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.example.SeaReaUrl_back;

import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import jakarta.persistence.EntityManager;

@Component
@RequiredArgsConstructor
public class InitFraudAccount {

private final InitFraudAccountService initFraudAccountService;

@PostConstruct
public void init() {
initFraudAccountService.init();
}

@Component
@Transactional
@RequiredArgsConstructor
static class InitFraudAccountService {

private final EntityManager em;

public void init() {
FraudAccount fraudAccount1 = createFraudAccount("https://www.instagram.com/newjeans_official/", false, 0L,0L);
FraudAccount fraudAccount2 = createFraudAccount("NewJeans_twt", false, 0L,0L);
FraudAccount fraudAccount3 = createFraudAccount("https://www.facebook.com/official.newjeans/", false, 0L,0L);
FraudAccount fraudAccount4 = createFraudAccount("https://www.instagram.com/jennierubyjane/", false, 0L,0L);
FraudAccount fraudAccount5 = createFraudAccount("https://www.instagram.com/thv/", false, 0L,0L);
FraudAccount fraudAccount6 = createFraudAccount("elonmusk", false, 0L,0L);
FraudAccount fraudAccount7 = createFraudAccount("https://www.instagram.com/hm_son7/", false, 0L,0L);
FraudAccount fraudAccount8 = createFraudAccount("https://www.facebook.com/HeungMinSonOfficial/", false, 0L,0L);
FraudAccount fraudAccount9 = createFraudAccount("https://www.instagram.com/paikscuisine_official/", false, 0L,0L);
FraudAccount fraudAccount10 = createFraudAccount("https://www.instagram.com/gamst17172/", false, 0L,0L);
FraudAccount fraudAccount11 = createFraudAccount("https://www.instagram.com/hhh_07/", false, 0L,0L);

em.persist(fraudAccount1);
em.persist(fraudAccount2);
em.persist(fraudAccount3);
em.persist(fraudAccount4);
em.persist(fraudAccount5);
em.persist(fraudAccount6);
em.persist(fraudAccount7);
em.persist(fraudAccount8);
em.persist(fraudAccount9);
em.persist(fraudAccount10);
em.persist(fraudAccount11);



}
private FraudAccount createFraudAccount(String accountName, Boolean isFraud, Long view, Long report) {
return new FraudAccount(accountName, isFraud, view, report);
}

}


}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.example.SeaReaUrl_back;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;

import java.util.List;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class IsFraudUrlResponse {
private List<String> responseList;
// private List<String> responseList;
private String fraudPossibility;
}

0 comments on commit 9ad169b

Please # to comment.