Skip to content

Commit

Permalink
refactor : card create logic and company recommend
Browse files Browse the repository at this point in the history
  • Loading branch information
jyc0011 committed Nov 14, 2024
1 parent ab00fff commit ee06c1a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
16 changes: 8 additions & 8 deletions src/main/frontend/src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import Link from 'next/link';
const NavigationBar = () =>{
const [isAuthenticated, setIsAuthenticated] = useState(false);

// useEffect(() => {
// const fetchAuthStatus = async () => {
// const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/oauth/status`, { credentials: 'include' });
// const data = await response.json();
// setIsAuthenticated(data.authenticated);
// };
// fetchAuthStatus();
// }, []);
useEffect(() => {
const fetchAuthStatus = async () => {
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/oauth/status`, { credentials: 'include' });
const data = await response.json();
setIsAuthenticated(data.authenticated);
};
fetchAuthStatus();
}, []);

const handleLogout = async () => {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public ResponseEntity<String> createAiCard(HttpSession session,
}
card.setECImageUrl(imageUrl);
card.setECPdfUrl(pdfUrl);
String result = cardService.createAiCard(card, pdfFile);
String result = cardService.createAiCard(card, imageUrl);
if ("success".equals(result)) {
return ResponseEntity.ok("{\"status\":\"success\"}");
} else {
Expand Down Expand Up @@ -140,9 +140,10 @@ public ResponseEntity<String> updateAiCard(@PathVariable int card_id,
if (updatedCardDTO.getReflection() != null) {
existingCard.setECReflection(updatedCardDTO.getReflection());
}
if(imageFile != null &&!imageFile.isEmpty()){
String imageUrl = null;
if (imageFile != null && !imageFile.isEmpty()) {
S3FileService.deleteFileFromS3(updatedCardDTO.getImageUrl());
String imageUrl = null;
imageUrl = null;
if (!imageFile.isEmpty()) {
try {
imageUrl = S3FileService.upload(imageFile);
Expand All @@ -153,7 +154,7 @@ public ResponseEntity<String> updateAiCard(@PathVariable int card_id,
}
card.setECImageUrl(imageUrl);
}
if(pdfFile != null &&!pdfFile.isEmpty()){
if (pdfFile != null && !pdfFile.isEmpty()) {
S3FileService.deleteFileFromS3(updatedCardDTO.getPdfUrl());
String pdfUrl;
try {
Expand All @@ -167,14 +168,14 @@ public ResponseEntity<String> updateAiCard(@PathVariable int card_id,
card.setECPdfUrl(pdfUrl);
} else {
try {
pdfFile= S3FileService.downloadFileAsMultipartFile(updatedCardDTO.getPdfUrl());
pdfFile = S3FileService.downloadFileAsMultipartFile(updatedCardDTO.getPdfUrl());
} catch (Exception e) {
log.error("PDF 파일 다운로드 실패: {}", e.getMessage());
return ResponseEntity.status(500).body("PDF 파일 다운로드에 실패했습니다.");
}
}
// Call the service to update the card
String result = cardService.updateAiCard(user, card_id, existingCard, imageFile, pdfFile);
String result = cardService.updateAiCard(user, card_id, existingCard, imageFile, imageUrl);
if ("success".equals(result)) {
return ResponseEntity.ok("{\"status\":\"success\"}");
} else {
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/com/project/sanhak/card/service/cardService.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ public aiCardDTO getTargetCard(int ecId) {
.orElse(null);
}

public String createAiCard(ExperienceCard card, MultipartFile pdfFile) throws IOException {
String pdfText = extractTextFromPDF(pdfFile); // PDF에서 텍스트 추출
public String createAiCard(ExperienceCard card, String pdfFileURL) throws IOException {
String url = apiBaseUrl + "/createCard";

// 요청 데이터 설정
Expand All @@ -67,7 +66,7 @@ public String createAiCard(ExperienceCard card, MultipartFile pdfFile) throws IO
requestData.put("tool", toolsList);
requestData.put("position", positionList);
requestData.put("reflection", card.getECReflection());
requestData.put("pdfText", pdfText);
requestData.put("pdfURL", pdfFileURL);

System.out.println("Request data: " + requestData);

Expand Down Expand Up @@ -122,8 +121,7 @@ public String extractTextFromPDF(MultipartFile pdfFile) throws IOException {
}
}

public String updateAiCard(User user, int cardId, ExperienceCard card, MultipartFile imageFile, MultipartFile pdfFile) throws IOException {
String pdfText = extractTextFromPDF(pdfFile);
public String updateAiCard(User user, int cardId, ExperienceCard card, MultipartFile imageFile, String pdfFileURL) throws IOException {
// 외부 API 요청으로 요약 생성
String url = apiBaseUrl + "/createCard";
Map<String, Object> requestData = new HashMap<>();
Expand All @@ -133,7 +131,7 @@ public String updateAiCard(User user, int cardId, ExperienceCard card, Multipart
requestData.put("tool", toolsList);
requestData.put("position", positionList);
requestData.put("reflection", card.getECReflection());
requestData.put("pdfText", pdfText);
requestData.put("pdfURL", pdfFileURL);

System.out.println("Request data: " + requestData);

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/project/sanhak/company/dto/companyDTO.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.project.sanhak.company.dto;

import com.project.sanhak.card.dto.skill;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

Expand All @@ -19,5 +20,5 @@ public class companyDTO {
@Schema(description = "부가 설명")
private String description;
@Schema(description = "스킬 종류")
private List<String> skill;
private List<skill> skill;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.project.sanhak.company.service;

import com.project.sanhak.card.dto.skill;
import com.project.sanhak.company.dto.companyDTO;
import com.project.sanhak.company.repository.companyRepository;
import com.project.sanhak.category.repository.categoryRepository;
import com.project.sanhak.domain.company.Company;
import com.project.sanhak.domain.user.Badge;
import com.project.sanhak.domain.user.User;
Expand All @@ -23,6 +25,9 @@ public class companyService {
private companyRepository companyRepository;
@Autowired
private BadgeRepository badgeRepository;
@Autowired
private categoryRepository categoryRepository;

private final WebClient webClient;

public companyService(WebClient webClient) {
Expand Down Expand Up @@ -54,7 +59,9 @@ public List<companyDTO> recommandCompany(User user) {
for (Map<String, Object> companyData : companyResponseList) {
String comName = companyData.get("company_name").toString();
String comPosition = companyData.get("result").toString();
List<String> comSkill =(List<String>) companyData.get("extracted_skills");
List<skill> skills = categoryRepository.findByCSNameIn((List<String>) companyData.get("extracted_skills")).stream()
.map(codeSkill -> new skill(codeSkill.getCSId(), codeSkill.getCSName()))
.collect(Collectors.toList());
List<Company> companies = companyRepository.findByCOMNameAndCOMPosition(comName, comPosition);

for (Company company : companies) {
Expand All @@ -64,7 +71,7 @@ public List<companyDTO> recommandCompany(User user) {
dto.setLocation(company.getCOMPlace());
dto.setPosition(company.getCOMPosition());
dto.setDescription(company.getCOMDescription());
dto.setSkill(comSkill);
dto.setSkill(skills);
companyDTOList.add(dto);
}
}
Expand Down

0 comments on commit ee06c1a

Please sign in to comment.