diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/bookmark/api/BookmarkApi.java b/backend/core/src/main/java/com/rollthedice/backend/domain/bookmark/api/BookmarkApi.java index d9673019..3b0e9760 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/bookmark/api/BookmarkApi.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/bookmark/api/BookmarkApi.java @@ -2,41 +2,42 @@ import com.rollthedice.backend.domain.bookmark.dto.response.BookmarkResponse; import com.rollthedice.backend.domain.news.dto.response.NewsResponse; +import com.rollthedice.backend.global.common.response.SuccessResponse; 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.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.data.domain.Pageable; import java.util.List; +@Tag(name = "Bookmark") public interface BookmarkApi { @Operation( summary = "북마크 전체 조회", description = "회원이 북마크한 뉴스를 페이지로 나누어 조회합니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"북마크"} + security = {@SecurityRequirement(name = "access_token")} ) @ApiResponse( responseCode = "200", - description = "OK" + description = "북마크 전체 조회를 성공했습니다." ) - List getAllBookmarkedNews( + SuccessResponse> getAllBookmarkedNews( Pageable pageable ); @Operation( summary = "뉴스 북마크 여부 조회", description = "로그인한 회원이 해당 뉴스를 북마크 했는지 여부를 조회합니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"북마크"} + security = {@SecurityRequirement(name = "access_token")} ) @ApiResponse( responseCode = "200", - description = "OK" + description = "뉴스가 북마크 여부 조회를 성공했습니다." ) - BookmarkResponse getIsBookmarked( + SuccessResponse getIsBookmarked( @Parameter(in = ParameterIn.PATH, description = "뉴스 ID", required = true) Long newsId ); @@ -45,14 +46,13 @@ BookmarkResponse getIsBookmarked( @Operation( summary = "북마크 저장", description = "뉴스에 대하여 북마크로 저장합니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"북마크"} + security = {@SecurityRequirement(name = "access_token")} ) @ApiResponse( responseCode = "201", - description = "Created" + description = "북마크 저장에 성공했습니다." ) - void saveBookmark( + SuccessResponse saveBookmark( @Parameter(in = ParameterIn.PATH, description = "뉴스 ID", required = true) Long newsId ); @@ -60,14 +60,13 @@ void saveBookmark( @Operation( summary = "북마크 삭제", description = "저장된 북마크를 해제합니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"북마크"} + security = {@SecurityRequirement(name = "access_token")} ) @ApiResponse( responseCode = "204", - description = "No Content" + description = "북마크 삭제에 성공했습니다." ) - void deleteBookmark( + SuccessResponse deleteBookmark( @Parameter(in = ParameterIn.PATH, description = "뉴스 ID", required = true) Long newsId ); diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/bookmark/api/BookmarkController.java b/backend/core/src/main/java/com/rollthedice/backend/domain/bookmark/api/BookmarkController.java index 23dd1b85..d9556f93 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/bookmark/api/BookmarkController.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/bookmark/api/BookmarkController.java @@ -3,6 +3,7 @@ import com.rollthedice.backend.domain.bookmark.dto.response.BookmarkResponse; import com.rollthedice.backend.domain.bookmark.service.BookmarkService; import com.rollthedice.backend.domain.news.dto.response.NewsResponse; +import com.rollthedice.backend.global.common.response.SuccessResponse; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -10,6 +11,8 @@ import java.util.List; +import static com.rollthedice.backend.global.common.response.SuccessCode.*; + @RestController @RequiredArgsConstructor @RequestMapping("bookmarks") @@ -19,28 +22,32 @@ public class BookmarkController implements BookmarkApi { @ResponseStatus(HttpStatus.OK) @GetMapping("") @Override - public List getAllBookmarkedNews(final Pageable pageable) { - return bookmarkService.getAllBookmarkedNews(pageable); + public SuccessResponse> getAllBookmarkedNews(final Pageable pageable) { + List response = bookmarkService.getAllBookmarkedNews(pageable); + return SuccessResponse.of(GET_ALL_BOOKMARK_SUCCESS, response); } @ResponseStatus(HttpStatus.OK) @GetMapping("/{newsId}") @Override - public BookmarkResponse getIsBookmarked(@PathVariable final Long newsId) { - return bookmarkService.getIsBookmarked(newsId); + public SuccessResponse getIsBookmarked(@PathVariable final Long newsId) { + BookmarkResponse response = bookmarkService.getIsBookmarked(newsId); + return SuccessResponse.of(GET_IS_BOOKMARKED_SUCCESS, response); } @ResponseStatus(HttpStatus.CREATED) @PostMapping("/{newsId}") @Override - public void saveBookmark(@PathVariable final Long newsId) { + public SuccessResponse saveBookmark(@PathVariable final Long newsId) { bookmarkService.saveBookmark(newsId); + return SuccessResponse.of(CREATE_BOOKMARK_SUCCESS); } @ResponseStatus(HttpStatus.NO_CONTENT) @DeleteMapping("/{newsId}") @Override - public void deleteBookmark(@PathVariable final Long newsId) { + public SuccessResponse deleteBookmark(@PathVariable final Long newsId) { bookmarkService.deleteBookmark(newsId); + return SuccessResponse.of(DELETE_BOOKMARK_SUCCESS); } } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/bookmark/entity/Bookmark.java b/backend/core/src/main/java/com/rollthedice/backend/domain/bookmark/entity/Bookmark.java index 6af1d02f..f3cb925a 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/bookmark/entity/Bookmark.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/bookmark/entity/Bookmark.java @@ -2,7 +2,7 @@ import com.rollthedice.backend.domain.member.entity.Member; import com.rollthedice.backend.domain.news.entity.News; -import com.rollthedice.backend.global.config.BaseTimeEntity; +import com.rollthedice.backend.global.common.BaseTimeEntity; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Builder; diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateApi.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateApi.java index f70a4d3b..8c808f47 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateApi.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateApi.java @@ -6,69 +6,67 @@ import com.rollthedice.backend.domain.debate.dto.response.DebateRoomResponse; import com.rollthedice.backend.domain.debate.dto.response.DebateRoomSaveResponse; import com.rollthedice.backend.domain.debate.dto.response.DebateSummaryResponse; +import com.rollthedice.backend.global.common.response.SuccessResponse; 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 io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.data.domain.Pageable; import org.springframework.web.bind.annotation.RequestBody; import java.util.List; - +@Tag(name = "Debate") public interface DebateApi { @Operation( summary = "토론방 생성", description = "주제가 선택된 토론방을 생성합니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"토론방"} + security = {@SecurityRequirement(name = "access_token")} ) @ApiResponse( responseCode = "201", - description = "Created" + description = "토론방 생성에 성공했습니다." ) - DebateRoomSaveResponse saveDebateRoom(@RequestBody DebateRoomRequest request); + SuccessResponse saveDebateRoom(@RequestBody DebateRoomRequest request); @Operation( summary = "토론방 전체 조회", description = "회원의 토론방을 페이지로 나누어 조회합니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"토론방"} + security = {@SecurityRequirement(name = "access_token")} ) @ApiResponse( responseCode = "200", - description = "요청에 성공하였습니다." + description = "토론방 전체 조회에 성공했습니다" ) - List getDebateRooms(Pageable pageable); + SuccessResponse> getDebateRooms(Pageable pageable); @Operation( summary = "토론방 삭제", description = "토론방을 삭제합니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"토론방"} + security = {@SecurityRequirement(name = "access_token")} ) @ApiResponse( responseCode = "204", - description = "토론방 삭제에 성공하였으며, 응답값은 없습니다." + description = "토론방 삭제에 성공했습니다." ) - void deleteDebateRoom(@Parameter(in = ParameterIn.PATH, description = "토론방 ID", required = true) + SuccessResponse deleteDebateRoom(@Parameter(in = ParameterIn.PATH, description = "토론방 ID", required = true) Long roomId ); @Operation( summary = "[인간] 토론 메세지 저장", description = "사용자가 보낸 토론 메세지를 저장합니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"토론 메세지"} + security = {@SecurityRequirement(name = "access_token")} ) @ApiResponse( responseCode = "201", - description = "Created" + description = "사용자가 보낸 토론 메세지 저장에 성공했습니다." ) - void saveHumanDebateMessage( + SuccessResponse saveHumanDebateMessage( @Parameter(in = ParameterIn.PATH, description = "토론방 ID", required = true) Long roomId, @@ -78,14 +76,13 @@ void saveHumanDebateMessage( @Operation( summary = "[AI] 토론 메세지 저장", description = "ChatGPT OPENAI가 보낸 토론 메세지를 저장합니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"토론 메세지"} + security = {@SecurityRequirement(name = "access_token")} ) @ApiResponse( responseCode = "201", - description = "Created" + description = "AI가 보낸 토론 메세지 저장에 성공했습니다." ) - void saveAIDebateMessage( + SuccessResponse saveAIDebateMessage( @Parameter(in = ParameterIn.PATH, description = "토론방 ID", required = true) Long roomId, @@ -95,20 +92,19 @@ void saveAIDebateMessage( @Operation( summary = "토론 종료", description = "토론을 종료합니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"토론방"} + security = {@SecurityRequirement(name = "access_token")} ) @ApiResponses(value = { @ApiResponse( responseCode = "204", - description = "요청에 성공하였으며 응답값은 없습니다." + description = "토론 종료에 성공했습니다." ), @ApiResponse( responseCode = "404", description = "토론방을 찾지 못했습니다." ) }) - void finishDebate( + SuccessResponse finishDebate( @Parameter(in = ParameterIn.PATH, description = "토론방 ID", required = true) Long roomId ); @@ -116,14 +112,13 @@ void finishDebate( @Operation( summary = "토론 메세지 조회", description = "토론방의 토론 메세지 이력을 조회합니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"토론 메세지"} + security = {@SecurityRequirement(name = "access_token")} ) @ApiResponse( responseCode = "200", - description = "요청에 성공하였습니다." + description = "토론 메세지 조회에 성공했습니다." ) - List getDebateMessages( + SuccessResponse> getDebateMessages( @Parameter(in = ParameterIn.PATH, description = "토론방 ID", required = true) Long roomId ); @@ -131,20 +126,19 @@ List getDebateMessages( @Operation( summary = "토론 요약", description = "토론방의 토론 메세지들을 요약합니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"토론방"} + security = {@SecurityRequirement(name = "access_token")} ) @ApiResponses(value = { @ApiResponse( responseCode = "201", - description = "토론 요약이 성공하였습니다." + description = "토론 요약에 성공했습니다." ), @ApiResponse( responseCode = "404", description = "토론방을 찾지 못했습니다." ) }) - DebateSummaryResponse summarizeDebate( + SuccessResponse summarizeDebate( @Parameter(in = ParameterIn.PATH, description = "토론방 ID", required = true) Long roomId ); @@ -152,22 +146,20 @@ DebateSummaryResponse summarizeDebate( @Operation( summary = "토론 요약 조회", description = "토론 요약 내용을 조회합니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"토론방"} + security = {@SecurityRequirement(name = "access_token")} ) @ApiResponses(value = { @ApiResponse( responseCode = "200", - description = "요청에 성공하였습니다." + description = "토론 요약 조회에 성공했습니다." ), @ApiResponse( responseCode = "404", description = "토론방을 찾지 못했습니다." ) }) - DebateSummaryResponse getSummarizedDebate( + SuccessResponse getSummarizedDebate( @Parameter(in = ParameterIn.PATH, description = "토론방 ID", required = true) Long roomId ); - } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java index 9c5863aa..e43c256e 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java @@ -8,6 +8,7 @@ import com.rollthedice.backend.domain.debate.dto.response.DebateSummaryResponse; import com.rollthedice.backend.domain.debate.service.DebateMessageService; import com.rollthedice.backend.domain.debate.service.DebateRoomService; +import com.rollthedice.backend.global.common.response.SuccessResponse; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; @@ -16,6 +17,8 @@ import java.util.List; +import static com.rollthedice.backend.global.common.response.SuccessCode.*; + @RestController @RequiredArgsConstructor @RequestMapping("debates") @@ -26,62 +29,71 @@ public class DebateController implements DebateApi { @ResponseStatus(HttpStatus.CREATED) @PostMapping("") @Override - public DebateRoomSaveResponse saveDebateRoom(@RequestBody @Valid final DebateRoomRequest request) { - return debateRoomService.saveDebateRoom(request); + public SuccessResponse saveDebateRoom(@RequestBody @Valid final DebateRoomRequest request) { + DebateRoomSaveResponse response = debateRoomService.saveDebateRoom(request); + return SuccessResponse.of(CREATE_DEBATE_ROOM_SUCCESS, response); } @ResponseStatus(HttpStatus.OK) @GetMapping("") @Override - public List getDebateRooms(final Pageable pageable) { - return debateRoomService.getDebateRooms(pageable); + public SuccessResponse> getDebateRooms(final Pageable pageable) { + List response = debateRoomService.getDebateRooms(pageable); + return SuccessResponse.of(GET_ALL_DEBATE_ROOM_SUCCESS, response); } @ResponseStatus(HttpStatus.NO_CONTENT) @DeleteMapping("/{roomId}") @Override - public void deleteDebateRoom(@PathVariable final Long roomId) { + public SuccessResponse deleteDebateRoom(@PathVariable final Long roomId) { debateRoomService.deleteDebateRoom(roomId); + return SuccessResponse.of(DELETE_DEBATE_ROOM_SUCCESS); } @ResponseStatus(HttpStatus.CREATED) @PostMapping("/{roomId}/human") @Override - public void saveHumanDebateMessage(@PathVariable final Long roomId, @RequestBody final DebateMessageRequest request) { + public SuccessResponse saveHumanDebateMessage(@PathVariable final Long roomId, @RequestBody final DebateMessageRequest request) { debateMessageService.saveHumanDebateMessage(roomId, request); + return SuccessResponse.of(CREATE_HUMAN_DEBATE_MESSAGE_SUCCESS); } @ResponseStatus(HttpStatus.CREATED) @PostMapping("/{roomId}/ai") @Override - public void saveAIDebateMessage(@PathVariable final Long roomId, @RequestBody final DebateMessageRequest request) { + public SuccessResponse saveAIDebateMessage(@PathVariable final Long roomId, @RequestBody final DebateMessageRequest request) { debateMessageService.saveAIDebateMessage(roomId, request); + return SuccessResponse.of(CREATE_AI_DEBATE_MESSAGE_SUCCESS); } @ResponseStatus(HttpStatus.NO_CONTENT) @PatchMapping("/{roomId}") - public void finishDebate(@PathVariable final Long roomId) { + public SuccessResponse finishDebate(@PathVariable final Long roomId) { debateRoomService.closeDebate(roomId); + return SuccessResponse.of(UPDATE_DEBATE_ROOM_IS_CLOSED_SUCCESS); } - @ResponseStatus(HttpStatus.CREATED) + @ResponseStatus(HttpStatus.OK) @GetMapping("/{roomId}") @Override - public List getDebateMessages(@PathVariable final Long roomId) { - return debateMessageService.getDebateMessages(roomId); + public SuccessResponse> getDebateMessages(@PathVariable final Long roomId) { + List response = debateMessageService.getDebateMessages(roomId); + return SuccessResponse.of(GET_DEBATE_MESSAGES_SUCCESS, response); } - @ResponseStatus(HttpStatus.OK) + @ResponseStatus(HttpStatus.CREATED) @PostMapping("/summary/{roomId}") @Override - public DebateSummaryResponse summarizeDebate(@PathVariable final Long roomId) { - return debateRoomService.summaryDebate(roomId); + public SuccessResponse summarizeDebate(@PathVariable final Long roomId) { + DebateSummaryResponse response = debateRoomService.summaryDebate(roomId); + return SuccessResponse.of(CREATE_DEBATE_SUMMARY_SUCCESS, response); } @ResponseStatus(HttpStatus.OK) @GetMapping("/summary/{roomId}") @Override - public DebateSummaryResponse getSummarizedDebate(@PathVariable final Long roomId) { - return debateRoomService.getSummarizedDebate(roomId); + public SuccessResponse getSummarizedDebate(@PathVariable final Long roomId) { + DebateSummaryResponse response = debateRoomService.getSummarizedDebate(roomId); + return SuccessResponse.of(GET_DEBATE_MESSAGES_SUCCESS, response); } } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateMessage.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateMessage.java index 91221c01..162926df 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateMessage.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateMessage.java @@ -1,7 +1,6 @@ package com.rollthedice.backend.domain.debate.entity; -import com.rollthedice.backend.domain.member.entity.Member; -import com.rollthedice.backend.global.config.BaseTimeEntity; +import com.rollthedice.backend.global.common.BaseTimeEntity; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Builder; @@ -31,5 +30,4 @@ public DebateMessage(String message, SenderType senderType, DebateRoom debateRoo this.senderType = senderType; this.debateRoom = debateRoom; } - } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateRoom.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateRoom.java index 566463e4..8ffeb0f4 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateRoom.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/entity/DebateRoom.java @@ -1,7 +1,7 @@ package com.rollthedice.backend.domain.debate.entity; import com.rollthedice.backend.domain.member.entity.Member; -import com.rollthedice.backend.global.config.BaseTimeEntity; +import com.rollthedice.backend.global.common.BaseTimeEntity; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Builder; diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/ClovaSummary.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/ClovaSummary.java index 6f1b71d7..c4a2f3c9 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/ClovaSummary.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/ClovaSummary.java @@ -36,15 +36,12 @@ public class ClovaSummary { private String CLIENT_ID; public String summaryDebate(String messages) { - log.info("요약할 메세지: {}" ,messages); try { URL url = new URL(API_URL); HttpURLConnection connection = createRequestHeader(url); createRequestBody(connection, messages); - log.info("정상1"); StringBuilder response = getResponse(connection); - log.info("정상2"); return parseResponse(response); } catch (Exception e) { e.printStackTrace(); diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/member/api/MemberApi.java b/backend/core/src/main/java/com/rollthedice/backend/domain/member/api/MemberApi.java index 3f87ce34..3ebcc3ee 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/member/api/MemberApi.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/member/api/MemberApi.java @@ -1,20 +1,22 @@ package com.rollthedice.backend.domain.member.api; import com.rollthedice.backend.domain.member.dto.response.MemberResponse; +import com.rollthedice.backend.global.common.response.SuccessResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +@Tag(name = "Member") public interface MemberApi { @Operation( summary = "회원 정보 조회", description = "회원 정보를 조회합니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"member"} + security = {@SecurityRequirement(name = "access_token")} ) @ApiResponse( responseCode = "200", - description = "OK" + description = "사용자 정보 조회에 성공했습니다." ) - MemberResponse getMemberInfo(); + SuccessResponse getMemberInfo(); } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/member/api/MemberController.java b/backend/core/src/main/java/com/rollthedice/backend/domain/member/api/MemberController.java index 63411b19..d625e588 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/member/api/MemberController.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/member/api/MemberController.java @@ -1,15 +1,14 @@ package com.rollthedice.backend.domain.member.api; -import com.rollthedice.backend.domain.member.dto.MemberServiceDto; -import com.rollthedice.backend.domain.member.dto.MemberUpdateDto; import com.rollthedice.backend.domain.member.dto.response.MemberResponse; import com.rollthedice.backend.domain.member.service.MemberService; -import com.rollthedice.backend.global.annotation.LoginMemberEmail; +import com.rollthedice.backend.global.common.response.SuccessResponse; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import static com.rollthedice.backend.global.common.response.SuccessCode.GET_MEMBER_INFO_SUCCESS; + @RestController @RequiredArgsConstructor @RequestMapping("members") @@ -19,7 +18,8 @@ public class MemberController implements MemberApi{ @ResponseStatus(HttpStatus.OK) @GetMapping("") @Override - public MemberResponse getMemberInfo() { - return memberService.getMemberInfo(); + public SuccessResponse getMemberInfo() { + MemberResponse response = memberService.getMemberInfo(); + return SuccessResponse.of(GET_MEMBER_INFO_SUCCESS, response); } } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/member/entity/Member.java b/backend/core/src/main/java/com/rollthedice/backend/domain/member/entity/Member.java index 6395057d..390f7490 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/member/entity/Member.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/member/entity/Member.java @@ -1,7 +1,7 @@ package com.rollthedice.backend.domain.member.entity; import com.rollthedice.backend.domain.member.dto.MemberServiceDto; -import com.rollthedice.backend.global.config.BaseTimeEntity; +import com.rollthedice.backend.global.common.BaseTimeEntity; import jakarta.persistence.*; import lombok.*; diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/news/api/NewsApi.java b/backend/core/src/main/java/com/rollthedice/backend/domain/news/api/NewsApi.java index b6d19e4f..ccc2d8c8 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/news/api/NewsApi.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/news/api/NewsApi.java @@ -3,61 +3,48 @@ import com.rollthedice.backend.domain.news.dto.response.NewsDetailResponse; import com.rollthedice.backend.domain.news.dto.response.NewsResponse; import com.rollthedice.backend.domain.news.dto.response.ReadNewsResponse; +import com.rollthedice.backend.global.common.response.SuccessResponse; 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 io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.data.domain.Pageable; import java.util.List; +@Tag(name = "Tag") public interface NewsApi { @Operation( summary = "요약 뉴스 전체 조회", description = "요약 뉴스를 페이지로 나누어 조회합니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"news"} + security = {@SecurityRequirement(name = "access_token")} ) @ApiResponse( responseCode = "200", - description = "요청에 성공하였습니다." + description = "전체 뉴스 조회에 성공했습니다." ) - List getNews(Pageable pageable); + SuccessResponse> getNews(Pageable pageable); @Operation( summary = "요약 뉴스 상세 조회", description = "하나의 요약 뉴스를 상세 조회합니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"news"} + security = {@SecurityRequirement(name = "access_token")} ) @ApiResponses(value = { @ApiResponse( responseCode = "200", - description = "요청에 성공하였습니다." + description = "요약 뉴스 상세 조회에 성공했습니다." ), @ApiResponse( responseCode = "404", description = "뉴스를 찾지 못했습니다." ) }) - NewsDetailResponse getDetailNews( + SuccessResponse getDetailNews( @Parameter(in = ParameterIn.PATH, description = "뉴스 ID", required = true) Long newsId ); - - @Operation( - summary = "최근 읽은 뉴스 조회", - description = "가장 최근에 읽은 3개의 뉴스를 조회합니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"news"} - ) - @ApiResponse( - responseCode = "200", - description = "요청에 성공하였습니다." - ) - List getReadNews(); - - } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/news/api/NewsController.java b/backend/core/src/main/java/com/rollthedice/backend/domain/news/api/NewsController.java index 0f50123a..977d1922 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/news/api/NewsController.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/news/api/NewsController.java @@ -2,9 +2,8 @@ import com.rollthedice.backend.domain.news.dto.response.NewsDetailResponse; import com.rollthedice.backend.domain.news.dto.response.NewsResponse; -import com.rollthedice.backend.domain.news.dto.response.ReadNewsResponse; import com.rollthedice.backend.domain.news.service.NewsService; -import com.rollthedice.backend.domain.news.service.ReadNewsService; +import com.rollthedice.backend.global.common.response.SuccessResponse; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -12,29 +11,28 @@ import java.util.List; +import static com.rollthedice.backend.global.common.response.SuccessCode.GET_ALL_NEWS_SUCCESS; +import static com.rollthedice.backend.global.common.response.SuccessCode.GET_DETAIL_NEWS_SUCCESS; + @RestController @RequiredArgsConstructor @RequestMapping("news") public class NewsController implements NewsApi { private final NewsService newsService; - private final ReadNewsService readNewsService; @ResponseStatus(HttpStatus.OK) @GetMapping("") @Override - public List getNews(final Pageable pageable) { - return newsService.getNews(pageable); + public SuccessResponse> getNews(final Pageable pageable) { + List response = newsService.getNews(pageable); + return SuccessResponse.of(GET_ALL_NEWS_SUCCESS, response); } @ResponseStatus(HttpStatus.OK) @GetMapping("/{newsId}") - public NewsDetailResponse getDetailNews(final @PathVariable Long newsId) { - return newsService.getDetailNews(newsId); - } - - @ResponseStatus(HttpStatus.OK) - @GetMapping("/viewed-history") - public List getReadNews() { - return readNewsService.getReadNews(); + @Override + public SuccessResponse getDetailNews(final @PathVariable Long newsId) { + NewsDetailResponse response = newsService.getDetailNews(newsId); + return SuccessResponse.of(GET_DETAIL_NEWS_SUCCESS, response); } } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/news/entity/News.java b/backend/core/src/main/java/com/rollthedice/backend/domain/news/entity/News.java index c96859cd..eba53bfe 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/news/entity/News.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/news/entity/News.java @@ -1,6 +1,6 @@ package com.rollthedice.backend.domain.news.entity; -import com.rollthedice.backend.global.config.BaseTimeEntity; +import com.rollthedice.backend.global.common.BaseTimeEntity; import jakarta.persistence.*; import lombok.*; import lombok.extern.slf4j.Slf4j; diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/news/repository/ReadNewsRepository.java b/backend/core/src/main/java/com/rollthedice/backend/domain/news/repository/ReadNewsRepository.java index 0dec52dc..c1c49b32 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/news/repository/ReadNewsRepository.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/news/repository/ReadNewsRepository.java @@ -1,7 +1,7 @@ package com.rollthedice.backend.domain.news.repository; import com.rollthedice.backend.domain.member.entity.Member; -import com.rollthedice.backend.domain.news.entity.ReadNews; +import com.rollthedice.backend.domain.readNews.entity.ReadNews; import com.rollthedice.backend.domain.statistics.repository.ReadNewsCustomRepository; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/news/service/NewsService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/news/service/NewsService.java index bb3136c1..8dac390a 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/news/service/NewsService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/news/service/NewsService.java @@ -4,7 +4,7 @@ import com.rollthedice.backend.domain.member.entity.Member; import com.rollthedice.backend.domain.news.dto.response.NewsDetailResponse; import com.rollthedice.backend.domain.news.dto.response.ReadNewsResponse; -import com.rollthedice.backend.domain.news.entity.ReadNews; +import com.rollthedice.backend.domain.readNews.entity.ReadNews; import com.rollthedice.backend.domain.news.exception.NewsNotFoundException; import com.rollthedice.backend.domain.news.repository.ReadNewsRepository; import com.rollthedice.backend.global.oauth2.service.AuthService; @@ -30,11 +30,11 @@ @RequiredArgsConstructor public class NewsService { private final AuthService authService; + private final BookmarkService bookmarkService; private final ContentProducer contentProducer; private final NewsRepository newsRepository; private final ReadNewsRepository readNewsRepository; private final NewsMapper newsMapper; - private final BookmarkService bookmarkService; @Transactional diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/readNews/api/ReadNewsApi.java b/backend/core/src/main/java/com/rollthedice/backend/domain/readNews/api/ReadNewsApi.java new file mode 100644 index 00000000..6279d7e8 --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/readNews/api/ReadNewsApi.java @@ -0,0 +1,24 @@ +package com.rollthedice.backend.domain.readNews.api; + +import com.rollthedice.backend.domain.news.dto.response.ReadNewsResponse; +import com.rollthedice.backend.global.common.response.SuccessResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; + +import java.util.List; + +@Tag(name = "Read News") +public interface ReadNewsApi { + @Operation( + summary = "최근 읽은 뉴스 조회", + description = "가장 최근에 읽은 3개의 뉴스를 조회합니다.", + security = {@SecurityRequirement(name = "access_token")} + ) + @ApiResponse( + responseCode = "200", + description = "최근 읽은 뉴스 조회에 성공했습니다." + ) + SuccessResponse> getReadNews(); +} diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/readNews/api/ReadNewsController.java b/backend/core/src/main/java/com/rollthedice/backend/domain/readNews/api/ReadNewsController.java new file mode 100644 index 00000000..67d02ed2 --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/readNews/api/ReadNewsController.java @@ -0,0 +1,31 @@ +package com.rollthedice.backend.domain.readNews.api; + +import com.rollthedice.backend.domain.news.dto.response.ReadNewsResponse; +import com.rollthedice.backend.domain.readNews.service.ReadNewsService; +import com.rollthedice.backend.global.common.response.SuccessResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +import static com.rollthedice.backend.global.common.response.SuccessCode.GET_RECENT_READ_NEWS_SUCCESS; + +@RestController +@RequiredArgsConstructor +@RequestMapping("read-news") +public class ReadNewsController implements ReadNewsApi { + + private final ReadNewsService readNewsService; + + @ResponseStatus(HttpStatus.OK) + @GetMapping("/viewed-history") + @Override + public SuccessResponse> getReadNews() { + List response = readNewsService.getReadNews(); + return SuccessResponse.of(GET_RECENT_READ_NEWS_SUCCESS, response); + } +} diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/news/entity/ReadNews.java b/backend/core/src/main/java/com/rollthedice/backend/domain/readNews/entity/ReadNews.java similarity index 80% rename from backend/core/src/main/java/com/rollthedice/backend/domain/news/entity/ReadNews.java rename to backend/core/src/main/java/com/rollthedice/backend/domain/readNews/entity/ReadNews.java index 03abeb91..2d6f23be 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/news/entity/ReadNews.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/readNews/entity/ReadNews.java @@ -1,7 +1,8 @@ -package com.rollthedice.backend.domain.news.entity; +package com.rollthedice.backend.domain.readNews.entity; import com.rollthedice.backend.domain.member.entity.Member; -import com.rollthedice.backend.global.config.BaseTimeEntity; +import com.rollthedice.backend.domain.news.entity.News; +import com.rollthedice.backend.global.common.BaseTimeEntity; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Builder; diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/news/service/ReadNewsService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/readNews/service/ReadNewsService.java similarity index 79% rename from backend/core/src/main/java/com/rollthedice/backend/domain/news/service/ReadNewsService.java rename to backend/core/src/main/java/com/rollthedice/backend/domain/readNews/service/ReadNewsService.java index c2618ff0..78795df1 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/news/service/ReadNewsService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/readNews/service/ReadNewsService.java @@ -1,9 +1,10 @@ -package com.rollthedice.backend.domain.news.service; +package com.rollthedice.backend.domain.readNews.service; import com.rollthedice.backend.domain.member.entity.Member; import com.rollthedice.backend.domain.news.dto.response.ReadNewsResponse; -import com.rollthedice.backend.domain.news.entity.ReadNews; +import com.rollthedice.backend.domain.readNews.entity.ReadNews; import com.rollthedice.backend.domain.news.repository.ReadNewsRepository; +import com.rollthedice.backend.domain.news.service.NewsService; import com.rollthedice.backend.global.oauth2.service.AuthService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -21,6 +22,6 @@ public class ReadNewsService { public List getReadNews() { Member member = authService.getMember(); List readNews = readNewsReository.getTop3ByMemberOrderByCreatedAtDesc(member); - return newsService.getNewsByReadNews(readNews.stream().map(r -> r.getNews()).collect(Collectors.toList())); + return newsService.getNewsByReadNews(readNews.stream().map(ReadNews::getNews).collect(Collectors.toList())); } } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/statistics/api/StatisticsApi.java b/backend/core/src/main/java/com/rollthedice/backend/domain/statistics/api/StatisticsApi.java index 6866c2bb..be7e86e7 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/statistics/api/StatisticsApi.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/statistics/api/StatisticsApi.java @@ -2,34 +2,35 @@ import com.rollthedice.backend.domain.statistics.dto.response.CategoryStatisticsResponse; import com.rollthedice.backend.domain.statistics.dto.response.DateViewStatisticsResponse; +import com.rollthedice.backend.global.common.response.SuccessResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; import java.util.List; +@Tag(name = "Statistics") public interface StatisticsApi { @Operation( summary = "최근 일주일 날짜별 뉴스 조회수 조회", description = "최근 일주일간 날짜별로 뉴스 조회수를 조회합니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"통계"} + security = {@SecurityRequirement(name = "access_token")} ) @ApiResponse( responseCode = "200", - description = "요청에 성공하였습니다." + description = "최근 일주일 날짜별 뉴스 조회수 조회에 성공했습니다." ) - List getViewsOfDates(); + SuccessResponse> getViewsOfDates(); @Operation( summary = "카테고리별 조회수 조회", description = "카테고리별 조회수를 조회합니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"통계"} + security = {@SecurityRequirement(name = "access_token")} ) @ApiResponse( responseCode = "200", - description = "요청에 성공하였습니다." + description = "카테고리별 조회수 조회에 성공했습니다." ) - List getCategoryStatistics(); + SuccessResponse> getCategoryStatistics(); } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/statistics/api/StatisticsController.java b/backend/core/src/main/java/com/rollthedice/backend/domain/statistics/api/StatisticsController.java index 8dc19f3d..14634964 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/statistics/api/StatisticsController.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/statistics/api/StatisticsController.java @@ -3,6 +3,7 @@ import com.rollthedice.backend.domain.statistics.dto.response.CategoryStatisticsResponse; import com.rollthedice.backend.domain.statistics.dto.response.DateViewStatisticsResponse; import com.rollthedice.backend.domain.statistics.service.StatisticsService; +import com.rollthedice.backend.global.common.response.SuccessResponse; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; @@ -12,6 +13,9 @@ import java.util.List; +import static com.rollthedice.backend.global.common.response.SuccessCode.GET_CATEGORY_VIEWS_SUCCESS; +import static com.rollthedice.backend.global.common.response.SuccessCode.GET_VIEWS_OF_DATE_SUCCESS; + @RestController @RequiredArgsConstructor @RequestMapping("statistics") @@ -21,14 +25,16 @@ public class StatisticsController implements StatisticsApi { @ResponseStatus(HttpStatus.OK) @GetMapping("/per-dates") @Override - public List getViewsOfDates() { - return statisticsService.getViewsOfDates(); + public SuccessResponse> getViewsOfDates() { + List response = statisticsService.getViewsOfDates(); + return SuccessResponse.of(GET_VIEWS_OF_DATE_SUCCESS, response); } @ResponseStatus(HttpStatus.OK) @GetMapping("/categories") @Override - public List getCategoryStatistics() { - return statisticsService.getCategoryStatistics(); + public SuccessResponse> getCategoryStatistics() { + List response = statisticsService.getCategoryStatistics(); + return SuccessResponse.of(GET_CATEGORY_VIEWS_SUCCESS, response); } } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/statistics/repository/ReadNewsCustomRepositoryImpl.java b/backend/core/src/main/java/com/rollthedice/backend/domain/statistics/repository/ReadNewsCustomRepositoryImpl.java index 8fe479f3..7e42c6c4 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/statistics/repository/ReadNewsCustomRepositoryImpl.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/statistics/repository/ReadNewsCustomRepositoryImpl.java @@ -7,7 +7,7 @@ import java.time.LocalDate; import static com.rollthedice.backend.domain.news.entity.QNews.news; -import static com.rollthedice.backend.domain.news.entity.QReadNews.readNews; +import static com.rollthedice.backend.domain.readNews.entity.QReadNews.readNews; @RequiredArgsConstructor public class ReadNewsCustomRepositoryImpl implements ReadNewsCustomRepository { diff --git a/backend/core/src/main/java/com/rollthedice/backend/global/config/BaseTimeEntity.java b/backend/core/src/main/java/com/rollthedice/backend/global/common/BaseTimeEntity.java similarity index 93% rename from backend/core/src/main/java/com/rollthedice/backend/global/config/BaseTimeEntity.java rename to backend/core/src/main/java/com/rollthedice/backend/global/common/BaseTimeEntity.java index 5aff4ca7..fce2d4d0 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/global/config/BaseTimeEntity.java +++ b/backend/core/src/main/java/com/rollthedice/backend/global/common/BaseTimeEntity.java @@ -1,4 +1,4 @@ -package com.rollthedice.backend.global.config; +package com.rollthedice.backend.global.common; import jakarta.persistence.Column; import jakarta.persistence.EntityListeners; diff --git a/backend/core/src/main/java/com/rollthedice/backend/global/common/response/SuccessCode.java b/backend/core/src/main/java/com/rollthedice/backend/global/common/response/SuccessCode.java new file mode 100644 index 00000000..0adb906f --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/global/common/response/SuccessCode.java @@ -0,0 +1,47 @@ +package com.rollthedice.backend.global.common.response; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum SuccessCode { + // bookmark + GET_ALL_BOOKMARK_SUCCESS(200, "북마크 전체 조회를 성공했습니다."), + GET_IS_BOOKMARKED_SUCCESS(200, "뉴스가 북마크 여부 조회를 성공했습니다."), + CREATE_BOOKMARK_SUCCESS(201, "북마크 저장에 성공했습니다."), + DELETE_BOOKMARK_SUCCESS(204, "북마크 삭제에 성공했습니다."), + + // debate + CREATE_DEBATE_ROOM_SUCCESS(201, "토론방 생성에 성공했습니다."), + GET_ALL_DEBATE_ROOM_SUCCESS(200, "토론방 전체 조회에 성공했습니다"), + DELETE_DEBATE_ROOM_SUCCESS(204, "토론방 삭제에 성공했습니다."), + CREATE_HUMAN_DEBATE_MESSAGE_SUCCESS(201, "사용자가 보낸 토론 메세지 저장에 성공했습니다."), + CREATE_AI_DEBATE_MESSAGE_SUCCESS(201, "AI가 보낸 토론 메세지 저장에 성공했습니다."), + UPDATE_DEBATE_ROOM_IS_CLOSED_SUCCESS(204, "토론 종료에 성공했습니다."), + GET_DEBATE_MESSAGES_SUCCESS(200, "토론 메세지 조회에 성공했습니다."), + CREATE_DEBATE_SUMMARY_SUCCESS(201, "토론 요약에 성공했습니다."), + GET_DEBATE_SUMMARY_SUCCESS(200, "토론 요약 조회에 성공했습니다."), + + // member + GET_MEMBER_INFO_SUCCESS(200, "사용자 정보 조회에 성공했습니다."), + + // news + GET_ALL_NEWS_SUCCESS(200, "전체 뉴스 조회에 성공했습니다."), + GET_DETAIL_NEWS_SUCCESS(200, "요약 뉴스 상세 조회에 성공했습니다."), + + // read news + GET_RECENT_READ_NEWS_SUCCESS(200, "최근 읽은 뉴스 조회에 성공했습니다."), + + // statistics + GET_VIEWS_OF_DATE_SUCCESS(200, "최근 일주일 날짜별 뉴스 조회수 조회에 성공했습니다."), + GET_CATEGORY_VIEWS_SUCCESS(200, "카테고리별 조회수 조회에 성공했습니다."), + + // auth + GET_SOCIAL_LOGIN_SUCCESS(201, "소셜 로그인에 성공했습니다."), + UPDATE_NICKNAME_SUCCESS(204, "닉네임 입력에 성공했습니다.") + ; + + private final int status; + private final String message; +} diff --git a/backend/core/src/main/java/com/rollthedice/backend/global/common/response/SuccessResponse.java b/backend/core/src/main/java/com/rollthedice/backend/global/common/response/SuccessResponse.java new file mode 100644 index 00000000..803b9ac9 --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/global/common/response/SuccessResponse.java @@ -0,0 +1,18 @@ +package com.rollthedice.backend.global.common.response; + +public record SuccessResponse( + int status, + String message, + T data +) { + + private static final String NOTHING = ""; + + public static SuccessResponse of(SuccessCode code) { + return new SuccessResponse<>(code.getStatus(), code.getMessage(), NOTHING); + } + + public static SuccessResponse of(SuccessCode code, T data) { + return new SuccessResponse<>(code.getStatus(), code.getMessage(), data); + } +} diff --git a/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/api/AuthApi.java b/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/api/AuthApi.java index b8528389..c9cabee7 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/api/AuthApi.java +++ b/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/api/AuthApi.java @@ -1,27 +1,29 @@ package com.rollthedice.backend.global.oauth2.api; import com.rollthedice.backend.domain.member.dto.MemberUpdateDto; +import com.rollthedice.backend.global.common.response.SuccessResponse; import com.rollthedice.backend.global.oauth2.dto.LoginRequest; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletResponse; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestBody; +@Tag(name = "Auth") public interface AuthApi { @Operation( summary = "소셜 로그인", description = "소셜 로그인을 합니다. 회원가입이 되어있지 않은 회원일 경우, 회원가입이 진행됩니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"인증"} + security = {@SecurityRequirement(name = "access_token")} ) @ApiResponse( - responseCode = "201", - description = "Created" + responseCode = "200", + description = "소셜 로그인에 성공했습니다." ) - ResponseEntity login( + SuccessResponse login( @RequestBody LoginRequest request, HttpServletResponse response ); @@ -29,14 +31,13 @@ ResponseEntity login( @Operation( summary = "닉네임 입력", description = "닉네임을 입력합니다. 해당 로직이 진행되어야 회원가입이 완료됩니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"인증"} + security = {@SecurityRequirement(name = "access_token")} ) @ApiResponse( responseCode = "201", - description = "Created" + description = "닉네임 입력에 성공했습니다." ) - ResponseEntity updateMember( + SuccessResponse updateMember( String email, @RequestBody MemberUpdateDto memberUpdateDto ); diff --git a/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/api/AuthController.java b/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/api/AuthController.java index dad5b0f7..27ba7e0a 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/api/AuthController.java +++ b/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/api/AuthController.java @@ -3,6 +3,7 @@ import com.rollthedice.backend.domain.member.dto.MemberUpdateDto; import com.rollthedice.backend.domain.member.service.MemberService; import com.rollthedice.backend.global.annotation.LoginMemberEmail; +import com.rollthedice.backend.global.common.response.SuccessResponse; import com.rollthedice.backend.global.oauth2.dto.LoginRequest; import com.rollthedice.backend.global.oauth2.service.AuthService; import jakarta.servlet.http.HttpServletResponse; @@ -12,8 +13,12 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; +import static com.rollthedice.backend.global.common.response.SuccessCode.GET_SOCIAL_LOGIN_SUCCESS; +import static com.rollthedice.backend.global.common.response.SuccessCode.UPDATE_NICKNAME_SUCCESS; + @Slf4j @RestController @RequiredArgsConstructor @@ -21,20 +26,20 @@ public class AuthController implements AuthApi { private final AuthService authService; private final MemberService memberService; + @ResponseStatus(HttpStatus.OK) @PostMapping("/login") @Override - public ResponseEntity login(@RequestBody LoginRequest request, HttpServletResponse response) { + public SuccessResponse login(@RequestBody LoginRequest request, HttpServletResponse response) { authService.authenticateOrRegisterUser(request, response); - return new ResponseEntity<>(HttpStatus.OK); + return SuccessResponse.of(GET_SOCIAL_LOGIN_SUCCESS); } @PostMapping("/oauth2/sign-up") @Override - public ResponseEntity updateMember(@LoginMemberEmail String email, + public SuccessResponse updateMember(@LoginMemberEmail String email, @RequestBody MemberUpdateDto memberUpdateDto) { memberService.update(memberUpdateDto); - - return ResponseEntity.status(HttpStatus.OK).build(); + return SuccessResponse.of(UPDATE_NICKNAME_SUCCESS); } } \ No newline at end of file diff --git a/backend/core/src/test/java/com/rollthedice/backend/domain/news/api/NewsControllerTest.java b/backend/core/src/test/java/com/rollthedice/backend/domain/news/api/NewsControllerTest.java index 200419be..056cb0f4 100644 --- a/backend/core/src/test/java/com/rollthedice/backend/domain/news/api/NewsControllerTest.java +++ b/backend/core/src/test/java/com/rollthedice/backend/domain/news/api/NewsControllerTest.java @@ -3,7 +3,7 @@ import com.rollthedice.backend.domain.news.exception.NewsNotFoundException; import com.rollthedice.backend.domain.news.repository.NewsRepository; import com.rollthedice.backend.domain.news.service.NewsService; -import com.rollthedice.backend.domain.news.service.ReadNewsService; +import com.rollthedice.backend.domain.readNews.service.ReadNewsService; import com.rollthedice.backend.global.BaseControllerTest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -25,10 +25,6 @@ class NewsControllerTest extends BaseControllerTest { @MockBean private NewsService newsService; - @MockBean - private ReadNewsService readNewsService; - @MockBean - private NewsRepository newsRepository; @Test @DisplayName("News 전체 조회 API가 수행되는가") @@ -76,18 +72,4 @@ void getDetailNewsNotFound() throws Exception { perform.andExpect(status().isNotFound()) .andExpect(jsonPath(ERROR_MESSAGE, NEWS_NOT_FOUND_ERROR.getErrorMessage()).exists()); } - - @Test - @DisplayName("조회한 News 전체 조회 API가 수행되는가") - void getReadNews() throws Exception{ - //when - final ResultActions perform = mockMvc.perform( - get("/news/viewed-history") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken) - ).andDo(print()); - - //then - perform.andExpect(status().isOk()); - } } diff --git a/backend/core/src/test/java/com/rollthedice/backend/domain/news/service/NewsServiceTest.java b/backend/core/src/test/java/com/rollthedice/backend/domain/news/service/NewsServiceTest.java index 0ebf8b3b..0ab9133e 100644 --- a/backend/core/src/test/java/com/rollthedice/backend/domain/news/service/NewsServiceTest.java +++ b/backend/core/src/test/java/com/rollthedice/backend/domain/news/service/NewsServiceTest.java @@ -16,7 +16,6 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; @@ -33,7 +32,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.BDDMockito.given; -@Slf4j @DisplayName("NewsService의") @ExtendWith(MockitoExtension.class) class NewsServiceTest extends LoginTest { @@ -44,11 +42,7 @@ class NewsServiceTest extends LoginTest { @MockBean private NewsRepository newsRepository; @MockBean - private BookmarkRepository bookmarkRepository; - @MockBean private ReadNewsRepository readNewsRepository; - @Mock - private NewsMapper newsMapper; private News news; @@ -87,7 +81,7 @@ void getNews() { } @Test - @DisplayName("뉴스를 상세조회할 수 있는가") + @DisplayName("뉴스를 상세 조회할 수 있는가") void getDetailNews() { //given NewsDetailResponse expect = NEWS_DETAIL_RESPONSE(); diff --git a/backend/core/src/test/java/com/rollthedice/backend/domain/readNews/ReadNewsFixture.java b/backend/core/src/test/java/com/rollthedice/backend/domain/readNews/ReadNewsFixture.java new file mode 100644 index 00000000..96b77256 --- /dev/null +++ b/backend/core/src/test/java/com/rollthedice/backend/domain/readNews/ReadNewsFixture.java @@ -0,0 +1,23 @@ +package com.rollthedice.backend.domain.readNews; + +import com.rollthedice.backend.domain.member.entity.Member; +import com.rollthedice.backend.domain.news.dto.response.ReadNewsResponse; +import com.rollthedice.backend.domain.readNews.entity.ReadNews; + +import static com.rollthedice.backend.domain.news.NewsFixture.NEWS; + +public class ReadNewsFixture { + public static ReadNews READ_NEWS(Member member) { + return ReadNews.builder() + .member(member) + .news(NEWS(member)) + .build(); + } + + public static ReadNewsResponse READ_NEWS_RESPONSE() { + return ReadNewsResponse.builder() + .id(1L) + .title("임연지 대통령 되다.") + .build(); + } +} diff --git a/backend/core/src/test/java/com/rollthedice/backend/domain/readNews/api/ReadNewsControllerTest.java b/backend/core/src/test/java/com/rollthedice/backend/domain/readNews/api/ReadNewsControllerTest.java new file mode 100644 index 00000000..78e7653e --- /dev/null +++ b/backend/core/src/test/java/com/rollthedice/backend/domain/readNews/api/ReadNewsControllerTest.java @@ -0,0 +1,35 @@ +package com.rollthedice.backend.domain.readNews.api; + +import com.rollthedice.backend.domain.readNews.service.ReadNewsService; +import com.rollthedice.backend.global.BaseControllerTest; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.ResultActions; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@DisplayName("ReadNewsController의 ") +@WebMvcTest(ReadNewsController.class) +class ReadNewsControllerTest extends BaseControllerTest { + @MockBean + private ReadNewsService readNewsService; + + @Test + @DisplayName("조회한 News 전체 조회 API가 수행되는가") + void getReadNews() throws Exception{ + //when + final ResultActions perform = mockMvc.perform( + get("/read-news/viewed-history") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer " + accessToken) + ).andDo(print()); + + //then + perform.andExpect(status().isOk()); + } +} diff --git a/backend/core/src/test/java/com/rollthedice/backend/domain/news/repository/ReadNewsRepositoryTest.java b/backend/core/src/test/java/com/rollthedice/backend/domain/readNews/repository/ReadNewsRepositoryTest.java similarity index 88% rename from backend/core/src/test/java/com/rollthedice/backend/domain/news/repository/ReadNewsRepositoryTest.java rename to backend/core/src/test/java/com/rollthedice/backend/domain/readNews/repository/ReadNewsRepositoryTest.java index 5427888c..5e2bf860 100644 --- a/backend/core/src/test/java/com/rollthedice/backend/domain/news/repository/ReadNewsRepositoryTest.java +++ b/backend/core/src/test/java/com/rollthedice/backend/domain/readNews/repository/ReadNewsRepositoryTest.java @@ -1,10 +1,12 @@ -package com.rollthedice.backend.domain.news.repository; +package com.rollthedice.backend.domain.readNews.repository; import com.rollthedice.backend.domain.member.entity.Member; import com.rollthedice.backend.domain.member.repository.MemberRepository; import com.rollthedice.backend.domain.news.entity.News; import com.rollthedice.backend.domain.news.entity.NewsCategory; -import com.rollthedice.backend.domain.news.entity.ReadNews; +import com.rollthedice.backend.domain.news.repository.NewsRepository; +import com.rollthedice.backend.domain.news.repository.ReadNewsRepository; +import com.rollthedice.backend.domain.readNews.entity.ReadNews; import com.rollthedice.backend.support.RepositoryTest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -18,7 +20,7 @@ @DisplayName("ReadNewsRepository의 ") @RepositoryTest -public class ReadNewsRepositoryTest { +class ReadNewsRepositoryTest { @Autowired private ReadNewsRepository readNewsRepository; @Autowired