Skip to content
Merged

Dev #64

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 @@ -51,16 +51,11 @@ public AnalysisResultDto analyzeResult(String repoUrl, String prompt, String aut
AnalyzeResponse analyzeResult = analyzeAI(repoUrl, prompt, authorizationHeader);
log.info("AI ๋ถ„์„ ์™„๋ฃŒ - ๋””๋ ‰ํ„ฐ๋ฆฌ: {}", analyzeResult.getDirs_analyzed());

// Step 3: ์ƒ์„ฑ๋œ ๊ทธ๋ž˜ํ”„ ๋ฐ์ดํ„ฐ ์กฐํšŒ
MindmapGraphDto graphData = getGraph(mapId, authorizationHeader);
log.info("๊ทธ๋ž˜ํ”„ ์กฐํšŒ ์™„๋ฃŒ - ๋…ธ๋“œ: {}, ์—ฃ์ง€: {}",
graphData.getNodes().size(), graphData.getEdges().size());

// Step 4: ์ €์žฅ์†Œ ์ •๋ณด ์กฐํšŒ (TODO: FastAPI์— ์—”๋“œํฌ์ธํŠธ ์ถ”๊ฐ€ ํ•„์š”)
// Step 3: ์ €์žฅ์†Œ ์ •๋ณด ์กฐํšŒ
RepoInfoResponse repoInfo = getRepoInfo(mapId, authorizationHeader);

// ๋ชจ๋“  ๋ฐ์ดํ„ฐ๋ฅผ ์ข…ํ•ฉํ•˜์—ฌ DTO ์ƒ์„ฑ
return buildAnalysisResultDto(mapId, analyzeResult, graphData, repoInfo);
return buildAnalysisResultDto(repoInfo);

} catch (Exception e) {
log.error("์ €์žฅ์†Œ ๋ถ„์„ ์‹คํŒจ: {}", e.getMessage(), e);
Expand All @@ -83,14 +78,11 @@ public AnalysisResultDto refreshMindmap(String repoUrl, String prompt, String au
log.info("์ƒˆ๋กœ๊ณ ์นจ ์™„๋ฃŒ - ๋ณ€๊ฒฝ ํŒŒ์ผ: {}, ๋ถ„์„ ๋””๋ ‰ํ„ฐ๋ฆฌ: {}",
refreshResult.getChanged_files(), refreshResult.getDirs_analyzed());

// Step 2: ์—…๋ฐ์ดํŠธ๋œ ๊ทธ๋ž˜ํ”„ ์กฐํšŒ
MindmapGraphDto graphData = getGraph(mapId, authorizationHeader);

// Step 3: ์ €์žฅ์†Œ ์ •๋ณด ์กฐํšŒ
// Step 2: ์ €์žฅ์†Œ ์ •๋ณด ์กฐํšŒ
RepoInfoResponse repoInfo = getRepoInfo(mapId, authorizationHeader);

// ์ƒˆ๋กœ๊ณ ์นจ ๊ฒฐ๊ณผ๋ฅผ DTO๋กœ ๋ณ€ํ™˜
return buildRefreshResultDto(mapId, refreshResult, graphData, repoInfo);
return buildRefreshResultDto(repoInfo);

} catch (Exception e) {
log.error("๋งˆ์ธ๋“œ๋งต ์ƒˆ๋กœ๊ณ ์นจ ์‹คํŒจ: {}", e.getMessage(), e);
Expand Down Expand Up @@ -202,7 +194,9 @@ public RefreshResponse refreshLatest(String mapId, String prompt, String authHea
/**
* ArangoDB์—์„œ repo_url ๊ธฐ๋ฐ˜์œผ๋กœ ๋งˆ์ธ๋“œ๋งต ๋ฐ์ดํ„ฐ๋ฅผ ์‚ญ์ œ
*/
public void deleteMindmapData(String mapId, String authorizationHeader) {
public void deleteMindmapData(String repoUrl, String authorizationHeader) {
String mapId = extractMapId(repoUrl);

webClient.delete()
.uri(uriBuilder -> uriBuilder
.path("/mindmap/{mapId}")
Expand All @@ -225,59 +219,25 @@ private String extractMapId(String repoUrl) {
}

private AnalysisResultDto buildAnalysisResultDto(
String mapId,
AnalyzeResponse analyzeResult,
MindmapGraphDto graphData,
RepoInfoResponse repoInfo
) {
// ๊ทธ๋ž˜ํ”„ ๋ฐ์ดํ„ฐ๋ฅผ JSON ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜
String mapDataJson = convertGraphToJson(graphData);

// AI๊ฐ€ ์ƒ์„ฑํ•œ ์ œ๋ชฉ ๋˜๋Š” ๊ธฐ๋ณธ ์ œ๋ชฉ
// TODO: ์ œ๋ชฉ ์ƒ์„ฑ fastapi ๋ฉ”์„œ๋“œ ํ•„์š”
String title = String.format("%s ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ ๋ถ„์„ (๋””๋ ‰ํ„ฐ๋ฆฌ %d๊ฐœ)",
mapId, analyzeResult.getDirs_analyzed());

return AnalysisResultDto.builder()
.defaultBranch(repoInfo.getDefaultBranch())
.lastCommit(repoInfo.getLastCommit())
.title(title)
.errorMessage(null)
.build();
}

private AnalysisResultDto buildRefreshResultDto(
String mapId,
RefreshResponse refreshResult,
MindmapGraphDto graphData,
RepoInfoResponse repoInfo
) {
String mapDataJson = convertGraphToJson(graphData);

// TODO: ์ œ๋ชฉ ์ƒ์„ฑ fastapi ๋ฉ”์„œ๋“œ ํ•„์š”
String title = String.format("%s (๋ณ€๊ฒฝ ํŒŒ์ผ %d๊ฐœ ๋ฐ˜์˜)",
mapId, refreshResult.getChanged_files());

return AnalysisResultDto.builder()
.defaultBranch(repoInfo.getDefaultBranch())
.lastCommit(repoInfo.getLastCommit())
.title(title)
.errorMessage(null)
.build();
}

private String convertGraphToJson(MindmapGraphDto graph) {
// TODO: ObjectMapper ์‚ฌ์šฉํ•˜์—ฌ ์‹ค์ œ JSON ๋ณ€ํ™˜
return String.format(
"{\"nodes\":%d,\"edges\":%d,\"data\":\"%s\"}",
graph.getNodes().size(),
graph.getEdges().size(),
graph.toString()
);
}



// === Response DTOs ===

@Getter
Expand Down Expand Up @@ -315,8 +275,6 @@ public static class RepoInfoResponse {
@JsonProperty("last_commit")
@JsonDeserialize(using = IsoToLocalDateTimeDeserializer.class)
private LocalDateTime lastCommit;


}

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class AnalysisResultDto {
private LocalDateTime lastCommit;

// Mindmap ๊ด€๋ จ ์ •๋ณด
private String title; // ํ”„๋กฌํ”„ํŠธ ๋ฐ mindmap ์ •๋ณด ์š”์•ฝ
private String summary; // ํ”„๋กฌํ”„ํŠธ ์š”์•ฝ
private String errorMessage; // ์‹คํŒจ ์‹œ ์ „๋‹ฌ๋  ์—๋Ÿฌ๋ฉ”์„ธ์ง€
// TODO: FastAPI ์‘๋‹ต์— ๋งž์ถฐ ํ•„๋“œ ์ •์˜
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand Down Expand Up @@ -40,7 +41,7 @@ public ResponseEntity<Void> inviteByEmail(
public ResponseEntity<Page<InvitationResponseDto>> getInvitations(
@PathVariable Long mapId,
@AuthenticationPrincipal CustomUserDetails userDetails,
@PageableDefault(size = 10, sort = "createdAt,desc") Pageable pageable
@PageableDefault(size = 10, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
) {
return ResponseEntity.ok(invitationService.getInvitationsByMindmap(mapId, userDetails.getId(), pageable));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ public ResponseEntity<MindmapCreationResponseDto> createMindmapAsync(
@GetMapping("/{mapId}")
public ResponseEntity<MindmapDetailResponseDto> getMindmap(
@PathVariable Long mapId,
@AuthenticationPrincipal CustomUserDetails userDetails
@AuthenticationPrincipal CustomUserDetails userDetails,
@RequestHeader("Authorization") String authorizationHeader
) {
MindmapDetailResponseDto responseDto = mindmapService.getMindmap(mapId, userDetails.getId());
MindmapDetailResponseDto responseDto = mindmapService.getMindmap(mapId, userDetails.getId(), authorizationHeader);
return ResponseEntity.ok(responseDto);
}

Expand All @@ -80,7 +81,10 @@ public ResponseEntity<MindmapDetailResponseDto> updateMindmapTitle(
@AuthenticationPrincipal CustomUserDetails userDetails,
@RequestBody MindmapTitleUpdateDto request
) {
MindmapDetailResponseDto responseDto = mindmapService.updateMindmapTitle(mapId, userDetails.getId(), request);
MindmapDetailResponseDto responseDto = mindmapService.updateMindmapTitle(
mapId,
userDetails.getId(),
request);
return ResponseEntity.ok(responseDto);
}

Expand Down Expand Up @@ -152,12 +156,12 @@ public ResponseEntity<PromptPreviewResponseDto> analyzePromptPreview(
public ResponseEntity<MindmapDetailResponseDto> applyPromptHistory(
@PathVariable Long mapId,
@AuthenticationPrincipal CustomUserDetails userDetails,
@RequestBody PromptApplyRequestDto request
@RequestBody PromptApplyRequestDto request,
@RequestHeader("Authorization") String authorizationHeader
) {
promptHistoryService.applyPromptHistory(mapId, userDetails.getId(), request);

// TODO: ๋งˆ์ธ๋“œ๋งต ์ •๋ณด ๊ฐฑ์‹  ์š”์ฒญ ํ›„ ์ƒ์„ธ ์กฐํšŒ
MindmapDetailResponseDto responseDto = mindmapService.getMindmap(mapId, userDetails.getId());
MindmapDetailResponseDto responseDto = mindmapService.getMindmap(mapId, userDetails.getId(), authorizationHeader);
return ResponseEntity.ok(responseDto);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
@NoArgsConstructor
public class MindmapCreateRequestDto {
private String repoUrl;
private String prompt;
private String title;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class PromptHistory extends CreatedEntity {
private String prompt;

@Column(length = 50)
private String title; // ๋ถ„์„ ๊ฒฐ๊ณผ ์š”์•ฝ (๊ธฐ๋ก ์ œ๋ชฉ)
private String summary; // ๋ถ„์„ ๊ฒฐ๊ณผ ์š”์•ฝ (๊ธฐ๋ก ์ œ๋ชฉ)

@Builder.Default
@Column(name = "applied", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.teamEWSN.gitdeun.mindmap.mapper;

import com.teamEWSN.gitdeun.mindmap.dto.MindmapDetailResponseDto;
import com.teamEWSN.gitdeun.mindmap.dto.MindmapGraphResponseDto;
import com.teamEWSN.gitdeun.mindmap.dto.MindmapResponseDto;
import com.teamEWSN.gitdeun.mindmap.dto.prompt.PromptHistoryResponseDto;
import com.teamEWSN.gitdeun.mindmap.entity.Mindmap;
Expand Down Expand Up @@ -28,4 +29,11 @@ public interface MindmapMapper {
@Mapping(source = "appliedPromptHistory", target = "appliedPromptHistory")
MindmapDetailResponseDto toDetailResponseDto(Mindmap mindmap);

@Mapping(source = "mindmap.id", target = "mindmapId")
@Mapping(source = "mindmap.promptHistories", target = "promptHistories")
@Mapping(source = "mindmap.appliedPromptHistory", target = "appliedPromptHistory")
@Mapping(source = "graphData", target = "mindmapGraph")
MindmapDetailResponseDto toDetailResponseDto(Mindmap mindmap,
MindmapGraphResponseDto graphData);

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void createMindmap(MindmapCreateRequestDto request, Long userId, String a
log.info("๋งˆ์ธ๋“œ๋งต ์ƒ์„ฑ ์š”์ฒญ ๊ฒ€์ฆ ์‹œ์ž‘ - ์‚ฌ์šฉ์ž: {}", userId);
ValidatedMindmapRequest validatedRequest = requestValidator.validateAndProcess(
request.getRepoUrl(),
request.getPrompt(),
null,
userId
);

Expand All @@ -59,13 +59,13 @@ public void createMindmap(MindmapCreateRequestDto request, Long userId, String a
// prompt๊ฐ€ null์ด๋ฉด ๊ธฐ๋ณธ ๋ถ„์„, ์žˆ์œผ๋ฉด ํ”„๋กฌํ”„ํŠธ ํฌํ•จ ๋ถ„์„
return fastApiClient.analyzeResult(
normalizedUrl,
processedPrompt,
null,
authHeader
);
}).thenApply(analysisResult -> {
// 2. ๋ถ„์„ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ DB์— ๋งˆ์ธ๋“œ๋งต ์ •๋ณด ์ €์žฅ (ํŠธ๋žœ์žญ์…˜)
log.info("๋ถ„์„ ์™„๋ฃŒ, DB ์ €์žฅ ์‹œ์ž‘ - ์‚ฌ์šฉ์ž: {}", userId);
return mindmapService.saveMindmapFromAnalysis(analysisResult, normalizedUrl, processedPrompt, userId);
return mindmapService.saveMindmapFromAnalysis(analysisResult, normalizedUrl, request.getTitle(), userId);
}).whenComplete((mindmap, throwable) -> {
// 3. ์ตœ์ข… ๊ฒฐ๊ณผ์— ๋”ฐ๋ผ ์•Œ๋ฆผ ์ „์†ก
if (throwable != null) {
Expand Down Expand Up @@ -96,7 +96,7 @@ public void refreshMindmap(Long mapId, String authHeader) {
);

// ๋ถ„์„ ๊ฒฐ๊ณผ๋ฅผ DB์— ์—…๋ฐ์ดํŠธ (ํŠธ๋žœ์žญ์…˜)
mindmapService.updateMindmapFromAnalysis(mapId, analysisResult);
mindmapService.updateMindmapFromAnalysis(mapId,authHeader, analysisResult);
log.info("๋น„๋™๊ธฐ ์ƒˆ๋กœ๊ณ ์นจ ์„ฑ๊ณต - ๋งˆ์ธ๋“œ๋งต ID: {}", mapId);

} catch (Exception e) {
Expand Down
Loading