Skip to content

Commit 64b237b

Browse files
committed
feat(be): 미커밋 로직
1 parent fd99201 commit 64b237b

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

backend/src/main/java/com/backend/domain/analysis/controller/AnalysisController.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,22 @@ public ResponseEntity<ApiResponse<HistoryResponseDto>> getAnalysisByRepositories
7979
@PathVariable("repositoriesId") Long repoId,
8080
HttpServletRequest httpRequest
8181
){
82-
Long jwtUserId = jwtUtil.getUserId(httpRequest);
83-
if (!jwtUserId.equals(userId)) {
84-
throw new BusinessException(ErrorCode.FORBIDDEN);
85-
}
8682

8783
// 1. Repository 정보 조회
8884
Repositories repository = repositoryService.findById(repoId)
8985
.orElseThrow(() -> new BusinessException(ErrorCode.GITHUB_REPO_NOT_FOUND));
9086

9187
RepositoryResponse repositoryResponse = new RepositoryResponse(repository);
9288

89+
// 권한 검증
90+
Long jwtUserId = jwtUtil.getUserId(httpRequest);
91+
boolean isOwner = jwtUserId.equals(userId);
92+
boolean isPublic = repository.isPublicRepository();
93+
94+
if (!isOwner && !isPublic) {
95+
throw new BusinessException(ErrorCode.FORBIDDEN);
96+
}
97+
9398
// 2. 분석 결과 목록 조회 (최신순 정렬)
9499
List<AnalysisResult> analysisResults =
95100
analysisService.getAnalysisResultList(repoId);
@@ -118,17 +123,22 @@ public ResponseEntity<ApiResponse<AnalysisResultResponseDto>> getAnalysisDetail(
118123
@PathVariable Long analysisId,
119124
HttpServletRequest httpRequest
120125
) {
121-
Long jwtUserId = jwtUtil.getUserId(httpRequest);
122-
if (!jwtUserId.equals(userId)) {
123-
throw new BusinessException(ErrorCode.FORBIDDEN);
124-
}
125-
126126
// 분석 결과 조회
127127
AnalysisResult analysisResult = analysisService.getAnalysisById(analysisId);
128128

129129
if (!analysisResult.getRepositories().getId().equals(repositoryId)) {
130130
throw new BusinessException(ErrorCode.INVALID_INPUT_VALUE);
131131
}
132+
133+
// 권한 검증
134+
Long jwtUserId = jwtUtil.getUserId(httpRequest);
135+
Repositories repository = analysisResult.getRepositories();
136+
boolean isOwner = jwtUserId.equals(userId);
137+
boolean isPublic = repository.isPublicRepository();
138+
139+
if (!isOwner && !isPublic) {
140+
throw new BusinessException(ErrorCode.FORBIDDEN);
141+
}
132142

133143
AnalysisResultResponseDto response =
134144
new AnalysisResultResponseDto(analysisResult, analysisResult.getScore());
@@ -163,7 +173,7 @@ public ResponseEntity<ApiResponse<Void>> deleteAnalysisResult(
163173
throw new BusinessException(ErrorCode.FORBIDDEN);
164174
}
165175

166-
analysisService.deleteAnalysisResult(analysisId, userId);
176+
analysisService.deleteAnalysisResult(analysisId, repositoryId, userId);
167177
return ResponseEntity.ok(ApiResponse.success());
168178
}
169179

backend/src/main/java/com/backend/domain/analysis/service/AnalysisService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ public void delete(Long repositoriesId, Long userId){
135135

136136
// 특정 분석 결과 삭제
137137
@Transactional
138-
public void deleteAnalysisResult(Long analysisResultId, Long memberId) {
138+
public void deleteAnalysisResult(Long analysisResultId, Long repositoryId, Long memberId) {
139139
if (analysisResultId == null) {
140140
throw new BusinessException(ErrorCode.INVALID_INPUT_VALUE);
141141
}
142142

143143
AnalysisResult analysisResult = analysisResultRepository.findById(analysisResultId)
144144
.orElseThrow(() -> new BusinessException(ErrorCode.ANALYSIS_NOT_FOUND));
145145

146-
if (!analysisResult.getRepositories().getId().equals(analysisResultId)) {
146+
if (!analysisResult.getRepositories().getId().equals(repositoryId)) {
147147
throw new BusinessException(ErrorCode.INVALID_INPUT_VALUE);
148148
}
149149

backend/src/main/java/com/backend/domain/community/dto/response/CommunityResponseDto.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public record CommunityResponseDto(
1818
List<String> language,
1919
int totalScore,
2020
LocalDateTime createDate,
21-
boolean vewingStatus
21+
boolean vewingStatus,
22+
String htmlUrl
2223
) {
2324
public CommunityResponseDto(Repositories repositories, AnalysisResult analysis, Score score) {
2425
this(
@@ -33,7 +34,8 @@ public CommunityResponseDto(Repositories repositories, AnalysisResult analysis,
3334
.collect(Collectors.toList()),
3435
score.getTotalScore(),
3536
analysis.getCreateDate(),
36-
repositories.isPublicRepository()
37+
repositories.isPublicRepository(),
38+
repositories.getHtmlUrl()
3739
);
3840
}
3941
}

backend/src/main/java/com/backend/domain/repository/dto/response/RepositoryResponse.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public record RepositoryResponse(
1818
boolean publicRepository,
1919
String mainBranch,
2020
List<String> languages,
21-
LocalDateTime createDate
21+
LocalDateTime createDate,
22+
Long ownerId
2223
) {
2324
public RepositoryResponse(Repositories repositories) {
2425
this(
@@ -31,7 +32,8 @@ public RepositoryResponse(Repositories repositories) {
3132
repositories.getLanguages().stream()
3233
.map(lang -> lang.getLanguage().name())
3334
.collect(Collectors.toList()),
34-
repositories.getCreateDate()
35+
repositories.getCreateDate(),
36+
repositories.getUser().getId()
3537
);
3638
}
3739
}

0 commit comments

Comments
 (0)