-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
tht-apis/src/main/java/com/tht/thtapis/dev/DevController.kt
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,38 @@ | ||
package com.tht.thtapis.dev | ||
|
||
import com.tht.domain.entity.like.UserLikeRepository | ||
import com.tht.domain.entity.user.repository.UserDailyFallingRepository | ||
import lombok.RequiredArgsConstructor | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.security.core.Authentication | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
import java.util.* | ||
|
||
@RestController | ||
@RequestMapping("/dev") | ||
@RequiredArgsConstructor | ||
class DevController( | ||
private val userLikeRepository: UserLikeRepository, | ||
private val userDailyFallingRepository: UserDailyFallingRepository | ||
) { | ||
|
||
@PostMapping("/like-and-dislike/reset") | ||
fun resetLikeData(authentication: Authentication?): ResponseEntity<Objects> { | ||
val userUuid: String = authentication?.credentials.toString() | ||
userLikeRepository.deleteAllByUserUuid(userUuid) | ||
|
||
return ResponseEntity.status(HttpStatus.NO_CONTENT).build() | ||
} | ||
|
||
@PostMapping("/selected-talk-keywords/reset") | ||
fun resetSelectedFallingKeyword(authentication: Authentication?): ResponseEntity<Objects> { | ||
val userUuid: String = authentication?.credentials.toString() | ||
userDailyFallingRepository.deleteAllByUserUuid(userUuid) | ||
|
||
return ResponseEntity.status(HttpStatus.NO_CONTENT).build() | ||
} | ||
|
||
} |
83 changes: 83 additions & 0 deletions
83
tht-apis/src/test/java/com/tht/thtapis/documentation/DevDocumentation.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,83 @@ | ||
package com.tht.thtapis.documentation; | ||
|
||
import com.epages.restdocs.apispec.ResourceSnippetParameters; | ||
import com.tht.domain.entity.like.UserLikeRepository; | ||
import com.tht.domain.entity.user.repository.UserDailyFallingRepository; | ||
import com.tht.thtapis.controller.config.ControllerTestConfig; | ||
import com.tht.thtapis.dev.DevController; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.bean.override.mockito.MockitoBean; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers; | ||
|
||
import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.document; | ||
import static com.epages.restdocs.apispec.ResourceDocumentation.resource; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.doNothing; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; | ||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; | ||
|
||
@WebMvcTest(DevController.class) | ||
class DevDocumentation extends ControllerTestConfig { | ||
|
||
@MockitoBean | ||
UserLikeRepository userLikeRepository; | ||
@MockitoBean | ||
UserDailyFallingRepository userDailyFallingRepository; | ||
|
||
@Test | ||
@DisplayName("유저 좋아요 싫어요 선택 데이터 초기화 api documentation") | ||
void resetLike() throws Exception { | ||
|
||
// Mock Repository 동작 정의 | ||
doNothing().when(userLikeRepository).deleteAllByUserUuid(anyString()); | ||
|
||
//give | ||
ResultActions resultActions = ControllerTestConfig.mockMvc.perform(post("/dev/like-and-dislike/reset") | ||
.accept(MediaType.APPLICATION_JSON) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.header("Authorization", "Bearer {ACCESS_TOKEN}") | ||
) | ||
.andDo(document("유저 좋아요 싫어요 선택 데이터 초기화 api", | ||
preprocessRequest(prettyPrint()), | ||
preprocessResponse(prettyPrint()), | ||
resource(ResourceSnippetParameters.builder() | ||
.tag("개발용") | ||
.description("유저 좋아요 싫어요 선택 데이터 전부 삭제") | ||
.responseFields() | ||
.build()) | ||
)); | ||
|
||
resultActions.andExpect(MockMvcResultMatchers.status().isNoContent()); | ||
} | ||
|
||
@Test | ||
@DisplayName("유저가 선택한 그날의 주제어 초기화 api documentation") | ||
void resetSelectedTalkKeyword() throws Exception { | ||
|
||
// Mock Repository 동작 정의 | ||
doNothing().when(userDailyFallingRepository).deleteAllByUserUuid(anyString()); | ||
|
||
//give | ||
ResultActions resultActions = ControllerTestConfig.mockMvc.perform(post("/dev/selected-talk-keywords/reset") | ||
.accept(MediaType.APPLICATION_JSON) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.header("Authorization", "Bearer {ACCESS_TOKEN}") | ||
) | ||
.andDo(document("유저가 선택한 그날의 주제어 초기화 api", | ||
preprocessRequest(prettyPrint()), | ||
preprocessResponse(prettyPrint()), | ||
resource(ResourceSnippetParameters.builder() | ||
.tag("개발용") | ||
.description("유저가 선택한 그날의 주제어 데이터 전부 삭제") | ||
.responseFields() | ||
.build()) | ||
)); | ||
|
||
resultActions.andExpect(MockMvcResultMatchers.status().isNoContent()); | ||
} | ||
|
||
} |
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