-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from tukcomCD2024/Dev-backend
Dev backend
- Loading branch information
Showing
17 changed files
with
209 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...ain/java/com/rollthedice/backend/domain/debate/exception/DebateRoomNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.rollthedice.backend.domain.debate.exception; | ||
|
||
import com.rollthedice.backend.global.error.exception.BusinessException; | ||
import com.rollthedice.backend.global.error.ErrorCode; | ||
|
||
public class DebateRoomNotFoundException extends BusinessException { | ||
public DebateRoomNotFoundException() { | ||
super(ErrorCode.DEBATE_ROOM_NOT_FOUND_ERROR); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...rc/main/java/com/rollthedice/backend/domain/member/exception/MemberNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.rollthedice.backend.domain.member.exception; | ||
|
||
import com.rollthedice.backend.global.error.ErrorCode; | ||
import com.rollthedice.backend.global.error.exception.BusinessException; | ||
|
||
public class MemberNotFoundException extends BusinessException { | ||
public MemberNotFoundException() { | ||
super(ErrorCode.MEMBER_NOT_FOUND_ERROR); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 28 additions & 2 deletions
30
backend/core/src/main/java/com/rollthedice/backend/domain/news/api/NewsApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,49 @@ | ||
package com.rollthedice.backend.domain.news.api; | ||
|
||
import com.rollthedice.backend.domain.news.dto.response.NewsDetailResponse; | ||
import com.rollthedice.backend.domain.news.dto.response.NewsResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.enums.ParameterIn; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import java.util.List; | ||
|
||
public interface NewsApi { | ||
@Operation( | ||
summary = "요약 뉴스 조회", | ||
summary = "요약 뉴스 전체 조회", | ||
description = "요약 뉴스를 페이지로 나누어 조회합니다.", | ||
security = {@SecurityRequirement(name = "access_token")}, | ||
tags = {"news"} | ||
) | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "OK" | ||
description = "요청에 성공하였습니다." | ||
) | ||
List<NewsResponse> getNews(Pageable pageable); | ||
|
||
@Operation( | ||
summary = "요약 뉴스 상세 조회", | ||
description = "하나의 요약 뉴스를 상세 조회합니다.", | ||
security = {@SecurityRequirement(name = "access_token")}, | ||
tags = {"news"} | ||
) | ||
@ApiResponses(value = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "요청에 성공하였습니다." | ||
), | ||
@ApiResponse( | ||
responseCode = "404", | ||
description = "뉴스를 찾지 못했습니다." | ||
) | ||
}) | ||
NewsDetailResponse getDetailNews( | ||
@Parameter(in = ParameterIn.PATH, description = "뉴스 ID", required = true) | ||
Long newsId | ||
); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...re/src/main/java/com/rollthedice/backend/domain/news/dto/response/NewsDetailResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.rollthedice.backend.domain.news.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class NewsDetailResponse { | ||
private Long id; | ||
private String url; | ||
private String title; | ||
private String content; | ||
private String thumbnailUrl; | ||
private String postDate; | ||
private Boolean isBookmarked; | ||
} |
12 changes: 12 additions & 0 deletions
12
...re/src/main/java/com/rollthedice/backend/domain/news/exception/NewsNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.rollthedice.backend.domain.news.exception; | ||
|
||
import com.rollthedice.backend.global.error.exception.BusinessException; | ||
import com.rollthedice.backend.global.error.ErrorCode; | ||
|
||
public class NewsNotFoundException extends BusinessException { | ||
|
||
public NewsNotFoundException() { | ||
super(ErrorCode.NEWS_NOT_FOUND_ERROR); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
backend/core/src/main/java/com/rollthedice/backend/global/error/ErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.rollthedice.backend.global.error; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum ErrorCode { | ||
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "내부 서버에 오류가 발생했습니다."), | ||
CLOVA_API_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "CLOVA API 호출에 실패했습니다."), | ||
|
||
// MEMBER | ||
MEMBER_NOT_FOUND_ERROR(HttpStatus.NOT_FOUND, "회원 정보를 찾지 못했습니다." ), | ||
|
||
// NEWS | ||
NEWS_NOT_FOUND_ERROR(HttpStatus.NOT_FOUND, "뉴스를 찾지 못했습니다."), | ||
|
||
// DEBATE | ||
DEBATE_ROOM_NOT_FOUND_ERROR(HttpStatus.NOT_FOUND, "토론방을 찾지 못했습니다."); | ||
|
||
|
||
private final HttpStatus status; | ||
private final String message; | ||
} |
24 changes: 24 additions & 0 deletions
24
backend/core/src/main/java/com/rollthedice/backend/global/error/ErrorResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.rollthedice.backend.global.error; | ||
|
||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
import java.util.Collections; | ||
|
||
@Getter | ||
public class ErrorResponse { | ||
private HttpStatus status; | ||
private String message; | ||
|
||
public ErrorResponse(HttpStatus status, String message) { | ||
this.status = status; | ||
this.message = message; | ||
} | ||
|
||
public static ErrorResponse create(final ErrorCode errorCode) { | ||
return new ErrorResponse( | ||
errorCode.getStatus(), | ||
errorCode.getMessage() | ||
); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
backend/core/src/main/java/com/rollthedice/backend/global/error/GlobalExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.rollthedice.backend.global.error; | ||
|
||
import com.rollthedice.backend.global.error.exception.BusinessException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@Slf4j | ||
@RestControllerAdvice | ||
public class GlobalExceptionHandler { | ||
|
||
@ExceptionHandler(BusinessException.class) | ||
protected ResponseEntity<ErrorResponse> handleRuntimeException(BusinessException e) { | ||
final ErrorCode errorCode = e.getErrorCode(); | ||
log.warn(e.getMessage()); | ||
|
||
return ResponseEntity | ||
.status(errorCode.getStatus()) | ||
.body(new ErrorResponse(errorCode.getStatus(), | ||
errorCode.getMessage())); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
.../core/src/main/java/com/rollthedice/backend/global/error/exception/BusinessException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.rollthedice.backend.global.error.exception; | ||
|
||
import com.rollthedice.backend.global.error.ErrorCode; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class BusinessException extends RuntimeException{ | ||
private final ErrorCode errorCode; | ||
|
||
public BusinessException(ErrorCode errorCode) { | ||
super(errorCode.getMessage()); | ||
this.errorCode = errorCode; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...re/src/main/java/com/rollthedice/backend/global/error/exception/ExternalApiException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.rollthedice.backend.global.error.exception; | ||
|
||
import com.rollthedice.backend.global.error.ErrorCode; | ||
import lombok.Getter; | ||
|
||
import java.io.IOException; | ||
|
||
@Getter | ||
public class ExternalApiException extends RuntimeException { | ||
|
||
private final ErrorCode errorCode; | ||
|
||
public ExternalApiException(ErrorCode errorCode) { | ||
this.errorCode = errorCode; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters