diff --git a/src/docs/asciidoc/api/mypage/mypage.adoc b/src/docs/asciidoc/api/mypage/mypage.adoc index b11e06bb..a8fb562a 100644 --- a/src/docs/asciidoc/api/mypage/mypage.adoc +++ b/src/docs/asciidoc/api/mypage/mypage.adoc @@ -7,3 +7,4 @@ include::exit-survey.adoc[] include::record-exit-survey.adoc[] include::comment-get.adoc[] include::subscribed-companies.adoc[] +include::random-nickname.adoc[] diff --git a/src/docs/asciidoc/api/mypage/random-nickname.adoc b/src/docs/asciidoc/api/mypage/random-nickname.adoc new file mode 100644 index 00000000..55173e79 --- /dev/null +++ b/src/docs/asciidoc/api/mypage/random-nickname.adoc @@ -0,0 +1,20 @@ +[[GetRandomNickname]] +== 랜덤 닉네임 생성 API(GET: /devdevdev/api/v1/mypage/nickname/random) +* 회원은 랜덤 닉네임을 생성할 수 있다. +* 비회원은 랜덤 닉네임을 생성할 수 없다. + +=== 정상 요청/응답 +==== HTTP Request +include::{snippets}/random-nickname/http-request.adoc[] +==== HTTP Request Header Fields +include::{snippets}/random-nickname/request-headers.adoc[] + +==== HTTP Response +include::{snippets}/random-nickname/http-response.adoc[] +==== HTTP Response Fields +include::{snippets}/random-nickname/response-fields.adoc[] + + +=== 예외 +==== HTTP Response +include::{snippets}/not-found-member-exception/response-body.adoc[] \ No newline at end of file diff --git a/src/main/java/com/dreamypatisiel/devdevdev/LocalInitData.java b/src/main/java/com/dreamypatisiel/devdevdev/LocalInitData.java index a3dc2f7e..97d552cb 100644 --- a/src/main/java/com/dreamypatisiel/devdevdev/LocalInitData.java +++ b/src/main/java/com/dreamypatisiel/devdevdev/LocalInitData.java @@ -208,15 +208,12 @@ private List createBookmarks(Member member, List techArti private List createTechArticles(Map companyIdMap) { List techArticles = new ArrayList<>(); Iterable elasticTechArticles = elasticTechArticleRepository.findTop10By(); - int count = 0; for (ElasticTechArticle elasticTechArticle : elasticTechArticles) { - count++; Company company = companyIdMap.get(elasticTechArticle.getCompanyId()); - if (company == null) { - log.info("company가 null 이다. elasticTechArticleId={} count={}", elasticTechArticle.getId(), count); + if (company != null) { + TechArticle techArticle = TechArticle.createTechArticle(elasticTechArticle, company); + techArticles.add(techArticle); } - TechArticle techArticle = TechArticle.createTechArticle(elasticTechArticle, company); - techArticles.add(techArticle); } return techArticles; } diff --git a/src/main/java/com/dreamypatisiel/devdevdev/web/controller/member/MypageController.java b/src/main/java/com/dreamypatisiel/devdevdev/web/controller/member/MypageController.java index f90a8c94..203a5cf3 100644 --- a/src/main/java/com/dreamypatisiel/devdevdev/web/controller/member/MypageController.java +++ b/src/main/java/com/dreamypatisiel/devdevdev/web/controller/member/MypageController.java @@ -1,6 +1,7 @@ package com.dreamypatisiel.devdevdev.web.controller.member; import com.dreamypatisiel.devdevdev.domain.repository.techArticle.BookmarkSort; +import com.dreamypatisiel.devdevdev.domain.service.member.MemberNicknameDictionaryService; import com.dreamypatisiel.devdevdev.domain.service.member.MemberService; import com.dreamypatisiel.devdevdev.global.security.jwt.model.JwtCookieConstant; import com.dreamypatisiel.devdevdev.global.utils.AuthenticationMemberUtils; @@ -42,6 +43,7 @@ public class MypageController { private final MemberService memberService; + private final MemberNicknameDictionaryService memberNicknameDictionaryService; @Operation(summary = "북마크 목록 조회") @GetMapping("/mypage/bookmarks") @@ -133,4 +135,11 @@ public ResponseEntity>> get return ResponseEntity.ok(BasicResponse.success(mySubscribedCompanies)); } + + @Operation(summary = "랜덤 닉네임 생성", description = "랜덤 닉네임을 생성합니다.") + @GetMapping("/mypage/nickname/random") + public ResponseEntity> getRandomNickname() { + String response = memberNicknameDictionaryService.createRandomNickname(); + return ResponseEntity.ok(BasicResponse.success(response)); + } } diff --git a/src/test/java/com/dreamypatisiel/devdevdev/web/controller/LogoutControllerTest.java b/src/test/java/com/dreamypatisiel/devdevdev/web/controller/member/LogoutControllerTest.java similarity index 96% rename from src/test/java/com/dreamypatisiel/devdevdev/web/controller/LogoutControllerTest.java rename to src/test/java/com/dreamypatisiel/devdevdev/web/controller/member/LogoutControllerTest.java index a7a30895..23bd418a 100644 --- a/src/test/java/com/dreamypatisiel/devdevdev/web/controller/LogoutControllerTest.java +++ b/src/test/java/com/dreamypatisiel/devdevdev/web/controller/member/LogoutControllerTest.java @@ -1,4 +1,4 @@ -package com.dreamypatisiel.devdevdev.web.controller; +package com.dreamypatisiel.devdevdev.web.controller.member; import static com.dreamypatisiel.devdevdev.global.constant.SecurityConstant.AUTHORIZATION_HEADER; import static com.dreamypatisiel.devdevdev.global.constant.SecurityConstant.BEARER_PREFIX; @@ -17,6 +17,7 @@ import com.dreamypatisiel.devdevdev.global.security.jwt.model.Token; import com.dreamypatisiel.devdevdev.global.security.oauth2.model.SocialMemberDto; import com.dreamypatisiel.devdevdev.global.utils.CookieUtils; +import com.dreamypatisiel.devdevdev.web.controller.SupportControllerTest; import com.dreamypatisiel.devdevdev.web.dto.response.ResultType; import jakarta.servlet.http.Cookie; import java.nio.charset.StandardCharsets; diff --git a/src/test/java/com/dreamypatisiel/devdevdev/web/controller/MyPageControllerTest.java b/src/test/java/com/dreamypatisiel/devdevdev/web/controller/member/MyPageControllerTest.java similarity index 99% rename from src/test/java/com/dreamypatisiel/devdevdev/web/controller/MyPageControllerTest.java rename to src/test/java/com/dreamypatisiel/devdevdev/web/controller/member/MyPageControllerTest.java index 8e813e2d..8073c50e 100644 --- a/src/test/java/com/dreamypatisiel/devdevdev/web/controller/MyPageControllerTest.java +++ b/src/test/java/com/dreamypatisiel/devdevdev/web/controller/member/MyPageControllerTest.java @@ -1,4 +1,4 @@ -package com.dreamypatisiel.devdevdev.web.controller; +package com.dreamypatisiel.devdevdev.web.controller.member; import com.dreamypatisiel.devdevdev.domain.entity.*; import com.dreamypatisiel.devdevdev.domain.entity.embedded.*; @@ -23,6 +23,7 @@ import com.dreamypatisiel.devdevdev.global.security.oauth2.model.SocialMemberDto; import com.dreamypatisiel.devdevdev.global.security.oauth2.model.UserPrincipal; import com.dreamypatisiel.devdevdev.global.utils.CookieUtils; +import com.dreamypatisiel.devdevdev.web.controller.SupportControllerTest; import com.dreamypatisiel.devdevdev.web.dto.request.member.RecordMemberExitSurveyAnswerRequest; import com.dreamypatisiel.devdevdev.web.dto.request.member.RecordMemberExitSurveyQuestionOptionsRequest; import com.dreamypatisiel.devdevdev.web.dto.response.ResultType; diff --git a/src/test/java/com/dreamypatisiel/devdevdev/web/controller/MyPageControllerUsedMockServiceTest.java b/src/test/java/com/dreamypatisiel/devdevdev/web/controller/member/MyPageControllerUsedMockServiceTest.java similarity index 92% rename from src/test/java/com/dreamypatisiel/devdevdev/web/controller/MyPageControllerUsedMockServiceTest.java rename to src/test/java/com/dreamypatisiel/devdevdev/web/controller/member/MyPageControllerUsedMockServiceTest.java index 17b4e70c..06434509 100644 --- a/src/test/java/com/dreamypatisiel/devdevdev/web/controller/MyPageControllerUsedMockServiceTest.java +++ b/src/test/java/com/dreamypatisiel/devdevdev/web/controller/member/MyPageControllerUsedMockServiceTest.java @@ -1,4 +1,4 @@ -package com.dreamypatisiel.devdevdev.web.controller; +package com.dreamypatisiel.devdevdev.web.controller.member; import static com.dreamypatisiel.devdevdev.web.dto.response.ResultType.SUCCESS; import static org.mockito.ArgumentMatchers.any; @@ -15,9 +15,11 @@ import com.dreamypatisiel.devdevdev.domain.entity.enums.Role; import com.dreamypatisiel.devdevdev.domain.entity.enums.SocialType; import com.dreamypatisiel.devdevdev.domain.repository.member.MemberRepository; +import com.dreamypatisiel.devdevdev.domain.service.member.MemberNicknameDictionaryService; import com.dreamypatisiel.devdevdev.domain.service.member.MemberService; import com.dreamypatisiel.devdevdev.global.constant.SecurityConstant; import com.dreamypatisiel.devdevdev.global.security.oauth2.model.SocialMemberDto; +import com.dreamypatisiel.devdevdev.web.controller.SupportControllerTest; import com.dreamypatisiel.devdevdev.web.dto.SliceCustom; import com.dreamypatisiel.devdevdev.web.dto.response.ResultType; import com.dreamypatisiel.devdevdev.web.dto.response.comment.MyWrittenCommentResponse; @@ -43,6 +45,29 @@ public class MyPageControllerUsedMockServiceTest extends SupportControllerTest { MemberRepository memberRepository; @MockBean MemberService memberService; + @MockBean + MemberNicknameDictionaryService memberNicknameDictionaryService; + + @Test + @DisplayName("회원은 랜덤 닉네임을 생성할 수 있다.") + void getRandomNickname() throws Exception { + // given + String result = "주말에 공부하는 토마토"; + + // when + when(memberNicknameDictionaryService.createRandomNickname()).thenReturn(result); + + // then + mockMvc.perform(get("/devdevdev/api/v1/mypage/nickname/random") + .contentType(MediaType.APPLICATION_JSON) + .characterEncoding(StandardCharsets.UTF_8) + .header(SecurityConstant.AUTHORIZATION_HEADER, SecurityConstant.BEARER_PREFIX + accessToken)) + .andDo(print()) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.resultType").value(SUCCESS.name())) + .andExpect(jsonPath("$.data").isNotEmpty()) + .andExpect(jsonPath("$.data").isString()); + } @Test @DisplayName("회원이 내가 썼어요 댓글을 조회한다.") diff --git a/src/test/java/com/dreamypatisiel/devdevdev/web/controller/TokenControllerTest.java b/src/test/java/com/dreamypatisiel/devdevdev/web/controller/member/TokenControllerTest.java similarity index 98% rename from src/test/java/com/dreamypatisiel/devdevdev/web/controller/TokenControllerTest.java rename to src/test/java/com/dreamypatisiel/devdevdev/web/controller/member/TokenControllerTest.java index a107d2aa..c3168bd5 100644 --- a/src/test/java/com/dreamypatisiel/devdevdev/web/controller/TokenControllerTest.java +++ b/src/test/java/com/dreamypatisiel/devdevdev/web/controller/member/TokenControllerTest.java @@ -1,4 +1,4 @@ -package com.dreamypatisiel.devdevdev.web.controller; +package com.dreamypatisiel.devdevdev.web.controller.member; import static com.dreamypatisiel.devdevdev.global.security.jwt.model.JwtCookieConstant.DEVDEVDEV_ACCESS_TOKEN; import static com.dreamypatisiel.devdevdev.global.security.jwt.model.JwtCookieConstant.DEVDEVDEV_LOGIN_STATUS; @@ -19,6 +19,7 @@ import com.dreamypatisiel.devdevdev.domain.repository.member.MemberRepository; import com.dreamypatisiel.devdevdev.global.security.oauth2.model.SocialMemberDto; import com.dreamypatisiel.devdevdev.global.utils.CookieUtils; +import com.dreamypatisiel.devdevdev.web.controller.SupportControllerTest; import com.dreamypatisiel.devdevdev.web.dto.response.ResultType; import jakarta.servlet.http.Cookie; import java.util.Date; diff --git a/src/test/java/com/dreamypatisiel/devdevdev/web/docs/MyPageControllerDocsUsedMockServiceTest.java b/src/test/java/com/dreamypatisiel/devdevdev/web/docs/MyPageControllerDocsUsedMockServiceTest.java index 13fdc0f0..64542688 100644 --- a/src/test/java/com/dreamypatisiel/devdevdev/web/docs/MyPageControllerDocsUsedMockServiceTest.java +++ b/src/test/java/com/dreamypatisiel/devdevdev/web/docs/MyPageControllerDocsUsedMockServiceTest.java @@ -30,6 +30,7 @@ import com.dreamypatisiel.devdevdev.domain.entity.enums.Role; import com.dreamypatisiel.devdevdev.domain.entity.enums.SocialType; import com.dreamypatisiel.devdevdev.domain.repository.member.MemberRepository; +import com.dreamypatisiel.devdevdev.domain.service.member.MemberNicknameDictionaryService; import com.dreamypatisiel.devdevdev.domain.service.member.MemberService; import com.dreamypatisiel.devdevdev.global.constant.SecurityConstant; import com.dreamypatisiel.devdevdev.global.security.oauth2.model.SocialMemberDto; @@ -57,6 +58,39 @@ public class MyPageControllerDocsUsedMockServiceTest extends SupportControllerDo MemberRepository memberRepository; @MockBean MemberService memberService; + @MockBean + MemberNicknameDictionaryService memberNicknameDictionaryService; + + @Test + @DisplayName("회원은 랜덤 닉네임을 생성할 수 있다.") + void getRandomNickname() throws Exception { + // given + String result = "주말에 공부하는 토마토"; + + // when + when(memberNicknameDictionaryService.createRandomNickname()).thenReturn(result); + + // then + ResultActions actions = mockMvc.perform(get("/devdevdev/api/v1/mypage/nickname/random") + .contentType(MediaType.APPLICATION_JSON) + .characterEncoding(StandardCharsets.UTF_8) + .header(SecurityConstant.AUTHORIZATION_HEADER, SecurityConstant.BEARER_PREFIX + accessToken)) + .andDo(print()) + .andExpect(status().isOk()); + + // docs + actions.andDo(document("random-nickname", + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint()), + requestHeaders( + headerWithName(AUTHORIZATION_HEADER).description("Bearer 엑세스 토큰") + ), + responseFields( + fieldWithPath("resultType").type(JsonFieldType.STRING).description("응답 결과"), + fieldWithPath("data").type(JsonFieldType.STRING).description("응답 데이터(생성된 랜덤 닉네임)") + ) + )); + } @Test @DisplayName("회원이 내가 썼어요 댓글을 조회한다.")