Skip to content

Commit

Permalink
Merge branch 'develop' into feature/#13-cd-init
Browse files Browse the repository at this point in the history
  • Loading branch information
thguss authored Jan 9, 2024
2 parents aae8cfa + c866d09 commit 83a03ce
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 72 deletions.
24 changes: 24 additions & 0 deletions src/main/java/com/soptie/server/common/handler/ErrorHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.soptie.server.common.handler;

import static com.soptie.server.common.dto.Response.*;
import static org.springframework.http.HttpStatus.*;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import com.soptie.server.common.dto.Response;

import jakarta.persistence.EntityNotFoundException;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestControllerAdvice
public class ErrorHandler {

@ExceptionHandler(EntityNotFoundException.class)
public ResponseEntity<Response> entityNotFoundException(EntityNotFoundException exception) {
log.error(exception.getMessage());
return ResponseEntity.status(NOT_FOUND).body(fail(exception.getMessage()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -28,8 +29,14 @@ public ResponseEntity<Response> getThemes() {
}

@GetMapping
public ResponseEntity<Response> getRoutines(@RequestParam String themes) {
public ResponseEntity<Response> getRoutinesByThemes(@RequestParam String themes) {
val response = dailyRoutineService.getRoutinesByThemes(themes);
return ResponseEntity.ok(success(SUCCESS_GET_ROUTINE.getMessage(), response));
}

@GetMapping("/{themeId}")
public ResponseEntity<Response> getRoutinesByTheme(@PathVariable Long themeId) {
val response = dailyRoutineService.getRoutinesByTheme(themeId);
return ResponseEntity.ok(success(SUCCESS_GET_ROUTINE.getMessage(), response));
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/soptie/server/routine/message/ErrorMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.soptie.server.routine.message;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Getter
public enum ErrorMessage {
INVALID_THEME("유효하지 않은 테마입니다."),
;

private final String message;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.soptie.server.routine.repository.daily.routine;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;

import com.soptie.server.routine.entity.daily.DailyRoutine;
import com.soptie.server.routine.entity.daily.DailyTheme;

public interface DailyRoutineRepository extends JpaRepository<DailyRoutine, Long>, DailyRoutineCustomRepository {
List<DailyRoutine> findAllByThemeOrderByContentAsc(DailyTheme theme);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public List<DailyRoutine> findAllByThemes(List<Long> themeIds) {
return queryFactory
.selectFrom(dailyRoutine)
.where(dailyRoutine.theme.id.in(themeIds))
.orderBy(dailyRoutine.content.asc())
.fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public interface DailyRoutineService {

DailyThemesResponse getThemes();
DailyRoutinesResponse getRoutinesByThemes(String themes);
DailyRoutinesResponse getRoutinesByTheme(Long themeId);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.soptie.server.routine.service;

import static com.soptie.server.routine.message.ErrorMessage.*;

import java.util.Arrays;
import java.util.List;

Expand All @@ -8,9 +10,11 @@

import com.soptie.server.routine.dto.DailyRoutinesResponse;
import com.soptie.server.routine.dto.DailyThemesResponse;
import com.soptie.server.routine.entity.daily.DailyTheme;
import com.soptie.server.routine.repository.daily.routine.DailyRoutineRepository;
import com.soptie.server.routine.repository.daily.theme.DailyThemeRepository;

import jakarta.persistence.EntityNotFoundException;
import lombok.*;

@Service
Expand Down Expand Up @@ -42,4 +46,16 @@ private List<Long> getThemeIds(String themes) {
private List<String> convertStringToList(String themes) {
return Arrays.stream(themes.split(",")).toList();
}

@Override
public DailyRoutinesResponse getRoutinesByTheme(Long themeId) {
val theme = getTheme(themeId);
val routines = dailyRoutineRepository.findAllByThemeOrderByContentAsc(theme);
return DailyRoutinesResponse.of(routines);
}

private DailyTheme getTheme(Long id) {
return dailyThemeRepository.findById(id)
.orElseThrow(() -> new EntityNotFoundException(INVALID_THEME.getMessage()));
}
}
70 changes: 0 additions & 70 deletions src/main/resources/static/docs/open-api-3.0.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,53 +69,6 @@
}
}
},
"/api/v1/routines/daily/member" : {
"post" : {
"tags" : [ "MEMBER DAILY ROUTINE" ],
"summary" : "회원 데일리 루틴 추가 성공",
"description" : "회원 데일리 루틴 추가 성공",
"operationId" : "post-routine-docs",
"requestBody" : {
"content" : {
"application/json;charset=UTF-8" : {
"schema" : {
"$ref" : "#/components/schemas/api-v1-routines-daily-member1721287602"
},
"examples" : {
"post-routine-docs" : {
"value" : "{\n \"routineId\" : 1\n}"
}
}
}
}
},
"responses" : {
"201" : {
"description" : "201",
"headers" : {
"Location" : {
"description" : "Redirect URI",
"schema" : {
"type" : "string"
}
}
},
"content" : {
"application/json;charset=UTF-8" : {
"schema" : {
"$ref" : "#/components/schemas/api-v1-routines-daily-member1327124516"
},
"examples" : {
"post-routine-docs" : {
"value" : "{\n \"success\" : true,\n \"message\" : \"루틴 추가 성공\",\n \"data\" : {\n \"routineId\" : 1\n }\n}"
}
}
}
}
}
}
}
},
"/api/v1/routines/daily/themes" : {
"get" : {
"tags" : [ "DAILY ROUTINE" ],
Expand Down Expand Up @@ -290,29 +243,6 @@
}
}
},
"api-v1-routines-daily-member1327124516" : {
"type" : "object",
"properties" : {
"data" : {
"type" : "object",
"properties" : {
"routineId" : {
"type" : "number",
"description" : "생성한 루틴 id"
}
},
"description" : "응답 데이터"
},
"success" : {
"type" : "boolean",
"description" : "응답 성공 여부"
},
"message" : {
"type" : "string",
"description" : "응답 메시지"
}
}
},
"api-v1-test486549215" : {
"type" : "object"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void success_getDailyRoutinesByThemes() throws Exception {
queries.add("themes", themes);

// when
when(controller.getRoutines(themes)).thenReturn(response);
when(controller.getRoutinesByThemes(themes)).thenReturn(response);

// then
mockMvc
Expand Down Expand Up @@ -120,4 +120,45 @@ void success_getDailyRoutinesByThemes() throws Exception {
.build())))
.andExpect(status().isOk());
}

@Test
@DisplayName("테마 별 데일리 루틴 리스트 조회 성공")
void success_getDailyRoutinesByTheme() throws Exception {
// given
DailyRoutinesResponse routines = DailyRoutineFixture.createDailyRoutinesResponseDTO();
ResponseEntity<Response> response = ResponseEntity.ok(Response.success("루틴 조회 성공", routines));

// when
when(controller.getRoutinesByTheme(anyLong())).thenReturn(response);

// then
mockMvc
.perform(
RestDocumentationRequestBuilders.get(DEFAULT_URL + "/{themeId}", 1L)
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andDo(
MockMvcRestDocumentation.document(
"get-routines-docs",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
resource(
ResourceSnippetParameters.builder()
.tag(TAG)
.description("테마 별 데일리 루틴 리스트 조회")
.pathParameters(
parameterWithName("themeId").description("테마 id")
)
.requestFields()
.responseFields(
fieldWithPath("success").type(BOOLEAN).description("응답 성공 여부"),
fieldWithPath("message").type(STRING).description("응답 메시지"),
fieldWithPath("data").type(OBJECT).description("응답 데이터"),
fieldWithPath("data.routines").type(ARRAY).description("루틴 정보 리스트"),
fieldWithPath("data.routines[].routineId").type(NUMBER).description("루틴 id"),
fieldWithPath("data.routines[].content").type(STRING).description("테마 내용")
)
.build())))
.andExpect(status().isOk());
}
}

0 comments on commit 83a03ce

Please sign in to comment.