From 62a2c5b90eae66ab11fbd4fdb51b7b3183724d1e Mon Sep 17 00:00:00 2001 From: thguss Date: Tue, 16 Jan 2024 13:22:38 +0900 Subject: [PATCH 01/86] =?UTF-8?q?[DELETE]=20=EC=B2=A8=EC=82=AD=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CorrectionController.java | 60 ------- .../dto/correction/CorrectionRequestDTO.java | 7 - .../dto/correction/CorrectionResponseDTO.java | 25 --- .../server/dto/diary/DiaryResponseDTO.java | 15 +- .../com/smeme/server/model/Correction.java | 53 ------ .../java/com/smeme/server/model/Diary.java | 3 - .../CorrectionCustomRepository.java | 7 - .../correction/CorrectionRepository.java | 14 -- .../correction/CorrectionRepositoryImpl.java | 28 --- .../diary/DiaryCustomRepository.java | 9 - .../repository/diary/DiaryRepository.java | 2 +- .../repository/diary/DiaryRepositoryImpl.java | 29 ---- .../server/service/CorrectionService.java | 82 --------- .../smeme/server/service/DiaryService.java | 10 +- .../server/service/auth/AuthService.java | 3 - .../server/controller/AuthControllerTest.java | 2 - .../controller/CorrectionControllerTest.java | 160 ------------------ .../controller/DiaryControllerTest.java | 18 +- .../fixture/correction/CorrectionFixture.java | 40 ----- 19 files changed, 5 insertions(+), 562 deletions(-) delete mode 100644 src/main/java/com/smeme/server/controller/CorrectionController.java delete mode 100644 src/main/java/com/smeme/server/dto/correction/CorrectionRequestDTO.java delete mode 100644 src/main/java/com/smeme/server/dto/correction/CorrectionResponseDTO.java delete mode 100644 src/main/java/com/smeme/server/model/Correction.java delete mode 100644 src/main/java/com/smeme/server/repository/correction/CorrectionCustomRepository.java delete mode 100644 src/main/java/com/smeme/server/repository/correction/CorrectionRepository.java delete mode 100644 src/main/java/com/smeme/server/repository/correction/CorrectionRepositoryImpl.java delete mode 100644 src/main/java/com/smeme/server/repository/diary/DiaryCustomRepository.java delete mode 100644 src/main/java/com/smeme/server/repository/diary/DiaryRepositoryImpl.java delete mode 100644 src/main/java/com/smeme/server/service/CorrectionService.java delete mode 100644 src/test/java/com/smeme/server/controller/CorrectionControllerTest.java delete mode 100644 src/test/java/com/smeme/server/fixture/correction/CorrectionFixture.java diff --git a/src/main/java/com/smeme/server/controller/CorrectionController.java b/src/main/java/com/smeme/server/controller/CorrectionController.java deleted file mode 100644 index a0049438..00000000 --- a/src/main/java/com/smeme/server/controller/CorrectionController.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.smeme.server.controller; - -import static com.smeme.server.util.ApiResponse.success; -import static com.smeme.server.util.Util.getMemberId; -import static com.smeme.server.util.Util.getURI; -import static com.smeme.server.util.message.ResponseMessage.*; - -import java.security.Principal; - -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PatchMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import com.smeme.server.dto.correction.CorrectionRequestDTO; -import com.smeme.server.dto.correction.CorrectionResponseDTO; -import com.smeme.server.service.CorrectionService; -import com.smeme.server.util.ApiResponse; - -import io.swagger.v3.oas.annotations.Operation; -import lombok.RequiredArgsConstructor; - -@RestController -@RequiredArgsConstructor -@RequestMapping("/api/v2/corrections") -public class CorrectionController { - - private final CorrectionService correctionService; - - @Operation(description = "일기 첨삭") - @PostMapping("/diary/{diaryId}") - public ResponseEntity save( - Principal principal, - @PathVariable Long diaryId, - @RequestBody CorrectionRequestDTO request - ) { - CorrectionResponseDTO response = correctionService.save(getMemberId(principal), diaryId, request); - return ResponseEntity - .created(getURI(diaryId)) - .body(success(SUCCESS_CREATE_CORRECTION.getMessage(), response)); - } - - @Operation(description = "첨삭 삭제") - @DeleteMapping("/{correctionId}") - public ResponseEntity delete(@PathVariable Long correctionId) { - correctionService.delete(correctionId); - return ResponseEntity.ok(success(SUCCESS_DELETE_CORRECTION.getMessage())); - } - - @Operation(description = "첨삭 수정") - @PatchMapping("/{correctionId}") - public ResponseEntity update(@PathVariable Long correctionId, @RequestBody CorrectionRequestDTO request) { - correctionService.update(correctionId, request); - return ResponseEntity.ok(success(SUCCESS_UPDATE_CORRECTION.getMessage())); - } -} diff --git a/src/main/java/com/smeme/server/dto/correction/CorrectionRequestDTO.java b/src/main/java/com/smeme/server/dto/correction/CorrectionRequestDTO.java deleted file mode 100644 index 7695c0ce..00000000 --- a/src/main/java/com/smeme/server/dto/correction/CorrectionRequestDTO.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.smeme.server.dto.correction; - -public record CorrectionRequestDTO( - String sentence, - String content -) { -} diff --git a/src/main/java/com/smeme/server/dto/correction/CorrectionResponseDTO.java b/src/main/java/com/smeme/server/dto/correction/CorrectionResponseDTO.java deleted file mode 100644 index 501985e2..00000000 --- a/src/main/java/com/smeme/server/dto/correction/CorrectionResponseDTO.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.smeme.server.dto.correction; - -import com.smeme.server.model.badge.Badge; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public record CorrectionResponseDTO( - Long diaryId, - List badges -) { - public static CorrectionResponseDTO of(Long diaryId, Badge badge) { - return new CorrectionResponseDTO(diaryId, new ArrayList<>(Collections.singleton(BadgeDTO.of(badge)))); - } - - record BadgeDTO( - String name, - String imageUrl - ) { - public static BadgeDTO of(Badge badge) { - return new BadgeDTO(badge.getName(), badge.getImageUrl()); - } - } -} diff --git a/src/main/java/com/smeme/server/dto/diary/DiaryResponseDTO.java b/src/main/java/com/smeme/server/dto/diary/DiaryResponseDTO.java index 3f0ee543..46853199 100644 --- a/src/main/java/com/smeme/server/dto/diary/DiaryResponseDTO.java +++ b/src/main/java/com/smeme/server/dto/diary/DiaryResponseDTO.java @@ -5,7 +5,6 @@ import java.util.List; -import com.smeme.server.model.Correction; import com.smeme.server.model.Diary; import lombok.AccessLevel; @@ -17,8 +16,7 @@ public record DiaryResponseDTO( String topic, String content, String createdAt, - String username, - List corrections + String username ) { public static DiaryResponseDTO of(Diary diary) { return DiaryResponseDTO.builder() @@ -27,19 +25,8 @@ public static DiaryResponseDTO of(Diary diary) { .content(diary.getContent()) .createdAt(dateToString(diary.getCreatedAt())) .username(diary.getMember().getUsername()) - .corrections(diary.getCorrections().stream().map(CorrectionDTO::of).toList()) .build(); } - public record CorrectionDTO( - Long correctionId, - String before, - String after - ) { - static CorrectionDTO of(Correction correction) { - return new CorrectionDTO(correction.getId(), correction.getBeforeSentence(), correction.getAfterSentence()); - } - } - } diff --git a/src/main/java/com/smeme/server/model/Correction.java b/src/main/java/com/smeme/server/model/Correction.java deleted file mode 100644 index 67f5d021..00000000 --- a/src/main/java/com/smeme/server/model/Correction.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.smeme.server.model; - -import static jakarta.persistence.FetchType.*; -import static jakarta.persistence.GenerationType.*; -import static java.util.Objects.*; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Entity -@NoArgsConstructor -@Getter -public class Correction { - - @Id - @GeneratedValue(strategy = IDENTITY) - @Column(name = "correction_id") - private Long id; - - private String beforeSentence; - - private String afterSentence; - - @ManyToOne(fetch = LAZY) - @JoinColumn(name = "diary_id") - private Diary diary; - - @Builder - public Correction(String beforeSentence, String afterSentence, Diary diary) { - this.beforeSentence = beforeSentence; - this.afterSentence = afterSentence; - setDiary(diary); - } - - public void updateContent(String content) { - this.afterSentence = content; - } - - private void setDiary(Diary diary) { - if (nonNull(this.diary)) { - this.diary.getCorrections().remove(this); - } - this.diary = diary; - diary.getCorrections().add(this); - } -} diff --git a/src/main/java/com/smeme/server/model/Diary.java b/src/main/java/com/smeme/server/model/Diary.java index c75ab5fa..4163e954 100644 --- a/src/main/java/com/smeme/server/model/Diary.java +++ b/src/main/java/com/smeme/server/model/Diary.java @@ -43,9 +43,6 @@ public class Diary extends BaseTimeEntity { @JoinColumn(name = "member_id") private Member member; - @OneToMany(mappedBy = "diary") - private final List corrections = new ArrayList<>(); - @Builder public Diary(String content, Topic topic, Member member) { this.content = content; diff --git a/src/main/java/com/smeme/server/repository/correction/CorrectionCustomRepository.java b/src/main/java/com/smeme/server/repository/correction/CorrectionCustomRepository.java deleted file mode 100644 index a9ba14e4..00000000 --- a/src/main/java/com/smeme/server/repository/correction/CorrectionCustomRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.smeme.server.repository.correction; - -import com.smeme.server.model.Member; - -public interface CorrectionCustomRepository { - int countByMember(Member member); -} diff --git a/src/main/java/com/smeme/server/repository/correction/CorrectionRepository.java b/src/main/java/com/smeme/server/repository/correction/CorrectionRepository.java deleted file mode 100644 index 7bff2e5b..00000000 --- a/src/main/java/com/smeme/server/repository/correction/CorrectionRepository.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.smeme.server.repository.correction; - -import java.util.List; - -import org.springframework.data.jpa.repository.JpaRepository; - -import com.smeme.server.model.Correction; -import com.smeme.server.model.Diary; - -public interface CorrectionRepository extends JpaRepository, CorrectionCustomRepository { - List findByDiaryOrderByIdDesc(Diary diary); - - void deleteAllByDiaryId(Long id); -} diff --git a/src/main/java/com/smeme/server/repository/correction/CorrectionRepositoryImpl.java b/src/main/java/com/smeme/server/repository/correction/CorrectionRepositoryImpl.java deleted file mode 100644 index 668903ca..00000000 --- a/src/main/java/com/smeme/server/repository/correction/CorrectionRepositoryImpl.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.smeme.server.repository.correction; - -import static com.smeme.server.model.QCorrection.*; -import static com.smeme.server.model.QDiary.*; - -import org.springframework.stereotype.Repository; - -import com.querydsl.jpa.impl.JPAQueryFactory; -import com.smeme.server.model.Member; - -import lombok.RequiredArgsConstructor; - -@Repository -@RequiredArgsConstructor -public class CorrectionRepositoryImpl implements CorrectionCustomRepository { - - private final JPAQueryFactory queryFactory; - - @Override - public int countByMember(Member member) { - return Math.toIntExact(queryFactory - .select(correction.count()) - .from(correction) - .leftJoin(correction.diary, diary) - .where(diary.member.eq(member)) - .fetchFirst()); - } -} diff --git a/src/main/java/com/smeme/server/repository/diary/DiaryCustomRepository.java b/src/main/java/com/smeme/server/repository/diary/DiaryCustomRepository.java deleted file mode 100644 index 7fc12091..00000000 --- a/src/main/java/com/smeme/server/repository/diary/DiaryCustomRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.smeme.server.repository.diary; - -import java.util.Optional; - -import com.smeme.server.model.Diary; - -public interface DiaryCustomRepository { - Optional findByIdFetchJoinCorrections(Long id); -} diff --git a/src/main/java/com/smeme/server/repository/diary/DiaryRepository.java b/src/main/java/com/smeme/server/repository/diary/DiaryRepository.java index fc7d0bfb..5f7f9ce0 100644 --- a/src/main/java/com/smeme/server/repository/diary/DiaryRepository.java +++ b/src/main/java/com/smeme/server/repository/diary/DiaryRepository.java @@ -7,7 +7,7 @@ import java.util.List; -public interface DiaryRepository extends JpaRepository, DiaryCustomRepository { +public interface DiaryRepository extends JpaRepository { void deleteAllByMember(Member member); diff --git a/src/main/java/com/smeme/server/repository/diary/DiaryRepositoryImpl.java b/src/main/java/com/smeme/server/repository/diary/DiaryRepositoryImpl.java deleted file mode 100644 index 54f70a91..00000000 --- a/src/main/java/com/smeme/server/repository/diary/DiaryRepositoryImpl.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.smeme.server.repository.diary; - -import static com.smeme.server.model.QCorrection.correction; -import static com.smeme.server.model.QDiary.*; - -import java.util.Optional; - -import org.springframework.stereotype.Repository; - -import com.querydsl.jpa.impl.JPAQueryFactory; -import com.smeme.server.model.Diary; - -import lombok.RequiredArgsConstructor; - -@Repository -@RequiredArgsConstructor -public class DiaryRepositoryImpl implements DiaryCustomRepository { - - private final JPAQueryFactory queryFactory; - - @Override - public Optional findByIdFetchJoinCorrections(Long id) { - return Optional.ofNullable(queryFactory - .selectFrom(diary) - .where(diary.id.eq(id)) - .leftJoin(diary.corrections, correction).fetchJoin().distinct() - .fetchFirst()); - } -} diff --git a/src/main/java/com/smeme/server/service/CorrectionService.java b/src/main/java/com/smeme/server/service/CorrectionService.java deleted file mode 100644 index d7925cfe..00000000 --- a/src/main/java/com/smeme/server/service/CorrectionService.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.smeme.server.service; - -import static com.smeme.server.util.message.ErrorMessage.*; -import static java.util.Objects.nonNull; - -import java.util.List; - -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import com.smeme.server.dto.correction.CorrectionRequestDTO; -import com.smeme.server.dto.correction.CorrectionResponseDTO; -import com.smeme.server.model.Correction; -import com.smeme.server.model.Diary; -import com.smeme.server.model.Member; -import com.smeme.server.model.badge.Badge; -import com.smeme.server.repository.correction.CorrectionRepository; - -import jakarta.persistence.EntityNotFoundException; -import lombok.RequiredArgsConstructor; - -@Service -@RequiredArgsConstructor -@Transactional(readOnly = true) -public class CorrectionService { - - private final CorrectionRepository correctionRepository; - - private final BadgeService badgeService; - private final DiaryService diaryService; - private final MemberService memberService; - - @Transactional - public CorrectionResponseDTO save(Long memberId, Long diaryId, CorrectionRequestDTO request) { - Diary diary = diaryService.get(diaryId); - correctionRepository.save(new Correction(request.sentence(), request.content(), diary)); - - Member member = memberService.get(memberId); - Badge countingBadge = obtainCountingBadge(member); - if (nonNull(countingBadge) && member.hasNotBadge(countingBadge)) { - badgeService.saveMemberBadge(member, countingBadge); - } - - return CorrectionResponseDTO.of(diaryId, countingBadge); - } - - @Transactional - public void delete(Long id) { - correctionRepository.deleteById(id); - } - - @Transactional - public void update(Long id, CorrectionRequestDTO request) { - Correction correction = get(id); - correction.updateContent(request.content()); - } - - @Transactional - public void deleteAllByDiaryId(Long diaryId) { - correctionRepository.deleteAllByDiaryId(diaryId); - } - - - protected void deleteCorrections(List corrections) { - correctionRepository.deleteAll(corrections); - } - - private Badge obtainCountingBadge(Member member) { - int count = correctionRepository.countByMember(member); - return switch (count) { - case 5 -> badgeService.get(12L); - case 3 -> badgeService.get(11L); - case 1 -> badgeService.get(10L); - default -> null; - }; - } - - private Correction get(Long id) { - return correctionRepository.findById(id) - .orElseThrow(() -> new EntityNotFoundException(INVALID_CORRECTION.getMessage())); - } -} diff --git a/src/main/java/com/smeme/server/service/DiaryService.java b/src/main/java/com/smeme/server/service/DiaryService.java index e7a854fe..5f95fed3 100644 --- a/src/main/java/com/smeme/server/service/DiaryService.java +++ b/src/main/java/com/smeme/server/service/DiaryService.java @@ -12,7 +12,6 @@ import com.smeme.server.config.ValueConfig; import com.smeme.server.model.DeletedDiary; -import com.smeme.server.repository.correction.CorrectionRepository; import com.smeme.server.repository.diary.DeletedDiaryRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -36,7 +35,6 @@ public class DiaryService { private final DiaryRepository diaryRepository; - private final CorrectionRepository correctionRepository; private final DeletedDiaryRepository deletedDiaryRepository; private final BadgeService badgeService; @@ -63,7 +61,7 @@ public CreatedDiaryResponseDTO save(Long memberId, DiaryRequestDTO request) { } public DiaryResponseDTO getDetail(Long id) { - Diary diary = getFetchJoinCorrections(id); + Diary diary = get(id); return DiaryResponseDTO.of(diary); } @@ -86,7 +84,6 @@ private void copyToDeletedDiary(Diary diary) { private void delete(Diary diary) { diary.deleteFromMember(); - correctionRepository.deleteAll(diary.getCorrections()); diaryRepository.deleteById(diary.getId()); } @@ -126,11 +123,6 @@ protected Diary get(Long id) { .orElseThrow(() -> new EntityNotFoundException(INVALID_DIARY.getMessage())); } - protected Diary getFetchJoinCorrections(Long id) { - return diaryRepository.findByIdFetchJoinCorrections(id) - .orElseThrow(() -> new EntityNotFoundException(INVALID_DIARY.getMessage())); - } - private List obtainBadges(Member member, LocalDateTime createdAt) { List badges = new ArrayList<>(); diff --git a/src/main/java/com/smeme/server/service/auth/AuthService.java b/src/main/java/com/smeme/server/service/auth/AuthService.java index 31d12e1c..472c832e 100644 --- a/src/main/java/com/smeme/server/service/auth/AuthService.java +++ b/src/main/java/com/smeme/server/service/auth/AuthService.java @@ -10,7 +10,6 @@ import com.smeme.server.model.Member; import com.smeme.server.model.SocialType; import com.smeme.server.repository.MemberRepository; -import com.smeme.server.service.CorrectionService; import com.smeme.server.service.DiaryService; import com.smeme.server.service.MemberBadgeService; import com.smeme.server.service.TrainingTimeService; @@ -45,7 +44,6 @@ public class AuthService { private final MemberBadgeService memberBadgeService; private final DiaryService diaryService; private final TrainingTimeService trainingTimeService; - private final CorrectionService correctionService; @Transactional public SignInResponseDTO signIn(String socialAccessToken, SignInRequestDTO request) throws NoSuchAlgorithmException, InvalidKeySpecException { @@ -98,7 +96,6 @@ public void signOut(Long memberId) { @Transactional public void withdraw(Long memberId) { Member member = get(memberId); - diaryService.getAllByMemberId(memberId).forEach(diary -> correctionService.deleteAllByDiaryId(diary.getId())); diaryService.deleteAllByMember(member); trainingTimeService.deleteAllByMember(member); memberBadgeService.deleteAllByMember(member); diff --git a/src/test/java/com/smeme/server/controller/AuthControllerTest.java b/src/test/java/com/smeme/server/controller/AuthControllerTest.java index 1345a45b..8e0d6ac1 100644 --- a/src/test/java/com/smeme/server/controller/AuthControllerTest.java +++ b/src/test/java/com/smeme/server/controller/AuthControllerTest.java @@ -3,7 +3,6 @@ import com.epages.restdocs.apispec.ResourceSnippetParameters; import com.smeme.server.fixture.auth.AuthFixture; -import com.smeme.server.fixture.correction.CorrectionFixture; import lombok.val; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -11,7 +10,6 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.ResponseEntity; -import java.net.URI; import java.security.Principal; import static com.epages.restdocs.apispec.ResourceDocumentation.resource; diff --git a/src/test/java/com/smeme/server/controller/CorrectionControllerTest.java b/src/test/java/com/smeme/server/controller/CorrectionControllerTest.java deleted file mode 100644 index b1c6ad33..00000000 --- a/src/test/java/com/smeme/server/controller/CorrectionControllerTest.java +++ /dev/null @@ -1,160 +0,0 @@ -package com.smeme.server.controller; - - -import com.epages.restdocs.apispec.ResourceSnippetParameters; -import com.smeme.server.fixture.correction.CorrectionFixture; -import lombok.val; -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.ResponseEntity; - -import java.net.URI; -import java.security.Principal; - -import static com.epages.restdocs.apispec.ResourceDocumentation.resource; -import static com.smeme.server.util.ApiResponse.success; -import static com.smeme.server.util.message.ResponseMessage.*; -import static org.mockito.Mockito.when; -import static org.springframework.http.MediaType.APPLICATION_JSON; -import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; -import static org.springframework.restdocs.payload.JsonFieldType.*; -import static org.springframework.restdocs.payload.JsonFieldType.STRING; -import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@DisplayName("CorrectionController 테스트") -@WebMvcTest(CorrectionController.class) -public class CorrectionControllerTest extends BaseControllerTest { - - @MockBean - CorrectionController correctionController; - - @MockBean - Principal principal; - - private final String DEFAULT_URL = "/api/v2/corrections"; - private final String TAG = "Correction"; - - private static final Long DIARY_ID = 1L; - private static final Long CORRECTION_ID = 1L; - - - - @DisplayName("첨삭 추가 API 성공") - @Test - void success_save() throws Exception { - val resources = ResourceSnippetParameters.builder() - .tag(TAG) - .description("첨삭 추가") - .requestFields( - fieldWithPath("sentence").type(STRING).description("첨삭 전 문장"), - fieldWithPath("content").type(STRING).description("첨삭 후 문장") - ) - .responseHeaders(headerWithName("Location").description("생성된 첨삭 조회 URI")) - .responseFields( - fieldWithPath("success").type(BOOLEAN).description("응답 성공 여부"), - fieldWithPath("message").type(STRING).description("응답 메시지"), - fieldWithPath("data").type(OBJECT).description("응답 데이터"), - fieldWithPath("data.diaryId").type(NUMBER).description("일기 ID"), - fieldWithPath("data.badges").type(ARRAY).description("뱃지 목록"), - fieldWithPath("data.badges[].name").type(STRING).description("뱃지 이름"), - fieldWithPath("data.badges[].imageUrl").type(STRING).description("뱃지 이미지 URL") - ) - .build(); - // when - val result = ResponseEntity. - created(URI.create(DEFAULT_URL +"/diary/" + DIARY_ID)) - .body(success(SUCCESS_CREATE_CORRECTION.getMessage(), CorrectionFixture.createCorrectionResponseDTO())); - - when(correctionController.save(principal, DIARY_ID, CorrectionFixture.createCorrectionRequestDTO())) - .thenReturn(result); - - - mockMvc.perform(post(DEFAULT_URL + "/diary/{diaryId}", DIARY_ID) - .contentType(APPLICATION_JSON) - .accept(APPLICATION_JSON) - .principal(principal) - .content(objectMapper.writeValueAsString(CorrectionFixture.createCorrectionRequestDTO()))) - .andDo( - document("첨삭 추가 Example", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint()), - resource(resources) - )) - .andExpect(status().isCreated()); - } - - @DisplayName("첨삭 삭제 API 성공") - @Test - void success_delete() throws Exception { - val resources = ResourceSnippetParameters.builder() - .tag(TAG) - .description("첨삭 삭제") - .responseFields( - fieldWithPath("success").type(BOOLEAN).description("응답 성공 여부"), - fieldWithPath("message").type(STRING).description("응답 메시지"), - fieldWithPath("data").type(NULL).description("응답 데이터") - ) - .build(); - // when - val result = ResponseEntity.ok(success(SUCCESS_DELETE_CORRECTION.getMessage())); - - when(correctionController.delete(CORRECTION_ID)) - .thenReturn(result); - - - mockMvc.perform(delete(DEFAULT_URL + "/{correctionId}", CORRECTION_ID) - .principal(principal) - .content(objectMapper.writeValueAsString(CorrectionFixture.createCorrectionRequestDTO()))) - .andDo( - document("첨삭 삭제 Example", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint()), - resource(resources) - )) - .andExpect(status().isOk()); - } - - @DisplayName("첨삭 수정 API 성공") - @Test - void success_update() throws Exception { - val resources = ResourceSnippetParameters.builder() - .tag(TAG) - .description("첨삭 수정") - .requestFields( - fieldWithPath("sentence").type(STRING).description("첨삭 전 문장"), - fieldWithPath("content").type(STRING).description("첨삭 후 문장") - ) - .responseFields( - fieldWithPath("success").type(BOOLEAN).description("응답 성공 여부"), - fieldWithPath("message").type(STRING).description("응답 메시지"), - fieldWithPath("data").type(NULL).description("응답 데이터") - ) - .build(); - // when - val result = ResponseEntity.ok(success(SUCCESS_UPDATE_CORRECTION.getMessage())); - when(correctionController.update(CORRECTION_ID, CorrectionFixture.createCorrectionRequestDTO())) - .thenReturn(result); - - - mockMvc.perform(patch(DEFAULT_URL + "/{correctionId}", CORRECTION_ID) - .contentType(APPLICATION_JSON) - .accept(APPLICATION_JSON) - .principal(principal) - .content(objectMapper.writeValueAsString(CorrectionFixture.createCorrectionRequestDTO()))) - .andDo( - document("첨삭 수정 Example", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint()), - resource(resources) - )) - .andExpect(status().isOk()); - } - -} diff --git a/src/test/java/com/smeme/server/controller/DiaryControllerTest.java b/src/test/java/com/smeme/server/controller/DiaryControllerTest.java index 3bb1092b..cc7a5c3c 100644 --- a/src/test/java/com/smeme/server/controller/DiaryControllerTest.java +++ b/src/test/java/com/smeme/server/controller/DiaryControllerTest.java @@ -6,7 +6,6 @@ import com.smeme.server.dto.diary.DiariesResponseDTO.DiaryDTO; import com.smeme.server.dto.diary.DiaryRequestDTO; import com.smeme.server.dto.diary.DiaryResponseDTO; -import com.smeme.server.dto.diary.DiaryResponseDTO.CorrectionDTO; import com.smeme.server.util.ApiResponse; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -104,8 +103,7 @@ void success_get_diary() throws Exception { "가보고 싶은 해외 여행 지가 있다면 소개해 주세요!", "I want to go Bla Bla ...", "2023-08-19 14:00", - "스미무", - corrections()); + "스미무"); ResponseEntity result = ResponseEntity.ok(success("일기 조회 성공", response)); // when @@ -134,11 +132,7 @@ void success_get_diary() throws Exception { fieldWithPath("data.topic").type(STRING).description("랜덤 주제"), fieldWithPath("data.content").type(STRING).description("일기 내용"), fieldWithPath("data.createdAt").type(STRING).description("작성 날짜"), - fieldWithPath("data.username").type(STRING).description("작성자 이름"), - fieldWithPath("data.corrections[]").type(ARRAY).description("첨삭 리스트"), - fieldWithPath("data.corrections[].correctionId").type(NUMBER).description("첨삭 id"), - fieldWithPath("data.corrections[].before").type(STRING).description("첨삭 전 내용"), - fieldWithPath("data.corrections[].after").type(STRING).description("첨삭 후 내용") + fieldWithPath("data.username").type(STRING).description("작성자 이름") ) .build() ) @@ -279,14 +273,6 @@ private List badges() { return badges; } - private List corrections() { - List corrections = new ArrayList<>(); - for (int i = 0; i < 2; i++) { - corrections.add(new CorrectionDTO(1L, "before" + (i + 1), "after" + (i + 1))); - } - return corrections; - } - private List diaries() { List diaries = new ArrayList<>(); for (int i = 0; i < 2; i++) { diff --git a/src/test/java/com/smeme/server/fixture/correction/CorrectionFixture.java b/src/test/java/com/smeme/server/fixture/correction/CorrectionFixture.java deleted file mode 100644 index 3315eed1..00000000 --- a/src/test/java/com/smeme/server/fixture/correction/CorrectionFixture.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.smeme.server.fixture.correction; - -import com.smeme.server.dto.correction.CorrectionRequestDTO; -import com.smeme.server.dto.correction.CorrectionResponseDTO; -import com.smeme.server.fixture.badge.BadgeFixture; -import com.smeme.server.fixture.diary.DiaryFixture; -import com.smeme.server.fixture.member.MemberFixture; -import com.smeme.server.model.Correction; - -public class CorrectionFixture { - - private static final String CORRECTION_SENTENCE = "correction test sentence"; - private static final String CORRECTION_CONTENT = "correction test content"; - private static final String BEFORE_SENTENCE ="correction before sentence"; - private static final String AFTER_SENTENCE ="correction after sentence"; - - private static final Long DIARY_ID = 1L; - - public static Correction createCorrection() { - return Correction.builder() - .beforeSentence(BEFORE_SENTENCE) - .afterSentence(AFTER_SENTENCE) - .diary(DiaryFixture.createDiary()) - .build(); - } - - public static CorrectionResponseDTO createCorrectionResponseDTO() { - return CorrectionResponseDTO.of( - DIARY_ID, - BadgeFixture.createBadge() - ); - } - - public static CorrectionRequestDTO createCorrectionRequestDTO() { - return new CorrectionRequestDTO( - CORRECTION_SENTENCE, - CORRECTION_CONTENT - ); - } -} From 3d47867c221885ea6f279fbbe2f09980ef1553ea Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 17 Jan 2024 00:10:02 +0900 Subject: [PATCH 02/86] =?UTF-8?q?[DELETE]=20=EC=8A=A4=EC=9B=A8=EA=B1=B0=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/AuthController.java | 26 ++---------------- .../server/controller/BadgeController.java | 12 --------- .../server/controller/DiaryController.java | 6 ----- .../server/controller/GoalController.java | 5 ---- .../server/controller/MemberController.java | 27 +------------------ .../server/controller/TestController.java | 12 --------- .../server/controller/TopicController.java | 9 ------- .../server/dto/auth/SignInRequestDTO.java | 4 --- .../server/dto/auth/SignInResponseDTO.java | 5 ---- .../dto/auth/beta/BetaSignInRequestDTO.java | 3 --- .../dto/auth/beta/BetaTokenResponseDTO.java | 2 -- .../dto/badge/BadgeListResponseDTO.java | 1 - .../server/dto/badge/BadgeResponseDTO.java | 8 ++---- .../server/dto/diary/DiaryRequestDTO.java | 2 -- .../server/dto/diary/DiaryResponseDTO.java | 2 -- .../dto/member/MemberGetResponseDTO.java | 13 ++------- .../dto/member/MemberNameResponseDTO.java | 3 --- .../member/MemberPlanUpdateRequestDTO.java | 6 ----- .../member/MemberPushUpdateRequestDTO.java | 5 ---- .../dto/member/MemberUpdateRequestDTO.java | 4 --- .../dto/member/MemberUpdateResponseDTO.java | 6 ++--- .../dto/training/TrainingTimeResponseDTO.java | 2 -- 22 files changed, 9 insertions(+), 154 deletions(-) diff --git a/src/main/java/com/smeme/server/controller/AuthController.java b/src/main/java/com/smeme/server/controller/AuthController.java index bcc5bb4b..b59dd7b1 100644 --- a/src/main/java/com/smeme/server/controller/AuthController.java +++ b/src/main/java/com/smeme/server/controller/AuthController.java @@ -1,15 +1,10 @@ package com.smeme.server.controller; - import com.smeme.server.dto.auth.SignInRequestDTO; import com.smeme.server.dto.auth.SignInResponseDTO; import com.smeme.server.dto.auth.token.TokenResponseDTO; import com.smeme.server.service.auth.AuthService; import com.smeme.server.util.ApiResponse; -import io.swagger.v3.oas.annotations.Operation; -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 lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -25,46 +20,29 @@ @RestController @RequiredArgsConstructor @RequestMapping("api/v2/auth") -@Tag(name = "Auth", description = "인증/인가 관련 API") public class AuthController { private final AuthService authService; - @Operation(summary = "소셜 로그인", description = "소셜 로그인을 합니다.") - @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "로그인 성공", - content = @io.swagger.v3.oas.annotations.media.Content(schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = SignInResponseDTO.class)))}) @PostMapping - public ResponseEntity signIn(@RequestHeader("Authorization") String socialAccessToken, @RequestBody SignInRequestDTO request) throws NoSuchAlgorithmException, InvalidKeySpecException { + public ResponseEntity signIn(@RequestHeader("Authorization") String socialAccessToken, @RequestBody SignInRequestDTO request + ) throws NoSuchAlgorithmException, InvalidKeySpecException { SignInResponseDTO response = authService.signIn(socialAccessToken, request); return ResponseEntity.ok(success(SUCCESS_SIGNIN.getMessage(), response)); } - @Operation(summary = "토큰 재발급", description = "토큰을 재발급 받습니다.") - @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "토큰 재발급 성공", - content = @io.swagger.v3.oas.annotations.media.Content(schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = TokenResponseDTO.class)))}) @PostMapping("/token") public ResponseEntity reissueToken(Principal principal) { TokenResponseDTO response = authService.issueToken(getMemberId(principal)); return ResponseEntity.ok(success(SUCCESS_ISSUE_TOKEN.getMessage(), response)); } - @SecurityRequirement(name = "Authorization") - @Operation(summary = "로그아웃", description = "로그아웃 합니다.") - @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "로그아웃 성공", - content = @io.swagger.v3.oas.annotations.media.Content(schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = ApiResponse.class)))}) @PostMapping("/sign-out") public ResponseEntity signOut(Principal principal) { authService.signOut(getMemberId(principal)); return ResponseEntity.ok(success(SUCCESS_SIGNOUT.getMessage())); } - @Operation(summary = "회원 탈퇴", description = "회원 탈퇴를 합니다.") - @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "회원 탈퇴 성공", - content = @io.swagger.v3.oas.annotations.media.Content(schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = ApiResponse.class)))}) @DeleteMapping public ResponseEntity withDrawl(Principal principal) { authService.withdraw(getMemberId(principal)); diff --git a/src/main/java/com/smeme/server/controller/BadgeController.java b/src/main/java/com/smeme/server/controller/BadgeController.java index 955b5523..2c7ebbe8 100644 --- a/src/main/java/com/smeme/server/controller/BadgeController.java +++ b/src/main/java/com/smeme/server/controller/BadgeController.java @@ -3,12 +3,6 @@ import com.smeme.server.dto.badge.BadgeListResponseDTO; import com.smeme.server.service.BadgeService; import com.smeme.server.util.ApiResponse; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -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 lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -24,16 +18,10 @@ @RestController @RequiredArgsConstructor @RequestMapping("/api/v2/members/badges") -@Tag(name = "Badge", description = "뱃지 관련 API") -@SecurityRequirement(name = "Authorization") public class BadgeController { private final BadgeService badgeService; - @Operation(summary = "사용자 뱃지 조회", description = "사용자의 뱃지를 조회합니다.") - @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "뱃지 조회 성공", - content = @Content(schema = @Schema(implementation = BadgeListResponseDTO.class)))}) @GetMapping public ResponseEntity getBadgeList(Principal principal) { BadgeListResponseDTO response = badgeService.getBadgeList(getMemberId(principal)); diff --git a/src/main/java/com/smeme/server/controller/DiaryController.java b/src/main/java/com/smeme/server/controller/DiaryController.java index 97235791..31dc8b47 100644 --- a/src/main/java/com/smeme/server/controller/DiaryController.java +++ b/src/main/java/com/smeme/server/controller/DiaryController.java @@ -25,7 +25,6 @@ import com.smeme.server.service.DiaryService; import com.smeme.server.util.ApiResponse; -import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; @RestController @@ -34,7 +33,6 @@ public class DiaryController { private final DiaryService diaryService; - @Operation(description = "일기 생성") @PostMapping public ResponseEntity save(Principal principal, @RequestBody DiaryRequestDTO request) { CreatedDiaryResponseDTO response = diaryService.save(getMemberId(principal), request); @@ -43,28 +41,24 @@ public ResponseEntity save(Principal principal, @RequestBody DiaryR .body(success(SUCCESS_CREATE_DIARY.getMessage(), response)); } - @Operation(description = "일기 조회") @GetMapping("/{diaryId}") public ResponseEntity getDetail(@PathVariable Long diaryId) { DiaryResponseDTO response = diaryService.getDetail(diaryId); return ResponseEntity.ok(success(SUCCESS_GET_DIARY.getMessage(), response)); } - @Operation(description = "일기 수정") @PatchMapping("/{diaryId}") public ResponseEntity update(@PathVariable Long diaryId, @RequestBody DiaryRequestDTO request) { diaryService.update(diaryId, request); return ResponseEntity.ok(success(SUCCESS_UPDATE_DAIRY.getMessage())); } - @Operation(description = "일기 삭제") @DeleteMapping("/{diaryId}") public ResponseEntity delete(@PathVariable Long diaryId) { diaryService.delete(diaryId); return ResponseEntity.ok(success(SUCCESS_DELETE_DIARY.getMessage())); } - @Operation(description = "일기 리스트 조회") @GetMapping public ResponseEntity getDiaries( Principal principal, diff --git a/src/main/java/com/smeme/server/controller/GoalController.java b/src/main/java/com/smeme/server/controller/GoalController.java index 22eee5bc..dedb22fb 100644 --- a/src/main/java/com/smeme/server/controller/GoalController.java +++ b/src/main/java/com/smeme/server/controller/GoalController.java @@ -15,11 +15,8 @@ import com.smeme.server.service.GoalService; import com.smeme.server.util.ApiResponse; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; -@Tag(name = "Goal", description = "학습 목표 API") @RestController @RequiredArgsConstructor @RequestMapping("/api/v2/goals") @@ -27,14 +24,12 @@ public class GoalController { private final GoalService goalService; - @Operation(description = "전체 학습 목표 조회") @GetMapping public ResponseEntity getAll() { GoalsResponseDTO response = goalService.getAll(); return ResponseEntity.ok(success(SUCCESS_GET_GOALS.getMessage(), response)); } - @Operation(description = "학습 목표 조회") @GetMapping("/{type}") public ResponseEntity getByType(@PathVariable GoalType type) { GoalResponseDTO response = goalService.getByType(type); diff --git a/src/main/java/com/smeme/server/controller/MemberController.java b/src/main/java/com/smeme/server/controller/MemberController.java index d1d4885b..9675b5f7 100644 --- a/src/main/java/com/smeme/server/controller/MemberController.java +++ b/src/main/java/com/smeme/server/controller/MemberController.java @@ -3,13 +3,7 @@ import com.smeme.server.dto.member.*; import com.smeme.server.service.MemberService; import com.smeme.server.util.ApiResponse; -import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -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 jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -24,53 +18,34 @@ @RestController @RequiredArgsConstructor @RequestMapping("/api/v2/members") -@Tag(name = "Member", description = "사용자 관련 API") -@SecurityRequirement(name = "Authorization") public class MemberController { private final MemberService memberService; - @Operation(summary = "사용자 정보 수정", description = "사용자의 정보를 수정합니다.") - @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "사용자 정보 수정 성공")}) - @PatchMapping() + @PatchMapping public ResponseEntity updateProfile(Principal principal, @RequestBody MemberUpdateRequestDTO request) { MemberUpdateResponseDTO response = memberService.updateMember(getMemberId(principal), request); return ResponseEntity.ok(success(SUCCESS_UPDATE_USERNAME.getMessage(), response)); } - @Operation(summary = "사용자 정보 조회", description = "사용자의 정보를 조회합니다.") - @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "사용자 정보 수정 성공" - , content = @Content(schema = @Schema(implementation = MemberGetResponseDTO.class)))}) @GetMapping("/me") public ResponseEntity getProfile(Principal principal) { MemberGetResponseDTO response = memberService.getProfile(getMemberId(principal)); return ResponseEntity.ok(success(SUCCESS_GET_USER.getMessage(), response)); } - @Operation(summary = "사용자 학습 계획 변경", description = "사용자의 학습 계획을 변경합니다.") - @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "사용자 학습 계획 성공")}) @PatchMapping("/plan") public ResponseEntity updateUserPlan(Principal principal, @Valid @RequestBody MemberPlanUpdateRequestDTO request) { memberService.updateMemberPlan(getMemberId(principal), request); return ResponseEntity.ok(success(SUCCESS_UPDATE_USER_PLAN.getMessage())); } - @Operation(summary = "닉네임 중복 체크", description = "닉네임 중복 체크를 합니다.") - @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "닉네임 중복 체크 성공" - , content = @Content(schema = @Schema(implementation = MemberNameResponseDTO.class)))}) @GetMapping("/nickname/check") public ResponseEntity checkDuplicatedName(@Parameter(description = "유저 닉네임") @RequestParam String name) { MemberNameResponseDTO response = memberService.checkDuplicatedName(name); return ResponseEntity.ok(success(SUCCESS_CHECK_DUPLICATED_NAME.getMessage(), response)); } - @Operation(summary = "사용자 푸쉬 알람 동의 여부 수정", description = "사용자의 푸쉬 알람 동의 여부를 수정합니다.") - @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "사용자 푸쉬 알람 동의 여부 수정 성공")}) @PatchMapping("/push") public ResponseEntity updateUserPush(Principal principal, @RequestBody MemberPushUpdateRequestDTO request) { memberService.updateHasAlarm(getMemberId(principal), request); diff --git a/src/main/java/com/smeme/server/controller/TestController.java b/src/main/java/com/smeme/server/controller/TestController.java index 6a630de7..e3f44acb 100644 --- a/src/main/java/com/smeme/server/controller/TestController.java +++ b/src/main/java/com/smeme/server/controller/TestController.java @@ -13,13 +13,9 @@ import com.smeme.server.service.MessageService; import com.smeme.server.util.ApiResponse; -import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.responses.ApiResponses; -import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; -@Tag(name = "Test", description = "테스트 API") @RestController @RequiredArgsConstructor @RequestMapping("/api/v2/test") @@ -28,19 +24,11 @@ public class TestController { private final MessageService messageService; private final ValueConfig valueConfig; - @Operation(summary = "서버 연결 테스트", description = "서버 연결을 테스트합니다.") - @ApiResponses({ - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "서버 연결 성공") - }) @GetMapping public ResponseEntity test() { return ResponseEntity.ok(success("server connect")); } - @Operation(summary = "푸시 알림 테스트", description = "푸시 알림을 테스트합니다.") - @ApiResponses({ - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "알림 전송 성공") - }) @GetMapping("/alarm") public ResponseEntity alarmTest(@Parameter(hidden = true) Principal principal) { messageService.pushTest(valueConfig.getMESSAGE_TITLE(), valueConfig.getMESSAGE_BODY(), Long.valueOf(principal.getName())); diff --git a/src/main/java/com/smeme/server/controller/TopicController.java b/src/main/java/com/smeme/server/controller/TopicController.java index 696e768c..b10fa454 100644 --- a/src/main/java/com/smeme/server/controller/TopicController.java +++ b/src/main/java/com/smeme/server/controller/TopicController.java @@ -3,7 +3,6 @@ import static com.smeme.server.util.ApiResponse.success; import static com.smeme.server.util.message.ResponseMessage.*; -import io.swagger.v3.oas.annotations.security.SecurityRequirement; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -13,23 +12,15 @@ import com.smeme.server.service.TopicService; import com.smeme.server.util.ApiResponse; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponses; -import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; -@Tag(name = "Topic", description = "랜덤 주제 API") @RestController @RequiredArgsConstructor @RequestMapping("/api/v2/topics") -@SecurityRequirement(name = "Authorization") public class TopicController { private final TopicService topicService; - @Operation(summary = "랜덤 주제 조회", description = "랜덤 주제를 임의로 조회합니다.") @GetMapping("/random") public ResponseEntity getRandom() { TopicResponseDTO response = topicService.getRandom(); diff --git a/src/main/java/com/smeme/server/dto/auth/SignInRequestDTO.java b/src/main/java/com/smeme/server/dto/auth/SignInRequestDTO.java index 0052d6fd..b93b3706 100644 --- a/src/main/java/com/smeme/server/dto/auth/SignInRequestDTO.java +++ b/src/main/java/com/smeme/server/dto/auth/SignInRequestDTO.java @@ -1,15 +1,11 @@ package com.smeme.server.dto.auth; - import com.fasterxml.jackson.annotation.JsonProperty; import com.smeme.server.model.SocialType; -import io.swagger.v3.oas.annotations.media.Schema; public record SignInRequestDTO( - @Schema(description = "소셜 로그인 타입", example = "KAKAO") @JsonProperty("social") SocialType socialType, - @Schema(description = "fcm 토큰", example = "dsdsdsdsds") String fcmToken ) { } diff --git a/src/main/java/com/smeme/server/dto/auth/SignInResponseDTO.java b/src/main/java/com/smeme/server/dto/auth/SignInResponseDTO.java index f6c4fc79..a2f9665c 100644 --- a/src/main/java/com/smeme/server/dto/auth/SignInResponseDTO.java +++ b/src/main/java/com/smeme/server/dto/auth/SignInResponseDTO.java @@ -2,19 +2,14 @@ import com.smeme.server.dto.auth.token.TokenVO; -import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; @Builder public record SignInResponseDTO( - @Schema(description = "smeme access token", example = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0IiwiaWF0IjoxNjIyMjU0NjY4LCJleHAiO") String accessToken, - @Schema(description = "smeme refresh token", example = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0IiwiaWF0IjoxNjIyMjU0NjY4LCJleHAiO") String refreshToken, - @Schema(description = "회원 정보 등록 여부", example = "true") boolean isRegistered, - @Schema(description = "회원의 목표 언어", example = "EN") boolean hasPlan ) { diff --git a/src/main/java/com/smeme/server/dto/auth/beta/BetaSignInRequestDTO.java b/src/main/java/com/smeme/server/dto/auth/beta/BetaSignInRequestDTO.java index cc9d2ec6..699ce229 100644 --- a/src/main/java/com/smeme/server/dto/auth/beta/BetaSignInRequestDTO.java +++ b/src/main/java/com/smeme/server/dto/auth/beta/BetaSignInRequestDTO.java @@ -1,9 +1,6 @@ package com.smeme.server.dto.auth.beta; -import io.swagger.v3.oas.annotations.media.Schema; - public record BetaSignInRequestDTO( - @Schema(description = "FCM 토큰", example = "dsdsdsdsds") String fcmToken ) { } diff --git a/src/main/java/com/smeme/server/dto/auth/beta/BetaTokenResponseDTO.java b/src/main/java/com/smeme/server/dto/auth/beta/BetaTokenResponseDTO.java index 0e6e55c3..cf1938ff 100644 --- a/src/main/java/com/smeme/server/dto/auth/beta/BetaTokenResponseDTO.java +++ b/src/main/java/com/smeme/server/dto/auth/beta/BetaTokenResponseDTO.java @@ -1,12 +1,10 @@ package com.smeme.server.dto.auth.beta; import com.smeme.server.dto.badge.BadgeResponseDTO; -import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; public record BetaTokenResponseDTO( - @Schema(description = "smeme beta access token", example = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0IiwiaWF0IjoxNjIyMjU0NjY4LCJleHAiO") String accessToken, List badges ) { diff --git a/src/main/java/com/smeme/server/dto/badge/BadgeListResponseDTO.java b/src/main/java/com/smeme/server/dto/badge/BadgeListResponseDTO.java index 295277dd..7beb67a5 100644 --- a/src/main/java/com/smeme/server/dto/badge/BadgeListResponseDTO.java +++ b/src/main/java/com/smeme/server/dto/badge/BadgeListResponseDTO.java @@ -1,6 +1,5 @@ package com.smeme.server.dto.badge; - import java.util.List; public record BadgeListResponseDTO(List badges) { diff --git a/src/main/java/com/smeme/server/dto/badge/BadgeResponseDTO.java b/src/main/java/com/smeme/server/dto/badge/BadgeResponseDTO.java index 129edff4..952c0910 100644 --- a/src/main/java/com/smeme/server/dto/badge/BadgeResponseDTO.java +++ b/src/main/java/com/smeme/server/dto/badge/BadgeResponseDTO.java @@ -2,17 +2,13 @@ import com.smeme.server.model.badge.Badge; import com.smeme.server.model.badge.MemberBadge; -import io.swagger.v3.oas.annotations.media.Schema; public record BadgeResponseDTO( - @Schema(description = "뱃지 id", example = "1") Long id, - @Schema(description = "뱃지 이름", example = "연속 3일 일기 뱃지") String name, - @Schema(description = "뱃지 타입", example = "STREAK") String type, - @Schema(description = "뱃지 이미지 url", example = "https://m.s3.ap-northeast-2.amazonaws.com/badge/streak.png") - String imageUrl) { + String imageUrl +) { public static BadgeResponseDTO of(MemberBadge memberBadge) { return new BadgeResponseDTO(memberBadge.getBadge().getId(), memberBadge.getBadge().getName(), memberBadge.getBadge().getType().toString(), memberBadge.getBadge().getImageUrl()); } diff --git a/src/main/java/com/smeme/server/dto/diary/DiaryRequestDTO.java b/src/main/java/com/smeme/server/dto/diary/DiaryRequestDTO.java index 3a8c7d76..af5fb8a9 100644 --- a/src/main/java/com/smeme/server/dto/diary/DiaryRequestDTO.java +++ b/src/main/java/com/smeme/server/dto/diary/DiaryRequestDTO.java @@ -1,9 +1,7 @@ package com.smeme.server.dto.diary; -import io.swagger.v3.oas.annotations.media.Schema; import lombok.NonNull; -@Schema(description = "일기 생성 요청 DTO") public record DiaryRequestDTO( @NonNull String content, diff --git a/src/main/java/com/smeme/server/dto/diary/DiaryResponseDTO.java b/src/main/java/com/smeme/server/dto/diary/DiaryResponseDTO.java index 46853199..d531da33 100644 --- a/src/main/java/com/smeme/server/dto/diary/DiaryResponseDTO.java +++ b/src/main/java/com/smeme/server/dto/diary/DiaryResponseDTO.java @@ -3,8 +3,6 @@ import static com.smeme.server.util.Util.dateToString; import static java.util.Objects.*; -import java.util.List; - import com.smeme.server.model.Diary; import lombok.AccessLevel; diff --git a/src/main/java/com/smeme/server/dto/member/MemberGetResponseDTO.java b/src/main/java/com/smeme/server/dto/member/MemberGetResponseDTO.java index 81c29b39..8dd7f4c4 100644 --- a/src/main/java/com/smeme/server/dto/member/MemberGetResponseDTO.java +++ b/src/main/java/com/smeme/server/dto/member/MemberGetResponseDTO.java @@ -4,26 +4,17 @@ import com.smeme.server.dto.goal.GoalResponseDTO; import com.smeme.server.dto.training.TrainingTimeResponseDTO; import com.smeme.server.model.Member; -import com.smeme.server.model.goal.Goal; -import io.swagger.v3.oas.annotations.media.Schema; public record MemberGetResponseDTO( - @Schema(description = "회원 아이디", example = "test") String username, - @Schema(description = "DEVELOP", example = "영어") String target, - @Schema(description = "목표 달성 방법", example = "주 5회 이상 오늘 하루를 돌아보는 일기 작성하기") String way, - @Schema(description = "목표 세부 내용", example = "사전 없이 일기 완성\nsmeem 연속 일기 배지 획득") String detail, - @Schema(description = "목표 언어", example = "en") String targetLang, - @Schema(description = "푸시 알림 여부", example = "true") boolean hasPushAlarm, - @Schema(description = "학습 시간") TrainingTimeResponseDTO trainingTime, - @Schema(description = "뱃지") - BadgeResponseDTO badge) { + BadgeResponseDTO badge +) { public static MemberGetResponseDTO of(GoalResponseDTO goal, Member member, TrainingTimeResponseDTO trainingTime, BadgeResponseDTO badge) { return new MemberGetResponseDTO( diff --git a/src/main/java/com/smeme/server/dto/member/MemberNameResponseDTO.java b/src/main/java/com/smeme/server/dto/member/MemberNameResponseDTO.java index b7ef8efc..2183f084 100644 --- a/src/main/java/com/smeme/server/dto/member/MemberNameResponseDTO.java +++ b/src/main/java/com/smeme/server/dto/member/MemberNameResponseDTO.java @@ -1,9 +1,6 @@ package com.smeme.server.dto.member; -import io.swagger.v3.oas.annotations.media.Schema; - public record MemberNameResponseDTO( - @Schema(description = "회원 이름 존재 여부", example = "true") boolean isExist ) { } diff --git a/src/main/java/com/smeme/server/dto/member/MemberPlanUpdateRequestDTO.java b/src/main/java/com/smeme/server/dto/member/MemberPlanUpdateRequestDTO.java index 9a7c4791..86f63d39 100644 --- a/src/main/java/com/smeme/server/dto/member/MemberPlanUpdateRequestDTO.java +++ b/src/main/java/com/smeme/server/dto/member/MemberPlanUpdateRequestDTO.java @@ -2,16 +2,10 @@ import com.smeme.server.dto.training.TrainingTimeRequestDTO; import com.smeme.server.model.goal.GoalType; -import io.swagger.v3.oas.annotations.media.Schema; - -@Schema(description = "사용자 학습 계획 수정 요청") public record MemberPlanUpdateRequestDTO( - @Schema(description = "목표 타입", example = "HOBBY") GoalType target, - @Schema(description = "학습 시간") TrainingTimeRequestDTO trainingTime, - @Schema(description = "알람 여부", example = "true") Boolean hasAlarm ) { } diff --git a/src/main/java/com/smeme/server/dto/member/MemberPushUpdateRequestDTO.java b/src/main/java/com/smeme/server/dto/member/MemberPushUpdateRequestDTO.java index 9d74fb2c..31d2a617 100644 --- a/src/main/java/com/smeme/server/dto/member/MemberPushUpdateRequestDTO.java +++ b/src/main/java/com/smeme/server/dto/member/MemberPushUpdateRequestDTO.java @@ -1,11 +1,6 @@ package com.smeme.server.dto.member; -import io.swagger.v3.oas.annotations.media.Schema; - -@Schema(description = "사용자 푸시알람 동의여부 수정 요청") public record MemberPushUpdateRequestDTO( - - @Schema(description = "알람 여부", example = "true") boolean hasAlarm ) { } diff --git a/src/main/java/com/smeme/server/dto/member/MemberUpdateRequestDTO.java b/src/main/java/com/smeme/server/dto/member/MemberUpdateRequestDTO.java index b86877ef..ecd9c301 100644 --- a/src/main/java/com/smeme/server/dto/member/MemberUpdateRequestDTO.java +++ b/src/main/java/com/smeme/server/dto/member/MemberUpdateRequestDTO.java @@ -1,12 +1,8 @@ package com.smeme.server.dto.member; -import io.swagger.v3.oas.annotations.media.Schema; - public record MemberUpdateRequestDTO( - @Schema(description = "회원 이름", example = "홍길동") @ValidUsername String username, - @Schema(description = "정책 동의 여부", example = "false") Boolean termAccepted ) { } diff --git a/src/main/java/com/smeme/server/dto/member/MemberUpdateResponseDTO.java b/src/main/java/com/smeme/server/dto/member/MemberUpdateResponseDTO.java index 81e75436..eb28517d 100644 --- a/src/main/java/com/smeme/server/dto/member/MemberUpdateResponseDTO.java +++ b/src/main/java/com/smeme/server/dto/member/MemberUpdateResponseDTO.java @@ -1,7 +1,6 @@ package com.smeme.server.dto.member; import com.smeme.server.model.badge.Badge; -import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; @@ -9,13 +8,12 @@ public record MemberUpdateResponseDTO( List badges ) { public static MemberUpdateResponseDTO of(List badges) { - return new MemberUpdateResponseDTO(badges.stream().map(badge -> new BadgeDTO(badge.getName(), badge.getImageUrl())).toList()); + return new MemberUpdateResponseDTO(badges.stream() + .map(badge -> new BadgeDTO(badge.getName(), badge.getImageUrl())).toList()); } record BadgeDTO( - @Schema(description = "뱃지 이름", example = "웰컴뱃지") String name, - @Schema(description = "뱃지 이미지 url", example = "https://m.s3.ap-northeast-2.amazonaws.com/badge/welcome.png") String imageUrl ) { } diff --git a/src/main/java/com/smeme/server/dto/training/TrainingTimeResponseDTO.java b/src/main/java/com/smeme/server/dto/training/TrainingTimeResponseDTO.java index 00ecac35..22d36025 100644 --- a/src/main/java/com/smeme/server/dto/training/TrainingTimeResponseDTO.java +++ b/src/main/java/com/smeme/server/dto/training/TrainingTimeResponseDTO.java @@ -1,7 +1,5 @@ package com.smeme.server.dto.training; -import lombok.Builder; - public record TrainingTimeResponseDTO(String day, int hour, int minute) { public static TrainingTimeResponseDTO of(String day, int hour, int minute) { return new TrainingTimeResponseDTO(day, hour, minute); From 39566330631e2df1a271e7d8323893a2882aa7db Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 17 Jan 2024 03:12:14 +0900 Subject: [PATCH 03/86] =?UTF-8?q?[FIX]=20=EB=B1=83=EC=A7=80=20=EC=A0=84?= =?UTF-8?q?=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/badge/BadgeListResponseDTO.java | 38 +- .../server/dto/badge/BadgeResponseDTO.java | 6 +- .../{controller => handler}/ErrorHandler.java | 2 +- .../com/smeme/server/model/badge/Badge.java | 10 +- .../smeme/server/service/BadgeService.java | 10 +- .../resources/static/docs/open-api-3.0.1.json | 374 ++++-------------- .../controller/BadgeControllerTest.java | 1 - .../server/fixture/badge/BadgeFixture.java | 44 +-- 8 files changed, 134 insertions(+), 351 deletions(-) rename src/main/java/com/smeme/server/{controller => handler}/ErrorHandler.java (98%) diff --git a/src/main/java/com/smeme/server/dto/badge/BadgeListResponseDTO.java b/src/main/java/com/smeme/server/dto/badge/BadgeListResponseDTO.java index 7beb67a5..dd307ee8 100644 --- a/src/main/java/com/smeme/server/dto/badge/BadgeListResponseDTO.java +++ b/src/main/java/com/smeme/server/dto/badge/BadgeListResponseDTO.java @@ -1,10 +1,42 @@ package com.smeme.server.dto.badge; +import com.smeme.server.model.badge.Badge; +import com.smeme.server.model.badge.BadgeType; +import com.smeme.server.model.badge.MemberBadge; +import lombok.Builder; + import java.util.List; -public record BadgeListResponseDTO(List badges) { - public static BadgeListResponseDTO of(List badges) { - return new BadgeListResponseDTO(badges); +public record BadgeListResponseDTO( + List badges +) { + public static BadgeListResponseDTO of(List badges, List memberBadges) { + return new BadgeListResponseDTO(badges.stream() + .map(badge -> BadgeResponseDTO.of(badge, memberBadges)) + .toList()); } + @Builder + public record BadgeResponseDTO( + String name, + BadgeType type, + String imageUrl + ) { + + private static BadgeResponseDTO of(Badge badge, List memberBadges) { + return BadgeResponseDTO.builder() + .name(badge.getName()) + .type(badge.getType()) + .imageUrl(getImageUrl(badge, memberBadges)) + .build(); + } + + private static String getImageUrl(Badge badge, List memberBadges) { + return hasBadge(badge, memberBadges) ? badge.getImageUrl() : badge.getGrayImageUrl(); + } + + private static boolean hasBadge(Badge badge, List memberBadges) { + return memberBadges.stream().anyMatch(memberBadge -> memberBadge.getBadge().equals(badge)); + } + } } \ No newline at end of file diff --git a/src/main/java/com/smeme/server/dto/badge/BadgeResponseDTO.java b/src/main/java/com/smeme/server/dto/badge/BadgeResponseDTO.java index 952c0910..822bc404 100644 --- a/src/main/java/com/smeme/server/dto/badge/BadgeResponseDTO.java +++ b/src/main/java/com/smeme/server/dto/badge/BadgeResponseDTO.java @@ -1,17 +1,15 @@ package com.smeme.server.dto.badge; import com.smeme.server.model.badge.Badge; -import com.smeme.server.model.badge.MemberBadge; +import lombok.Builder; +@Builder public record BadgeResponseDTO( Long id, String name, String type, String imageUrl ) { - public static BadgeResponseDTO of(MemberBadge memberBadge) { - return new BadgeResponseDTO(memberBadge.getBadge().getId(), memberBadge.getBadge().getName(), memberBadge.getBadge().getType().toString(), memberBadge.getBadge().getImageUrl()); - } public static BadgeResponseDTO of(Badge badge) { return new BadgeResponseDTO(badge.getId(), badge.getName(), badge.getType().toString(), badge.getImageUrl()); diff --git a/src/main/java/com/smeme/server/controller/ErrorHandler.java b/src/main/java/com/smeme/server/handler/ErrorHandler.java similarity index 98% rename from src/main/java/com/smeme/server/controller/ErrorHandler.java rename to src/main/java/com/smeme/server/handler/ErrorHandler.java index 90cc0718..9222192c 100644 --- a/src/main/java/com/smeme/server/controller/ErrorHandler.java +++ b/src/main/java/com/smeme/server/handler/ErrorHandler.java @@ -1,4 +1,4 @@ -package com.smeme.server.controller; +package com.smeme.server.handler; import static com.smeme.server.util.ApiResponse.fail; import static org.springframework.http.HttpStatus.*; diff --git a/src/main/java/com/smeme/server/model/badge/Badge.java b/src/main/java/com/smeme/server/model/badge/Badge.java index f894ab69..56a79a2a 100644 --- a/src/main/java/com/smeme/server/model/badge/Badge.java +++ b/src/main/java/com/smeme/server/model/badge/Badge.java @@ -7,7 +7,6 @@ import jakarta.persistence.Enumerated; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; -import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -27,12 +26,5 @@ public class Badge { private String imageUrl; - - @Builder - public Badge(Long id, BadgeType type, String name, String imageUrl) { - this.id = id; - this.type = type; - this.name = name; - this.imageUrl = imageUrl; - } + private String grayImageUrl; } diff --git a/src/main/java/com/smeme/server/service/BadgeService.java b/src/main/java/com/smeme/server/service/BadgeService.java index c768aa3d..8530c607 100644 --- a/src/main/java/com/smeme/server/service/BadgeService.java +++ b/src/main/java/com/smeme/server/service/BadgeService.java @@ -1,7 +1,6 @@ package com.smeme.server.service; import com.smeme.server.dto.badge.BadgeListResponseDTO; -import com.smeme.server.dto.badge.BadgeResponseDTO; import com.smeme.server.model.Member; import com.smeme.server.model.badge.Badge; import com.smeme.server.model.badge.MemberBadge; @@ -16,7 +15,6 @@ import static com.smeme.server.util.message.ErrorMessage.INVALID_BADGE; - @Service @RequiredArgsConstructor @Transactional(readOnly = true) @@ -26,11 +24,9 @@ public class BadgeService { private final BadgeRepository badgeRepository; public BadgeListResponseDTO getBadgeList(Long memberId) { - List badgeResponseDTOList = memberBadgeRepository.findAllByMemberId(memberId) - .stream() - .map(BadgeResponseDTO::of) - .toList(); - return BadgeListResponseDTO.of(badgeResponseDTOList); + List badges = badgeRepository.findAll(); + List memberBadges = memberBadgeRepository.findAllByMemberId(memberId); + return BadgeListResponseDTO.of(badges, memberBadges); } @Transactional diff --git a/src/main/resources/static/docs/open-api-3.0.1.json b/src/main/resources/static/docs/open-api-3.0.1.json index 816a5756..463e6a5d 100644 --- a/src/main/resources/static/docs/open-api-3.0.1.json +++ b/src/main/resources/static/docs/open-api-3.0.1.json @@ -69,7 +69,7 @@ "content" : { "application/json;charset=UTF-8" : { "schema" : { - "$ref" : "#/components/schemas/api-v2-corrections-correctionId594740350" + "$ref" : "#/components/schemas/api-v2-auth594740350" }, "examples" : { "회원탈퇴 Example" : { @@ -204,7 +204,7 @@ "content" : { "application/json;charset=UTF-8" : { "schema" : { - "$ref" : "#/components/schemas/api-v2-corrections-correctionId486549215" + "$ref" : "#/components/schemas/api-v2-members486549215" }, "examples" : { "유저 프로필 업데이트 성공 Example" : { @@ -245,7 +245,7 @@ "content" : { "application/json;charset=UTF-8" : { "schema" : { - "$ref" : "#/components/schemas/api-v2-corrections-correctionId594740350" + "$ref" : "#/components/schemas/api-v2-auth594740350" }, "examples" : { "test-docs" : { @@ -270,7 +270,7 @@ "content" : { "application/json;charset=UTF-8" : { "schema" : { - "$ref" : "#/components/schemas/api-v2-corrections-correctionId594740350" + "$ref" : "#/components/schemas/api-v2-auth594740350" }, "examples" : { "로그아웃 Example" : { @@ -308,100 +308,6 @@ } } }, - "/api/v2/corrections/{correctionId}" : { - "delete" : { - "tags" : [ "Correction" ], - "summary" : "첨삭 삭제", - "description" : "첨삭 삭제", - "operationId" : "첨삭 삭제 Example", - "parameters" : [ { - "name" : "correctionId", - "in" : "path", - "description" : "", - "required" : true, - "schema" : { - "type" : "string" - } - } ], - "requestBody" : { - "content" : { - "application/json" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-corrections-correctionId486549215" - }, - "examples" : { - "첨삭 삭제 Example" : { - "value" : "{\n \"sentence\" : \"correction test sentence\",\n \"content\" : \"correction test content\"\n}" - } - } - } - } - }, - "responses" : { - "200" : { - "description" : "200", - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-corrections-correctionId594740350" - }, - "examples" : { - "첨삭 삭제 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"첨삭 삭제 성공\",\n \"data\" : null\n}" - } - } - } - } - } - } - }, - "patch" : { - "tags" : [ "Correction" ], - "summary" : "첨삭 수정", - "description" : "첨삭 수정", - "operationId" : "첨삭 수정 Example", - "parameters" : [ { - "name" : "correctionId", - "in" : "path", - "description" : "", - "required" : true, - "schema" : { - "type" : "string" - } - } ], - "requestBody" : { - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-corrections-correctionId-539047035" - }, - "examples" : { - "첨삭 수정 Example" : { - "value" : "{\n \"sentence\" : \"correction test sentence\",\n \"content\" : \"correction test content\"\n}" - } - } - } - } - }, - "responses" : { - "200" : { - "description" : "200", - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-corrections-correctionId594740350" - }, - "examples" : { - "첨삭 수정 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"첨삭 수정 성공\",\n \"data\" : null\n}" - } - } - } - } - } - } - } - }, "/api/v2/diaries/{diaryId}" : { "get" : { "tags" : [ "Diary" ], @@ -423,11 +329,11 @@ "content" : { "application/json;charset=UTF-8" : { "schema" : { - "$ref" : "#/components/schemas/api-v2-diaries-diaryId-1124023080" + "$ref" : "#/components/schemas/api-v2-diaries-diaryId-1777546585" }, "examples" : { "일기 조회 성공 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"일기 조회 성공\",\n \"data\" : {\n \"diaryId\" : 1,\n \"topic\" : \"가보고 싶은 해외 여행 지가 있다면 소개해 주세요!\",\n \"content\" : \"I want to go Bla Bla ...\",\n \"createdAt\" : \"2023-08-19 14:00\",\n \"username\" : \"스미무\",\n \"corrections\" : [ {\n \"correctionId\" : 1,\n \"before\" : \"before1\",\n \"after\" : \"after1\"\n }, {\n \"correctionId\" : 1,\n \"before\" : \"before2\",\n \"after\" : \"after2\"\n } ]\n }\n}" + "value" : "{\n \"success\" : true,\n \"message\" : \"일기 조회 성공\",\n \"data\" : {\n \"diaryId\" : 1,\n \"topic\" : \"가보고 싶은 해외 여행 지가 있다면 소개해 주세요!\",\n \"content\" : \"I want to go Bla Bla ...\",\n \"createdAt\" : \"2023-08-19 14:00\",\n \"username\" : \"스미무\"\n }\n}" } } } @@ -455,7 +361,7 @@ "content" : { "application/json;charset=UTF-8" : { "schema" : { - "$ref" : "#/components/schemas/api-v2-corrections-correctionId594740350" + "$ref" : "#/components/schemas/api-v2-auth594740350" }, "examples" : { "일기 삭제 성공 Example" : { @@ -501,7 +407,7 @@ "content" : { "application/json;charset=UTF-8" : { "schema" : { - "$ref" : "#/components/schemas/api-v2-corrections-correctionId594740350" + "$ref" : "#/components/schemas/api-v2-auth594740350" }, "examples" : { "일기 수정 성공 Example" : { @@ -560,11 +466,11 @@ "content" : { "application/json;charset=UTF-8" : { "schema" : { - "$ref" : "#/components/schemas/api-v2-members-badges-599940611" + "$ref" : "#/components/schemas/api-v2-members-badges1519826817" }, "examples" : { "뱃지 목록 조회 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"뱃지 리스트 조회 성공\",\n \"data\" : {\n \"badges\" : [ {\n \"id\" : 1,\n \"name\" : \"연속 3일 일기 뱃지\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://m.s3.ap-northeast-2.amazonaws.com/badge/streak.png\"\n }, {\n \"id\" : 2,\n \"name\" : \"연속 3일 일기 뱃지\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://m.s3.ap-northeast-2.amazonaws.com/badge/streak.png\"\n } ]\n }\n}" + "value" : "{\n \"success\" : true,\n \"message\" : \"뱃지 리스트 조회 성공\",\n \"data\" : {\n \"badges\" : [ {\n \"name\" : \"연속 3일 일기 뱃지1\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지2\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지3\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지4\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지5\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n } ]\n }\n}" } } } @@ -608,7 +514,7 @@ "content" : { "application/json;charset=UTF-8" : { "schema" : { - "$ref" : "#/components/schemas/api-v2-corrections-correctionId486549215" + "$ref" : "#/components/schemas/api-v2-members486549215" }, "examples" : { "사용자 정보 수정 성공 Example" : { @@ -624,7 +530,7 @@ "content" : { "application/json;charset=UTF-8" : { "schema" : { - "$ref" : "#/components/schemas/api-v2-corrections-correctionId594740350" + "$ref" : "#/components/schemas/api-v2-auth594740350" }, "examples" : { "사용자 정보 수정 성공 Example" : { @@ -663,7 +569,7 @@ "content" : { "application/json;charset=UTF-8" : { "schema" : { - "$ref" : "#/components/schemas/api-v2-corrections-correctionId594740350" + "$ref" : "#/components/schemas/api-v2-auth594740350" }, "examples" : { "푸시 알림 동의여부 성공 Example" : { @@ -701,62 +607,6 @@ } } }, - "/api/v2/corrections/diary/{diaryId}" : { - "post" : { - "tags" : [ "Correction" ], - "summary" : "첨삭 추가", - "description" : "첨삭 추가", - "operationId" : "첨삭 추가 Example", - "parameters" : [ { - "name" : "diaryId", - "in" : "path", - "description" : "", - "required" : true, - "schema" : { - "type" : "string" - } - } ], - "requestBody" : { - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-corrections-correctionId-539047035" - }, - "examples" : { - "첨삭 추가 Example" : { - "value" : "{\n \"sentence\" : \"correction test sentence\",\n \"content\" : \"correction test content\"\n}" - } - } - } - } - }, - "responses" : { - "201" : { - "description" : "201", - "headers" : { - "Location" : { - "description" : "생성된 첨삭 조회 URI", - "schema" : { - "type" : "string" - } - } - }, - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-corrections-diary-diaryId1208203954" - }, - "examples" : { - "첨삭 추가 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"일기 첨삭 성공\",\n \"data\" : {\n \"diaryId\" : 1,\n \"badges\" : [ {\n \"name\" : \"연속 3일 일기 뱃지\",\n \"imageUrl\" : \"https://m.s3.ap-northeast-2.amazonaws.com/badge/streak.png\"\n } ]\n }\n}" - } - } - } - } - } - } - } - }, "/api/v2/members/nickname/check" : { "get" : { "tags" : [ "Member" ], @@ -769,7 +619,7 @@ "content" : { "application/json;charset=UTF-8" : { "schema" : { - "$ref" : "#/components/schemas/api-v2-corrections-correctionId594740350" + "$ref" : "#/components/schemas/api-v2-auth594740350" }, "examples" : { "닉네임 중복 체크 성공 Example" : { @@ -785,50 +635,6 @@ }, "components" : { "schemas" : { - "api-v2-members-badges-599940611" : { - "type" : "object", - "properties" : { - "data" : { - "type" : "object", - "properties" : { - "badges" : { - "type" : "array", - "description" : "뱃지 목록", - "items" : { - "type" : "object", - "properties" : { - "imageUrl" : { - "type" : "string", - "description" : "뱃지 이미지 URL" - }, - "name" : { - "type" : "string", - "description" : "뱃지 이름" - }, - "id" : { - "type" : "number", - "description" : "뱃지 ID" - }, - "type" : { - "type" : "string", - "description" : "뱃지 타입" - } - } - } - } - }, - "description" : "응답 데이터" - }, - "success" : { - "type" : "boolean", - "description" : "응답 성공 여부" - }, - "message" : { - "type" : "string", - "description" : "응답 메시지" - } - } - }, "api-v2-members1042223039" : { "type" : "object", "properties" : { @@ -1000,6 +806,45 @@ } } }, + "api-v2-diaries-diaryId-1777546585" : { + "type" : "object", + "properties" : { + "data" : { + "type" : "object", + "properties" : { + "createdAt" : { + "type" : "string", + "description" : "작성 날짜" + }, + "diaryId" : { + "type" : "number", + "description" : "일기 id" + }, + "topic" : { + "type" : "string", + "description" : "랜덤 주제" + }, + "content" : { + "type" : "string", + "description" : "일기 내용" + }, + "username" : { + "type" : "string", + "description" : "작성자 이름" + } + }, + "description" : "응답 데이터" + }, + "success" : { + "type" : "boolean", + "description" : "응답 성공 여부" + }, + "message" : { + "type" : "string", + "description" : "응답 메시지" + } + } + }, "api-v2-members-push-1005876473" : { "type" : "object", "properties" : { @@ -1009,7 +854,7 @@ } } }, - "api-v2-corrections-correctionId594740350" : { + "api-v2-auth594740350" : { "type" : "object", "properties" : { "success" : { @@ -1049,7 +894,20 @@ } } }, - "api-v2-corrections-diary-diaryId1208203954" : { + "api-v2-diaries-diaryId1231150871" : { + "type" : "object", + "properties" : { + "topicId" : { + "type" : "number", + "description" : "랜덤 주제 id" + }, + "content" : { + "type" : "string", + "description" : "수정할 일기 내용" + } + } + }, + "api-v2-members-badges1519826817" : { "type" : "object", "properties" : { "data" : { @@ -1068,13 +926,13 @@ "name" : { "type" : "string", "description" : "뱃지 이름" + }, + "type" : { + "type" : "string", + "description" : "뱃지 타입" } } } - }, - "diaryId" : { - "type" : "number", - "description" : "일기 ID" } }, "description" : "응답 데이터" @@ -1089,19 +947,6 @@ } } }, - "api-v2-diaries-diaryId1231150871" : { - "type" : "object", - "properties" : { - "topicId" : { - "type" : "number", - "description" : "랜덤 주제 id" - }, - "content" : { - "type" : "string", - "description" : "수정할 일기 내용" - } - } - }, "api-v2-diaries-486735900" : { "type" : "object", "properties" : { @@ -1186,79 +1031,6 @@ } } }, - "api-v2-diaries-diaryId-1124023080" : { - "type" : "object", - "properties" : { - "data" : { - "type" : "object", - "properties" : { - "createdAt" : { - "type" : "string", - "description" : "작성 날짜" - }, - "corrections" : { - "type" : "array", - "description" : "첨삭 리스트", - "items" : { - "type" : "object", - "properties" : { - "before" : { - "type" : "string", - "description" : "첨삭 전 내용" - }, - "after" : { - "type" : "string", - "description" : "첨삭 후 내용" - }, - "correctionId" : { - "type" : "number", - "description" : "첨삭 id" - } - } - } - }, - "diaryId" : { - "type" : "number", - "description" : "일기 id" - }, - "topic" : { - "type" : "string", - "description" : "랜덤 주제" - }, - "content" : { - "type" : "string", - "description" : "일기 내용" - }, - "username" : { - "type" : "string", - "description" : "작성자 이름" - } - }, - "description" : "응답 데이터" - }, - "success" : { - "type" : "boolean", - "description" : "응답 성공 여부" - }, - "message" : { - "type" : "string", - "description" : "응답 메시지" - } - } - }, - "api-v2-corrections-correctionId-539047035" : { - "type" : "object", - "properties" : { - "sentence" : { - "type" : "string", - "description" : "첨삭 전 문장" - }, - "content" : { - "type" : "string", - "description" : "첨삭 후 문장" - } - } - }, "api-v2-goals-1163689825" : { "type" : "object", "properties" : { @@ -1322,7 +1094,7 @@ } } }, - "api-v2-corrections-correctionId486549215" : { + "api-v2-members486549215" : { "type" : "object" } } diff --git a/src/test/java/com/smeme/server/controller/BadgeControllerTest.java b/src/test/java/com/smeme/server/controller/BadgeControllerTest.java index a22c57b3..331eee5a 100644 --- a/src/test/java/com/smeme/server/controller/BadgeControllerTest.java +++ b/src/test/java/com/smeme/server/controller/BadgeControllerTest.java @@ -47,7 +47,6 @@ void success_getBadgesList() throws Exception { fieldWithPath("message").type(STRING).description("응답 메시지"), fieldWithPath("data").type(OBJECT).description("응답 데이터"), fieldWithPath("data.badges").type(ARRAY).description("뱃지 목록"), - fieldWithPath("data.badges[].id").type(NUMBER).description("뱃지 ID"), fieldWithPath("data.badges[].name").type(STRING).description("뱃지 이름"), fieldWithPath("data.badges[].type").type(STRING).description("뱃지 타입"), fieldWithPath("data.badges[].imageUrl").type(STRING).description("뱃지 이미지 URL") diff --git a/src/test/java/com/smeme/server/fixture/badge/BadgeFixture.java b/src/test/java/com/smeme/server/fixture/badge/BadgeFixture.java index 3c2cfa10..30c3d607 100644 --- a/src/test/java/com/smeme/server/fixture/badge/BadgeFixture.java +++ b/src/test/java/com/smeme/server/fixture/badge/BadgeFixture.java @@ -1,13 +1,11 @@ package com.smeme.server.fixture.badge; - import com.smeme.server.dto.badge.BadgeListResponseDTO; import com.smeme.server.dto.badge.BadgeResponseDTO; -import com.smeme.server.model.badge.Badge; import com.smeme.server.model.badge.BadgeType; -import java.util.ArrayList; import java.util.List; +import java.util.stream.Stream; public class BadgeFixture { @@ -16,35 +14,31 @@ public class BadgeFixture { private static final BadgeType BADGE_TYPE = BadgeType.COMBO; private static final String BADGE_IMAGE_URL = "https://m.s3.ap-northeast-2.amazonaws.com/badge/streak.png"; - public static Badge createBadge() { - return Badge.builder() - .name(BADGE_NAME) + public static BadgeResponseDTO createBadgeResponseDTO() { + return BadgeResponseDTO.builder() .id(BADGE_ID) - .type(BADGE_TYPE) + .name(BADGE_NAME) + .type(BADGE_TYPE.toString()) .imageUrl(BADGE_IMAGE_URL) .build(); } - public static BadgeResponseDTO createBadgeResponseDTO() { - return BadgeResponseDTO.of(createBadge()); + public static BadgeListResponseDTO createBadgeListResponseDTO() { + return new BadgeListResponseDTO(createBadgeResponses()); } - public static BadgeListResponseDTO createBadgeListResponseDTO() { - List badges = new ArrayList<>(); - - for (long l = 1L; l < 3L; l++) { - badges.add( - BadgeResponseDTO.of( - Badge.builder() - .id(l) - .name(BADGE_NAME) - .type(BADGE_TYPE) - .imageUrl(BADGE_IMAGE_URL) - .build() - ) - ); - } - return BadgeListResponseDTO.of(badges); + private static List createBadgeResponses() { + return Stream.iterate(1, i -> i + 1).limit(5) + .map(BadgeFixture::createBadgeResponse) + .toList(); + } + + private static BadgeListResponseDTO.BadgeResponseDTO createBadgeResponse(int i) { + return BadgeListResponseDTO.BadgeResponseDTO.builder() + .name(BADGE_NAME + i) + .type(BADGE_TYPE) + .imageUrl("https://...") + .build(); } } From 0a17961ee6294a6fa3e7ae32c549b2c815f98a53 Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 17 Jan 2024 03:14:11 +0900 Subject: [PATCH 04/86] =?UTF-8?q?[DELETE]=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/repository/badge/MemberBadgeRepository.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/main/java/com/smeme/server/repository/badge/MemberBadgeRepository.java b/src/main/java/com/smeme/server/repository/badge/MemberBadgeRepository.java index 978208b2..27897e30 100644 --- a/src/main/java/com/smeme/server/repository/badge/MemberBadgeRepository.java +++ b/src/main/java/com/smeme/server/repository/badge/MemberBadgeRepository.java @@ -1,7 +1,4 @@ package com.smeme.server.repository.badge; - -import com.smeme.server.model.Member; -import com.smeme.server.model.badge.Badge; import com.smeme.server.model.badge.MemberBadge; import org.springframework.data.jpa.repository.JpaRepository; @@ -11,10 +8,5 @@ public interface MemberBadgeRepository extends JpaRepository { List findAllByMemberId(Long memberId); - - boolean existsByMemberAndBadge(Member member, Badge badge); - Optional findFirstByMemberIdOrderByCreatedAtDesc(Long memberId); - - void deleteAllByMemberId(Long id); } From ff2e989f42c5adb62cd8a996123c6bdbadd1cedf Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 17 Jan 2024 03:19:04 +0900 Subject: [PATCH 05/86] =?UTF-8?q?[DELETE]=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/fixture/member/MemberFixture.java | 37 ------------------- 1 file changed, 37 deletions(-) diff --git a/src/test/java/com/smeme/server/fixture/member/MemberFixture.java b/src/test/java/com/smeme/server/fixture/member/MemberFixture.java index 82c2a919..019bf1cd 100644 --- a/src/test/java/com/smeme/server/fixture/member/MemberFixture.java +++ b/src/test/java/com/smeme/server/fixture/member/MemberFixture.java @@ -7,17 +7,9 @@ import com.smeme.server.model.LangType; import com.smeme.server.model.Member; import com.smeme.server.model.SocialType; -import com.smeme.server.model.badge.Badge; -import com.smeme.server.model.badge.BadgeType; import com.smeme.server.model.goal.GoalType; import lombok.val; -import java.util.ArrayList; -import java.util.List; - -import static com.smeme.server.fixture.badge.BadgeFixture.createBadgeResponseDTO; -import static com.smeme.server.fixture.goal.GoalFixture.createGoalResponseDTO; - public class MemberFixture { private static final String MEMBER_USERNAME = "홍길동"; @@ -26,17 +18,8 @@ public class MemberFixture { private static final String MEMBER_SOCIAL_ID = "123456789"; private static final String MEMBER_FCM_TOKEN = "fcm_token"; private static final LangType TARGET_LANG = LangType.en; - private static final boolean MEMBER_IS_EXIST = true; - - private static final boolean HAS_ALARM = true; - // Badge - private static final String BADGE_NAME = "연속 3일 일기 뱃지"; - private static final Long BADGE_ID = 1L; - private static final BadgeType BADGE_TYPE = BadgeType.COMBO; - private static final String BADGE_IMAGE_URL = "https://m.s3.ap-northeast-2.amazonaws.com/badge/streak.png"; - public static Member createMember() { val member = Member.builder() .social(MEMBER_SOCIAL) @@ -57,10 +40,6 @@ public static MemberGetResponseDTO createMemberGetResponseDTO() { ); } - public static MemberNameResponseDTO createMemberNameResponseDTO() { - return new MemberNameResponseDTO(MEMBER_IS_EXIST); - } - public static MemberUpdateRequestDTO createMemberUpdateRequestDTO() { return new MemberUpdateRequestDTO(MEMBER_USERNAME, HAS_ALARM); } @@ -73,22 +52,6 @@ public static MemberPlanUpdateRequestDTO createMemberPlanUpdateRequestDTO() { ); } - public static MemberUpdateResponseDTO createMemberUpdateResponseDTO() { - - List badges = new ArrayList<>(); - - for (long l = 1L; l < 5L; l++) { - Badge badge = Badge.builder() - .id(l) - .name(BADGE_NAME) - .type(BADGE_TYPE) - .imageUrl(BADGE_IMAGE_URL) - .build(); - badges.add(badge); - } - return MemberUpdateResponseDTO.of(badges); - } - public static MemberPushUpdateRequestDTO createMemberPushUpdateRequestDTO() { return new MemberPushUpdateRequestDTO(HAS_ALARM); } From fa7d9537a9accaba9057caecb47964758894180e Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 24 Jan 2024 00:05:06 +0900 Subject: [PATCH 06/86] =?UTF-8?q?[TEST]=20=EB=B1=83=EC=A7=80=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/BadgeControllerTest.java | 11 +++++++---- .../smeme/server/fixture/badge/BadgeFixture.java | 13 ++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/smeme/server/controller/BadgeControllerTest.java b/src/test/java/com/smeme/server/controller/BadgeControllerTest.java index 331eee5a..15e63376 100644 --- a/src/test/java/com/smeme/server/controller/BadgeControllerTest.java +++ b/src/test/java/com/smeme/server/controller/BadgeControllerTest.java @@ -46,10 +46,13 @@ void success_getBadgesList() throws Exception { fieldWithPath("success").type(BOOLEAN).description("응답 성공 여부"), fieldWithPath("message").type(STRING).description("응답 메시지"), fieldWithPath("data").type(OBJECT).description("응답 데이터"), - fieldWithPath("data.badges").type(ARRAY).description("뱃지 목록"), - fieldWithPath("data.badges[].name").type(STRING).description("뱃지 이름"), - fieldWithPath("data.badges[].type").type(STRING).description("뱃지 타입"), - fieldWithPath("data.badges[].imageUrl").type(STRING).description("뱃지 이미지 URL") + fieldWithPath("data.badgeTypes").type(ARRAY).description("뱃지 타입 목록"), + fieldWithPath("data.badgeTypes[].badgeType").type(STRING).description("뱃지 타입"), + fieldWithPath("data.badgeTypes[].badgeTypeName").type(STRING).description("뱃지 타입 이름"), + fieldWithPath("data.badgeTypes[].badges").type(ARRAY).description("타입별 뱃지 리스트"), + fieldWithPath("data.badgeTypes[].badges[].name").type(STRING).description("뱃지 이름"), + fieldWithPath("data.badgeTypes[].badges[].type").type(STRING).description("뱃지 타입"), + fieldWithPath("data.badgeTypes[].badges[].imageUrl").type(STRING).description("뱃지 이미지 URL") ) .build(); // when diff --git a/src/test/java/com/smeme/server/fixture/badge/BadgeFixture.java b/src/test/java/com/smeme/server/fixture/badge/BadgeFixture.java index 30c3d607..61303c0f 100644 --- a/src/test/java/com/smeme/server/fixture/badge/BadgeFixture.java +++ b/src/test/java/com/smeme/server/fixture/badge/BadgeFixture.java @@ -1,6 +1,7 @@ package com.smeme.server.fixture.badge; import com.smeme.server.dto.badge.BadgeListResponseDTO; +import com.smeme.server.dto.badge.BadgeListResponseDTO.BadgeTypeResponseDTO; import com.smeme.server.dto.badge.BadgeResponseDTO; import com.smeme.server.model.badge.BadgeType; @@ -24,7 +25,17 @@ public static BadgeResponseDTO createBadgeResponseDTO() { } public static BadgeListResponseDTO createBadgeListResponseDTO() { - return new BadgeListResponseDTO(createBadgeResponses()); + return new BadgeListResponseDTO(createBadgeTypesResponse()); + } + + private static List createBadgeTypesResponse() { + return Stream.iterate(1, i -> i + 1).limit(5) + .map(i -> createBadgeTypeResponse()) + .toList(); + } + + private static BadgeTypeResponseDTO createBadgeTypeResponse() { + return new BadgeTypeResponseDTO(BADGE_TYPE, BADGE_NAME, createBadgeResponses()); } private static List createBadgeResponses() { From 91b2df0af2f6e283ad8d69cb9eb3d1c12dfb7bfd Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 24 Jan 2024 00:06:28 +0900 Subject: [PATCH 07/86] =?UTF-8?q?[FIX]=20=EB=B1=83=EC=A7=80=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=A0=95=EB=A0=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/badge/BadgeListResponseDTO.java | 39 ++++++++++++++++--- .../badge/BadgeCustomRepository.java | 9 +++++ .../repository/badge/BadgeRepository.java | 3 +- .../repository/badge/BadgeRepositoryImpl.java | 26 +++++++++++++ .../smeme/server/service/BadgeService.java | 23 +++++++++-- 5 files changed, 88 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/smeme/server/repository/badge/BadgeCustomRepository.java create mode 100644 src/main/java/com/smeme/server/repository/badge/BadgeRepositoryImpl.java diff --git a/src/main/java/com/smeme/server/dto/badge/BadgeListResponseDTO.java b/src/main/java/com/smeme/server/dto/badge/BadgeListResponseDTO.java index dd307ee8..9b6f2df2 100644 --- a/src/main/java/com/smeme/server/dto/badge/BadgeListResponseDTO.java +++ b/src/main/java/com/smeme/server/dto/badge/BadgeListResponseDTO.java @@ -3,17 +3,44 @@ import com.smeme.server.model.badge.Badge; import com.smeme.server.model.badge.BadgeType; import com.smeme.server.model.badge.MemberBadge; -import lombok.Builder; +import lombok.*; import java.util.List; +import java.util.Map; public record BadgeListResponseDTO( - List badges + List badgeTypes ) { - public static BadgeListResponseDTO of(List badges, List memberBadges) { - return new BadgeListResponseDTO(badges.stream() - .map(badge -> BadgeResponseDTO.of(badge, memberBadges)) - .toList()); + public static BadgeListResponseDTO of(Map> badgeMap, List memberBadges) { + val badgeTypes = getBadgesType(badgeMap, memberBadges); + return new BadgeListResponseDTO(badgeTypes); + } + + private static List getBadgesType(Map> badgeMap, List memberBadges) { + return badgeMap.keySet().stream() + .map(type -> BadgeTypeResponseDTO.of(type, badgeMap.get(type), memberBadges)) + .toList(); + } + + @Builder + public record BadgeTypeResponseDTO( + BadgeType badgeType, + String badgeTypeName, + List badges + ) { + public static BadgeTypeResponseDTO of(BadgeType type, List badges, List memberBadges) { + return BadgeTypeResponseDTO.builder() + .badgeType(type) + .badgeTypeName(type.getDescription()) + .badges(getBadges(badges, memberBadges)) + .build(); + } + + private static List getBadges(List badges, List memberBadges) { + return badges.stream() + .map(badge -> BadgeResponseDTO.of(badge, memberBadges)) + .toList(); + } } @Builder diff --git a/src/main/java/com/smeme/server/repository/badge/BadgeCustomRepository.java b/src/main/java/com/smeme/server/repository/badge/BadgeCustomRepository.java new file mode 100644 index 00000000..60a71612 --- /dev/null +++ b/src/main/java/com/smeme/server/repository/badge/BadgeCustomRepository.java @@ -0,0 +1,9 @@ +package com.smeme.server.repository.badge; + +import com.smeme.server.model.badge.Badge; + +import java.util.List; + +public interface BadgeCustomRepository { + List findAllOrderByName(); +} diff --git a/src/main/java/com/smeme/server/repository/badge/BadgeRepository.java b/src/main/java/com/smeme/server/repository/badge/BadgeRepository.java index 0ab494d1..3b55f411 100644 --- a/src/main/java/com/smeme/server/repository/badge/BadgeRepository.java +++ b/src/main/java/com/smeme/server/repository/badge/BadgeRepository.java @@ -3,6 +3,5 @@ import com.smeme.server.model.badge.Badge; import org.springframework.data.jpa.repository.JpaRepository; -public interface BadgeRepository extends JpaRepository { - +public interface BadgeRepository extends JpaRepository, BadgeCustomRepository { } diff --git a/src/main/java/com/smeme/server/repository/badge/BadgeRepositoryImpl.java b/src/main/java/com/smeme/server/repository/badge/BadgeRepositoryImpl.java new file mode 100644 index 00000000..2408122c --- /dev/null +++ b/src/main/java/com/smeme/server/repository/badge/BadgeRepositoryImpl.java @@ -0,0 +1,26 @@ +package com.smeme.server.repository.badge; + +import com.querydsl.core.types.dsl.Expressions; +import com.querydsl.jpa.impl.JPAQueryFactory; +import com.smeme.server.model.badge.Badge; +import lombok.*; +import org.springframework.stereotype.Repository; +import java.util.List; + +import static com.smeme.server.model.badge.QBadge.badge; + +@Repository +@RequiredArgsConstructor +public class BadgeRepositoryImpl implements BadgeCustomRepository { + + private final JPAQueryFactory queryFactory; + + @Override + public List findAllOrderByName() { + val contentInKRExpression = Expressions.stringTemplate("SUBSTR({0}, 1, 1)", badge.name); + return queryFactory + .selectFrom(badge) + .orderBy(contentInKRExpression.asc()) + .fetch(); + } +} diff --git a/src/main/java/com/smeme/server/service/BadgeService.java b/src/main/java/com/smeme/server/service/BadgeService.java index 8530c607..704acb6f 100644 --- a/src/main/java/com/smeme/server/service/BadgeService.java +++ b/src/main/java/com/smeme/server/service/BadgeService.java @@ -3,15 +3,19 @@ import com.smeme.server.dto.badge.BadgeListResponseDTO; import com.smeme.server.model.Member; import com.smeme.server.model.badge.Badge; +import com.smeme.server.model.badge.BadgeType; import com.smeme.server.model.badge.MemberBadge; import com.smeme.server.repository.badge.BadgeRepository; import com.smeme.server.repository.badge.MemberBadgeRepository; import jakarta.persistence.EntityNotFoundException; -import lombok.RequiredArgsConstructor; +import lombok.*; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import static com.smeme.server.util.message.ErrorMessage.INVALID_BADGE; @@ -24,9 +28,20 @@ public class BadgeService { private final BadgeRepository badgeRepository; public BadgeListResponseDTO getBadgeList(Long memberId) { - List badges = badgeRepository.findAll(); - List memberBadges = memberBadgeRepository.findAllByMemberId(memberId); - return BadgeListResponseDTO.of(badges, memberBadges); + val badges = badgeRepository.findAllOrderByName(); + val badgeMap = classifiedByType(badges); + val memberBadges = memberBadgeRepository.findAllByMemberId(memberId); + return BadgeListResponseDTO.of(badgeMap, memberBadges); + } + + private Map> classifiedByType(List badges) { + val badgeMap = new HashMap>(); + badges.forEach(badge -> putBadgeMap(badgeMap, badge)); + return badgeMap; + } + + private void putBadgeMap(Map> badgeMap, Badge badge) { + badgeMap.computeIfAbsent(badge.getType(), k -> new ArrayList<>()).add(badge); } @Transactional From c38e7eb50e494a9b7989d301256dbd3454d63c8c Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 24 Jan 2024 00:15:35 +0900 Subject: [PATCH 08/86] =?UTF-8?q?[FIX]=20=EB=B1=83=EC=A7=80=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=A0=95=EB=A0=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../badge/BadgeCustomRepository.java | 2 +- .../repository/badge/BadgeRepositoryImpl.java | 6 +-- .../smeme/server/service/BadgeService.java | 2 +- .../resources/static/docs/open-api-3.0.1.json | 41 +++++++++++++------ 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/smeme/server/repository/badge/BadgeCustomRepository.java b/src/main/java/com/smeme/server/repository/badge/BadgeCustomRepository.java index 60a71612..59c89901 100644 --- a/src/main/java/com/smeme/server/repository/badge/BadgeCustomRepository.java +++ b/src/main/java/com/smeme/server/repository/badge/BadgeCustomRepository.java @@ -5,5 +5,5 @@ import java.util.List; public interface BadgeCustomRepository { - List findAllOrderByName(); + List findAllOrderById(); } diff --git a/src/main/java/com/smeme/server/repository/badge/BadgeRepositoryImpl.java b/src/main/java/com/smeme/server/repository/badge/BadgeRepositoryImpl.java index 2408122c..54a4140f 100644 --- a/src/main/java/com/smeme/server/repository/badge/BadgeRepositoryImpl.java +++ b/src/main/java/com/smeme/server/repository/badge/BadgeRepositoryImpl.java @@ -1,6 +1,5 @@ package com.smeme.server.repository.badge; -import com.querydsl.core.types.dsl.Expressions; import com.querydsl.jpa.impl.JPAQueryFactory; import com.smeme.server.model.badge.Badge; import lombok.*; @@ -16,11 +15,10 @@ public class BadgeRepositoryImpl implements BadgeCustomRepository { private final JPAQueryFactory queryFactory; @Override - public List findAllOrderByName() { - val contentInKRExpression = Expressions.stringTemplate("SUBSTR({0}, 1, 1)", badge.name); + public List findAllOrderById() { return queryFactory .selectFrom(badge) - .orderBy(contentInKRExpression.asc()) + .orderBy(badge.id.asc()) .fetch(); } } diff --git a/src/main/java/com/smeme/server/service/BadgeService.java b/src/main/java/com/smeme/server/service/BadgeService.java index 704acb6f..992f1b4d 100644 --- a/src/main/java/com/smeme/server/service/BadgeService.java +++ b/src/main/java/com/smeme/server/service/BadgeService.java @@ -28,7 +28,7 @@ public class BadgeService { private final BadgeRepository badgeRepository; public BadgeListResponseDTO getBadgeList(Long memberId) { - val badges = badgeRepository.findAllOrderByName(); + val badges = badgeRepository.findAllOrderById(); val badgeMap = classifiedByType(badges); val memberBadges = memberBadgeRepository.findAllByMemberId(memberId); return BadgeListResponseDTO.of(badgeMap, memberBadges); diff --git a/src/main/resources/static/docs/open-api-3.0.1.json b/src/main/resources/static/docs/open-api-3.0.1.json index 463e6a5d..77e1c10f 100644 --- a/src/main/resources/static/docs/open-api-3.0.1.json +++ b/src/main/resources/static/docs/open-api-3.0.1.json @@ -466,11 +466,11 @@ "content" : { "application/json;charset=UTF-8" : { "schema" : { - "$ref" : "#/components/schemas/api-v2-members-badges1519826817" + "$ref" : "#/components/schemas/api-v2-members-badges1884183897" }, "examples" : { "뱃지 목록 조회 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"뱃지 리스트 조회 성공\",\n \"data\" : {\n \"badges\" : [ {\n \"name\" : \"연속 3일 일기 뱃지1\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지2\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지3\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지4\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지5\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n } ]\n }\n}" + "value" : "{\n \"success\" : true,\n \"message\" : \"뱃지 리스트 조회 성공\",\n \"data\" : {\n \"badgeTypes\" : [ {\n \"badgeType\" : \"COMBO\",\n \"badgeTypeName\" : \"연속 3일 일기 뱃지\",\n \"badges\" : [ {\n \"name\" : \"연속 3일 일기 뱃지1\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지2\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지3\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지4\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지5\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n } ]\n }, {\n \"badgeType\" : \"COMBO\",\n \"badgeTypeName\" : \"연속 3일 일기 뱃지\",\n \"badges\" : [ {\n \"name\" : \"연속 3일 일기 뱃지1\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지2\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지3\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지4\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지5\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n } ]\n }, {\n \"badgeType\" : \"COMBO\",\n \"badgeTypeName\" : \"연속 3일 일기 뱃지\",\n \"badges\" : [ {\n \"name\" : \"연속 3일 일기 뱃지1\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지2\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지3\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지4\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지5\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n } ]\n }, {\n \"badgeType\" : \"COMBO\",\n \"badgeTypeName\" : \"연속 3일 일기 뱃지\",\n \"badges\" : [ {\n \"name\" : \"연속 3일 일기 뱃지1\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지2\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지3\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지4\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지5\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n } ]\n }, {\n \"badgeType\" : \"COMBO\",\n \"badgeTypeName\" : \"연속 3일 일기 뱃지\",\n \"badges\" : [ {\n \"name\" : \"연속 3일 일기 뱃지1\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지2\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지3\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지4\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지5\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n } ]\n } ]\n }\n}" } } } @@ -907,29 +907,46 @@ } } }, - "api-v2-members-badges1519826817" : { + "api-v2-members-badges1884183897" : { "type" : "object", "properties" : { "data" : { "type" : "object", "properties" : { - "badges" : { + "badgeTypes" : { "type" : "array", - "description" : "뱃지 목록", + "description" : "뱃지 타입 목록", "items" : { "type" : "object", "properties" : { - "imageUrl" : { - "type" : "string", - "description" : "뱃지 이미지 URL" + "badges" : { + "type" : "array", + "description" : "타입별 뱃지 리스트", + "items" : { + "type" : "object", + "properties" : { + "imageUrl" : { + "type" : "string", + "description" : "뱃지 이미지 URL" + }, + "name" : { + "type" : "string", + "description" : "뱃지 이름" + }, + "type" : { + "type" : "string", + "description" : "뱃지 타입" + } + } + } }, - "name" : { + "badgeType" : { "type" : "string", - "description" : "뱃지 이름" + "description" : "뱃지 타입" }, - "type" : { + "badgeTypeName" : { "type" : "string", - "description" : "뱃지 타입" + "description" : "뱃지 타입 이름" } } } From 5386cdbad6feaebdf8430f53c7a46fc05c30d9da Mon Sep 17 00:00:00 2001 From: thguss Date: Sun, 28 Jan 2024 12:50:26 +0900 Subject: [PATCH 09/86] =?UTF-8?q?[FIX]=20=ED=9A=8C=EC=9B=90=EC=9D=B4=20?= =?UTF-8?q?=EC=9E=84=EC=8B=9C=20=EC=82=AD=EC=A0=9C=ED=95=9C=20=EC=9D=BC?= =?UTF-8?q?=EA=B8=B0=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smeme/server/repository/diary/DeletedDiaryRepository.java | 2 ++ src/main/java/com/smeme/server/service/DiaryService.java | 1 + 2 files changed, 3 insertions(+) diff --git a/src/main/java/com/smeme/server/repository/diary/DeletedDiaryRepository.java b/src/main/java/com/smeme/server/repository/diary/DeletedDiaryRepository.java index 0d83c298..e8d67c55 100644 --- a/src/main/java/com/smeme/server/repository/diary/DeletedDiaryRepository.java +++ b/src/main/java/com/smeme/server/repository/diary/DeletedDiaryRepository.java @@ -1,10 +1,12 @@ package com.smeme.server.repository.diary; import com.smeme.server.model.DeletedDiary; +import com.smeme.server.model.Member; import org.springframework.data.jpa.repository.JpaRepository; import java.time.LocalDateTime; public interface DeletedDiaryRepository extends JpaRepository { void deleteByUpdatedAtBefore(LocalDateTime expiredAt); + void deleteByMember(Member member); } diff --git a/src/main/java/com/smeme/server/service/DiaryService.java b/src/main/java/com/smeme/server/service/DiaryService.java index 5f95fed3..16bf3f2c 100644 --- a/src/main/java/com/smeme/server/service/DiaryService.java +++ b/src/main/java/com/smeme/server/service/DiaryService.java @@ -112,6 +112,7 @@ private LocalDateTime getExpiryDate() { @Transactional public void deleteAllByMember(Member member) { diaryRepository.deleteAllByMember(member); + deletedDiaryRepository.deleteByMember(member); } public List getAllByMemberId(Long memberId) { From db8a8e6a0d2cdadca726c1cce4901a3b91876cbe Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 31 Jan 2024 00:05:31 +0900 Subject: [PATCH 10/86] =?UTF-8?q?[ADD]=20=ED=9A=8D=EB=93=9D=ED=95=9C=20?= =?UTF-8?q?=EB=B1=83=EC=A7=80=EC=97=90=20=ED=83=80=EC=9E=85=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/badge/AcquiredBadgeResponseDTO.java | 21 +++++++++++++++++++ .../dto/diary/CreatedDiaryResponseDTO.java | 16 +++----------- .../dto/member/MemberUpdateResponseDTO.java | 13 +++--------- .../controller/DiaryControllerTest.java | 19 ++++++++++------- 4 files changed, 39 insertions(+), 30 deletions(-) create mode 100644 src/main/java/com/smeme/server/dto/badge/AcquiredBadgeResponseDTO.java diff --git a/src/main/java/com/smeme/server/dto/badge/AcquiredBadgeResponseDTO.java b/src/main/java/com/smeme/server/dto/badge/AcquiredBadgeResponseDTO.java new file mode 100644 index 00000000..aae5ca1e --- /dev/null +++ b/src/main/java/com/smeme/server/dto/badge/AcquiredBadgeResponseDTO.java @@ -0,0 +1,21 @@ +package com.smeme.server.dto.badge; + +import com.smeme.server.model.badge.Badge; +import com.smeme.server.model.badge.BadgeType; +import lombok.AccessLevel; +import lombok.Builder; + +@Builder(access = AccessLevel.PRIVATE) +public record AcquiredBadgeResponseDTO( + String name, + String imageUrl, + BadgeType type +) { + public static AcquiredBadgeResponseDTO of(Badge badge) { + return AcquiredBadgeResponseDTO.builder() + .name(badge.getName()) + .imageUrl(badge.getImageUrl()) + .type(badge.getType()) + .build(); + } +} diff --git a/src/main/java/com/smeme/server/dto/diary/CreatedDiaryResponseDTO.java b/src/main/java/com/smeme/server/dto/diary/CreatedDiaryResponseDTO.java index 46ca9571..2ac67bdc 100644 --- a/src/main/java/com/smeme/server/dto/diary/CreatedDiaryResponseDTO.java +++ b/src/main/java/com/smeme/server/dto/diary/CreatedDiaryResponseDTO.java @@ -2,24 +2,14 @@ import java.util.List; +import com.smeme.server.dto.badge.AcquiredBadgeResponseDTO; import com.smeme.server.model.badge.Badge; public record CreatedDiaryResponseDTO( Long diaryId, - List badges + List badges ) { public static CreatedDiaryResponseDTO of(Long diaryId, List badges) { - return new CreatedDiaryResponseDTO(diaryId, badges.stream().map(BadgeDTO::of).toList()); - } - - public record BadgeDTO( - String name, - String imageUrl - ) { - public static BadgeDTO of(Badge badge) { - return new BadgeDTO(badge.getName(), badge.getImageUrl()); - } + return new CreatedDiaryResponseDTO(diaryId, badges.stream().map(AcquiredBadgeResponseDTO::of).toList()); } } - - diff --git a/src/main/java/com/smeme/server/dto/member/MemberUpdateResponseDTO.java b/src/main/java/com/smeme/server/dto/member/MemberUpdateResponseDTO.java index eb28517d..debe3c27 100644 --- a/src/main/java/com/smeme/server/dto/member/MemberUpdateResponseDTO.java +++ b/src/main/java/com/smeme/server/dto/member/MemberUpdateResponseDTO.java @@ -1,21 +1,14 @@ package com.smeme.server.dto.member; +import com.smeme.server.dto.badge.AcquiredBadgeResponseDTO; import com.smeme.server.model.badge.Badge; import java.util.List; public record MemberUpdateResponseDTO( - List badges + List badges ) { public static MemberUpdateResponseDTO of(List badges) { - return new MemberUpdateResponseDTO(badges.stream() - .map(badge -> new BadgeDTO(badge.getName(), badge.getImageUrl())).toList()); - } - - record BadgeDTO( - String name, - String imageUrl - ) { + return new MemberUpdateResponseDTO(badges.stream().map(AcquiredBadgeResponseDTO::of).toList()); } } - diff --git a/src/test/java/com/smeme/server/controller/DiaryControllerTest.java b/src/test/java/com/smeme/server/controller/DiaryControllerTest.java index cc7a5c3c..1746790e 100644 --- a/src/test/java/com/smeme/server/controller/DiaryControllerTest.java +++ b/src/test/java/com/smeme/server/controller/DiaryControllerTest.java @@ -1,11 +1,13 @@ package com.smeme.server.controller; import com.epages.restdocs.apispec.ResourceSnippetParameters; +import com.smeme.server.dto.badge.AcquiredBadgeResponseDTO; import com.smeme.server.dto.diary.CreatedDiaryResponseDTO; import com.smeme.server.dto.diary.DiariesResponseDTO; import com.smeme.server.dto.diary.DiariesResponseDTO.DiaryDTO; import com.smeme.server.dto.diary.DiaryRequestDTO; import com.smeme.server.dto.diary.DiaryResponseDTO; +import com.smeme.server.model.badge.BadgeType; import com.smeme.server.util.ApiResponse; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -19,6 +21,7 @@ import java.security.Principal; import java.util.ArrayList; import java.util.List; +import java.util.stream.Stream; import static com.epages.restdocs.apispec.ResourceDocumentation.resource; import static com.smeme.server.util.ApiResponse.success; @@ -87,7 +90,8 @@ void success_create_diary() throws Exception { fieldWithPath("data.diaryId").type(NUMBER).description("생성한 일기 id"), fieldWithPath("data.badges[]").type(ARRAY).description("획득한 뱃지 리스트"), fieldWithPath("data.badges[].name").type(STRING).description("뱃지 이름"), - fieldWithPath("data.badges[].imageUrl").type(STRING).description("뱃지 이미지 url") + fieldWithPath("data.badges[].imageUrl").type(STRING).description("뱃지 이미지 url"), + fieldWithPath("data.badges[].type").type(STRING).description("뱃지 타입") ) .build() ) @@ -265,12 +269,13 @@ void success_get_diaries() throws Exception { .andExpect(status().isOk()); } - private List badges() { - List badges = new ArrayList<>(); - for (int i = 0; i < 2; i++) { - badges.add(new CreatedDiaryResponseDTO.BadgeDTO("뱃지 이름" + (i + 1), "image-url" + (i + 1))); - } - return badges; + private List badges() { // acquiredBadge + return Stream.iterate(1, i -> i + 1).limit(5) + .map(i -> acquiredBadge()).toList(); + } + + private AcquiredBadgeResponseDTO acquiredBadge() { + return new AcquiredBadgeResponseDTO("뱃지 이름", "badge-image-url", BadgeType.EVENT); } private List diaries() { From 2596051e0b82fab8d3a883e3c61ba706b4d8823a Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 31 Jan 2024 00:07:26 +0900 Subject: [PATCH 11/86] =?UTF-8?q?[FIX]=20=EB=A9=94=EC=86=8C=EB=93=9C?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/smeme/server/controller/DiaryControllerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/smeme/server/controller/DiaryControllerTest.java b/src/test/java/com/smeme/server/controller/DiaryControllerTest.java index 1746790e..f83833f4 100644 --- a/src/test/java/com/smeme/server/controller/DiaryControllerTest.java +++ b/src/test/java/com/smeme/server/controller/DiaryControllerTest.java @@ -54,7 +54,7 @@ class DiaryControllerTest extends BaseControllerTest { void success_create_diary() throws Exception { // given DiaryRequestDTO request = new DiaryRequestDTO("Hello SMEEM!", 1L); - CreatedDiaryResponseDTO response = new CreatedDiaryResponseDTO(1L, badges()); + CreatedDiaryResponseDTO response = new CreatedDiaryResponseDTO(1L, acquiredBadges()); ResponseEntity result = ResponseEntity .created(URI.create("localhost:8080/api/v2/diaries/1")) .body(success("일기 작성 성공", response)); @@ -269,7 +269,7 @@ void success_get_diaries() throws Exception { .andExpect(status().isOk()); } - private List badges() { // acquiredBadge + private List acquiredBadges() { return Stream.iterate(1, i -> i + 1).limit(5) .map(i -> acquiredBadge()).toList(); } From aff6927c365a5b203faf187860330e1633a2f7d4 Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 31 Jan 2024 00:08:20 +0900 Subject: [PATCH 12/86] =?UTF-8?q?[FIX]=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/static/docs/open-api-3.0.1.json | 88 ++++++++++--------- 1 file changed, 46 insertions(+), 42 deletions(-) diff --git a/src/main/resources/static/docs/open-api-3.0.1.json b/src/main/resources/static/docs/open-api-3.0.1.json index 77e1c10f..38cf2d04 100644 --- a/src/main/resources/static/docs/open-api-3.0.1.json +++ b/src/main/resources/static/docs/open-api-3.0.1.json @@ -156,11 +156,11 @@ "content" : { "application/json;charset=UTF-8" : { "schema" : { - "$ref" : "#/components/schemas/api-v2-diaries-486735900" + "$ref" : "#/components/schemas/api-v2-diaries-609397821" }, "examples" : { "일기 작성 성공 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"일기 작성 성공\",\n \"data\" : {\n \"diaryId\" : 1,\n \"badges\" : [ {\n \"name\" : \"뱃지 이름1\",\n \"imageUrl\" : \"image-url1\"\n }, {\n \"name\" : \"뱃지 이름2\",\n \"imageUrl\" : \"image-url2\"\n } ]\n }\n}" + "value" : "{\n \"success\" : true,\n \"message\" : \"일기 작성 성공\",\n \"data\" : {\n \"diaryId\" : 1,\n \"badges\" : [ {\n \"name\" : \"뱃지 이름\",\n \"imageUrl\" : \"badge-image-url\",\n \"type\" : \"EVENT\"\n }, {\n \"name\" : \"뱃지 이름\",\n \"imageUrl\" : \"badge-image-url\",\n \"type\" : \"EVENT\"\n }, {\n \"name\" : \"뱃지 이름\",\n \"imageUrl\" : \"badge-image-url\",\n \"type\" : \"EVENT\"\n }, {\n \"name\" : \"뱃지 이름\",\n \"imageUrl\" : \"badge-image-url\",\n \"type\" : \"EVENT\"\n }, {\n \"name\" : \"뱃지 이름\",\n \"imageUrl\" : \"badge-image-url\",\n \"type\" : \"EVENT\"\n } ]\n }\n}" } } } @@ -867,6 +867,50 @@ } } }, + "api-v2-diaries-609397821" : { + "type" : "object", + "properties" : { + "data" : { + "type" : "object", + "properties" : { + "badges" : { + "type" : "array", + "description" : "획득한 뱃지 리스트", + "items" : { + "type" : "object", + "properties" : { + "imageUrl" : { + "type" : "string", + "description" : "뱃지 이미지 url" + }, + "name" : { + "type" : "string", + "description" : "뱃지 이름" + }, + "type" : { + "type" : "string", + "description" : "뱃지 타입" + } + } + } + }, + "diaryId" : { + "type" : "number", + "description" : "생성한 일기 id" + } + }, + "description" : "응답 데이터" + }, + "success" : { + "type" : "boolean", + "description" : "응답 성공 여부" + }, + "message" : { + "type" : "string", + "description" : "응답 메시지" + } + } + }, "api-v2-topics-random459952356" : { "type" : "object", "properties" : { @@ -964,46 +1008,6 @@ } } }, - "api-v2-diaries-486735900" : { - "type" : "object", - "properties" : { - "data" : { - "type" : "object", - "properties" : { - "badges" : { - "type" : "array", - "description" : "획득한 뱃지 리스트", - "items" : { - "type" : "object", - "properties" : { - "imageUrl" : { - "type" : "string", - "description" : "뱃지 이미지 url" - }, - "name" : { - "type" : "string", - "description" : "뱃지 이름" - } - } - } - }, - "diaryId" : { - "type" : "number", - "description" : "생성한 일기 id" - } - }, - "description" : "응답 데이터" - }, - "success" : { - "type" : "boolean", - "description" : "응답 성공 여부" - }, - "message" : { - "type" : "string", - "description" : "응답 메시지" - } - } - }, "api-v2-diaries1551664804" : { "type" : "object", "properties" : { From beedb2958b7f16cd94e0cc93612f816a31f10420 Mon Sep 17 00:00:00 2001 From: thguss Date: Tue, 6 Feb 2024 22:29:05 +0900 Subject: [PATCH 13/86] =?UTF-8?q?[REFACTOR]=20=EB=AA=A8=EB=93=88=201?= =?UTF-8?q?=EC=B0=A8=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 6 +- build.gradle | 8 +-- scripts/health_check.sh | 2 +- settings.gradle | 8 +++ .../smeem}/SmemeServerRenewalApplication.java | 2 +- .../auth}/controller/AuthController.java | 20 +++--- .../dto/request}/SignInRequestDTO.java | 2 +- .../dto/response}/SignInResponseDTO.java | 4 +- .../dto/response}/token/TokenResponseDTO.java | 2 +- .../dto/response}/token/TokenVO.java | 2 +- .../CustomJwtAuthenticationEntryPoint.java | 6 +- .../auth}/jwt/JwtAuthenticationFilter.java | 8 +-- .../com/smeem/auth}/jwt/JwtTokenProvider.java | 8 +-- .../smeem/auth}/jwt/JwtValidationType.java | 2 +- .../smeem/auth}/jwt/UserAuthentication.java | 2 +- .../com/smeem/auth/service}/AuthService.java | 12 ++-- .../badge}/controller/BadgeController.java | 6 +- .../response}/AcquiredBadgeResponseDTO.java | 2 +- .../dto/response}/BadgeListResponseDTO.java | 2 +- .../dto/response}/BadgeResponseDTO.java | 2 +- .../smeem/badge}/service/BadgeService.java | 4 +- .../java/com/smeem/common}/ApiResponse.java | 2 +- .../diary}/controller/DiaryController.java | 18 ++--- .../dto/request}/DiaryRequestDTO.java | 2 +- .../response}/CreatedDiaryResponseDTO.java | 2 +- .../dto/response}/DiariesResponseDTO.java | 4 +- .../dto/response}/DiaryResponseDTO.java | 4 +- .../smeem/diary}/service/DiaryService.java | 8 +-- .../goal}/controller/GoalController.java | 6 +- .../dto/response}/GoalResponseDTO.java | 2 +- .../dto/response}/GoalsResponseDTO.java | 2 +- .../com/smeem/goal}/service/GoalService.java | 4 +- .../member}/controller/MemberController.java | 21 +++--- .../controller/dto}/UsernameValidator.java | 2 +- .../member/controller/dto}/ValidUsername.java | 2 +- .../request}/MemberPlanUpdateRequestDTO.java | 2 +- .../request}/MemberPushUpdateRequestDTO.java | 2 +- .../dto/request}/MemberUpdateRequestDTO.java | 4 +- .../dto/request}/TrainingTimeRequestDTO.java | 2 +- .../dto/response}/MemberGetResponseDTO.java | 2 +- .../dto/response}/MemberNameResponseDTO.java | 2 +- .../response}/MemberUpdateResponseDTO.java | 2 +- .../response}/TrainingTimeResponseDTO.java | 2 +- .../member}/service/MemberBadgeService.java | 2 +- .../smeem/member}/service/MemberService.java | 2 +- .../member}/service/TrainingTimeService.java | 2 +- .../test}/controller/TestController.java | 8 +-- .../topic}/controller/TopicController.java | 5 +- .../dto/response}/TopicResponseDTO.java | 2 +- .../smeem/topic}/service/TopicService.java | 4 +- .../src}/main/resources/application-dev.yml | 0 .../src}/main/resources/application-prod.yml | 0 .../resources/static/docs/open-api-3.0.1.json | 0 .../SmemeServerRenewalApplicationTests.java | 2 +- .../smeem}/controller/AuthControllerTest.java | 6 +- .../controller/BadgeControllerTest.java | 4 +- .../smeem}/controller/BaseControllerTest.java | 3 +- .../controller/DiaryControllerTest.java | 6 +- .../smeem}/controller/GoalControllerTest.java | 2 +- .../controller/MemberControllerTest.java | 28 ++++---- .../smeem}/controller/TestControllerTest.java | 7 +- .../controller/TopicControllerTest.java | 2 +- .../com/smeem}/fixture/auth/AuthFixture.java | 6 +- .../smeem}/fixture/badge/BadgeFixture.java | 2 +- .../smeem}/fixture/diary/DiaryFixture.java | 6 +- .../com/smeem}/fixture/goal/GoalFixture.java | 2 +- .../smeem}/fixture/member/MemberFixture.java | 9 ++- .../memberbadge/MemberBadgeFixture.java | 4 ++ .../smeem}/fixture/topic/TopicFixture.java | 4 +- .../trainingtime/TrainingTimeFixture.java | 4 +- .../com/smeem}/scheduler/DiaryScheduler.java | 2 +- .../smeem}/scheduler/MessageScheduler.java | 2 +- .../java/com/smeem/advicer}/ErrorHandler.java | 20 +++--- .../java/com/smeem/code}/ErrorMessage.java | 14 ++-- .../java/com/smeem/code}/ResponseMessage.java | 10 +-- .../com/smeem}/config/JpaAuditingConfig.java | 2 +- .../smeem}/config/JpaQueryFactoryConfig.java | 2 +- .../com/smeem/config}/RestTemplateConfig.java | 2 +- .../com/smeem}/config/SecurityConfig.java | 6 +- .../java/com/smeem}/config/SwaggerConfig.java | 2 +- .../com/smeem}/config/TimezoneConfig.java | 2 +- .../java/com/smeem}/config/ValueConfig.java | 4 +- .../src/main/java/com/smeem}/util/Util.java | 2 +- .../java/com/smeem/badge/model}/Badge.java | 4 +- .../com/smeem/badge/model}/BadgeType.java | 2 +- .../repository}/BadgeCustomRepository.java | 2 +- .../badge/repository}/BadgeRepository.java | 2 +- .../repository}/BadgeRepositoryImpl.java | 6 +- .../smeem/common}/model/BaseTimeEntity.java | 2 +- .../com/smeem/diary}/model/DeletedDiary.java | 8 +-- .../java/com/smeem/diary}/model/Diary.java | 18 +++-- .../repository}/DeletedDiaryRepository.java | 2 +- .../diary/repository}/DiaryRepository.java | 2 +- .../main/java/com/smeem/goal/model}/Goal.java | 4 +- .../java/com/smeem/goal/model}/GoalType.java | 2 +- .../goal/repository}/GoalRepository.java | 2 +- .../com/smeem/member}/model/LangType.java | 2 +- .../java/com/smeem/member}/model/Member.java | 4 +- .../com/smeem/member/model}/MemberBadge.java | 9 +-- .../com/smeem/member}/model/SocialType.java | 2 +- .../repository}/MemberBadgeRepository.java | 2 +- .../member}/repository/MemberRepository.java | 2 +- .../java/com/smeem/topic/model}/Category.java | 2 +- .../java/com/smeem/topic/model}/Topic.java | 4 +- .../repository}/TopicCustomRepository.java | 2 +- .../topic/repository}/TopicRepository.java | 2 +- .../repository}/TopicRepositoryImpl.java | 8 +-- .../com/smeem/training/model}/DayType.java | 2 +- .../smeem/training/model}/TrainingTime.java | 6 +- .../TrainingTimeCustomRepository.java | 2 +- .../repository}/TrainingTimeRepository.java | 2 +- .../TrainingTimeRepositoryImpl.java | 18 ++--- .../com/smeem/apple}/AppleSignInService.java | 2 +- .../java/com/smeem/firebase}/MessageDTO.java | 2 +- .../com/smeem/firebase}/MessageService.java | 4 +- .../com/smeem/kakao}/KakaoSignInService.java | 2 +- .../server/controller/BetaAuthController.java | 40 ----------- .../dto/auth/beta/BetaSignInRequestDTO.java | 6 -- .../dto/auth/beta/BetaTokenResponseDTO.java | 14 ---- .../server/service/auth/BetaAuthService.java | 67 ------------------- src/main/resources/test | 0 .../memberbadge/MemberBadgeFixture.java | 4 -- 122 files changed, 272 insertions(+), 393 deletions(-) rename {src/main/java/com/smeme/server => smeem-api/src/main/java/com/smeem}/SmemeServerRenewalApplication.java (92%) rename {src/main/java/com/smeme/server => smeem-api/src/main/java/com/smeem/auth}/controller/AuthController.java (64%) rename {src/main/java/com/smeme/server/dto/auth => smeem-api/src/main/java/com/smeem/auth/controller/dto/request}/SignInRequestDTO.java (82%) rename {src/main/java/com/smeme/server/dto/auth => smeem-api/src/main/java/com/smeem/auth/controller/dto/response}/SignInResponseDTO.java (79%) rename {src/main/java/com/smeme/server/dto/auth => smeem-api/src/main/java/com/smeem/auth/controller/dto/response}/token/TokenResponseDTO.java (83%) rename {src/main/java/com/smeme/server/dto/auth => smeem-api/src/main/java/com/smeem/auth/controller/dto/response}/token/TokenVO.java (78%) rename {src/main/java/com/smeme/server/config => smeem-api/src/main/java/com/smeem/auth}/jwt/CustomJwtAuthenticationEntryPoint.java (88%) rename {src/main/java/com/smeme/server/config => smeem-api/src/main/java/com/smeem/auth}/jwt/JwtAuthenticationFilter.java (84%) rename {src/main/java/com/smeme/server/config => smeem-api/src/main/java/com/smeem/auth}/jwt/JwtTokenProvider.java (91%) rename {src/main/java/com/smeme/server/config => smeem-api/src/main/java/com/smeem/auth}/jwt/JwtValidationType.java (81%) rename {src/main/java/com/smeme/server/config => smeem-api/src/main/java/com/smeem/auth}/jwt/UserAuthentication.java (92%) rename {src/main/java/com/smeme/server/service/auth => smeem-api/src/main/java/com/smeem/auth/service}/AuthService.java (91%) rename {src/main/java/com/smeme/server => smeem-api/src/main/java/com/smeem/badge}/controller/BadgeController.java (84%) rename {src/main/java/com/smeme/server/dto/badge => smeem-api/src/main/java/com/smeem/badge/controller/dto/response}/AcquiredBadgeResponseDTO.java (92%) rename {src/main/java/com/smeme/server/dto/badge => smeem-api/src/main/java/com/smeem/badge/controller/dto/response}/BadgeListResponseDTO.java (98%) rename {src/main/java/com/smeme/server/dto/badge => smeem-api/src/main/java/com/smeem/badge/controller/dto/response}/BadgeResponseDTO.java (88%) rename {src/main/java/com/smeme/server => smeem-api/src/main/java/com/smeem/badge}/service/BadgeService.java (93%) rename {src/main/java/com/smeme/server/util => smeem-api/src/main/java/com/smeem/common}/ApiResponse.java (97%) rename {src/main/java/com/smeme/server => smeem-api/src/main/java/com/smeem/diary}/controller/DiaryController.java (72%) rename {src/main/java/com/smeme/server/dto/diary => smeem-api/src/main/java/com/smeem/diary/controller/dto/request}/DiaryRequestDTO.java (72%) rename {src/main/java/com/smeme/server/dto/diary => smeem-api/src/main/java/com/smeem/diary/controller/dto/response}/CreatedDiaryResponseDTO.java (90%) rename {src/main/java/com/smeme/server/dto/diary => smeem-api/src/main/java/com/smeem/diary/controller/dto/response}/DiariesResponseDTO.java (87%) rename {src/main/java/com/smeme/server/dto/diary => smeem-api/src/main/java/com/smeem/diary/controller/dto/response}/DiaryResponseDTO.java (86%) rename {src/main/java/com/smeme/server => smeem-api/src/main/java/com/smeem/diary}/service/DiaryService.java (94%) rename {src/main/java/com/smeme/server => smeem-api/src/main/java/com/smeem/goal}/controller/GoalController.java (81%) rename {src/main/java/com/smeme/server/dto/goal => smeem-api/src/main/java/com/smeem/goal/controller/dto/response}/GoalResponseDTO.java (87%) rename {src/main/java/com/smeme/server/dto/goal => smeem-api/src/main/java/com/smeem/goal/controller/dto/response}/GoalsResponseDTO.java (92%) rename {src/main/java/com/smeme/server => smeem-api/src/main/java/com/smeem/goal}/service/GoalService.java (94%) rename {src/main/java/com/smeme/server => smeem-api/src/main/java/com/smeem/member}/controller/MemberController.java (65%) rename {src/main/java/com/smeme/server/dto/member => smeem-api/src/main/java/com/smeem/member/controller/dto}/UsernameValidator.java (94%) rename {src/main/java/com/smeme/server/dto/member => smeem-api/src/main/java/com/smeem/member/controller/dto}/ValidUsername.java (88%) rename {src/main/java/com/smeme/server/dto/member => smeem-api/src/main/java/com/smeem/member/controller/dto/request}/MemberPlanUpdateRequestDTO.java (83%) rename {src/main/java/com/smeme/server/dto/member => smeem-api/src/main/java/com/smeem/member/controller/dto/request}/MemberPushUpdateRequestDTO.java (60%) rename {src/main/java/com/smeme/server/dto/member => smeem-api/src/main/java/com/smeem/member/controller/dto/request}/MemberUpdateRequestDTO.java (53%) rename {src/main/java/com/smeme/server/dto/training => smeem-api/src/main/java/com/smeem/member/controller/dto/request}/TrainingTimeRequestDTO.java (80%) rename {src/main/java/com/smeme/server/dto/member => smeem-api/src/main/java/com/smeem/member/controller/dto/response}/MemberGetResponseDTO.java (95%) rename {src/main/java/com/smeme/server/dto/member => smeem-api/src/main/java/com/smeem/member/controller/dto/response}/MemberNameResponseDTO.java (57%) rename {src/main/java/com/smeme/server/dto/member => smeem-api/src/main/java/com/smeem/member/controller/dto/response}/MemberUpdateResponseDTO.java (88%) rename {src/main/java/com/smeme/server/dto/training => smeem-api/src/main/java/com/smeem/member/controller/dto/response}/TrainingTimeResponseDTO.java (81%) rename {src/main/java/com/smeme/server => smeem-api/src/main/java/com/smeem/member}/service/MemberBadgeService.java (97%) rename {src/main/java/com/smeme/server => smeem-api/src/main/java/com/smeem/member}/service/MemberService.java (99%) rename {src/main/java/com/smeme/server => smeem-api/src/main/java/com/smeem/member}/service/TrainingTimeService.java (96%) rename {src/main/java/com/smeme/server => smeem-api/src/main/java/com/smeem/test}/controller/TestController.java (81%) rename {src/main/java/com/smeme/server => smeem-api/src/main/java/com/smeem/topic}/controller/TopicController.java (80%) rename {src/main/java/com/smeme/server/dto/topic => smeem-api/src/main/java/com/smeem/topic/controller/dto/response}/TopicResponseDTO.java (84%) rename {src/main/java/com/smeme/server => smeem-api/src/main/java/com/smeem/topic}/service/TopicService.java (86%) rename {src => smeem-api/src}/main/resources/application-dev.yml (100%) rename {src => smeem-api/src}/main/resources/application-prod.yml (100%) rename {src => smeem-api/src}/main/resources/static/docs/open-api-3.0.1.json (100%) rename {src/test/java/com/smeme/server => smeem-api/src/test/java/com/smeem}/SmemeServerRenewalApplicationTests.java (82%) rename {src/test/java/com/smeme/server => smeem-api/src/test/java/com/smeem}/controller/AuthControllerTest.java (98%) rename {src/test/java/com/smeme/server => smeem-api/src/test/java/com/smeem}/controller/BadgeControllerTest.java (97%) rename {src/test/java/com/smeme/server => smeem-api/src/test/java/com/smeem}/controller/BaseControllerTest.java (95%) rename {src/test/java/com/smeme/server => smeem-api/src/test/java/com/smeem}/controller/DiaryControllerTest.java (98%) rename {src/test/java/com/smeme/server => smeem-api/src/test/java/com/smeem}/controller/GoalControllerTest.java (99%) rename {src/test/java/com/smeme/server => smeem-api/src/test/java/com/smeem}/controller/MemberControllerTest.java (89%) rename {src/test/java/com/smeme/server => smeem-api/src/test/java/com/smeem}/controller/TestControllerTest.java (93%) rename {src/test/java/com/smeme/server => smeem-api/src/test/java/com/smeem}/controller/TopicControllerTest.java (99%) rename {src/test/java/com/smeme/server => smeem-api/src/test/java/com/smeem}/fixture/auth/AuthFixture.java (87%) rename {src/test/java/com/smeme/server => smeem-api/src/test/java/com/smeem}/fixture/badge/BadgeFixture.java (98%) rename {src/test/java/com/smeme/server => smeem-api/src/test/java/com/smeem}/fixture/diary/DiaryFixture.java (81%) rename {src/test/java/com/smeme/server => smeem-api/src/test/java/com/smeem}/fixture/goal/GoalFixture.java (95%) rename {src/test/java/com/smeme/server => smeem-api/src/test/java/com/smeem}/fixture/member/MemberFixture.java (88%) create mode 100644 smeem-api/src/test/java/com/smeem/fixture/memberbadge/MemberBadgeFixture.java rename {src/test/java/com/smeme/server => smeem-api/src/test/java/com/smeem}/fixture/topic/TopicFixture.java (81%) rename {src/test/java/com/smeme/server => smeem-api/src/test/java/com/smeem}/fixture/trainingtime/TrainingTimeFixture.java (90%) rename {src/main/java/com/smeme/server => smeem-batch/src/main/java/com/smeem}/scheduler/DiaryScheduler.java (93%) rename {src/main/java/com/smeme/server => smeem-batch/src/main/java/com/smeem}/scheduler/MessageScheduler.java (95%) rename {src/main/java/com/smeme/server/handler => smeem-common/src/main/java/com/smeem/advicer}/ErrorHandler.java (69%) rename {src/main/java/com/smeme/server/util/message => smeem-common/src/main/java/com/smeem/code}/ErrorMessage.java (89%) rename {src/main/java/com/smeme/server/util/message => smeem-common/src/main/java/com/smeem/code}/ResponseMessage.java (93%) rename {src/main/java/com/smeme/server => smeem-common/src/main/java/com/smeem}/config/JpaAuditingConfig.java (86%) rename {src/main/java/com/smeme/server => smeem-common/src/main/java/com/smeem}/config/JpaQueryFactoryConfig.java (91%) rename {src/main/java/com/smeme/server/config/jwt => smeem-common/src/main/java/com/smeem/config}/RestTemplateConfig.java (89%) rename {src/main/java/com/smeme/server => smeem-common/src/main/java/com/smeem}/config/SecurityConfig.java (96%) rename {src/main/java/com/smeme/server => smeem-common/src/main/java/com/smeem}/config/SwaggerConfig.java (96%) rename {src/main/java/com/smeme/server => smeem-common/src/main/java/com/smeem}/config/TimezoneConfig.java (89%) rename {src/main/java/com/smeme/server => smeem-common/src/main/java/com/smeem}/config/ValueConfig.java (93%) rename {src/main/java/com/smeme/server => smeem-common/src/main/java/com/smeem}/util/Util.java (97%) rename {src/main/java/com/smeme/server/model/badge => smeem-domain/src/main/java/com/smeem/badge/model}/Badge.java (86%) rename {src/main/java/com/smeme/server/model/badge => smeem-domain/src/main/java/com/smeem/badge/model}/BadgeType.java (87%) rename {src/main/java/com/smeme/server/repository/badge => smeem-domain/src/main/java/com/smeem/badge/repository}/BadgeCustomRepository.java (77%) rename {src/main/java/com/smeme/server/repository/badge => smeem-domain/src/main/java/com/smeem/badge/repository}/BadgeRepository.java (82%) rename {src/main/java/com/smeme/server/repository/badge => smeem-domain/src/main/java/com/smeem/badge/repository}/BadgeRepositoryImpl.java (80%) rename {src/main/java/com/smeme/server => smeem-domain/src/main/java/com/smeem/common}/model/BaseTimeEntity.java (94%) rename {src/main/java/com/smeme/server => smeem-domain/src/main/java/com/smeem/diary}/model/DeletedDiary.java (87%) rename {src/main/java/com/smeme/server => smeem-domain/src/main/java/com/smeem/diary}/model/Diary.java (82%) rename {src/main/java/com/smeme/server/repository/diary => smeem-domain/src/main/java/com/smeem/diary/repository}/DeletedDiaryRepository.java (89%) rename {src/main/java/com/smeme/server/repository/diary => smeem-domain/src/main/java/com/smeem/diary/repository}/DiaryRepository.java (88%) rename {src/main/java/com/smeme/server/model/goal => smeem-domain/src/main/java/com/smeem/goal/model}/Goal.java (90%) rename {src/main/java/com/smeme/server/model/goal => smeem-domain/src/main/java/com/smeem/goal/model}/GoalType.java (90%) rename {src/main/java/com/smeme/server/repository/goal => smeem-domain/src/main/java/com/smeem/goal/repository}/GoalRepository.java (87%) rename {src/main/java/com/smeme/server => smeem-domain/src/main/java/com/smeem/member}/model/LangType.java (50%) rename {src/main/java/com/smeme/server => smeem-domain/src/main/java/com/smeem/member}/model/Member.java (97%) rename {src/main/java/com/smeme/server/model/badge => smeem-domain/src/main/java/com/smeem/member/model}/MemberBadge.java (85%) rename {src/main/java/com/smeme/server => smeem-domain/src/main/java/com/smeem/member}/model/SocialType.java (64%) rename {src/main/java/com/smeme/server/repository/badge => smeem-domain/src/main/java/com/smeem/member/repository}/MemberBadgeRepository.java (89%) rename {src/main/java/com/smeme/server => smeem-domain/src/main/java/com/smeem/member}/repository/MemberRepository.java (92%) rename {src/main/java/com/smeme/server/model/topic => smeem-domain/src/main/java/com/smeem/topic/model}/Category.java (87%) rename {src/main/java/com/smeme/server/model/topic => smeem-domain/src/main/java/com/smeem/topic/model}/Topic.java (85%) rename {src/main/java/com/smeme/server/repository/topic => smeem-domain/src/main/java/com/smeem/topic/repository}/TopicCustomRepository.java (72%) rename {src/main/java/com/smeme/server/repository/topic => smeem-domain/src/main/java/com/smeem/topic/repository}/TopicRepository.java (82%) rename {src/main/java/com/smeme/server/repository/topic => smeem-domain/src/main/java/com/smeem/topic/repository}/TopicRepositoryImpl.java (77%) rename {src/main/java/com/smeme/server/model/training => smeem-domain/src/main/java/com/smeem/training/model}/DayType.java (86%) rename {src/main/java/com/smeme/server/model/training => smeem-domain/src/main/java/com/smeem/training/model}/TrainingTime.java (92%) rename {src/main/java/com/smeme/server/repository/trainingTime => smeem-domain/src/main/java/com/smeem/training/repository}/TrainingTimeCustomRepository.java (82%) rename {src/main/java/com/smeme/server/repository/trainingTime => smeem-domain/src/main/java/com/smeem/training/repository}/TrainingTimeRepository.java (88%) rename {src/main/java/com/smeme/server/repository/trainingTime => smeem-domain/src/main/java/com/smeem/training/repository}/TrainingTimeRepositoryImpl.java (64%) rename {src/main/java/com/smeme/server/service/auth => smeem-external/src/main/java/com/smeem/apple}/AppleSignInService.java (99%) rename {src/main/java/com/smeme/server/dto/message => smeem-external/src/main/java/com/smeem/firebase}/MessageDTO.java (93%) rename {src/main/java/com/smeme/server/service => smeem-external/src/main/java/com/smeem/firebase}/MessageService.java (96%) rename {src/main/java/com/smeme/server/service/auth => smeem-external/src/main/java/com/smeem/kakao}/KakaoSignInService.java (96%) delete mode 100644 src/main/java/com/smeme/server/controller/BetaAuthController.java delete mode 100644 src/main/java/com/smeme/server/dto/auth/beta/BetaSignInRequestDTO.java delete mode 100644 src/main/java/com/smeme/server/dto/auth/beta/BetaTokenResponseDTO.java delete mode 100644 src/main/java/com/smeme/server/service/auth/BetaAuthService.java delete mode 100644 src/main/resources/test delete mode 100644 src/test/java/com/smeme/server/fixture/memberbadge/MemberBadgeFixture.java diff --git a/.gitignore b/.gitignore index 2c2b599e..d1ac6455 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ HELP.md build/ !gradle/wrapper/gradle-wrapper.jar !**/src/main/**/build/ -!**/src/test/**/build/ +!**/src/com.smeem.test/**/build/ ### STS ### .apt_generated @@ -15,7 +15,7 @@ build/ .sts4-cache bin/ !**/src/main/**/bin/ -!**/src/test/**/bin/ +!**/src/com.smeem.test/**/bin/ ### IntelliJ IDEA ### .idea @@ -24,7 +24,7 @@ bin/ *.ipr out/ !**/src/main/**/out/ -!**/src/test/**/out/ +!**/src/com.smeem.test/**/out/ ### NetBeans ### /nbproject/private/ diff --git a/build.gradle b/build.gradle index 389f343a..494e5a84 100644 --- a/build.gradle +++ b/build.gradle @@ -72,8 +72,8 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' implementation 'org.springframework.boot:spring-boot-starter-validation' - testImplementation 'org.springframework.boot:spring-boot-starter-test' - testImplementation 'org.springframework.security:spring-security-test' + testImplementation 'org.springframework.boot:spring-boot-starter-com.smeem.test' + testImplementation 'org.springframework.security:spring-security-com.smeem.test' // JWT implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.5' @@ -110,9 +110,7 @@ dependencies { runtimeOnly 'org.postgresql:postgresql' } -tasks.named('test') { - useJUnitPlatform() -} + tasks.withType(GenerateSwaggerUI) { dependsOn 'openapi3' diff --git a/scripts/health_check.sh b/scripts/health_check.sh index 378271e9..65e7a73c 100644 --- a/scripts/health_check.sh +++ b/scripts/health_check.sh @@ -20,7 +20,7 @@ echo "> Start health check of WAS at 'http://127.0.0.1:${TARGET_PORT}/api/v2/tes for RETRY_COUNT in 1 2 3 4 5 6 7 8 9 10 do echo "> #${RETRY_COUNT} trying..." - RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:${TARGET_PORT}/api/v2/test) + RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:${TARGET_PORT}/api/v2/com.smeem.test) if [ ${RESPONSE_CODE} -eq 200 ]; then echo "> New WAS successfully running" diff --git a/settings.gradle b/settings.gradle index 096502d2..8ffdc0b1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,9 @@ rootProject.name = 'server' +include 'smeem-api' +include 'smeem-domain' +include 'smeem-batch' +include 'smeem-batch' +include 'smeem-batch' +include 'smeem-external' +include 'smeem-common' + diff --git a/src/main/java/com/smeme/server/SmemeServerRenewalApplication.java b/smeem-api/src/main/java/com/smeem/SmemeServerRenewalApplication.java similarity index 92% rename from src/main/java/com/smeme/server/SmemeServerRenewalApplication.java rename to smeem-api/src/main/java/com/smeem/SmemeServerRenewalApplication.java index 90abc6d5..b7514be9 100644 --- a/src/main/java/com/smeme/server/SmemeServerRenewalApplication.java +++ b/smeem-api/src/main/java/com/smeem/SmemeServerRenewalApplication.java @@ -1,4 +1,4 @@ -package com.smeme.server; +package com.smeem; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/src/main/java/com/smeme/server/controller/AuthController.java b/smeem-api/src/main/java/com/smeem/auth/controller/AuthController.java similarity index 64% rename from src/main/java/com/smeme/server/controller/AuthController.java rename to smeem-api/src/main/java/com/smeem/auth/controller/AuthController.java index b59dd7b1..dfb3903f 100644 --- a/src/main/java/com/smeme/server/controller/AuthController.java +++ b/smeem-api/src/main/java/com/smeem/auth/controller/AuthController.java @@ -1,8 +1,8 @@ -package com.smeme.server.controller; +package com.smeem.auth.controller; import com.smeme.server.dto.auth.SignInRequestDTO; import com.smeme.server.dto.auth.SignInResponseDTO; -import com.smeme.server.dto.auth.token.TokenResponseDTO; +import com.smeem.auth.controller.dto.response.token.TokenResponseDTO; import com.smeme.server.service.auth.AuthService; import com.smeme.server.util.ApiResponse; import lombok.RequiredArgsConstructor; @@ -19,7 +19,7 @@ @RestController @RequiredArgsConstructor -@RequestMapping("api/v2/auth") +@RequestMapping("api/v2/com.smeem.auth") public class AuthController { private final AuthService authService; @@ -28,24 +28,24 @@ public class AuthController { public ResponseEntity signIn(@RequestHeader("Authorization") String socialAccessToken, @RequestBody SignInRequestDTO request ) throws NoSuchAlgorithmException, InvalidKeySpecException { SignInResponseDTO response = authService.signIn(socialAccessToken, request); - return ResponseEntity.ok(success(SUCCESS_SIGNIN.getMessage(), response)); + return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_SIGNIN.getMessage(), response)); } @PostMapping("/token") public ResponseEntity reissueToken(Principal principal) { - TokenResponseDTO response = authService.issueToken(getMemberId(principal)); - return ResponseEntity.ok(success(SUCCESS_ISSUE_TOKEN.getMessage(), response)); + TokenResponseDTO response = authService.issueToken(Util.getMemberId(principal)); + return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_ISSUE_TOKEN.getMessage(), response)); } @PostMapping("/sign-out") public ResponseEntity signOut(Principal principal) { - authService.signOut(getMemberId(principal)); - return ResponseEntity.ok(success(SUCCESS_SIGNOUT.getMessage())); + authService.signOut(Util.getMemberId(principal)); + return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_SIGNOUT.getMessage())); } @DeleteMapping public ResponseEntity withDrawl(Principal principal) { - authService.withdraw(getMemberId(principal)); - return ResponseEntity.ok(success(SUCCESS_WITHDRAW.getMessage())); + authService.withdraw(Util.getMemberId(principal)); + return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_WITHDRAW.getMessage())); } } diff --git a/src/main/java/com/smeme/server/dto/auth/SignInRequestDTO.java b/smeem-api/src/main/java/com/smeem/auth/controller/dto/request/SignInRequestDTO.java similarity index 82% rename from src/main/java/com/smeme/server/dto/auth/SignInRequestDTO.java rename to smeem-api/src/main/java/com/smeem/auth/controller/dto/request/SignInRequestDTO.java index b93b3706..4242f337 100644 --- a/src/main/java/com/smeme/server/dto/auth/SignInRequestDTO.java +++ b/smeem-api/src/main/java/com/smeem/auth/controller/dto/request/SignInRequestDTO.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.auth; +package com.smeem.auth.controller.dto.request; import com.fasterxml.jackson.annotation.JsonProperty; import com.smeme.server.model.SocialType; diff --git a/src/main/java/com/smeme/server/dto/auth/SignInResponseDTO.java b/smeem-api/src/main/java/com/smeem/auth/controller/dto/response/SignInResponseDTO.java similarity index 79% rename from src/main/java/com/smeme/server/dto/auth/SignInResponseDTO.java rename to smeem-api/src/main/java/com/smeem/auth/controller/dto/response/SignInResponseDTO.java index a2f9665c..732e4940 100644 --- a/src/main/java/com/smeme/server/dto/auth/SignInResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/auth/controller/dto/response/SignInResponseDTO.java @@ -1,7 +1,7 @@ -package com.smeme.server.dto.auth; +package com.smeem.auth.controller.dto.response; -import com.smeme.server.dto.auth.token.TokenVO; +import com.smeem.auth.controller.dto.response.token.TokenVO; import lombok.Builder; diff --git a/src/main/java/com/smeme/server/dto/auth/token/TokenResponseDTO.java b/smeem-api/src/main/java/com/smeem/auth/controller/dto/response/token/TokenResponseDTO.java similarity index 83% rename from src/main/java/com/smeme/server/dto/auth/token/TokenResponseDTO.java rename to smeem-api/src/main/java/com/smeem/auth/controller/dto/response/token/TokenResponseDTO.java index 6e23797f..1c8ba32c 100644 --- a/src/main/java/com/smeme/server/dto/auth/token/TokenResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/auth/controller/dto/response/token/TokenResponseDTO.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.auth.token; +package com.smeem.auth.controller.dto.response.token; import lombok.Builder; diff --git a/src/main/java/com/smeme/server/dto/auth/token/TokenVO.java b/smeem-api/src/main/java/com/smeem/auth/controller/dto/response/token/TokenVO.java similarity index 78% rename from src/main/java/com/smeme/server/dto/auth/token/TokenVO.java rename to smeem-api/src/main/java/com/smeem/auth/controller/dto/response/token/TokenVO.java index 8d55ae6f..7fbc4786 100644 --- a/src/main/java/com/smeme/server/dto/auth/token/TokenVO.java +++ b/smeem-api/src/main/java/com/smeem/auth/controller/dto/response/token/TokenVO.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.auth.token; +package com.smeem.auth.controller.dto.response.token; public record TokenVO(String accessToken, String refreshToken) { diff --git a/src/main/java/com/smeme/server/config/jwt/CustomJwtAuthenticationEntryPoint.java b/smeem-api/src/main/java/com/smeem/auth/jwt/CustomJwtAuthenticationEntryPoint.java similarity index 88% rename from src/main/java/com/smeme/server/config/jwt/CustomJwtAuthenticationEntryPoint.java rename to smeem-api/src/main/java/com/smeem/auth/jwt/CustomJwtAuthenticationEntryPoint.java index eca00a23..071ba79a 100644 --- a/src/main/java/com/smeme/server/config/jwt/CustomJwtAuthenticationEntryPoint.java +++ b/smeem-api/src/main/java/com/smeem/auth/jwt/CustomJwtAuthenticationEntryPoint.java @@ -1,4 +1,4 @@ -package com.smeme.server.config.jwt; +package com.smeem.auth.jwt; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.servlet.http.HttpServletRequest; @@ -26,8 +26,8 @@ public void commence(HttpServletRequest request, HttpServletResponse response, A private void setResponse(HttpServletResponse response) throws IOException { response.setCharacterEncoding("UTF-8"); - response.setContentType(APPLICATION_JSON_VALUE); - response.setStatus(SC_UNAUTHORIZED); + response.setContentType(MediaType.APPLICATION_JSON_VALUE); + response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.getWriter().println(objectMapper.writeValueAsString(fail(INVALID_TOKEN.getMessage()))); } } diff --git a/src/main/java/com/smeme/server/config/jwt/JwtAuthenticationFilter.java b/smeem-api/src/main/java/com/smeem/auth/jwt/JwtAuthenticationFilter.java similarity index 84% rename from src/main/java/com/smeme/server/config/jwt/JwtAuthenticationFilter.java rename to smeem-api/src/main/java/com/smeem/auth/jwt/JwtAuthenticationFilter.java index 07b0a3b4..ffd8785f 100644 --- a/src/main/java/com/smeme/server/config/jwt/JwtAuthenticationFilter.java +++ b/smeem-api/src/main/java/com/smeem/auth/jwt/JwtAuthenticationFilter.java @@ -1,4 +1,4 @@ -package com.smeme.server.config.jwt; +package com.smeem.auth.jwt; import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; @@ -15,7 +15,7 @@ import java.io.IOException; -import static com.smeme.server.config.jwt.JwtValidationType.*; +import static com.smeem.auth.jwt.JwtValidationType.*; import static org.springframework.util.StringUtils.hasText; @Slf4j @@ -30,7 +30,7 @@ protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull Ht try { final String token = getJwtFromRequest(request); - if (hasText(token) && jwtTokenProvider.validateToken(token) == VALID_JWT) { + if (StringUtils.hasText(token) && jwtTokenProvider.validateToken(token) == VALID_JWT) { Long userId = jwtTokenProvider.getUserFromJwt(token); UserAuthentication authentication = new UserAuthentication(userId, null, null); authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); @@ -45,6 +45,6 @@ protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull Ht private String getJwtFromRequest(HttpServletRequest request) { String bearerToken = request.getHeader("Authorization"); - return (hasText(bearerToken) && bearerToken.startsWith("Bearer ")) ? bearerToken.substring("Bearer ".length()) : null; + return (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) ? bearerToken.substring("Bearer ".length()) : null; } } diff --git a/src/main/java/com/smeme/server/config/jwt/JwtTokenProvider.java b/smeem-api/src/main/java/com/smeem/auth/jwt/JwtTokenProvider.java similarity index 91% rename from src/main/java/com/smeme/server/config/jwt/JwtTokenProvider.java rename to smeem-api/src/main/java/com/smeem/auth/jwt/JwtTokenProvider.java index cf5c4786..b0459fc4 100644 --- a/src/main/java/com/smeme/server/config/jwt/JwtTokenProvider.java +++ b/smeem-api/src/main/java/com/smeem/auth/jwt/JwtTokenProvider.java @@ -1,4 +1,4 @@ -package com.smeme.server.config.jwt; +package com.smeem.auth.jwt; import com.smeme.server.config.ValueConfig; @@ -11,7 +11,7 @@ import javax.crypto.SecretKey; import java.util.Date; -import static com.smeme.server.config.jwt.JwtValidationType.*; +import static com.smeem.auth.jwt.JwtValidationType.*; import static io.jsonwebtoken.Header.*; import static io.jsonwebtoken.security.Keys.hmacShaKeyFor; import static java.util.Base64.getEncoder; @@ -33,7 +33,7 @@ public String generateToken(Authentication authentication, Long tokenExpirationT claims.put("memberId", authentication.getPrincipal()); return Jwts.builder() - .setHeaderParam(TYPE, JWT_TYPE) + .setHeaderParam(Header.TYPE, Header.JWT_TYPE) .setClaims(claims) .signWith(getSigningKey()) .compact(); @@ -65,7 +65,7 @@ public Long getUserFromJwt(String token) { private SecretKey getSigningKey() { String encodedKey = getEncoder().encodeToString(valueConfig.getJWT_SECRET().getBytes()); - return hmacShaKeyFor(encodedKey.getBytes()); + return Keys.hmacShaKeyFor(encodedKey.getBytes()); } private Claims getBody(final String token) { diff --git a/src/main/java/com/smeme/server/config/jwt/JwtValidationType.java b/smeem-api/src/main/java/com/smeem/auth/jwt/JwtValidationType.java similarity index 81% rename from src/main/java/com/smeme/server/config/jwt/JwtValidationType.java rename to smeem-api/src/main/java/com/smeem/auth/jwt/JwtValidationType.java index 8887013d..eba30954 100644 --- a/src/main/java/com/smeme/server/config/jwt/JwtValidationType.java +++ b/smeem-api/src/main/java/com/smeem/auth/jwt/JwtValidationType.java @@ -1,4 +1,4 @@ -package com.smeme.server.config.jwt; +package com.smeem.auth.jwt; public enum JwtValidationType { VALID_JWT, diff --git a/src/main/java/com/smeme/server/config/jwt/UserAuthentication.java b/smeem-api/src/main/java/com/smeem/auth/jwt/UserAuthentication.java similarity index 92% rename from src/main/java/com/smeme/server/config/jwt/UserAuthentication.java rename to smeem-api/src/main/java/com/smeem/auth/jwt/UserAuthentication.java index 86da6df0..d271686a 100644 --- a/src/main/java/com/smeme/server/config/jwt/UserAuthentication.java +++ b/smeem-api/src/main/java/com/smeem/auth/jwt/UserAuthentication.java @@ -1,4 +1,4 @@ -package com.smeme.server.config.jwt; +package com.smeem.auth.jwt; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; diff --git a/src/main/java/com/smeme/server/service/auth/AuthService.java b/smeem-api/src/main/java/com/smeem/auth/service/AuthService.java similarity index 91% rename from src/main/java/com/smeme/server/service/auth/AuthService.java rename to smeem-api/src/main/java/com/smeem/auth/service/AuthService.java index 472c832e..b480efcb 100644 --- a/src/main/java/com/smeme/server/service/auth/AuthService.java +++ b/smeem-api/src/main/java/com/smeem/auth/service/AuthService.java @@ -1,11 +1,11 @@ -package com.smeme.server.service.auth; +package com.smeem.auth.service; import com.smeme.server.config.jwt.JwtTokenProvider; import com.smeme.server.config.jwt.UserAuthentication; import com.smeme.server.dto.auth.SignInRequestDTO; import com.smeme.server.dto.auth.SignInResponseDTO; -import com.smeme.server.dto.auth.token.TokenResponseDTO; -import com.smeme.server.dto.auth.token.TokenVO; +import com.smeem.auth.controller.dto.response.token.TokenResponseDTO; +import com.smeem.auth.controller.dto.response.token.TokenVO; import com.smeme.server.model.LangType; import com.smeme.server.model.Member; import com.smeme.server.model.SocialType; @@ -111,12 +111,12 @@ private TokenVO generateToken(Authentication authentication) { private Member get(Long memberId) { return memberRepository.findById(memberId) - .orElseThrow(() -> new RuntimeException(INVALID_MEMBER.getMessage())); + .orElseThrow(() -> new RuntimeException(ErrorMessage.INVALID_MEMBER.getMessage())); } private Member getMemberBySocialAndSocialId(SocialType socialType, String socialId) { return memberRepository.findBySocialAndSocialId(socialType, socialId) - .orElseThrow(() -> new RuntimeException(INVALID_MEMBER.getMessage())); + .orElseThrow(() -> new RuntimeException(ErrorMessage.INVALID_MEMBER.getMessage())); } private boolean isMemberBySocialAndSocialId(SocialType socialType, String socialId) { @@ -127,7 +127,7 @@ private String login(SocialType socialType, String socialAccessToken) throws NoS return switch (socialType.toString()) { case "APPLE" -> appleSignInService.getAppleData(socialAccessToken); case "KAKAO" -> kakaoSignInService.getKakaoData(socialAccessToken); - default -> throw new InvalidBearerTokenException(INVALID_TOKEN.getMessage()); + default -> throw new InvalidBearerTokenException(ErrorMessage.INVALID_TOKEN.getMessage()); }; } } diff --git a/src/main/java/com/smeme/server/controller/BadgeController.java b/smeem-api/src/main/java/com/smeem/badge/controller/BadgeController.java similarity index 84% rename from src/main/java/com/smeme/server/controller/BadgeController.java rename to smeem-api/src/main/java/com/smeem/badge/controller/BadgeController.java index 2c7ebbe8..6660b3da 100644 --- a/src/main/java/com/smeme/server/controller/BadgeController.java +++ b/smeem-api/src/main/java/com/smeem/badge/controller/BadgeController.java @@ -1,4 +1,4 @@ -package com.smeme.server.controller; +package com.smeem.badge.controller; import com.smeme.server.dto.badge.BadgeListResponseDTO; import com.smeme.server.service.BadgeService; @@ -24,8 +24,8 @@ public class BadgeController { @GetMapping public ResponseEntity getBadgeList(Principal principal) { - BadgeListResponseDTO response = badgeService.getBadgeList(getMemberId(principal)); - return ResponseEntity.ok(success(SUCCESS_GET_BADGES.getMessage(), response)); + BadgeListResponseDTO response = badgeService.getBadgeList(Util.getMemberId(principal)); + return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_GET_BADGES.getMessage(), response)); } } diff --git a/src/main/java/com/smeme/server/dto/badge/AcquiredBadgeResponseDTO.java b/smeem-api/src/main/java/com/smeem/badge/controller/dto/response/AcquiredBadgeResponseDTO.java similarity index 92% rename from src/main/java/com/smeme/server/dto/badge/AcquiredBadgeResponseDTO.java rename to smeem-api/src/main/java/com/smeem/badge/controller/dto/response/AcquiredBadgeResponseDTO.java index aae5ca1e..52931ea5 100644 --- a/src/main/java/com/smeme/server/dto/badge/AcquiredBadgeResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/badge/controller/dto/response/AcquiredBadgeResponseDTO.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.badge; +package com.smeem.badge.controller.dto.response; import com.smeme.server.model.badge.Badge; import com.smeme.server.model.badge.BadgeType; diff --git a/src/main/java/com/smeme/server/dto/badge/BadgeListResponseDTO.java b/smeem-api/src/main/java/com/smeem/badge/controller/dto/response/BadgeListResponseDTO.java similarity index 98% rename from src/main/java/com/smeme/server/dto/badge/BadgeListResponseDTO.java rename to smeem-api/src/main/java/com/smeem/badge/controller/dto/response/BadgeListResponseDTO.java index 9b6f2df2..b611cf9c 100644 --- a/src/main/java/com/smeme/server/dto/badge/BadgeListResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/badge/controller/dto/response/BadgeListResponseDTO.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.badge; +package com.smeem.badge.controller.dto.response; import com.smeme.server.model.badge.Badge; import com.smeme.server.model.badge.BadgeType; diff --git a/src/main/java/com/smeme/server/dto/badge/BadgeResponseDTO.java b/smeem-api/src/main/java/com/smeem/badge/controller/dto/response/BadgeResponseDTO.java similarity index 88% rename from src/main/java/com/smeme/server/dto/badge/BadgeResponseDTO.java rename to smeem-api/src/main/java/com/smeem/badge/controller/dto/response/BadgeResponseDTO.java index 822bc404..ba83729f 100644 --- a/src/main/java/com/smeme/server/dto/badge/BadgeResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/badge/controller/dto/response/BadgeResponseDTO.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.badge; +package com.smeem.badge.controller.dto.response; import com.smeme.server.model.badge.Badge; import lombok.Builder; diff --git a/src/main/java/com/smeme/server/service/BadgeService.java b/smeem-api/src/main/java/com/smeem/badge/service/BadgeService.java similarity index 93% rename from src/main/java/com/smeme/server/service/BadgeService.java rename to smeem-api/src/main/java/com/smeem/badge/service/BadgeService.java index 992f1b4d..e379f7e0 100644 --- a/src/main/java/com/smeme/server/service/BadgeService.java +++ b/smeem-api/src/main/java/com/smeem/badge/service/BadgeService.java @@ -1,4 +1,4 @@ -package com.smeme.server.service; +package com.smeem.badge.service; import com.smeme.server.dto.badge.BadgeListResponseDTO; import com.smeme.server.model.Member; @@ -51,6 +51,6 @@ public void saveMemberBadge(Member member, Badge badge) { protected Badge get(Long id) { return badgeRepository.findById(id) - .orElseThrow(() -> new EntityNotFoundException(INVALID_BADGE.getMessage())); + .orElseThrow(() -> new EntityNotFoundException(ErrorMessage.INVALID_BADGE.getMessage())); } } diff --git a/src/main/java/com/smeme/server/util/ApiResponse.java b/smeem-api/src/main/java/com/smeem/common/ApiResponse.java similarity index 97% rename from src/main/java/com/smeme/server/util/ApiResponse.java rename to smeem-api/src/main/java/com/smeem/common/ApiResponse.java index 7a97a6ba..f8d71754 100644 --- a/src/main/java/com/smeme/server/util/ApiResponse.java +++ b/smeem-api/src/main/java/com/smeem/common/ApiResponse.java @@ -1,4 +1,4 @@ -package com.smeme.server.util; +package com.smeem.common; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; diff --git a/src/main/java/com/smeme/server/controller/DiaryController.java b/smeem-api/src/main/java/com/smeem/diary/controller/DiaryController.java similarity index 72% rename from src/main/java/com/smeme/server/controller/DiaryController.java rename to smeem-api/src/main/java/com/smeem/diary/controller/DiaryController.java index 31dc8b47..7fe9e9b3 100644 --- a/src/main/java/com/smeme/server/controller/DiaryController.java +++ b/smeem-api/src/main/java/com/smeem/diary/controller/DiaryController.java @@ -1,4 +1,4 @@ -package com.smeme.server.controller; +package com.smeem.diary.controller; import static com.smeme.server.util.ApiResponse.success; import static com.smeme.server.util.Util.getMemberId; @@ -35,28 +35,28 @@ public class DiaryController { @PostMapping public ResponseEntity save(Principal principal, @RequestBody DiaryRequestDTO request) { - CreatedDiaryResponseDTO response = diaryService.save(getMemberId(principal), request); + CreatedDiaryResponseDTO response = diaryService.save(Util.getMemberId(principal), request); return ResponseEntity - .created(getURI(response.diaryId())) - .body(success(SUCCESS_CREATE_DIARY.getMessage(), response)); + .created(Util.getURI(response.diaryId())) + .body(ApiResponse.success(ResponseMessage.SUCCESS_CREATE_DIARY.getMessage(), response)); } @GetMapping("/{diaryId}") public ResponseEntity getDetail(@PathVariable Long diaryId) { DiaryResponseDTO response = diaryService.getDetail(diaryId); - return ResponseEntity.ok(success(SUCCESS_GET_DIARY.getMessage(), response)); + return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_GET_DIARY.getMessage(), response)); } @PatchMapping("/{diaryId}") public ResponseEntity update(@PathVariable Long diaryId, @RequestBody DiaryRequestDTO request) { diaryService.update(diaryId, request); - return ResponseEntity.ok(success(SUCCESS_UPDATE_DAIRY.getMessage())); + return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_UPDATE_DAIRY.getMessage())); } @DeleteMapping("/{diaryId}") public ResponseEntity delete(@PathVariable Long diaryId) { diaryService.delete(diaryId); - return ResponseEntity.ok(success(SUCCESS_DELETE_DIARY.getMessage())); + return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_DELETE_DIARY.getMessage())); } @GetMapping @@ -65,7 +65,7 @@ public ResponseEntity getDiaries( @RequestParam(name = "start") String startDate, @RequestParam(name = "end") String endDate ) { - DiariesResponseDTO response = diaryService.getDiaries(getMemberId(principal), startDate, endDate); - return ResponseEntity.ok(success(SUCCESS_GET_DIARIES.getMessage(), response)); + DiariesResponseDTO response = diaryService.getDiaries(Util.getMemberId(principal), startDate, endDate); + return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_GET_DIARIES.getMessage(), response)); } } diff --git a/src/main/java/com/smeme/server/dto/diary/DiaryRequestDTO.java b/smeem-api/src/main/java/com/smeem/diary/controller/dto/request/DiaryRequestDTO.java similarity index 72% rename from src/main/java/com/smeme/server/dto/diary/DiaryRequestDTO.java rename to smeem-api/src/main/java/com/smeem/diary/controller/dto/request/DiaryRequestDTO.java index af5fb8a9..bb40ed81 100644 --- a/src/main/java/com/smeme/server/dto/diary/DiaryRequestDTO.java +++ b/smeem-api/src/main/java/com/smeem/diary/controller/dto/request/DiaryRequestDTO.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.diary; +package com.smeem.diary.controller.dto.request; import lombok.NonNull; diff --git a/src/main/java/com/smeme/server/dto/diary/CreatedDiaryResponseDTO.java b/smeem-api/src/main/java/com/smeem/diary/controller/dto/response/CreatedDiaryResponseDTO.java similarity index 90% rename from src/main/java/com/smeme/server/dto/diary/CreatedDiaryResponseDTO.java rename to smeem-api/src/main/java/com/smeem/diary/controller/dto/response/CreatedDiaryResponseDTO.java index 2ac67bdc..5b6cd745 100644 --- a/src/main/java/com/smeme/server/dto/diary/CreatedDiaryResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/diary/controller/dto/response/CreatedDiaryResponseDTO.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.diary; +package com.smeem.diary.controller.dto.response; import java.util.List; diff --git a/src/main/java/com/smeme/server/dto/diary/DiariesResponseDTO.java b/smeem-api/src/main/java/com/smeem/diary/controller/dto/response/DiariesResponseDTO.java similarity index 87% rename from src/main/java/com/smeme/server/dto/diary/DiariesResponseDTO.java rename to smeem-api/src/main/java/com/smeem/diary/controller/dto/response/DiariesResponseDTO.java index d2c30d77..3e8187a5 100644 --- a/src/main/java/com/smeme/server/dto/diary/DiariesResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/diary/controller/dto/response/DiariesResponseDTO.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.diary; +package com.smeem.diary.controller.dto.response; import java.util.List; @@ -20,7 +20,7 @@ public record DiaryDTO( String createdAt ) { public static DiaryDTO of(Diary diary) { - return new DiaryDTO(diary.getId(), diary.getContent(), dateToString(diary.getCreatedAt())); + return new DiaryDTO(diary.getId(), diary.getContent(), Util.dateToString(diary.getCreatedAt())); } } } diff --git a/src/main/java/com/smeme/server/dto/diary/DiaryResponseDTO.java b/smeem-api/src/main/java/com/smeem/diary/controller/dto/response/DiaryResponseDTO.java similarity index 86% rename from src/main/java/com/smeme/server/dto/diary/DiaryResponseDTO.java rename to smeem-api/src/main/java/com/smeem/diary/controller/dto/response/DiaryResponseDTO.java index d531da33..e5fbebe4 100644 --- a/src/main/java/com/smeme/server/dto/diary/DiaryResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/diary/controller/dto/response/DiaryResponseDTO.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.diary; +package com.smeem.diary.controller.dto.response; import static com.smeme.server.util.Util.dateToString; import static java.util.Objects.*; @@ -21,7 +21,7 @@ public static DiaryResponseDTO of(Diary diary) { .diaryId(diary.getId()) .topic(nonNull(diary.getTopic()) ? diary.getTopic().getContent() : "") .content(diary.getContent()) - .createdAt(dateToString(diary.getCreatedAt())) + .createdAt(Util.dateToString(diary.getCreatedAt())) .username(diary.getMember().getUsername()) .build(); } diff --git a/src/main/java/com/smeme/server/service/DiaryService.java b/smeem-api/src/main/java/com/smeem/diary/service/DiaryService.java similarity index 94% rename from src/main/java/com/smeme/server/service/DiaryService.java rename to smeem-api/src/main/java/com/smeem/diary/service/DiaryService.java index 16bf3f2c..410ff31c 100644 --- a/src/main/java/com/smeme/server/service/DiaryService.java +++ b/smeem-api/src/main/java/com/smeem/diary/service/DiaryService.java @@ -1,4 +1,4 @@ -package com.smeme.server.service; +package com.smeem.diary.service; import static com.smeme.server.util.Util.stringToDate; import static com.smeme.server.util.message.ErrorMessage.*; @@ -48,7 +48,7 @@ public CreatedDiaryResponseDTO save(Long memberId, DiaryRequestDTO request) { Member member = memberService.get(memberId); if (member.wroteDiaryToday()) { - throw new IllegalStateException(EXIST_TODAY_DIARY.getMessage()); + throw new IllegalStateException(ErrorMessage.EXIST_TODAY_DIARY.getMessage()); } Topic topic = topicService.get(request.topicId()); @@ -90,7 +90,7 @@ private void delete(Diary diary) { public DiariesResponseDTO getDiaries(Long memberId, String startDate, String endDate) { Member member = memberService.get(memberId); List diaries = member.getDiaries().stream() - .filter(diary -> diary.isBetween(stringToDate(startDate), stringToDate(endDate))) + .filter(diary -> diary.isBetween(Util.stringToDate(startDate), Util.stringToDate(endDate))) .toList(); boolean hasRemind = member.getDiaries().stream() .anyMatch(diary -> diary.isCreatedAt(now().minusDays(parseInt(valueConfig.getDURATION_REMIND())))); @@ -121,7 +121,7 @@ public List getAllByMemberId(Long memberId) { protected Diary get(Long id) { return diaryRepository.findById(id) - .orElseThrow(() -> new EntityNotFoundException(INVALID_DIARY.getMessage())); + .orElseThrow(() -> new EntityNotFoundException(ErrorMessage.INVALID_DIARY.getMessage())); } private List obtainBadges(Member member, LocalDateTime createdAt) { diff --git a/src/main/java/com/smeme/server/controller/GoalController.java b/smeem-api/src/main/java/com/smeem/goal/controller/GoalController.java similarity index 81% rename from src/main/java/com/smeme/server/controller/GoalController.java rename to smeem-api/src/main/java/com/smeem/goal/controller/GoalController.java index dedb22fb..cd565c18 100644 --- a/src/main/java/com/smeme/server/controller/GoalController.java +++ b/smeem-api/src/main/java/com/smeem/goal/controller/GoalController.java @@ -1,4 +1,4 @@ -package com.smeme.server.controller; +package com.smeem.goal.controller; import static com.smeme.server.util.ApiResponse.success; import static com.smeme.server.util.message.ResponseMessage.*; @@ -27,12 +27,12 @@ public class GoalController { @GetMapping public ResponseEntity getAll() { GoalsResponseDTO response = goalService.getAll(); - return ResponseEntity.ok(success(SUCCESS_GET_GOALS.getMessage(), response)); + return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_GET_GOALS.getMessage(), response)); } @GetMapping("/{type}") public ResponseEntity getByType(@PathVariable GoalType type) { GoalResponseDTO response = goalService.getByType(type); - return ResponseEntity.ok(success(SUCCESS_GET_GOAL.getMessage(), response)); + return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_GET_GOAL.getMessage(), response)); } } diff --git a/src/main/java/com/smeme/server/dto/goal/GoalResponseDTO.java b/smeem-api/src/main/java/com/smeem/goal/controller/dto/response/GoalResponseDTO.java similarity index 87% rename from src/main/java/com/smeme/server/dto/goal/GoalResponseDTO.java rename to smeem-api/src/main/java/com/smeem/goal/controller/dto/response/GoalResponseDTO.java index b1c3005d..3487d14d 100644 --- a/src/main/java/com/smeme/server/dto/goal/GoalResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/goal/controller/dto/response/GoalResponseDTO.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.goal; +package com.smeem.goal.controller.dto.response; import com.smeme.server.model.goal.Goal; diff --git a/src/main/java/com/smeme/server/dto/goal/GoalsResponseDTO.java b/smeem-api/src/main/java/com/smeem/goal/controller/dto/response/GoalsResponseDTO.java similarity index 92% rename from src/main/java/com/smeme/server/dto/goal/GoalsResponseDTO.java rename to smeem-api/src/main/java/com/smeem/goal/controller/dto/response/GoalsResponseDTO.java index ccd82ca3..f6dbed93 100644 --- a/src/main/java/com/smeme/server/dto/goal/GoalsResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/goal/controller/dto/response/GoalsResponseDTO.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.goal; +package com.smeem.goal.controller.dto.response; import java.util.List; diff --git a/src/main/java/com/smeme/server/service/GoalService.java b/smeem-api/src/main/java/com/smeem/goal/service/GoalService.java similarity index 94% rename from src/main/java/com/smeme/server/service/GoalService.java rename to smeem-api/src/main/java/com/smeem/goal/service/GoalService.java index 120a61f1..4b688ac4 100644 --- a/src/main/java/com/smeme/server/service/GoalService.java +++ b/smeem-api/src/main/java/com/smeem/goal/service/GoalService.java @@ -1,4 +1,4 @@ -package com.smeme.server.service; +package com.smeem.goal.service; import static com.smeme.server.util.message.ErrorMessage.*; @@ -30,7 +30,7 @@ public GoalsResponseDTO getAll() { public GoalResponseDTO getByType(GoalType goalType) { Goal goal = goalRepository.findOneByType(goalType) - .orElseThrow(() -> new EntityNotFoundException(EMPTY_GOAL.getMessage())); + .orElseThrow(() -> new EntityNotFoundException(ErrorMessage.EMPTY_GOAL.getMessage())); return new GoalResponseDTO(goal.getType().getDescription(), goal.getWay(), goal.getDetail()); } } diff --git a/src/main/java/com/smeme/server/controller/MemberController.java b/smeem-api/src/main/java/com/smeem/member/controller/MemberController.java similarity index 65% rename from src/main/java/com/smeme/server/controller/MemberController.java rename to smeem-api/src/main/java/com/smeem/member/controller/MemberController.java index 9675b5f7..8e416d4b 100644 --- a/src/main/java/com/smeme/server/controller/MemberController.java +++ b/smeem-api/src/main/java/com/smeem/member/controller/MemberController.java @@ -1,4 +1,4 @@ -package com.smeme.server.controller; +package com.smeem.member.controller; import com.smeme.server.dto.member.*; import com.smeme.server.service.MemberService; @@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.Parameter; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import com.smeem.member.service.MemberService; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -24,32 +25,32 @@ public class MemberController { @PatchMapping public ResponseEntity updateProfile(Principal principal, @RequestBody MemberUpdateRequestDTO request) { - MemberUpdateResponseDTO response = memberService.updateMember(getMemberId(principal), request); - return ResponseEntity.ok(success(SUCCESS_UPDATE_USERNAME.getMessage(), response)); + MemberUpdateResponseDTO response = memberService.updateMember(Util.getMemberId(principal), request); + return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_UPDATE_USERNAME.getMessage(), response)); } @GetMapping("/me") public ResponseEntity getProfile(Principal principal) { - MemberGetResponseDTO response = memberService.getProfile(getMemberId(principal)); - return ResponseEntity.ok(success(SUCCESS_GET_USER.getMessage(), response)); + MemberGetResponseDTO response = memberService.getProfile(Util.getMemberId(principal)); + return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_GET_USER.getMessage(), response)); } @PatchMapping("/plan") public ResponseEntity updateUserPlan(Principal principal, @Valid @RequestBody MemberPlanUpdateRequestDTO request) { - memberService.updateMemberPlan(getMemberId(principal), request); - return ResponseEntity.ok(success(SUCCESS_UPDATE_USER_PLAN.getMessage())); + memberService.updateMemberPlan(Util.getMemberId(principal), request); + return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_UPDATE_USER_PLAN.getMessage())); } @GetMapping("/nickname/check") public ResponseEntity checkDuplicatedName(@Parameter(description = "유저 닉네임") @RequestParam String name) { MemberNameResponseDTO response = memberService.checkDuplicatedName(name); - return ResponseEntity.ok(success(SUCCESS_CHECK_DUPLICATED_NAME.getMessage(), response)); + return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_CHECK_DUPLICATED_NAME.getMessage(), response)); } @PatchMapping("/push") public ResponseEntity updateUserPush(Principal principal, @RequestBody MemberPushUpdateRequestDTO request) { - memberService.updateHasAlarm(getMemberId(principal), request); - return ResponseEntity.ok(success(SUCCESS_UPDATE_USER_PUSH.getMessage())); + memberService.updateHasAlarm(Util.getMemberId(principal), request); + return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_UPDATE_USER_PUSH.getMessage())); } } diff --git a/src/main/java/com/smeme/server/dto/member/UsernameValidator.java b/smeem-api/src/main/java/com/smeem/member/controller/dto/UsernameValidator.java similarity index 94% rename from src/main/java/com/smeme/server/dto/member/UsernameValidator.java rename to smeem-api/src/main/java/com/smeem/member/controller/dto/UsernameValidator.java index 8a0e0130..5d3172b8 100644 --- a/src/main/java/com/smeme/server/dto/member/UsernameValidator.java +++ b/smeem-api/src/main/java/com/smeem/member/controller/dto/UsernameValidator.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.member; +package com.smeem.member.controller.dto; import jakarta.validation.ConstraintValidator; import jakarta.validation.ConstraintValidatorContext; diff --git a/src/main/java/com/smeme/server/dto/member/ValidUsername.java b/smeem-api/src/main/java/com/smeem/member/controller/dto/ValidUsername.java similarity index 88% rename from src/main/java/com/smeme/server/dto/member/ValidUsername.java rename to smeem-api/src/main/java/com/smeem/member/controller/dto/ValidUsername.java index 0bd0c5b9..7f6add25 100644 --- a/src/main/java/com/smeme/server/dto/member/ValidUsername.java +++ b/smeem-api/src/main/java/com/smeem/member/controller/dto/ValidUsername.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.member; +package com.smeem.member.controller.dto; import jakarta.validation.Constraint; diff --git a/src/main/java/com/smeme/server/dto/member/MemberPlanUpdateRequestDTO.java b/smeem-api/src/main/java/com/smeem/member/controller/dto/request/MemberPlanUpdateRequestDTO.java similarity index 83% rename from src/main/java/com/smeme/server/dto/member/MemberPlanUpdateRequestDTO.java rename to smeem-api/src/main/java/com/smeem/member/controller/dto/request/MemberPlanUpdateRequestDTO.java index 86f63d39..19ceeee5 100644 --- a/src/main/java/com/smeme/server/dto/member/MemberPlanUpdateRequestDTO.java +++ b/smeem-api/src/main/java/com/smeem/member/controller/dto/request/MemberPlanUpdateRequestDTO.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.member; +package com.smeem.member.controller.dto.request; import com.smeme.server.dto.training.TrainingTimeRequestDTO; import com.smeme.server.model.goal.GoalType; diff --git a/src/main/java/com/smeme/server/dto/member/MemberPushUpdateRequestDTO.java b/smeem-api/src/main/java/com/smeem/member/controller/dto/request/MemberPushUpdateRequestDTO.java similarity index 60% rename from src/main/java/com/smeme/server/dto/member/MemberPushUpdateRequestDTO.java rename to smeem-api/src/main/java/com/smeem/member/controller/dto/request/MemberPushUpdateRequestDTO.java index 31d2a617..41e657c7 100644 --- a/src/main/java/com/smeme/server/dto/member/MemberPushUpdateRequestDTO.java +++ b/smeem-api/src/main/java/com/smeem/member/controller/dto/request/MemberPushUpdateRequestDTO.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.member; +package com.smeem.member.controller.dto.request; public record MemberPushUpdateRequestDTO( boolean hasAlarm diff --git a/src/main/java/com/smeme/server/dto/member/MemberUpdateRequestDTO.java b/smeem-api/src/main/java/com/smeem/member/controller/dto/request/MemberUpdateRequestDTO.java similarity index 53% rename from src/main/java/com/smeme/server/dto/member/MemberUpdateRequestDTO.java rename to smeem-api/src/main/java/com/smeem/member/controller/dto/request/MemberUpdateRequestDTO.java index ecd9c301..9bff04db 100644 --- a/src/main/java/com/smeme/server/dto/member/MemberUpdateRequestDTO.java +++ b/smeem-api/src/main/java/com/smeem/member/controller/dto/request/MemberUpdateRequestDTO.java @@ -1,4 +1,6 @@ -package com.smeme.server.dto.member; +package com.smeem.member.controller.dto.request; + +import com.smeem.member.controller.dto.ValidUsername; public record MemberUpdateRequestDTO( @ValidUsername diff --git a/src/main/java/com/smeme/server/dto/training/TrainingTimeRequestDTO.java b/smeem-api/src/main/java/com/smeem/member/controller/dto/request/TrainingTimeRequestDTO.java similarity index 80% rename from src/main/java/com/smeme/server/dto/training/TrainingTimeRequestDTO.java rename to smeem-api/src/main/java/com/smeem/member/controller/dto/request/TrainingTimeRequestDTO.java index 9034c4ea..d55139ab 100644 --- a/src/main/java/com/smeme/server/dto/training/TrainingTimeRequestDTO.java +++ b/smeem-api/src/main/java/com/smeem/member/controller/dto/request/TrainingTimeRequestDTO.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.training; +package com.smeem.member.controller.dto.request; import jakarta.validation.constraints.NotNull; diff --git a/src/main/java/com/smeme/server/dto/member/MemberGetResponseDTO.java b/smeem-api/src/main/java/com/smeem/member/controller/dto/response/MemberGetResponseDTO.java similarity index 95% rename from src/main/java/com/smeme/server/dto/member/MemberGetResponseDTO.java rename to smeem-api/src/main/java/com/smeem/member/controller/dto/response/MemberGetResponseDTO.java index 8dd7f4c4..e0dd171b 100644 --- a/src/main/java/com/smeme/server/dto/member/MemberGetResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/member/controller/dto/response/MemberGetResponseDTO.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.member; +package com.smeem.member.controller.dto.response; import com.smeme.server.dto.badge.BadgeResponseDTO; import com.smeme.server.dto.goal.GoalResponseDTO; diff --git a/src/main/java/com/smeme/server/dto/member/MemberNameResponseDTO.java b/smeem-api/src/main/java/com/smeem/member/controller/dto/response/MemberNameResponseDTO.java similarity index 57% rename from src/main/java/com/smeme/server/dto/member/MemberNameResponseDTO.java rename to smeem-api/src/main/java/com/smeem/member/controller/dto/response/MemberNameResponseDTO.java index 2183f084..1dcfd287 100644 --- a/src/main/java/com/smeme/server/dto/member/MemberNameResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/member/controller/dto/response/MemberNameResponseDTO.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.member; +package com.smeem.member.controller.dto.response; public record MemberNameResponseDTO( boolean isExist diff --git a/src/main/java/com/smeme/server/dto/member/MemberUpdateResponseDTO.java b/smeem-api/src/main/java/com/smeem/member/controller/dto/response/MemberUpdateResponseDTO.java similarity index 88% rename from src/main/java/com/smeme/server/dto/member/MemberUpdateResponseDTO.java rename to smeem-api/src/main/java/com/smeem/member/controller/dto/response/MemberUpdateResponseDTO.java index debe3c27..a635d955 100644 --- a/src/main/java/com/smeme/server/dto/member/MemberUpdateResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/member/controller/dto/response/MemberUpdateResponseDTO.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.member; +package com.smeem.member.controller.dto.response; import com.smeme.server.dto.badge.AcquiredBadgeResponseDTO; import com.smeme.server.model.badge.Badge; diff --git a/src/main/java/com/smeme/server/dto/training/TrainingTimeResponseDTO.java b/smeem-api/src/main/java/com/smeem/member/controller/dto/response/TrainingTimeResponseDTO.java similarity index 81% rename from src/main/java/com/smeme/server/dto/training/TrainingTimeResponseDTO.java rename to smeem-api/src/main/java/com/smeem/member/controller/dto/response/TrainingTimeResponseDTO.java index 22d36025..10d5fe00 100644 --- a/src/main/java/com/smeme/server/dto/training/TrainingTimeResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/member/controller/dto/response/TrainingTimeResponseDTO.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.training; +package com.smeem.member.controller.dto.response; public record TrainingTimeResponseDTO(String day, int hour, int minute) { public static TrainingTimeResponseDTO of(String day, int hour, int minute) { diff --git a/src/main/java/com/smeme/server/service/MemberBadgeService.java b/smeem-api/src/main/java/com/smeem/member/service/MemberBadgeService.java similarity index 97% rename from src/main/java/com/smeme/server/service/MemberBadgeService.java rename to smeem-api/src/main/java/com/smeem/member/service/MemberBadgeService.java index a0209244..3a35a69c 100644 --- a/src/main/java/com/smeme/server/service/MemberBadgeService.java +++ b/smeem-api/src/main/java/com/smeem/member/service/MemberBadgeService.java @@ -1,4 +1,4 @@ -package com.smeme.server.service; +package com.smeem.member.service; import com.smeme.server.model.Member; import com.smeme.server.model.badge.Badge; diff --git a/src/main/java/com/smeme/server/service/MemberService.java b/smeem-api/src/main/java/com/smeem/member/service/MemberService.java similarity index 99% rename from src/main/java/com/smeme/server/service/MemberService.java rename to smeem-api/src/main/java/com/smeem/member/service/MemberService.java index 2b4614b6..fbf81db5 100644 --- a/src/main/java/com/smeme/server/service/MemberService.java +++ b/smeem-api/src/main/java/com/smeem/member/service/MemberService.java @@ -1,4 +1,4 @@ -package com.smeme.server.service; +package com.smeem.member.service; import com.smeme.server.config.ValueConfig; import com.smeme.server.dto.badge.BadgeResponseDTO; diff --git a/src/main/java/com/smeme/server/service/TrainingTimeService.java b/smeem-api/src/main/java/com/smeem/member/service/TrainingTimeService.java similarity index 96% rename from src/main/java/com/smeme/server/service/TrainingTimeService.java rename to smeem-api/src/main/java/com/smeem/member/service/TrainingTimeService.java index e4fe7a52..445eaab5 100644 --- a/src/main/java/com/smeme/server/service/TrainingTimeService.java +++ b/smeem-api/src/main/java/com/smeem/member/service/TrainingTimeService.java @@ -1,4 +1,4 @@ -package com.smeme.server.service; +package com.smeem.member.service; import com.smeme.server.model.Member; import com.smeme.server.model.training.TrainingTime; diff --git a/src/main/java/com/smeme/server/controller/TestController.java b/smeem-api/src/main/java/com/smeem/test/controller/TestController.java similarity index 81% rename from src/main/java/com/smeme/server/controller/TestController.java rename to smeem-api/src/main/java/com/smeem/test/controller/TestController.java index e3f44acb..2433ffbe 100644 --- a/src/main/java/com/smeme/server/controller/TestController.java +++ b/smeem-api/src/main/java/com/smeem/test/controller/TestController.java @@ -1,4 +1,4 @@ -package com.smeme.server.controller; +package com.smeem.test.controller; import static com.smeme.server.util.ApiResponse.*; @@ -18,7 +18,7 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/api/v2/test") +@RequestMapping("/api/v2/com.smeem.test") public class TestController { private final MessageService messageService; @@ -26,12 +26,12 @@ public class TestController { @GetMapping public ResponseEntity test() { - return ResponseEntity.ok(success("server connect")); + return ResponseEntity.ok(ApiResponse.success("server connect")); } @GetMapping("/alarm") public ResponseEntity alarmTest(@Parameter(hidden = true) Principal principal) { messageService.pushTest(valueConfig.getMESSAGE_TITLE(), valueConfig.getMESSAGE_BODY(), Long.valueOf(principal.getName())); - return ResponseEntity.ok(success("푸시 알림 전송 성공")); + return ResponseEntity.ok(ApiResponse.success("푸시 알림 전송 성공")); } } diff --git a/src/main/java/com/smeme/server/controller/TopicController.java b/smeem-api/src/main/java/com/smeem/topic/controller/TopicController.java similarity index 80% rename from src/main/java/com/smeme/server/controller/TopicController.java rename to smeem-api/src/main/java/com/smeem/topic/controller/TopicController.java index b10fa454..c61aeb8c 100644 --- a/src/main/java/com/smeme/server/controller/TopicController.java +++ b/smeem-api/src/main/java/com/smeem/topic/controller/TopicController.java @@ -1,4 +1,4 @@ -package com.smeme.server.controller; +package com.smeem.topic.controller; import static com.smeme.server.util.ApiResponse.success; import static com.smeme.server.util.message.ResponseMessage.*; @@ -13,6 +13,7 @@ import com.smeme.server.util.ApiResponse; import lombok.RequiredArgsConstructor; +import com.smeem.topic.service.TopicService; @RestController @RequiredArgsConstructor @@ -24,6 +25,6 @@ public class TopicController { @GetMapping("/random") public ResponseEntity getRandom() { TopicResponseDTO response = topicService.getRandom(); - return ResponseEntity.ok(success(SUCCESS_GET_RANDOM_TOPIC.getMessage(), response)); + return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_GET_RANDOM_TOPIC.getMessage(), response)); } } diff --git a/src/main/java/com/smeme/server/dto/topic/TopicResponseDTO.java b/smeem-api/src/main/java/com/smeem/topic/controller/dto/response/TopicResponseDTO.java similarity index 84% rename from src/main/java/com/smeme/server/dto/topic/TopicResponseDTO.java rename to smeem-api/src/main/java/com/smeem/topic/controller/dto/response/TopicResponseDTO.java index a9f97206..5a0f253d 100644 --- a/src/main/java/com/smeme/server/dto/topic/TopicResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/topic/controller/dto/response/TopicResponseDTO.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.topic; +package com.smeem.topic.controller.dto.response; import com.smeme.server.model.topic.Topic; diff --git a/src/main/java/com/smeme/server/service/TopicService.java b/smeem-api/src/main/java/com/smeem/topic/service/TopicService.java similarity index 86% rename from src/main/java/com/smeme/server/service/TopicService.java rename to smeem-api/src/main/java/com/smeem/topic/service/TopicService.java index db4cc434..ab2065ac 100644 --- a/src/main/java/com/smeme/server/service/TopicService.java +++ b/smeem-api/src/main/java/com/smeem/topic/service/TopicService.java @@ -1,4 +1,4 @@ -package com.smeme.server.service; +package com.smeem.topic.service; import jakarta.persistence.EntityNotFoundException; import org.springframework.stereotype.Service; @@ -28,7 +28,7 @@ public TopicResponseDTO getRandom() { protected Topic get(Long id) { return nonNull(id) ? topicRepository.findById(id) - .orElseThrow(() -> new EntityNotFoundException(INVALID_TOPIC.getMessage())) + .orElseThrow(() -> new EntityNotFoundException(ErrorMessage.INVALID_TOPIC.getMessage())) : null; } } diff --git a/src/main/resources/application-dev.yml b/smeem-api/src/main/resources/application-dev.yml similarity index 100% rename from src/main/resources/application-dev.yml rename to smeem-api/src/main/resources/application-dev.yml diff --git a/src/main/resources/application-prod.yml b/smeem-api/src/main/resources/application-prod.yml similarity index 100% rename from src/main/resources/application-prod.yml rename to smeem-api/src/main/resources/application-prod.yml diff --git a/src/main/resources/static/docs/open-api-3.0.1.json b/smeem-api/src/main/resources/static/docs/open-api-3.0.1.json similarity index 100% rename from src/main/resources/static/docs/open-api-3.0.1.json rename to smeem-api/src/main/resources/static/docs/open-api-3.0.1.json diff --git a/src/test/java/com/smeme/server/SmemeServerRenewalApplicationTests.java b/smeem-api/src/test/java/com/smeem/SmemeServerRenewalApplicationTests.java similarity index 82% rename from src/test/java/com/smeme/server/SmemeServerRenewalApplicationTests.java rename to smeem-api/src/test/java/com/smeem/SmemeServerRenewalApplicationTests.java index fa3a381b..c283a60a 100644 --- a/src/test/java/com/smeme/server/SmemeServerRenewalApplicationTests.java +++ b/smeem-api/src/test/java/com/smeem/SmemeServerRenewalApplicationTests.java @@ -1,4 +1,4 @@ -package com.smeme.server; +package com.smeem; import org.springframework.boot.test.context.SpringBootTest; diff --git a/src/test/java/com/smeme/server/controller/AuthControllerTest.java b/smeem-api/src/test/java/com/smeem/controller/AuthControllerTest.java similarity index 98% rename from src/test/java/com/smeme/server/controller/AuthControllerTest.java rename to smeem-api/src/test/java/com/smeem/controller/AuthControllerTest.java index 8e0d6ac1..937c25b8 100644 --- a/src/test/java/com/smeme/server/controller/AuthControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/controller/AuthControllerTest.java @@ -1,8 +1,8 @@ -package com.smeme.server.controller; +package com.smeem.controller; import com.epages.restdocs.apispec.ResourceSnippetParameters; -import com.smeme.server.fixture.auth.AuthFixture; +import com.smeem.fixture.auth.AuthFixture; import lombok.val; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -36,7 +36,7 @@ public class AuthControllerTest extends BaseControllerTest { @MockBean Principal principal; - private final String DEFAULT_URL = "/api/v2/auth"; + private final String DEFAULT_URL = "/api/v2/com.smeem.auth"; private final String TAG = "Auth"; private static final String SOCIAL_ACCESS_TOKEN = "TEST SOCIAL_ACCESS_TOKEN"; diff --git a/src/test/java/com/smeme/server/controller/BadgeControllerTest.java b/smeem-api/src/test/java/com/smeem/controller/BadgeControllerTest.java similarity index 97% rename from src/test/java/com/smeme/server/controller/BadgeControllerTest.java rename to smeem-api/src/test/java/com/smeem/controller/BadgeControllerTest.java index 15e63376..3d6ecf99 100644 --- a/src/test/java/com/smeme/server/controller/BadgeControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/controller/BadgeControllerTest.java @@ -1,7 +1,7 @@ -package com.smeme.server.controller; +package com.smeem.controller; import com.epages.restdocs.apispec.ResourceSnippetParameters; -import com.smeme.server.fixture.badge.BadgeFixture; +import com.smeem.fixture.badge.BadgeFixture; import lombok.val; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/smeme/server/controller/BaseControllerTest.java b/smeem-api/src/test/java/com/smeem/controller/BaseControllerTest.java similarity index 95% rename from src/test/java/com/smeme/server/controller/BaseControllerTest.java rename to smeem-api/src/test/java/com/smeem/controller/BaseControllerTest.java index 6de0f80c..566ee875 100644 --- a/src/test/java/com/smeme/server/controller/BaseControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/controller/BaseControllerTest.java @@ -1,4 +1,4 @@ -package com.smeme.server.controller; +package com.smeem.controller; import com.fasterxml.jackson.databind.ObjectMapper; import com.smeme.server.config.jwt.CustomJwtAuthenticationEntryPoint; @@ -12,7 +12,6 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.restdocs.RestDocumentationContextProvider; import org.springframework.restdocs.RestDocumentationExtension; -import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; diff --git a/src/test/java/com/smeme/server/controller/DiaryControllerTest.java b/smeem-api/src/test/java/com/smeem/controller/DiaryControllerTest.java similarity index 98% rename from src/test/java/com/smeme/server/controller/DiaryControllerTest.java rename to smeem-api/src/test/java/com/smeem/controller/DiaryControllerTest.java index f83833f4..381ac61d 100644 --- a/src/test/java/com/smeme/server/controller/DiaryControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/controller/DiaryControllerTest.java @@ -1,4 +1,4 @@ -package com.smeme.server.controller; +package com.smeem.controller; import com.epages.restdocs.apispec.ResourceSnippetParameters; import com.smeme.server.dto.badge.AcquiredBadgeResponseDTO; @@ -133,7 +133,7 @@ void success_get_diary() throws Exception { fieldWithPath("message").type(STRING).description("응답 메시지"), fieldWithPath("data").type(OBJECT).description("응답 데이터"), fieldWithPath("data.diaryId").type(NUMBER).description("일기 id"), - fieldWithPath("data.topic").type(STRING).description("랜덤 주제"), + fieldWithPath("data.com.smeem.topic").type(STRING).description("랜덤 주제"), fieldWithPath("data.content").type(STRING).description("일기 내용"), fieldWithPath("data.createdAt").type(STRING).description("작성 날짜"), fieldWithPath("data.username").type(STRING).description("작성자 이름") @@ -275,7 +275,7 @@ private List acquiredBadges() { } private AcquiredBadgeResponseDTO acquiredBadge() { - return new AcquiredBadgeResponseDTO("뱃지 이름", "badge-image-url", BadgeType.EVENT); + return new AcquiredBadgeResponseDTO("뱃지 이름", "com.smeem.badge-image-url", BadgeType.EVENT); } private List diaries() { diff --git a/src/test/java/com/smeme/server/controller/GoalControllerTest.java b/smeem-api/src/test/java/com/smeem/controller/GoalControllerTest.java similarity index 99% rename from src/test/java/com/smeme/server/controller/GoalControllerTest.java rename to smeem-api/src/test/java/com/smeem/controller/GoalControllerTest.java index c0b2b00b..7a81d5cf 100644 --- a/src/test/java/com/smeme/server/controller/GoalControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/controller/GoalControllerTest.java @@ -1,4 +1,4 @@ -package com.smeme.server.controller; +package com.smeem.controller; import com.epages.restdocs.apispec.ResourceSnippetParameters; import com.smeme.server.dto.goal.GoalResponseDTO; diff --git a/src/test/java/com/smeme/server/controller/MemberControllerTest.java b/smeem-api/src/test/java/com/smeem/controller/MemberControllerTest.java similarity index 89% rename from src/test/java/com/smeme/server/controller/MemberControllerTest.java rename to smeem-api/src/test/java/com/smeem/controller/MemberControllerTest.java index cf06ceb4..ab36ff4d 100644 --- a/src/test/java/com/smeme/server/controller/MemberControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/controller/MemberControllerTest.java @@ -1,8 +1,8 @@ -package com.smeme.server.controller; +package com.smeem.controller; import com.epages.restdocs.apispec.ResourceSnippetParameters; -import com.smeme.server.fixture.member.MemberFixture; +import com.smeem.fixture.member.MemberFixture; import lombok.val; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -58,11 +58,11 @@ void success_updateProfile() throws Exception { fieldWithPath("data.trainingTime.day").type(STRING).description("학습 요일"), fieldWithPath("data.trainingTime.hour").type(NUMBER).description("학습 시간"), fieldWithPath("data.trainingTime.minute").type(NUMBER).description("학습 분"), - fieldWithPath("data.badge").type(OBJECT).description("뱃지"), - fieldWithPath("data.badge.id").type(NUMBER).description("뱃지 아이디"), - fieldWithPath("data.badge.name").type(STRING).description("뱃지 이름"), - fieldWithPath("data.badge.type").type(STRING).description("뱃지 설명"), - fieldWithPath("data.badge.imageUrl").type(STRING).description("뱃지 이미지") + fieldWithPath("data.com.smeem.badge").type(OBJECT).description("뱃지"), + fieldWithPath("data.com.smeem.badge.id").type(NUMBER).description("뱃지 아이디"), + fieldWithPath("data.com.smeem.badge.name").type(STRING).description("뱃지 이름"), + fieldWithPath("data.com.smeem.badge.type").type(STRING).description("뱃지 설명"), + fieldWithPath("data.com.smeem.badge.imageUrl").type(STRING).description("뱃지 이미지") ) .build(); @@ -105,11 +105,11 @@ void success_getProfile() throws Exception { fieldWithPath("data.trainingTime.day").type(STRING).description("학습 요일"), fieldWithPath("data.trainingTime.hour").type(NUMBER).description("학습 시간"), fieldWithPath("data.trainingTime.minute").type(NUMBER).description("학습 분"), - fieldWithPath("data.badge").type(OBJECT).description("뱃지"), - fieldWithPath("data.badge.id").type(NUMBER).description("뱃지 아이디"), - fieldWithPath("data.badge.name").type(STRING).description("뱃지 이름"), - fieldWithPath("data.badge.type").type(STRING).description("뱃지 설명"), - fieldWithPath("data.badge.imageUrl").type(STRING).description("뱃지 이미지") + fieldWithPath("data.com.smeem.badge").type(OBJECT).description("뱃지"), + fieldWithPath("data.com.smeem.badge.id").type(NUMBER).description("뱃지 아이디"), + fieldWithPath("data.com.smeem.badge.name").type(STRING).description("뱃지 이름"), + fieldWithPath("data.com.smeem.badge.type").type(STRING).description("뱃지 설명"), + fieldWithPath("data.com.smeem.badge.imageUrl").type(STRING).description("뱃지 이미지") ) .build(); val result = ResponseEntity.ok(success("사용자 정보 조회 성공", MemberFixture.createMemberGetResponseDTO())); @@ -173,14 +173,14 @@ void success_checkDuplicatedName() throws Exception { ) .build(); // when - when(memberController.checkDuplicatedName("test")) + when(memberController.checkDuplicatedName("com.smeem.test")) .thenReturn(ResponseEntity.ok(success("닉네임 중복 체크 성공"))); // then mockMvc.perform(get(DEFAULT_URL + "/nickname/check") .contentType(APPLICATION_JSON) .principal(principal) - .param("name", "test")) + .param("name", "com.smeem.test")) .andDo( document("닉네임 중복 체크 성공 Example", preprocessRequest(prettyPrint()), diff --git a/src/test/java/com/smeme/server/controller/TestControllerTest.java b/smeem-api/src/test/java/com/smeem/controller/TestControllerTest.java similarity index 93% rename from src/test/java/com/smeme/server/controller/TestControllerTest.java rename to smeem-api/src/test/java/com/smeem/controller/TestControllerTest.java index 26ab3386..60a621bd 100644 --- a/src/test/java/com/smeme/server/controller/TestControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/controller/TestControllerTest.java @@ -1,4 +1,4 @@ -package com.smeme.server.controller; +package com.smeem.controller; import com.epages.restdocs.apispec.ResourceSnippetParameters; import com.smeme.server.util.ApiResponse; @@ -11,7 +11,6 @@ import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; import org.springframework.restdocs.payload.JsonFieldType; -import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.result.MockMvcResultMatchers; @@ -24,7 +23,7 @@ @WebMvcTest(value = TestController.class) class TestControllerTest extends BaseControllerTest { - private static final String DEFAULT_URL = "/api/v2/test"; + private static final String DEFAULT_URL = "/api/v2/com.smeem.test"; @MockBean TestController testController; @@ -44,7 +43,7 @@ void success_test() throws Exception { .accept(MediaType.APPLICATION_JSON) ).andDo( MockMvcRestDocumentation.document( - "test-docs", + "com.smeem.test-docs", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), resource( diff --git a/src/test/java/com/smeme/server/controller/TopicControllerTest.java b/smeem-api/src/test/java/com/smeem/controller/TopicControllerTest.java similarity index 99% rename from src/test/java/com/smeme/server/controller/TopicControllerTest.java rename to smeem-api/src/test/java/com/smeem/controller/TopicControllerTest.java index 19c4e64f..232fa67d 100644 --- a/src/test/java/com/smeme/server/controller/TopicControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/controller/TopicControllerTest.java @@ -1,4 +1,4 @@ -package com.smeme.server.controller; +package com.smeem.controller; import com.epages.restdocs.apispec.ResourceSnippetParameters; import com.smeme.server.dto.topic.TopicResponseDTO; diff --git a/src/test/java/com/smeme/server/fixture/auth/AuthFixture.java b/smeem-api/src/test/java/com/smeem/fixture/auth/AuthFixture.java similarity index 87% rename from src/test/java/com/smeme/server/fixture/auth/AuthFixture.java rename to smeem-api/src/test/java/com/smeem/fixture/auth/AuthFixture.java index a7424fbd..c902d81b 100644 --- a/src/test/java/com/smeme/server/fixture/auth/AuthFixture.java +++ b/smeem-api/src/test/java/com/smeem/fixture/auth/AuthFixture.java @@ -1,9 +1,9 @@ -package com.smeme.server.fixture.auth; +package com.smeem.fixture.auth; import com.smeme.server.dto.auth.SignInRequestDTO; import com.smeme.server.dto.auth.SignInResponseDTO; -import com.smeme.server.dto.auth.token.TokenResponseDTO; -import com.smeme.server.dto.auth.token.TokenVO; +import com.smeem.auth.controller.dto.response.token.TokenResponseDTO; +import com.smeem.auth.controller.dto.response.token.TokenVO; import com.smeme.server.model.SocialType; public class AuthFixture { diff --git a/src/test/java/com/smeme/server/fixture/badge/BadgeFixture.java b/smeem-api/src/test/java/com/smeem/fixture/badge/BadgeFixture.java similarity index 98% rename from src/test/java/com/smeme/server/fixture/badge/BadgeFixture.java rename to smeem-api/src/test/java/com/smeem/fixture/badge/BadgeFixture.java index 61303c0f..14b27091 100644 --- a/src/test/java/com/smeme/server/fixture/badge/BadgeFixture.java +++ b/smeem-api/src/test/java/com/smeem/fixture/badge/BadgeFixture.java @@ -1,4 +1,4 @@ -package com.smeme.server.fixture.badge; +package com.smeem.fixture.badge; import com.smeme.server.dto.badge.BadgeListResponseDTO; import com.smeme.server.dto.badge.BadgeListResponseDTO.BadgeTypeResponseDTO; diff --git a/src/test/java/com/smeme/server/fixture/diary/DiaryFixture.java b/smeem-api/src/test/java/com/smeem/fixture/diary/DiaryFixture.java similarity index 81% rename from src/test/java/com/smeme/server/fixture/diary/DiaryFixture.java rename to smeem-api/src/test/java/com/smeem/fixture/diary/DiaryFixture.java index ee47fa14..34a4091e 100644 --- a/src/test/java/com/smeme/server/fixture/diary/DiaryFixture.java +++ b/smeem-api/src/test/java/com/smeem/fixture/diary/DiaryFixture.java @@ -1,7 +1,7 @@ -package com.smeme.server.fixture.diary; +package com.smeem.fixture.diary; -import com.smeme.server.fixture.member.MemberFixture; -import com.smeme.server.fixture.topic.TopicFixture; +import com.smeem.fixture.member.MemberFixture; +import com.smeem.fixture.topic.TopicFixture; import com.smeme.server.model.Diary; import com.smeme.server.model.LangType; diff --git a/src/test/java/com/smeme/server/fixture/goal/GoalFixture.java b/smeem-api/src/test/java/com/smeem/fixture/goal/GoalFixture.java similarity index 95% rename from src/test/java/com/smeme/server/fixture/goal/GoalFixture.java rename to smeem-api/src/test/java/com/smeem/fixture/goal/GoalFixture.java index 8d7842d4..e7c5694f 100644 --- a/src/test/java/com/smeme/server/fixture/goal/GoalFixture.java +++ b/smeem-api/src/test/java/com/smeem/fixture/goal/GoalFixture.java @@ -1,4 +1,4 @@ -package com.smeme.server.fixture.goal; +package com.smeem.fixture.goal; import com.smeme.server.dto.goal.GoalResponseDTO; import com.smeme.server.model.goal.Goal; diff --git a/src/test/java/com/smeme/server/fixture/member/MemberFixture.java b/smeem-api/src/test/java/com/smeem/fixture/member/MemberFixture.java similarity index 88% rename from src/test/java/com/smeme/server/fixture/member/MemberFixture.java rename to smeem-api/src/test/java/com/smeem/fixture/member/MemberFixture.java index 019bf1cd..e66fb8c6 100644 --- a/src/test/java/com/smeme/server/fixture/member/MemberFixture.java +++ b/smeem-api/src/test/java/com/smeem/fixture/member/MemberFixture.java @@ -1,9 +1,8 @@ -package com.smeme.server.fixture.member; +package com.smeem.fixture.member; -import com.smeme.server.dto.member.*; -import com.smeme.server.fixture.badge.BadgeFixture; -import com.smeme.server.fixture.goal.GoalFixture; -import com.smeme.server.fixture.trainingtime.TrainingTimeFixture; +import com.smeem.fixture.badge.BadgeFixture; +import com.smeem.fixture.goal.GoalFixture; +import com.smeem.fixture.trainingtime.TrainingTimeFixture; import com.smeme.server.model.LangType; import com.smeme.server.model.Member; import com.smeme.server.model.SocialType; diff --git a/smeem-api/src/test/java/com/smeem/fixture/memberbadge/MemberBadgeFixture.java b/smeem-api/src/test/java/com/smeem/fixture/memberbadge/MemberBadgeFixture.java new file mode 100644 index 00000000..0a9b2488 --- /dev/null +++ b/smeem-api/src/test/java/com/smeem/fixture/memberbadge/MemberBadgeFixture.java @@ -0,0 +1,4 @@ +package com.smeem.fixture.memberbadge; + +public class MemberBadgeFixture { +} diff --git a/src/test/java/com/smeme/server/fixture/topic/TopicFixture.java b/smeem-api/src/test/java/com/smeem/fixture/topic/TopicFixture.java similarity index 81% rename from src/test/java/com/smeme/server/fixture/topic/TopicFixture.java rename to smeem-api/src/test/java/com/smeem/fixture/topic/TopicFixture.java index 8c8f971b..dec46c0b 100644 --- a/src/test/java/com/smeme/server/fixture/topic/TopicFixture.java +++ b/smeem-api/src/test/java/com/smeem/fixture/topic/TopicFixture.java @@ -1,4 +1,4 @@ -package com.smeme.server.fixture.topic; +package com.smeem.fixture.topic; import com.smeme.server.dto.topic.TopicResponseDTO; import com.smeme.server.model.topic.Category; @@ -7,7 +7,7 @@ public class TopicFixture { private static final Category TOPIC_CATEGORY = Category.DEVELOP; - private static final String TOPIC_CONTENT = "test topic content"; + private static final String TOPIC_CONTENT = "com.smeem.test com.smeem.topic content"; public static Topic createTopic() { diff --git a/src/test/java/com/smeme/server/fixture/trainingtime/TrainingTimeFixture.java b/smeem-api/src/test/java/com/smeem/fixture/trainingtime/TrainingTimeFixture.java similarity index 90% rename from src/test/java/com/smeme/server/fixture/trainingtime/TrainingTimeFixture.java rename to smeem-api/src/test/java/com/smeem/fixture/trainingtime/TrainingTimeFixture.java index 347840b3..8a2b0b68 100644 --- a/src/test/java/com/smeme/server/fixture/trainingtime/TrainingTimeFixture.java +++ b/smeem-api/src/test/java/com/smeem/fixture/trainingtime/TrainingTimeFixture.java @@ -1,8 +1,8 @@ -package com.smeme.server.fixture.trainingtime; +package com.smeem.fixture.trainingtime; import com.smeme.server.dto.training.TrainingTimeRequestDTO; import com.smeme.server.dto.training.TrainingTimeResponseDTO; -import com.smeme.server.fixture.member.MemberFixture; +import com.smeem.fixture.member.MemberFixture; import com.smeme.server.model.training.DayType; import com.smeme.server.model.training.TrainingTime; diff --git a/src/main/java/com/smeme/server/scheduler/DiaryScheduler.java b/smeem-batch/src/main/java/com/smeem/scheduler/DiaryScheduler.java similarity index 93% rename from src/main/java/com/smeme/server/scheduler/DiaryScheduler.java rename to smeem-batch/src/main/java/com/smeem/scheduler/DiaryScheduler.java index b59d1db1..fe65d116 100644 --- a/src/main/java/com/smeme/server/scheduler/DiaryScheduler.java +++ b/smeem-batch/src/main/java/com/smeem/scheduler/DiaryScheduler.java @@ -1,4 +1,4 @@ -package com.smeme.server.scheduler; +package com.smeem.scheduler; import com.smeme.server.service.DiaryService; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/smeme/server/scheduler/MessageScheduler.java b/smeem-batch/src/main/java/com/smeem/scheduler/MessageScheduler.java similarity index 95% rename from src/main/java/com/smeme/server/scheduler/MessageScheduler.java rename to smeem-batch/src/main/java/com/smeem/scheduler/MessageScheduler.java index 275263a4..50415ea9 100644 --- a/src/main/java/com/smeme/server/scheduler/MessageScheduler.java +++ b/smeem-batch/src/main/java/com/smeem/scheduler/MessageScheduler.java @@ -1,4 +1,4 @@ -package com.smeme.server.scheduler; +package com.smeem.scheduler; import com.smeme.server.config.ValueConfig; import com.smeme.server.service.MessageService; diff --git a/src/main/java/com/smeme/server/handler/ErrorHandler.java b/smeem-common/src/main/java/com/smeem/advicer/ErrorHandler.java similarity index 69% rename from src/main/java/com/smeme/server/handler/ErrorHandler.java rename to smeem-common/src/main/java/com/smeem/advicer/ErrorHandler.java index 9222192c..eb8bc500 100644 --- a/src/main/java/com/smeme/server/handler/ErrorHandler.java +++ b/smeem-common/src/main/java/com/smeem/advicer/ErrorHandler.java @@ -1,4 +1,4 @@ -package com.smeme.server.handler; +package com.smeem.advicer; import static com.smeme.server.util.ApiResponse.fail; import static org.springframework.http.HttpStatus.*; @@ -23,46 +23,46 @@ public class ErrorHandler { @ExceptionHandler(EntityNotFoundException.class) public ResponseEntity entityNotFoundException(EntityNotFoundException ex) { - return ResponseEntity.status(NOT_FOUND).body(fail(ex.getMessage())); + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ApiResponse.fail(ex.getMessage())); } @ExceptionHandler(ChangeSetPersister.NotFoundException.class) public ResponseEntity notFoundException(ChangeSetPersister.NotFoundException ex) { - return ResponseEntity.status(NOT_FOUND).body(fail(ex.getMessage())); + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ApiResponse.fail(ex.getMessage())); } @ExceptionHandler(NoSuchElementException.class) public ResponseEntity noSuchElementException(NoSuchElementException ex) { - return ResponseEntity.status(NOT_FOUND).body(fail(ex.getMessage())); + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ApiResponse.fail(ex.getMessage())); } @ExceptionHandler(IllegalArgumentException.class) public ResponseEntity illegalArgumentException(IllegalArgumentException ex) { - return ResponseEntity.status(BAD_REQUEST).body(fail(ex.getMessage())); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.fail(ex.getMessage())); } @ExceptionHandler(ConstraintViolationException.class) public ResponseEntity constraintViolationException(ConstraintViolationException ex) { - return ResponseEntity.status(BAD_REQUEST).body(fail(ex.getMessage())); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.fail(ex.getMessage())); } @ExceptionHandler(EntityExistsException.class) public ResponseEntity entityExistsException(EntityExistsException ex) { - return ResponseEntity.status(BAD_REQUEST).body(fail(ex.getMessage())); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.fail(ex.getMessage())); } @ExceptionHandler(InvalidBearerTokenException.class) public ResponseEntity invalidBearerTokenException(InvalidBearerTokenException ex) { - return ResponseEntity.status(UNAUTHORIZED).body(fail(ex.getMessage())); + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(ApiResponse.fail(ex.getMessage())); } @ExceptionHandler(IOException.class) public ResponseEntity ioException(IOException ex) { - return ResponseEntity.status(INTERNAL_SERVER_ERROR).body(fail(ex.getMessage())); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ApiResponse.fail(ex.getMessage())); } @ExceptionHandler(IllegalStateException.class) public ResponseEntity illegalStateException(IllegalStateException ex) { - return ResponseEntity.status(BAD_REQUEST).body(fail(ex.getMessage())); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.fail(ex.getMessage())); } } diff --git a/src/main/java/com/smeme/server/util/message/ErrorMessage.java b/smeem-common/src/main/java/com/smeem/code/ErrorMessage.java similarity index 89% rename from src/main/java/com/smeme/server/util/message/ErrorMessage.java rename to smeem-common/src/main/java/com/smeem/code/ErrorMessage.java index d96b281b..52a4fe3c 100644 --- a/src/main/java/com/smeme/server/util/message/ErrorMessage.java +++ b/smeem-common/src/main/java/com/smeem/code/ErrorMessage.java @@ -1,4 +1,4 @@ -package com.smeme.server.util.message; +package com.smeem.code; import lombok.AllArgsConstructor; import lombok.Getter; @@ -7,19 +7,19 @@ @AllArgsConstructor public enum ErrorMessage { - // auth + // com.smeem.auth EMPTY_ACCESS_TOKEN("액세스 토큰이 없습니다."), EMPTY_REFRESH_TOKEN("리프레시 토큰이 없습니다"), INVALID_TOKEN("유효하지 않은 토큰입니다"), MESSAGE_UNAUTHORIZED("유효하지 않은 토큰"), - // member + // com.smeem.member EMPTY_MEMBER("존재하지 않는 회원입니다."), DUPLICATE_USERNAME("이미 존재하는 닉네임입니다."), INVALID_MEMBER("유효하지 않은 회원입니다."), INVALID_USERNAME("유효하지 않은 닉네임입니다."), - // diary + // com.smeem.diary EXIST_TODAY_DIARY("일기는 하루에 한 번씩 작성할 수 있습니다."), INVALID_DIARY("유효하지 않은 일기입니다."), DELETED_DIARY("삭제된 일기입니다."), @@ -27,7 +27,7 @@ public enum ErrorMessage { // correction INVALID_CORRECTION("유효하지 않은 첨삭입니다."), - // topic + // com.smeem.topic INVALID_TOPIC("유효하지 않은 랜덤주제입니다."), // Push Alarm @@ -37,11 +37,11 @@ public enum ErrorMessage { EMPTY_TRAINING_TIME("존재하지 않는 학습계획 입니다."), NOT_SET_TRAINING_TIME("학습계획이 설정되지 않았습니다."), - // badge + // com.smeem.badge INVALID_BADGE("유효하지 않은 뱃지입니다."), EMPTY_BADGE("존재하지 않는 뱃지입니다."), - // goal + // com.smeem.goal EMPTY_GOAL("존재하지 않는 목표입니다."); private final String message; diff --git a/src/main/java/com/smeme/server/util/message/ResponseMessage.java b/smeem-common/src/main/java/com/smeem/code/ResponseMessage.java similarity index 93% rename from src/main/java/com/smeme/server/util/message/ResponseMessage.java rename to smeem-common/src/main/java/com/smeem/code/ResponseMessage.java index fb3a9016..da3b9b35 100644 --- a/src/main/java/com/smeme/server/util/message/ResponseMessage.java +++ b/smeem-common/src/main/java/com/smeem/code/ResponseMessage.java @@ -1,4 +1,4 @@ -package com.smeme.server.util.message; +package com.smeem.code; import lombok.AllArgsConstructor; import lombok.Getter; @@ -6,14 +6,14 @@ @AllArgsConstructor @Getter public enum ResponseMessage { - // diary + // com.smeem.diary SUCCESS_CREATE_DIARY("일기 생성 성공"), SUCCESS_GET_DIARY("일기 상세 조회 성공"), SUCCESS_UPDATE_DAIRY("일기 수정 성공"), SUCCESS_DELETE_DIARY("일기 삭제 성공"), SUCCESS_GET_DIARIES("일기 리스트 조회 성공"), - // topic + // com.smeem.topic SUCCESS_GET_RANDOM_TOPIC("랜덤 주제 조회 성공"), // badges @@ -24,7 +24,7 @@ public enum ResponseMessage { SUCCESS_DELETE_CORRECTION("첨삭 삭제 성공"), SUCCESS_UPDATE_CORRECTION("첨삭 수정 성공"), - // member + // com.smeem.member SUCCESS_UPDATE_USERNAME("닉네임 변경 성공"), SUCCESS_GET_USER("회원 정보 조회 성공"), SUCCESS_UPDATE_USER_PLAN("회원 학습 계획 업데이트 성공"), @@ -45,7 +45,7 @@ public enum ResponseMessage { // beta SUCCESS_BETA_AUTH_TOKEN("임시토큰 발급 성공"), - // goal + // com.smeem.goal SUCCESS_GET_GOALS("학습 목표 리스트 조회 성공"), SUCCESS_GET_GOAL("학습 목표 조회 성공"); diff --git a/src/main/java/com/smeme/server/config/JpaAuditingConfig.java b/smeem-common/src/main/java/com/smeem/config/JpaAuditingConfig.java similarity index 86% rename from src/main/java/com/smeme/server/config/JpaAuditingConfig.java rename to smeem-common/src/main/java/com/smeem/config/JpaAuditingConfig.java index 69b61962..d32530f4 100644 --- a/src/main/java/com/smeme/server/config/JpaAuditingConfig.java +++ b/smeem-common/src/main/java/com/smeem/config/JpaAuditingConfig.java @@ -1,4 +1,4 @@ -package com.smeme.server.config; +package com.smeem.config; import org.springframework.context.annotation.Configuration; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; diff --git a/src/main/java/com/smeme/server/config/JpaQueryFactoryConfig.java b/smeem-common/src/main/java/com/smeem/config/JpaQueryFactoryConfig.java similarity index 91% rename from src/main/java/com/smeme/server/config/JpaQueryFactoryConfig.java rename to smeem-common/src/main/java/com/smeem/config/JpaQueryFactoryConfig.java index c7f7c03b..0cad9a16 100644 --- a/src/main/java/com/smeme/server/config/JpaQueryFactoryConfig.java +++ b/smeem-common/src/main/java/com/smeem/config/JpaQueryFactoryConfig.java @@ -1,4 +1,4 @@ -package com.smeme.server.config; +package com.smeem.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/src/main/java/com/smeme/server/config/jwt/RestTemplateConfig.java b/smeem-common/src/main/java/com/smeem/config/RestTemplateConfig.java similarity index 89% rename from src/main/java/com/smeme/server/config/jwt/RestTemplateConfig.java rename to smeem-common/src/main/java/com/smeem/config/RestTemplateConfig.java index aba07481..f3c26ab5 100644 --- a/src/main/java/com/smeme/server/config/jwt/RestTemplateConfig.java +++ b/smeem-common/src/main/java/com/smeem/config/RestTemplateConfig.java @@ -1,4 +1,4 @@ -package com.smeme.server.config.jwt; +package com.smeem.config; import org.springframework.context.annotation.Bean; diff --git a/src/main/java/com/smeme/server/config/SecurityConfig.java b/smeem-common/src/main/java/com/smeem/config/SecurityConfig.java similarity index 96% rename from src/main/java/com/smeme/server/config/SecurityConfig.java rename to smeem-common/src/main/java/com/smeem/config/SecurityConfig.java index d599f7e9..2b93f648 100644 --- a/src/main/java/com/smeme/server/config/SecurityConfig.java +++ b/smeem-common/src/main/java/com/smeem/config/SecurityConfig.java @@ -1,4 +1,4 @@ -package com.smeme.server.config; +package com.smeem.config; import com.smeme.server.config.jwt.CustomJwtAuthenticationEntryPoint; import com.smeme.server.config.jwt.JwtAuthenticationFilter; @@ -22,8 +22,8 @@ public class SecurityConfig { private final CustomJwtAuthenticationEntryPoint customJwtAuthenticationEntryPoint; private static final String[] AUTH_WHITELIST = { - "/api/v2/auth", - "/api/v2/test", + "/api/v2/com.smeem.auth", + "/api/v2/com.smeem.test", "/api/beta/token", "/error", "/favicon.ico", diff --git a/src/main/java/com/smeme/server/config/SwaggerConfig.java b/smeem-common/src/main/java/com/smeem/config/SwaggerConfig.java similarity index 96% rename from src/main/java/com/smeme/server/config/SwaggerConfig.java rename to smeem-common/src/main/java/com/smeem/config/SwaggerConfig.java index 58f20f0e..4f3d6889 100644 --- a/src/main/java/com/smeme/server/config/SwaggerConfig.java +++ b/smeem-common/src/main/java/com/smeem/config/SwaggerConfig.java @@ -1,4 +1,4 @@ -package com.smeme.server.config; +package com.smeem.config; import io.swagger.v3.oas.annotations.enums.SecuritySchemeIn; diff --git a/src/main/java/com/smeme/server/config/TimezoneConfig.java b/smeem-common/src/main/java/com/smeem/config/TimezoneConfig.java similarity index 89% rename from src/main/java/com/smeme/server/config/TimezoneConfig.java rename to smeem-common/src/main/java/com/smeem/config/TimezoneConfig.java index 5e1c2ff8..01d97685 100644 --- a/src/main/java/com/smeme/server/config/TimezoneConfig.java +++ b/smeem-common/src/main/java/com/smeem/config/TimezoneConfig.java @@ -1,4 +1,4 @@ -package com.smeme.server.config; +package com.smeem.config; import java.util.TimeZone; diff --git a/src/main/java/com/smeme/server/config/ValueConfig.java b/smeem-common/src/main/java/com/smeem/config/ValueConfig.java similarity index 93% rename from src/main/java/com/smeme/server/config/ValueConfig.java rename to smeem-common/src/main/java/com/smeem/config/ValueConfig.java index a7091bdc..b91512c2 100644 --- a/src/main/java/com/smeme/server/config/ValueConfig.java +++ b/smeem-common/src/main/java/com/smeem/config/ValueConfig.java @@ -1,4 +1,4 @@ -package com.smeme.server.config; +package com.smeem.config; import lombok.Getter; import org.springframework.beans.factory.annotation.Value; @@ -24,7 +24,7 @@ public class ValueConfig { @Value("${jwt.APPLE_URL}") private String APPLE_URL; - @Value("${badge.welcome-badge-id}") + @Value("${com.smeem.badge.welcome-com.smeem.badge-id}") private Long WELCOME_BADGE_ID; @Value("${jwt.KAKAO_URL}") diff --git a/src/main/java/com/smeme/server/util/Util.java b/smeem-common/src/main/java/com/smeem/util/Util.java similarity index 97% rename from src/main/java/com/smeme/server/util/Util.java rename to smeem-common/src/main/java/com/smeem/util/Util.java index d15b4e73..a65f67e7 100644 --- a/src/main/java/com/smeme/server/util/Util.java +++ b/smeem-common/src/main/java/com/smeem/util/Util.java @@ -1,4 +1,4 @@ -package com.smeme.server.util; +package com.smeem.util; import static com.smeme.server.util.message.ErrorMessage.*; import static java.util.Objects.*; diff --git a/src/main/java/com/smeme/server/model/badge/Badge.java b/smeem-domain/src/main/java/com/smeem/badge/model/Badge.java similarity index 86% rename from src/main/java/com/smeme/server/model/badge/Badge.java rename to smeem-domain/src/main/java/com/smeem/badge/model/Badge.java index 56a79a2a..1589e22a 100644 --- a/src/main/java/com/smeme/server/model/badge/Badge.java +++ b/smeem-domain/src/main/java/com/smeem/badge/model/Badge.java @@ -1,4 +1,4 @@ -package com.smeme.server.model.badge; +package com.smeem.badge.model; import static jakarta.persistence.GenerationType.*; @@ -16,7 +16,7 @@ public class Badge { @Id - @GeneratedValue(strategy = IDENTITY) + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Enumerated(value = EnumType.STRING) diff --git a/src/main/java/com/smeme/server/model/badge/BadgeType.java b/smeem-domain/src/main/java/com/smeem/badge/model/BadgeType.java similarity index 87% rename from src/main/java/com/smeme/server/model/badge/BadgeType.java rename to smeem-domain/src/main/java/com/smeem/badge/model/BadgeType.java index a2fae89e..e64bc196 100644 --- a/src/main/java/com/smeme/server/model/badge/BadgeType.java +++ b/smeem-domain/src/main/java/com/smeem/badge/model/BadgeType.java @@ -1,4 +1,4 @@ -package com.smeme.server.model.badge; +package com.smeem.badge.model; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/smeme/server/repository/badge/BadgeCustomRepository.java b/smeem-domain/src/main/java/com/smeem/badge/repository/BadgeCustomRepository.java similarity index 77% rename from src/main/java/com/smeme/server/repository/badge/BadgeCustomRepository.java rename to smeem-domain/src/main/java/com/smeem/badge/repository/BadgeCustomRepository.java index 59c89901..3e075c30 100644 --- a/src/main/java/com/smeme/server/repository/badge/BadgeCustomRepository.java +++ b/smeem-domain/src/main/java/com/smeem/badge/repository/BadgeCustomRepository.java @@ -1,4 +1,4 @@ -package com.smeme.server.repository.badge; +package com.smeem.badge.repository; import com.smeme.server.model.badge.Badge; diff --git a/src/main/java/com/smeme/server/repository/badge/BadgeRepository.java b/smeem-domain/src/main/java/com/smeem/badge/repository/BadgeRepository.java similarity index 82% rename from src/main/java/com/smeme/server/repository/badge/BadgeRepository.java rename to smeem-domain/src/main/java/com/smeem/badge/repository/BadgeRepository.java index 3b55f411..09a95618 100644 --- a/src/main/java/com/smeme/server/repository/badge/BadgeRepository.java +++ b/smeem-domain/src/main/java/com/smeem/badge/repository/BadgeRepository.java @@ -1,4 +1,4 @@ -package com.smeme.server.repository.badge; +package com.smeem.badge.repository; import com.smeme.server.model.badge.Badge; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/com/smeme/server/repository/badge/BadgeRepositoryImpl.java b/smeem-domain/src/main/java/com/smeem/badge/repository/BadgeRepositoryImpl.java similarity index 80% rename from src/main/java/com/smeme/server/repository/badge/BadgeRepositoryImpl.java rename to smeem-domain/src/main/java/com/smeem/badge/repository/BadgeRepositoryImpl.java index 54a4140f..e84d9357 100644 --- a/src/main/java/com/smeme/server/repository/badge/BadgeRepositoryImpl.java +++ b/smeem-domain/src/main/java/com/smeem/badge/repository/BadgeRepositoryImpl.java @@ -1,4 +1,4 @@ -package com.smeme.server.repository.badge; +package com.smeem.badge.repository; import com.querydsl.jpa.impl.JPAQueryFactory; import com.smeme.server.model.badge.Badge; @@ -17,8 +17,8 @@ public class BadgeRepositoryImpl implements BadgeCustomRepository { @Override public List findAllOrderById() { return queryFactory - .selectFrom(badge) - .orderBy(badge.id.asc()) + .selectFrom(QBadge.badge) + .orderBy(QBadge.badge.id.asc()) .fetch(); } } diff --git a/src/main/java/com/smeme/server/model/BaseTimeEntity.java b/smeem-domain/src/main/java/com/smeem/common/model/BaseTimeEntity.java similarity index 94% rename from src/main/java/com/smeme/server/model/BaseTimeEntity.java rename to smeem-domain/src/main/java/com/smeem/common/model/BaseTimeEntity.java index 7b5903ae..78a3262b 100644 --- a/src/main/java/com/smeme/server/model/BaseTimeEntity.java +++ b/smeem-domain/src/main/java/com/smeem/common/model/BaseTimeEntity.java @@ -1,4 +1,4 @@ -package com.smeme.server.model; +package com.smeem.common.model; import jakarta.persistence.EntityListeners; import jakarta.persistence.MappedSuperclass; diff --git a/src/main/java/com/smeme/server/model/DeletedDiary.java b/smeem-domain/src/main/java/com/smeem/diary/model/DeletedDiary.java similarity index 87% rename from src/main/java/com/smeme/server/model/DeletedDiary.java rename to smeem-domain/src/main/java/com/smeem/diary/model/DeletedDiary.java index 69c091d4..5cc94aa8 100644 --- a/src/main/java/com/smeme/server/model/DeletedDiary.java +++ b/smeem-domain/src/main/java/com/smeem/diary/model/DeletedDiary.java @@ -1,4 +1,4 @@ -package com.smeme.server.model; +package com.smeem.diary.model; import com.smeme.server.model.topic.Topic; import jakarta.persistence.*; @@ -15,7 +15,7 @@ @NoArgsConstructor public class DeletedDiary { @Id - @GeneratedValue(strategy = IDENTITY) + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "diary_id") private Long id; @@ -28,11 +28,11 @@ public class DeletedDiary { private boolean isPublic; - @ManyToOne(fetch = LAZY) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "topic_id") private Topic topic; - @ManyToOne(fetch = LAZY) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") private Member member; diff --git a/src/main/java/com/smeme/server/model/Diary.java b/smeem-domain/src/main/java/com/smeem/diary/model/Diary.java similarity index 82% rename from src/main/java/com/smeme/server/model/Diary.java rename to smeem-domain/src/main/java/com/smeem/diary/model/Diary.java index 4163e954..1b1cf121 100644 --- a/src/main/java/com/smeme/server/model/Diary.java +++ b/smeem-domain/src/main/java/com/smeem/diary/model/Diary.java @@ -1,4 +1,4 @@ -package com.smeme.server.model; +package com.smeem.diary.model; import static com.smeme.server.util.Util.getStartOfDay; import static jakarta.persistence.FetchType.*; @@ -11,8 +11,6 @@ import lombok.NoArgsConstructor; import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; import com.smeme.server.model.topic.Topic; @@ -22,7 +20,7 @@ public class Diary extends BaseTimeEntity { @Id - @GeneratedValue(strategy = IDENTITY) + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "diary_id") private Long id; @@ -35,11 +33,11 @@ public class Diary extends BaseTimeEntity { private boolean isPublic; - @ManyToOne(fetch = LAZY) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "topic_id") private Topic topic; - @ManyToOne(fetch = LAZY) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") private Member member; @@ -65,13 +63,13 @@ public void deleteFromMember() { } public boolean isCreatedAt(LocalDateTime createdAt) { - return getStartOfDay(this.createdAt).isEqual(getStartOfDay(createdAt)); + return Util.getStartOfDay(this.createdAt).isEqual(Util.getStartOfDay(createdAt)); } public boolean isBetween(LocalDateTime startAt, LocalDateTime endAt) { - LocalDateTime createdAt = getStartOfDay(this.createdAt); - startAt = getStartOfDay(startAt); - endAt = getStartOfDay(endAt); + LocalDateTime createdAt = Util.getStartOfDay(this.createdAt); + startAt = Util.getStartOfDay(startAt); + endAt = Util.getStartOfDay(endAt); return createdAt.equals(startAt) || (createdAt.isAfter(startAt) && createdAt.isBefore(endAt)) || createdAt.equals(endAt); } diff --git a/src/main/java/com/smeme/server/repository/diary/DeletedDiaryRepository.java b/smeem-domain/src/main/java/com/smeem/diary/repository/DeletedDiaryRepository.java similarity index 89% rename from src/main/java/com/smeme/server/repository/diary/DeletedDiaryRepository.java rename to smeem-domain/src/main/java/com/smeem/diary/repository/DeletedDiaryRepository.java index e8d67c55..f7ba0835 100644 --- a/src/main/java/com/smeme/server/repository/diary/DeletedDiaryRepository.java +++ b/smeem-domain/src/main/java/com/smeem/diary/repository/DeletedDiaryRepository.java @@ -1,4 +1,4 @@ -package com.smeme.server.repository.diary; +package com.smeem.diary.repository; import com.smeme.server.model.DeletedDiary; import com.smeme.server.model.Member; diff --git a/src/main/java/com/smeme/server/repository/diary/DiaryRepository.java b/smeem-domain/src/main/java/com/smeem/diary/repository/DiaryRepository.java similarity index 88% rename from src/main/java/com/smeme/server/repository/diary/DiaryRepository.java rename to smeem-domain/src/main/java/com/smeem/diary/repository/DiaryRepository.java index 5f7f9ce0..70f551e0 100644 --- a/src/main/java/com/smeme/server/repository/diary/DiaryRepository.java +++ b/smeem-domain/src/main/java/com/smeem/diary/repository/DiaryRepository.java @@ -1,4 +1,4 @@ -package com.smeme.server.repository.diary; +package com.smeem.diary.repository; import com.smeme.server.model.Member; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/com/smeme/server/model/goal/Goal.java b/smeem-domain/src/main/java/com/smeem/goal/model/Goal.java similarity index 90% rename from src/main/java/com/smeme/server/model/goal/Goal.java rename to smeem-domain/src/main/java/com/smeem/goal/model/Goal.java index 06a45963..481ea7d3 100644 --- a/src/main/java/com/smeme/server/model/goal/Goal.java +++ b/smeem-domain/src/main/java/com/smeem/goal/model/Goal.java @@ -1,4 +1,4 @@ -package com.smeme.server.model.goal; +package com.smeem.goal.model; import static jakarta.persistence.GenerationType.*; @@ -18,7 +18,7 @@ public class Goal { @Id - @GeneratedValue(strategy = IDENTITY) + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "goal_id") private Long id; diff --git a/src/main/java/com/smeme/server/model/goal/GoalType.java b/smeem-domain/src/main/java/com/smeem/goal/model/GoalType.java similarity index 90% rename from src/main/java/com/smeme/server/model/goal/GoalType.java rename to smeem-domain/src/main/java/com/smeem/goal/model/GoalType.java index d7c3b5bc..6f537ee1 100644 --- a/src/main/java/com/smeme/server/model/goal/GoalType.java +++ b/smeem-domain/src/main/java/com/smeem/goal/model/GoalType.java @@ -1,4 +1,4 @@ -package com.smeme.server.model.goal; +package com.smeem.goal.model; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/smeme/server/repository/goal/GoalRepository.java b/smeem-domain/src/main/java/com/smeem/goal/repository/GoalRepository.java similarity index 87% rename from src/main/java/com/smeme/server/repository/goal/GoalRepository.java rename to smeem-domain/src/main/java/com/smeem/goal/repository/GoalRepository.java index 43c97502..ad51a4e5 100644 --- a/src/main/java/com/smeme/server/repository/goal/GoalRepository.java +++ b/smeem-domain/src/main/java/com/smeem/goal/repository/GoalRepository.java @@ -1,4 +1,4 @@ -package com.smeme.server.repository.goal; +package com.smeem.goal.repository; import com.smeme.server.model.goal.Goal; import com.smeme.server.model.goal.GoalType; diff --git a/src/main/java/com/smeme/server/model/LangType.java b/smeem-domain/src/main/java/com/smeem/member/model/LangType.java similarity index 50% rename from src/main/java/com/smeme/server/model/LangType.java rename to smeem-domain/src/main/java/com/smeem/member/model/LangType.java index e002be82..9880fce4 100644 --- a/src/main/java/com/smeme/server/model/LangType.java +++ b/smeem-domain/src/main/java/com/smeem/member/model/LangType.java @@ -1,4 +1,4 @@ -package com.smeme.server.model; +package com.smeem.member.model; public enum LangType { en diff --git a/src/main/java/com/smeme/server/model/Member.java b/smeem-domain/src/main/java/com/smeem/member/model/Member.java similarity index 97% rename from src/main/java/com/smeme/server/model/Member.java rename to smeem-domain/src/main/java/com/smeem/member/model/Member.java index ddfda4b2..6e5a157e 100644 --- a/src/main/java/com/smeme/server/model/Member.java +++ b/smeem-domain/src/main/java/com/smeem/member/model/Member.java @@ -1,4 +1,4 @@ -package com.smeme.server.model; +package com.smeem.member.model; import static jakarta.persistence.GenerationType.*; import static java.time.LocalDateTime.now; @@ -23,7 +23,7 @@ public class Member extends BaseTimeEntity { @Id - @GeneratedValue(strategy = IDENTITY) + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "member_id") private Long id; diff --git a/src/main/java/com/smeme/server/model/badge/MemberBadge.java b/smeem-domain/src/main/java/com/smeem/member/model/MemberBadge.java similarity index 85% rename from src/main/java/com/smeme/server/model/badge/MemberBadge.java rename to smeem-domain/src/main/java/com/smeem/member/model/MemberBadge.java index 5a24dae3..2f5f8d08 100644 --- a/src/main/java/com/smeme/server/model/badge/MemberBadge.java +++ b/smeem-domain/src/main/java/com/smeem/member/model/MemberBadge.java @@ -1,9 +1,10 @@ -package com.smeme.server.model.badge; +package com.smeem.member.model; import static jakarta.persistence.FetchType.*; import static jakarta.persistence.GenerationType.*; import static java.util.Objects.*; +import com.smeem.badge.model.Badge; import com.smeme.server.model.BaseTimeEntity; import com.smeme.server.model.Member; @@ -23,15 +24,15 @@ public class MemberBadge extends BaseTimeEntity { @Id - @GeneratedValue(strategy = IDENTITY) + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "member_badge_id") private Long id; - @ManyToOne(fetch = LAZY) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") private Member member; - @ManyToOne(fetch = LAZY) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "badge_id") private Badge badge; diff --git a/src/main/java/com/smeme/server/model/SocialType.java b/smeem-domain/src/main/java/com/smeem/member/model/SocialType.java similarity index 64% rename from src/main/java/com/smeme/server/model/SocialType.java rename to smeem-domain/src/main/java/com/smeem/member/model/SocialType.java index 5911ca03..d014ce1b 100644 --- a/src/main/java/com/smeme/server/model/SocialType.java +++ b/smeem-domain/src/main/java/com/smeem/member/model/SocialType.java @@ -1,4 +1,4 @@ -package com.smeme.server.model; +package com.smeem.member.model; public enum SocialType { KAKAO, diff --git a/src/main/java/com/smeme/server/repository/badge/MemberBadgeRepository.java b/smeem-domain/src/main/java/com/smeem/member/repository/MemberBadgeRepository.java similarity index 89% rename from src/main/java/com/smeme/server/repository/badge/MemberBadgeRepository.java rename to smeem-domain/src/main/java/com/smeem/member/repository/MemberBadgeRepository.java index 27897e30..4fb85e9b 100644 --- a/src/main/java/com/smeme/server/repository/badge/MemberBadgeRepository.java +++ b/smeem-domain/src/main/java/com/smeem/member/repository/MemberBadgeRepository.java @@ -1,4 +1,4 @@ -package com.smeme.server.repository.badge; +package com.smeem.member.repository; import com.smeme.server.model.badge.MemberBadge; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/com/smeme/server/repository/MemberRepository.java b/smeem-domain/src/main/java/com/smeem/member/repository/MemberRepository.java similarity index 92% rename from src/main/java/com/smeme/server/repository/MemberRepository.java rename to smeem-domain/src/main/java/com/smeem/member/repository/MemberRepository.java index 2664a34c..76111b75 100644 --- a/src/main/java/com/smeme/server/repository/MemberRepository.java +++ b/smeem-domain/src/main/java/com/smeem/member/repository/MemberRepository.java @@ -1,4 +1,4 @@ -package com.smeme.server.repository; +package com.smeem.member.repository; import com.smeme.server.model.Member; diff --git a/src/main/java/com/smeme/server/model/topic/Category.java b/smeem-domain/src/main/java/com/smeem/topic/model/Category.java similarity index 87% rename from src/main/java/com/smeme/server/model/topic/Category.java rename to smeem-domain/src/main/java/com/smeem/topic/model/Category.java index 2581adad..2dc2ed08 100644 --- a/src/main/java/com/smeme/server/model/topic/Category.java +++ b/smeem-domain/src/main/java/com/smeem/topic/model/Category.java @@ -1,4 +1,4 @@ -package com.smeme.server.model.topic; +package com.smeem.topic.model; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/smeme/server/model/topic/Topic.java b/smeem-domain/src/main/java/com/smeem/topic/model/Topic.java similarity index 85% rename from src/main/java/com/smeme/server/model/topic/Topic.java rename to smeem-domain/src/main/java/com/smeem/topic/model/Topic.java index 92cf4ee6..51957c50 100644 --- a/src/main/java/com/smeme/server/model/topic/Topic.java +++ b/smeem-domain/src/main/java/com/smeem/topic/model/Topic.java @@ -1,4 +1,4 @@ -package com.smeme.server.model.topic; +package com.smeem.topic.model; import static jakarta.persistence.GenerationType.*; @@ -13,7 +13,7 @@ public class Topic { @Id - @GeneratedValue(strategy = IDENTITY) + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "topic_id") private Long id; diff --git a/src/main/java/com/smeme/server/repository/topic/TopicCustomRepository.java b/smeem-domain/src/main/java/com/smeem/topic/repository/TopicCustomRepository.java similarity index 72% rename from src/main/java/com/smeme/server/repository/topic/TopicCustomRepository.java rename to smeem-domain/src/main/java/com/smeem/topic/repository/TopicCustomRepository.java index e41bd9fc..88f7a871 100644 --- a/src/main/java/com/smeme/server/repository/topic/TopicCustomRepository.java +++ b/smeem-domain/src/main/java/com/smeem/topic/repository/TopicCustomRepository.java @@ -1,4 +1,4 @@ -package com.smeme.server.repository.topic; +package com.smeem.topic.repository; import com.smeme.server.model.topic.Topic; diff --git a/src/main/java/com/smeme/server/repository/topic/TopicRepository.java b/smeem-domain/src/main/java/com/smeem/topic/repository/TopicRepository.java similarity index 82% rename from src/main/java/com/smeme/server/repository/topic/TopicRepository.java rename to smeem-domain/src/main/java/com/smeem/topic/repository/TopicRepository.java index 8653581b..e3cf09dc 100644 --- a/src/main/java/com/smeme/server/repository/topic/TopicRepository.java +++ b/smeem-domain/src/main/java/com/smeem/topic/repository/TopicRepository.java @@ -1,4 +1,4 @@ -package com.smeme.server.repository.topic; +package com.smeem.topic.repository; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/com/smeme/server/repository/topic/TopicRepositoryImpl.java b/smeem-domain/src/main/java/com/smeem/topic/repository/TopicRepositoryImpl.java similarity index 77% rename from src/main/java/com/smeme/server/repository/topic/TopicRepositoryImpl.java rename to smeem-domain/src/main/java/com/smeem/topic/repository/TopicRepositoryImpl.java index d02c2fce..7ff83f52 100644 --- a/src/main/java/com/smeme/server/repository/topic/TopicRepositoryImpl.java +++ b/smeem-domain/src/main/java/com/smeem/topic/repository/TopicRepositoryImpl.java @@ -1,4 +1,4 @@ -package com.smeme.server.repository.topic; +package com.smeem.topic.repository; import static com.querydsl.core.types.dsl.NumberExpression.*; import static com.smeme.server.model.topic.QTopic.*; @@ -19,9 +19,9 @@ public class TopicRepositoryImpl implements TopicCustomRepository { @Override public Topic getRandom() { return queryFactory - .select(topic) - .from(topic) - .orderBy(random().asc()) + .select(QTopic.topic) + .from(QTopic.topic) + .orderBy(NumberExpression.random().asc()) .limit(1) .fetchFirst(); } diff --git a/src/main/java/com/smeme/server/model/training/DayType.java b/smeem-domain/src/main/java/com/smeem/training/model/DayType.java similarity index 86% rename from src/main/java/com/smeme/server/model/training/DayType.java rename to smeem-domain/src/main/java/com/smeem/training/model/DayType.java index 2e379010..83adc8b1 100644 --- a/src/main/java/com/smeme/server/model/training/DayType.java +++ b/smeem-domain/src/main/java/com/smeem/training/model/DayType.java @@ -1,4 +1,4 @@ -package com.smeme.server.model.training; +package com.smeem.training.model; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/smeme/server/model/training/TrainingTime.java b/smeem-domain/src/main/java/com/smeem/training/model/TrainingTime.java similarity index 92% rename from src/main/java/com/smeme/server/model/training/TrainingTime.java rename to smeem-domain/src/main/java/com/smeem/training/model/TrainingTime.java index f30220fd..199d0471 100644 --- a/src/main/java/com/smeme/server/model/training/TrainingTime.java +++ b/smeem-domain/src/main/java/com/smeem/training/model/TrainingTime.java @@ -1,4 +1,4 @@ -package com.smeme.server.model.training; +package com.smeem.training.model; import static jakarta.persistence.FetchType.*; import static jakarta.persistence.GenerationType.*; @@ -25,7 +25,7 @@ public class TrainingTime { @Id - @GeneratedValue(strategy = IDENTITY) + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Enumerated(value = EnumType.STRING) @@ -39,7 +39,7 @@ public class TrainingTime { @Max(value = 59, message = "분(minute)은 59 이하이어야 합니다.") private int minute; - @ManyToOne(fetch = LAZY) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") private Member member; diff --git a/src/main/java/com/smeme/server/repository/trainingTime/TrainingTimeCustomRepository.java b/smeem-domain/src/main/java/com/smeem/training/repository/TrainingTimeCustomRepository.java similarity index 82% rename from src/main/java/com/smeme/server/repository/trainingTime/TrainingTimeCustomRepository.java rename to smeem-domain/src/main/java/com/smeem/training/repository/TrainingTimeCustomRepository.java index 9e5b64e1..68b6734c 100644 --- a/src/main/java/com/smeme/server/repository/trainingTime/TrainingTimeCustomRepository.java +++ b/smeem-domain/src/main/java/com/smeem/training/repository/TrainingTimeCustomRepository.java @@ -1,4 +1,4 @@ -package com.smeme.server.repository.trainingTime; +package com.smeem.training.repository; import java.time.LocalDateTime; import java.util.List; diff --git a/src/main/java/com/smeme/server/repository/trainingTime/TrainingTimeRepository.java b/smeem-domain/src/main/java/com/smeem/training/repository/TrainingTimeRepository.java similarity index 88% rename from src/main/java/com/smeme/server/repository/trainingTime/TrainingTimeRepository.java rename to smeem-domain/src/main/java/com/smeem/training/repository/TrainingTimeRepository.java index 176fd10f..3b3000eb 100644 --- a/src/main/java/com/smeme/server/repository/trainingTime/TrainingTimeRepository.java +++ b/smeem-domain/src/main/java/com/smeem/training/repository/TrainingTimeRepository.java @@ -1,4 +1,4 @@ -package com.smeme.server.repository.trainingTime; +package com.smeem.training.repository; import com.smeme.server.model.Member; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/com/smeme/server/repository/trainingTime/TrainingTimeRepositoryImpl.java b/smeem-domain/src/main/java/com/smeem/training/repository/TrainingTimeRepositoryImpl.java similarity index 64% rename from src/main/java/com/smeme/server/repository/trainingTime/TrainingTimeRepositoryImpl.java rename to smeem-domain/src/main/java/com/smeem/training/repository/TrainingTimeRepositoryImpl.java index 78c14bc5..95aa5d23 100644 --- a/src/main/java/com/smeme/server/repository/trainingTime/TrainingTimeRepositoryImpl.java +++ b/smeem-domain/src/main/java/com/smeem/training/repository/TrainingTimeRepositoryImpl.java @@ -1,4 +1,4 @@ -package com.smeme.server.repository.trainingTime; +package com.smeem.training.repository; import static com.smeme.server.model.QMember.*; import static com.smeme.server.model.training.DayType.*; @@ -25,14 +25,14 @@ public class TrainingTimeRepositoryImpl implements TrainingTimeCustomRepository @Override public List getTrainingTimeForPushAlarm(LocalDateTime now) { return queryFactory - .select(trainingTime) - .from(trainingTime) - .join(trainingTime.member, member).fetchJoin() + .select(QTrainingTime.trainingTime) + .from(QTrainingTime.trainingTime) + .join(QTrainingTime.trainingTime.member, QMember.member).fetchJoin() .where( - trainingTime.day.eq(getDayType(now.getDayOfWeek().getValue())), - trainingTime.hour.eq(now.getHour()), - trainingTime.minute.eq(now.getMinute()), - member.hasPushAlarm.eq(true) + QTrainingTime.trainingTime.day.eq(getDayType(now.getDayOfWeek().getValue())), + QTrainingTime.trainingTime.hour.eq(now.getHour()), + QTrainingTime.trainingTime.minute.eq(now.getMinute()), + QMember.member.hasPushAlarm.eq(true) ) .fetch(); } @@ -46,7 +46,7 @@ private DayType getDayType(int dayValue) { case 5 -> FRI; case 6 -> SAT; case 7 -> SUN; - default -> throw new RuntimeException(INVALID_DAY_OF_WEEK.getMessage()); + default -> throw new RuntimeException(ErrorMessage.INVALID_DAY_OF_WEEK.getMessage()); }; } } diff --git a/src/main/java/com/smeme/server/service/auth/AppleSignInService.java b/smeem-external/src/main/java/com/smeem/apple/AppleSignInService.java similarity index 99% rename from src/main/java/com/smeme/server/service/auth/AppleSignInService.java rename to smeem-external/src/main/java/com/smeem/apple/AppleSignInService.java index 618ee22c..2647d42f 100644 --- a/src/main/java/com/smeme/server/service/auth/AppleSignInService.java +++ b/smeem-external/src/main/java/com/smeem/apple/AppleSignInService.java @@ -1,4 +1,4 @@ -package com.smeme.server.service.auth; +package com.smeem.apple; import com.google.gson.*; import com.smeme.server.config.ValueConfig; diff --git a/src/main/java/com/smeme/server/dto/message/MessageDTO.java b/smeem-external/src/main/java/com/smeem/firebase/MessageDTO.java similarity index 93% rename from src/main/java/com/smeme/server/dto/message/MessageDTO.java rename to smeem-external/src/main/java/com/smeem/firebase/MessageDTO.java index 2574bd3f..7f391a3f 100644 --- a/src/main/java/com/smeme/server/dto/message/MessageDTO.java +++ b/smeem-external/src/main/java/com/smeem/firebase/MessageDTO.java @@ -1,4 +1,4 @@ -package com.smeme.server.dto.message; +package com.smeem.firebase; import lombok.Builder; diff --git a/src/main/java/com/smeme/server/service/MessageService.java b/smeem-external/src/main/java/com/smeem/firebase/MessageService.java similarity index 96% rename from src/main/java/com/smeme/server/service/MessageService.java rename to smeem-external/src/main/java/com/smeem/firebase/MessageService.java index 8b280a7a..e9043c17 100644 --- a/src/main/java/com/smeme/server/service/MessageService.java +++ b/smeem-external/src/main/java/com/smeem/firebase/MessageService.java @@ -1,4 +1,4 @@ -package com.smeme.server.service; +package com.smeem.firebase; import static org.springframework.http.HttpHeaders.*; @@ -57,7 +57,7 @@ private void pushMessage(String targetToken, String title, String body) { Request request = new Request.Builder() .url(valueConfig.getFIREBASE_API_URI()) .post(requestBody) - .addHeader(AUTHORIZATION, "Bearer " + getAccessToken()) + .addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + getAccessToken()) .addHeader("Accept", "application/json; UTF-8") .build(); diff --git a/src/main/java/com/smeme/server/service/auth/KakaoSignInService.java b/smeem-external/src/main/java/com/smeem/kakao/KakaoSignInService.java similarity index 96% rename from src/main/java/com/smeme/server/service/auth/KakaoSignInService.java rename to smeem-external/src/main/java/com/smeem/kakao/KakaoSignInService.java index eaddfcbb..bf196f8c 100644 --- a/src/main/java/com/smeme/server/service/auth/KakaoSignInService.java +++ b/smeem-external/src/main/java/com/smeem/kakao/KakaoSignInService.java @@ -1,4 +1,4 @@ -package com.smeme.server.service.auth; +package com.smeem.kakao; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.JsonArray; diff --git a/src/main/java/com/smeme/server/controller/BetaAuthController.java b/src/main/java/com/smeme/server/controller/BetaAuthController.java deleted file mode 100644 index b01431c7..00000000 --- a/src/main/java/com/smeme/server/controller/BetaAuthController.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.smeme.server.controller; - -import com.smeme.server.dto.auth.beta.BetaSignInRequestDTO; -import com.smeme.server.dto.auth.beta.BetaTokenResponseDTO; -import com.smeme.server.service.auth.BetaAuthService; -import com.smeme.server.util.ApiResponse; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.responses.ApiResponses; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.RequiredArgsConstructor; -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.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import static com.smeme.server.util.message.ResponseMessage.*; - -/* -베타 테스트에 진행할 임시 토큰 발급 API를 구현하는 class입니다. - */ -@RestController -@RequiredArgsConstructor -@RequestMapping("/api/beta") -@Tag(name = "BetaAuth", description = "베타 테스트용 인증 API") -@Deprecated -public class BetaAuthController { - - private final BetaAuthService betaAuthService; - - @Operation(summary = "베타 테스트용 임시 토큰 발급", description = "베타 테스트용 임시 토큰을 발급합니다.") - @ApiResponses(value = { - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "베타 테스트용 임시 토큰 발급 성공" - , content = @io.swagger.v3.oas.annotations.media.Content(schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = BetaTokenResponseDTO.class)))}) - @PostMapping("/token") - public ResponseEntity getToken(@RequestBody BetaSignInRequestDTO request) { - BetaTokenResponseDTO response = betaAuthService.createBetaMember(request); - return ResponseEntity.ok(ApiResponse.success(SUCCESS_BETA_AUTH_TOKEN.getMessage(), response)); - } -} diff --git a/src/main/java/com/smeme/server/dto/auth/beta/BetaSignInRequestDTO.java b/src/main/java/com/smeme/server/dto/auth/beta/BetaSignInRequestDTO.java deleted file mode 100644 index 699ce229..00000000 --- a/src/main/java/com/smeme/server/dto/auth/beta/BetaSignInRequestDTO.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.smeme.server.dto.auth.beta; - -public record BetaSignInRequestDTO( - String fcmToken -) { -} diff --git a/src/main/java/com/smeme/server/dto/auth/beta/BetaTokenResponseDTO.java b/src/main/java/com/smeme/server/dto/auth/beta/BetaTokenResponseDTO.java deleted file mode 100644 index cf1938ff..00000000 --- a/src/main/java/com/smeme/server/dto/auth/beta/BetaTokenResponseDTO.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.smeme.server.dto.auth.beta; - -import com.smeme.server.dto.badge.BadgeResponseDTO; - -import java.util.List; - -public record BetaTokenResponseDTO( - String accessToken, - List badges -) { - public static BetaTokenResponseDTO of(String accessToken, List badges) { - return new BetaTokenResponseDTO(accessToken, badges); - } -} diff --git a/src/main/java/com/smeme/server/service/auth/BetaAuthService.java b/src/main/java/com/smeme/server/service/auth/BetaAuthService.java deleted file mode 100644 index ae974821..00000000 --- a/src/main/java/com/smeme/server/service/auth/BetaAuthService.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.smeme.server.service.auth; - -import com.smeme.server.config.ValueConfig; -import com.smeme.server.config.jwt.JwtTokenProvider; -import com.smeme.server.config.jwt.UserAuthentication; -import com.smeme.server.dto.auth.beta.BetaSignInRequestDTO; -import com.smeme.server.dto.auth.beta.BetaTokenResponseDTO; -import com.smeme.server.dto.badge.BadgeResponseDTO; -import com.smeme.server.model.Member; -import com.smeme.server.model.badge.Badge; -import com.smeme.server.model.badge.MemberBadge; -import com.smeme.server.repository.MemberRepository; -import com.smeme.server.repository.badge.BadgeRepository; -import com.smeme.server.repository.badge.MemberBadgeRepository; -import com.smeme.server.util.message.ErrorMessage; -import jakarta.persistence.EntityNotFoundException; -import lombok.RequiredArgsConstructor; -import org.springframework.security.core.Authentication; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; - -import static com.smeme.server.model.LangType.*; -import static com.smeme.server.model.SocialType.*; - -@Service -@RequiredArgsConstructor -@Transactional(readOnly = true) -@Deprecated -public class BetaAuthService { - - private final MemberRepository memberRepository; - private final MemberBadgeRepository memberBadgeRepository; - private final JwtTokenProvider tokenProvider; - private final BadgeRepository badgeRepository; - private final ValueConfig valueConfig; - - private static final Long BETA_USER_EXPIRED = 60 * 60 * 1000 * 24 * 21L; - - @Transactional - public BetaTokenResponseDTO createBetaMember(BetaSignInRequestDTO request) { - - AtomicInteger atomicInteger = new AtomicInteger(1); - Member betaMember = Member.builder() - .social(BETA) - .targetLang(en) - .socialId("beta" + atomicInteger.getAndIncrement()) - .fcmToken(request.fcmToken()) - .build(); - memberRepository.save(betaMember); - Authentication authentication = new UserAuthentication(betaMember.getId(), null, null); - List badges = new ArrayList<>(); - badges.add(BadgeResponseDTO.of(addWelcomeBadge(betaMember))); - return BetaTokenResponseDTO.of(tokenProvider.generateToken(authentication, BETA_USER_EXPIRED), badges); - } - - private Badge addWelcomeBadge(Member member) { - Badge badge = badgeRepository.findById(valueConfig.getWELCOME_BADGE_ID()).orElseThrow( - () -> new EntityNotFoundException(ErrorMessage.EMPTY_BADGE.getMessage()) - ); - memberBadgeRepository.save(new MemberBadge(member, badge)); - return badge; - } -} \ No newline at end of file diff --git a/src/main/resources/test b/src/main/resources/test deleted file mode 100644 index e69de29b..00000000 diff --git a/src/test/java/com/smeme/server/fixture/memberbadge/MemberBadgeFixture.java b/src/test/java/com/smeme/server/fixture/memberbadge/MemberBadgeFixture.java deleted file mode 100644 index cf96abb9..00000000 --- a/src/test/java/com/smeme/server/fixture/memberbadge/MemberBadgeFixture.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.smeme.server.fixture.memberbadge; - -public class MemberBadgeFixture { -} From b82ea75d48ccb2a961217d45630bad203aa3afbf Mon Sep 17 00:00:00 2001 From: thguss Date: Tue, 6 Feb 2024 22:29:39 +0900 Subject: [PATCH 14/86] =?UTF-8?q?[REFACTOR]=20=EB=AA=A8=EB=93=88=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smeem-api/build.gradle | 19 +++++++++++++++++++ smeem-batch/build.gradle | 19 +++++++++++++++++++ smeem-common/build.gradle | 19 +++++++++++++++++++ smeem-domain/build.gradle | 19 +++++++++++++++++++ smeem-external/build.gradle | 19 +++++++++++++++++++ 5 files changed, 95 insertions(+) create mode 100644 smeem-api/build.gradle create mode 100644 smeem-batch/build.gradle create mode 100644 smeem-common/build.gradle create mode 100644 smeem-domain/build.gradle create mode 100644 smeem-external/build.gradle diff --git a/smeem-api/build.gradle b/smeem-api/build.gradle new file mode 100644 index 00000000..3a1f9c05 --- /dev/null +++ b/smeem-api/build.gradle @@ -0,0 +1,19 @@ +plugins { + id 'java' +} + +group = 'com.smeme' +version = '0.0.1-SNAPSHOT' + +repositories { + mavenCentral() +} + +dependencies { + testImplementation platform('org.junit:junit-bom:5.9.1') + testImplementation 'org.junit.jupiter:junit-jupiter' +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/smeem-batch/build.gradle b/smeem-batch/build.gradle new file mode 100644 index 00000000..3a1f9c05 --- /dev/null +++ b/smeem-batch/build.gradle @@ -0,0 +1,19 @@ +plugins { + id 'java' +} + +group = 'com.smeme' +version = '0.0.1-SNAPSHOT' + +repositories { + mavenCentral() +} + +dependencies { + testImplementation platform('org.junit:junit-bom:5.9.1') + testImplementation 'org.junit.jupiter:junit-jupiter' +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/smeem-common/build.gradle b/smeem-common/build.gradle new file mode 100644 index 00000000..3a1f9c05 --- /dev/null +++ b/smeem-common/build.gradle @@ -0,0 +1,19 @@ +plugins { + id 'java' +} + +group = 'com.smeme' +version = '0.0.1-SNAPSHOT' + +repositories { + mavenCentral() +} + +dependencies { + testImplementation platform('org.junit:junit-bom:5.9.1') + testImplementation 'org.junit.jupiter:junit-jupiter' +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/smeem-domain/build.gradle b/smeem-domain/build.gradle new file mode 100644 index 00000000..3a1f9c05 --- /dev/null +++ b/smeem-domain/build.gradle @@ -0,0 +1,19 @@ +plugins { + id 'java' +} + +group = 'com.smeme' +version = '0.0.1-SNAPSHOT' + +repositories { + mavenCentral() +} + +dependencies { + testImplementation platform('org.junit:junit-bom:5.9.1') + testImplementation 'org.junit.jupiter:junit-jupiter' +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/smeem-external/build.gradle b/smeem-external/build.gradle new file mode 100644 index 00000000..3a1f9c05 --- /dev/null +++ b/smeem-external/build.gradle @@ -0,0 +1,19 @@ +plugins { + id 'java' +} + +group = 'com.smeme' +version = '0.0.1-SNAPSHOT' + +repositories { + mavenCentral() +} + +dependencies { + testImplementation platform('org.junit:junit-bom:5.9.1') + testImplementation 'org.junit.jupiter:junit-jupiter' +} + +test { + useJUnitPlatform() +} \ No newline at end of file From ce7acf387b11c4020c32477478237e430a86e2e9 Mon Sep 17 00:00:00 2001 From: unanchoi Date: Wed, 7 Feb 2024 00:57:05 +0900 Subject: [PATCH 15/86] =?UTF-8?q?Refactor:=20=EB=A9=80=ED=8B=B0=EB=AA=A8?= =?UTF-8?q?=EB=93=88=20=EA=B5=AC=EC=A1=B0=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 146 ++++-------------- settings.gradle | 2 - smeem-api/build.gradle | 77 +++++++-- .../smeem/SmemeServerRenewalApplication.java | 13 -- .../api/SmemeServerRenewalApplication.java | 19 +++ .../auth/controller/AuthController.java | 19 ++- .../dto/request/SignInRequestDTO.java | 4 +- .../dto/response/SignInResponseDTO.java | 4 +- .../dto/response/token/TokenResponseDTO.java | 2 +- .../dto/response/token/TokenVO.java | 2 +- .../CustomJwtAuthenticationEntryPoint.java | 10 +- .../auth/jwt/JwtAuthenticationFilter.java | 7 +- .../{ => api}/auth/jwt/JwtTokenProvider.java | 12 +- .../{ => api}/auth/jwt/JwtValidationType.java | 2 +- .../auth/jwt/UserAuthentication.java | 2 +- .../{ => api}/auth/service/AuthService.java | 44 +++--- .../badge/controller/BadgeController.java | 14 +- .../response/AcquiredBadgeResponseDTO.java | 6 +- .../dto/response/BadgeListResponseDTO.java | 8 +- .../dto/response/BadgeResponseDTO.java | 4 +- .../{ => api}/badge/service/BadgeService.java | 27 ++-- .../smeem/{ => api}/common/ApiResponse.java | 2 +- .../com/smeem/api}/config/SecurityConfig.java | 12 +- .../com/smeem/api}/config/SwaggerConfig.java | 2 +- .../diary/controller/DiaryController.java | 20 ++- .../dto/request/DiaryRequestDTO.java | 2 +- .../dto/response/CreatedDiaryResponseDTO.java | 8 +- .../dto/response/DiariesResponseDTO.java | 8 +- .../dto/response/DiaryResponseDTO.java | 7 +- .../{ => api}/diary/service/DiaryService.java | 58 +++---- .../goal/controller/GoalController.java | 16 +- .../dto/response/GoalResponseDTO.java | 5 +- .../dto/response/GoalsResponseDTO.java | 6 +- .../{ => api}/goal/service/GoalService.java | 14 +- .../member/controller/MemberController.java | 23 +-- .../controller/dto/UsernameValidator.java | 2 +- .../member/controller/dto/ValidUsername.java | 2 +- .../request/MemberPlanUpdateRequestDTO.java | 11 ++ .../request/MemberPushUpdateRequestDTO.java | 2 +- .../dto/request/MemberUpdateRequestDTO.java | 5 +- .../dto/request/TrainingTimeRequestDTO.java | 2 +- .../dto/response/MemberGetResponseDTO.java | 10 +- .../dto/response/MemberNameResponseDTO.java | 2 +- .../dto/response/MemberUpdateResponseDTO.java | 7 +- .../dto/response/TrainingTimeResponseDTO.java | 2 +- .../member/service/MemberBadgeService.java | 13 +- .../member/service/MemberService.java | 39 +++-- .../member/service/TrainingTimeService.java | 10 +- .../test}/TestController.java | 16 +- .../topic/controller/TopicController.java | 15 +- .../dto/response/TopicResponseDTO.java | 5 +- .../{ => api}/topic/service/TopicService.java | 12 +- .../request/MemberPlanUpdateRequestDTO.java | 11 -- .../src/main/resources/application-local.yml | 51 ++++++ .../controller/MemberControllerTest.java | 8 +- smeem-batch/build.gradle | 19 +-- .../{ => batch}/scheduler/DiaryScheduler.java | 3 +- .../scheduler/MessageScheduler.java | 9 +- smeem-common/build.gradle | 18 +-- .../java/com/smeem/advicer/ErrorHandler.java | 68 -------- .../smeem/common/advicer/ErrorHandler.java | 61 ++++++++ .../smeem/{ => common}/code/ErrorMessage.java | 2 +- .../{ => common}/code/ResponseMessage.java | 2 +- .../config/RestTemplateConfig.java | 2 +- .../{ => common}/config/TimezoneConfig.java | 4 +- .../{ => common}/config/ValueConfig.java | 6 +- .../com/smeem/{ => common}/util/Util.java | 4 +- smeem-domain/build.gradle | 30 ++-- .../smeem/{ => domain}/badge/model/Badge.java | 9 +- .../{ => domain}/badge/model/BadgeType.java | 2 +- .../repository/BadgeCustomRepository.java | 5 +- .../badge/repository/BadgeRepository.java | 5 +- .../badge/repository/BadgeRepositoryImpl.java | 7 +- .../domain}/config/JpaAuditingConfig.java | 2 +- .../domain}/config/JpaQueryFactoryConfig.java | 2 +- .../diary/model/DeletedDiary.java | 9 +- .../smeem/{ => domain}/diary/model/Diary.java | 13 +- .../repository/DeletedDiaryRepository.java | 7 +- .../diary/repository/DiaryRepository.java | 8 +- .../smeem/{ => domain}/goal/model/Goal.java | 9 +- .../{ => domain}/goal/model/GoalType.java | 2 +- .../goal/repository/GoalRepository.java | 7 +- .../smeem/domain/member/model/LangType.java | 5 + .../{ => domain}/member/model/Member.java | 12 +- .../member/model/MemberBadge.java | 16 +- .../{ => domain}/member/model/SocialType.java | 2 +- .../repository/MemberBadgeRepository.java | 5 +- .../member/repository/MemberRepository.java | 8 +- .../model/BaseTimeEntity.java | 6 +- .../{ => domain}/topic/model/Category.java | 2 +- .../smeem/{ => domain}/topic/model/Topic.java | 2 +- .../repository/TopicCustomRepository.java | 8 + .../topic/repository/TopicRepository.java | 6 +- .../topic/repository/TopicRepositoryImpl.java | 8 +- .../{ => domain}/training/model/DayType.java | 2 +- .../training/model/TrainingTime.java | 30 ++-- .../TrainingTimeCustomRepository.java | 5 +- .../repository/TrainingTimeRepository.java | 8 +- .../TrainingTimeRepositoryImpl.java | 15 +- .../java/com/smeem/member/model/LangType.java | 5 - .../repository/TopicCustomRepository.java | 7 - smeem-external/build.gradle | 26 ++-- .../apple/AppleSignInService.java | 17 +- .../{ => external}/firebase/MessageDTO.java | 2 +- .../external/firebase/MessageService.java | 74 +++++++++ .../kakao/KakaoSignInService.java | 6 +- .../com/smeem/firebase/MessageService.java | 83 ---------- 107 files changed, 753 insertions(+), 754 deletions(-) delete mode 100644 smeem-api/src/main/java/com/smeem/SmemeServerRenewalApplication.java create mode 100644 smeem-api/src/main/java/com/smeem/api/SmemeServerRenewalApplication.java rename smeem-api/src/main/java/com/smeem/{ => api}/auth/controller/AuthController.java (78%) rename smeem-api/src/main/java/com/smeem/{ => api}/auth/controller/dto/request/SignInRequestDTO.java (64%) rename smeem-api/src/main/java/com/smeem/{ => api}/auth/controller/dto/response/SignInResponseDTO.java (78%) rename smeem-api/src/main/java/com/smeem/{ => api}/auth/controller/dto/response/token/TokenResponseDTO.java (82%) rename smeem-api/src/main/java/com/smeem/{ => api}/auth/controller/dto/response/token/TokenVO.java (77%) rename smeem-api/src/main/java/com/smeem/{ => api}/auth/jwt/CustomJwtAuthenticationEntryPoint.java (78%) rename smeem-api/src/main/java/com/smeem/{ => api}/auth/jwt/JwtAuthenticationFilter.java (92%) rename smeem-api/src/main/java/com/smeem/{ => api}/auth/jwt/JwtTokenProvider.java (90%) rename smeem-api/src/main/java/com/smeem/{ => api}/auth/jwt/JwtValidationType.java (83%) rename smeem-api/src/main/java/com/smeem/{ => api}/auth/jwt/UserAuthentication.java (93%) rename smeem-api/src/main/java/com/smeem/{ => api}/auth/service/AuthService.java (79%) rename smeem-api/src/main/java/com/smeem/{ => api}/badge/controller/BadgeController.java (67%) rename smeem-api/src/main/java/com/smeem/{ => api}/badge/controller/dto/response/AcquiredBadgeResponseDTO.java (76%) rename smeem-api/src/main/java/com/smeem/{ => api}/badge/controller/dto/response/BadgeListResponseDTO.java (92%) rename smeem-api/src/main/java/com/smeem/{ => api}/badge/controller/dto/response/BadgeResponseDTO.java (77%) rename smeem-api/src/main/java/com/smeem/{ => api}/badge/service/BadgeService.java (73%) rename smeem-api/src/main/java/com/smeem/{ => api}/common/ApiResponse.java (97%) rename {smeem-common/src/main/java/com/smeem => smeem-api/src/main/java/com/smeem/api}/config/SecurityConfig.java (92%) rename {smeem-common/src/main/java/com/smeem => smeem-api/src/main/java/com/smeem/api}/config/SwaggerConfig.java (97%) rename smeem-api/src/main/java/com/smeem/{ => api}/diary/controller/DiaryController.java (82%) rename smeem-api/src/main/java/com/smeem/{ => api}/diary/controller/dto/request/DiaryRequestDTO.java (70%) rename smeem-api/src/main/java/com/smeem/{ => api}/diary/controller/dto/response/CreatedDiaryResponseDTO.java (66%) rename smeem-api/src/main/java/com/smeem/{ => api}/diary/controller/dto/response/DiariesResponseDTO.java (81%) rename smeem-api/src/main/java/com/smeem/{ => api}/diary/controller/dto/response/DiaryResponseDTO.java (83%) rename smeem-api/src/main/java/com/smeem/{ => api}/diary/service/DiaryService.java (80%) rename smeem-api/src/main/java/com/smeem/{ => api}/goal/controller/GoalController.java (72%) rename smeem-api/src/main/java/com/smeem/{ => api}/goal/controller/dto/response/GoalResponseDTO.java (76%) rename smeem-api/src/main/java/com/smeem/{ => api}/goal/controller/dto/response/GoalsResponseDTO.java (83%) rename smeem-api/src/main/java/com/smeem/{ => api}/goal/service/GoalService.java (70%) rename smeem-api/src/main/java/com/smeem/{ => api}/member/controller/MemberController.java (76%) rename smeem-api/src/main/java/com/smeem/{ => api}/member/controller/dto/UsernameValidator.java (93%) rename smeem-api/src/main/java/com/smeem/{ => api}/member/controller/dto/ValidUsername.java (87%) create mode 100644 smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPlanUpdateRequestDTO.java rename smeem-api/src/main/java/com/smeem/{ => api}/member/controller/dto/request/MemberPushUpdateRequestDTO.java (58%) rename smeem-api/src/main/java/com/smeem/{ => api}/member/controller/dto/request/MemberUpdateRequestDTO.java (52%) rename smeem-api/src/main/java/com/smeem/{ => api}/member/controller/dto/request/TrainingTimeRequestDTO.java (79%) rename smeem-api/src/main/java/com/smeem/{ => api}/member/controller/dto/response/MemberGetResponseDTO.java (75%) rename smeem-api/src/main/java/com/smeem/{ => api}/member/controller/dto/response/MemberNameResponseDTO.java (55%) rename smeem-api/src/main/java/com/smeem/{ => api}/member/controller/dto/response/MemberUpdateResponseDTO.java (62%) rename smeem-api/src/main/java/com/smeem/{ => api}/member/controller/dto/response/TrainingTimeResponseDTO.java (80%) rename smeem-api/src/main/java/com/smeem/{ => api}/member/service/MemberBadgeService.java (76%) rename smeem-api/src/main/java/com/smeem/{ => api}/member/service/MemberService.java (79%) rename smeem-api/src/main/java/com/smeem/{ => api}/member/service/TrainingTimeService.java (80%) rename smeem-api/src/main/java/com/smeem/{test/controller => api/test}/TestController.java (69%) rename smeem-api/src/main/java/com/smeem/{ => api}/topic/controller/TopicController.java (67%) rename smeem-api/src/main/java/com/smeem/{ => api}/topic/controller/dto/response/TopicResponseDTO.java (69%) rename smeem-api/src/main/java/com/smeem/{ => api}/topic/service/TopicService.java (71%) delete mode 100644 smeem-api/src/main/java/com/smeem/member/controller/dto/request/MemberPlanUpdateRequestDTO.java create mode 100644 smeem-api/src/main/resources/application-local.yml rename smeem-batch/src/main/java/com/smeem/{ => batch}/scheduler/DiaryScheduler.java (86%) rename smeem-batch/src/main/java/com/smeem/{ => batch}/scheduler/MessageScheduler.java (63%) delete mode 100644 smeem-common/src/main/java/com/smeem/advicer/ErrorHandler.java create mode 100644 smeem-common/src/main/java/com/smeem/common/advicer/ErrorHandler.java rename smeem-common/src/main/java/com/smeem/{ => common}/code/ErrorMessage.java (98%) rename smeem-common/src/main/java/com/smeem/{ => common}/code/ResponseMessage.java (98%) rename smeem-common/src/main/java/com/smeem/{ => common}/config/RestTemplateConfig.java (90%) rename smeem-common/src/main/java/com/smeem/{ => common}/config/TimezoneConfig.java (77%) rename smeem-common/src/main/java/com/smeem/{ => common}/config/ValueConfig.java (90%) rename smeem-common/src/main/java/com/smeem/{ => common}/util/Util.java (92%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/badge/model/Badge.java (57%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/badge/model/BadgeType.java (87%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/badge/repository/BadgeCustomRepository.java (54%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/badge/repository/BadgeRepository.java (64%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/badge/repository/BadgeRepositoryImpl.java (78%) rename {smeem-common/src/main/java/com/smeem => smeem-domain/src/main/java/com/smeem/domain}/config/JpaAuditingConfig.java (86%) rename {smeem-common/src/main/java/com/smeem => smeem-domain/src/main/java/com/smeem/domain}/config/JpaQueryFactoryConfig.java (91%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/diary/model/DeletedDiary.java (86%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/diary/model/Diary.java (89%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/diary/repository/DeletedDiaryRepository.java (66%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/diary/repository/DiaryRepository.java (66%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/goal/model/Goal.java (71%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/goal/model/GoalType.java (90%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/goal/repository/GoalRepository.java (62%) create mode 100644 smeem-domain/src/main/java/com/smeem/domain/member/model/LangType.java rename smeem-domain/src/main/java/com/smeem/{ => domain}/member/model/Member.java (91%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/member/model/MemberBadge.java (64%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/member/model/SocialType.java (60%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/member/repository/MemberBadgeRepository.java (78%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/member/repository/MemberRepository.java (73%) rename smeem-domain/src/main/java/com/smeem/{common => domain}/model/BaseTimeEntity.java (81%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/topic/model/Category.java (87%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/topic/model/Topic.java (93%) create mode 100644 smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicCustomRepository.java rename smeem-domain/src/main/java/com/smeem/{ => domain}/topic/repository/TopicRepository.java (65%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/topic/repository/TopicRepositoryImpl.java (74%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/training/model/DayType.java (86%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/training/model/TrainingTime.java (53%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/training/repository/TrainingTimeCustomRepository.java (64%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/training/repository/TrainingTimeRepository.java (68%) rename smeem-domain/src/main/java/com/smeem/{ => domain}/training/repository/TrainingTimeRepositoryImpl.java (79%) delete mode 100644 smeem-domain/src/main/java/com/smeem/member/model/LangType.java delete mode 100644 smeem-domain/src/main/java/com/smeem/topic/repository/TopicCustomRepository.java rename smeem-external/src/main/java/com/smeem/{ => external}/apple/AppleSignInService.java (88%) rename smeem-external/src/main/java/com/smeem/{ => external}/firebase/MessageDTO.java (93%) create mode 100644 smeem-external/src/main/java/com/smeem/external/firebase/MessageService.java rename smeem-external/src/main/java/com/smeem/{ => external}/kakao/KakaoSignInService.java (88%) delete mode 100644 smeem-external/src/main/java/com/smeem/firebase/MessageService.java diff --git a/build.gradle b/build.gradle index 494e5a84..9b607044 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,6 @@ -import org.hidetake.gradle.swagger.generator.GenerateSwaggerUI -import org.springframework.boot.gradle.tasks.bundling.BootJar - buildscript { - ext { - queryDslVersion = "5.0.0" - restdocsApiSpecVersion = "0.18.2" + repositories { + mavenCentral() } } @@ -12,125 +8,41 @@ plugins { id 'java' id 'org.springframework.boot' version '3.0.1' id 'io.spring.dependency-management' version '1.1.0' - // jacoco - id 'jacoco' - // restdocs-api-spec - id 'com.epages.restdocs-api-spec' version "${restdocsApiSpecVersion}" - // swagger generator - id 'org.hidetake.swagger.generator' version '2.18.2' } -swaggerSources { - sample { - setInputFile(file("${project.buildDir}/api-spec/openapi3.yaml")) - } - } - -openapi3 { - server('http://localhost:8080') - title = 'restdocs-swagger API Documentation' - description = 'Spring REST Docs with SwaggerUI.' - version = '0.0.1' - format = 'yaml' -} +allprojects { + apply plugin: 'java' + apply plugin: 'org.springframework.boot' + apply plugin: 'io.spring.dependency-management' + group = 'com.smeme' + version = '0.0.1-SNAPSHOT' + sourceCompatibility = '17' -jacoco { - toolVersion = "0.8.7" -} - -tasks.withType(Test) { - jacoco.includeNoLocationClasses = true - jacoco.excludes = ['jdk.internal.*'] - -} - -group = 'com.smeme' -version = '0.0.1-SNAPSHOT' -sourceCompatibility = '17' - -configurations { - compileOnly { - extendsFrom annotationProcessor + repositories { + mavenCentral() } -} - -repositories { - mavenCentral() -} - -ext { - set('snippetsDir', file("build/generated-snippets")) -} - -dependencies { - // Spring Boot Starter - implementation 'org.springframework.boot:spring-boot-starter-web' - implementation 'org.springframework.boot:spring-boot-starter-data-jpa' - implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server' - implementation 'org.springframework.boot:spring-boot-starter-security' - implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' - implementation 'org.springframework.boot:spring-boot-starter-validation' - testImplementation 'org.springframework.boot:spring-boot-starter-com.smeem.test' - testImplementation 'org.springframework.security:spring-security-com.smeem.test' - - // JWT - implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.5' - implementation group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.5' - implementation group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.5' - - - implementation 'com.google.code.gson:gson:2.10.1' - implementation 'javax.xml.bind:jaxb-api:2.4.0-b180830.0359' - - // Swagger & RestDocs - testImplementation "com.epages:restdocs-api-spec-mockmvc:${restdocsApiSpecVersion}" - testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' - implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2' - - // fcm - implementation 'com.google.firebase:firebase-admin:9.1.1' - implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.2.2' - - // QueryDSL - implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta' - annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta" - annotationProcessor "jakarta.annotation:jakarta.annotation-api" - annotationProcessor "jakarta.persistence:jakarta.persistence-api" - - // lombok - compileOnly 'org.projectlombok:lombok' - annotationProcessor 'org.projectlombok:lombok' - testCompileOnly 'org.projectlombok:lombok' - testAnnotationProcessor 'org.projectlombok:lombok' - - // DB - runtimeOnly 'com.h2database:h2' - runtimeOnly 'org.postgresql:postgresql' -} + configurations { + compileOnly { + extendsFrom annotationProcessor + } + } + dependencies { + // test + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'org.springframework.security:spring-security-test' -tasks.withType(GenerateSwaggerUI) { - dependsOn 'openapi3' - copy { - from "build/resources/main/static/docs" - into "src/main/resources/static/docs/" + // lombok + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + testAnnotationProcessor 'org.projectlombok:lombok' + testCompileOnly 'org.projectlombok:lombok' } -} -bootJar { - dependsOn(':openapi3') -} -// bootJar 실행 전, copySwaggerUI 를 실행하도록 설정 -openapi3 { - server = "http://localhost:8080" - title = "smeme api documentation" - description = "Spring REST Docs with SwaggerUI." - version = "0.0.1" - outputFileNamePrefix = 'open-api-3.0.1' - format = 'json' - - outputDirectory = 'build/resources/main/static/docs' -} + tasks.named('test') { + useJUnitPlatform() + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 8ffdc0b1..cf44cc1d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,8 +2,6 @@ rootProject.name = 'server' include 'smeem-api' include 'smeem-domain' include 'smeem-batch' -include 'smeem-batch' -include 'smeem-batch' include 'smeem-external' include 'smeem-common' diff --git a/smeem-api/build.gradle b/smeem-api/build.gradle index 3a1f9c05..31f950ff 100644 --- a/smeem-api/build.gradle +++ b/smeem-api/build.gradle @@ -1,19 +1,74 @@ +import org.hidetake.gradle.swagger.generator.GenerateSwaggerUI + plugins { - id 'java' + // restdocs-api-spec + id 'com.epages.restdocs-api-spec' version "0.18.2" + // swagger generator + id 'org.hidetake.swagger.generator' version '2.18.2' } -group = 'com.smeme' -version = '0.0.1-SNAPSHOT' +dependencies { + implementation project(':smeem-common') + implementation project(':smeem-domain') + implementation project(':smeem-external') + + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'org.springframework.boot:spring-boot-starter-validation' + + // JWT + implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.5' + implementation group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.5' + implementation group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.5' + + + // Swagger & RestDocs + testImplementation "com.epages:restdocs-api-spec-mockmvc:0.18.2" + testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2' -repositories { - mavenCentral() } -dependencies { - testImplementation platform('org.junit:junit-bom:5.9.1') - testImplementation 'org.junit.jupiter:junit-jupiter' +swaggerSources { + sample { + setInputFile(file("${project.buildDir}/api-spec/openapi3.yaml")) + } +} + +openapi3 { + server('http://localhost:8080') + title = 'restdocs-swagger API Documentation' + description = 'Spring REST Docs with SwaggerUI.' + version = '0.0.1' + format = 'yaml' } -test { - useJUnitPlatform() -} \ No newline at end of file + + +ext { + set('snippetsDir', file("build/generated-snippets")) +} + +tasks.withType(GenerateSwaggerUI) { + dependsOn 'openapi3' + copy { + from "build/resources/main/static/docs" + into "src/main/resources/static/docs/" + } +} + +bootJar { + dependsOn(':openapi3') +} +// bootJar 실행 전, copySwaggerUI 를 실행하도록 설정 +openapi3 { + server = "http://localhost:8080" + title = "smeme api documentation" + description = "Spring REST Docs with SwaggerUI." + version = "0.0.1" + outputFileNamePrefix = 'open-api-3.0.1' + format = 'json' + + outputDirectory = 'build/resources/main/static/docs' +} diff --git a/smeem-api/src/main/java/com/smeem/SmemeServerRenewalApplication.java b/smeem-api/src/main/java/com/smeem/SmemeServerRenewalApplication.java deleted file mode 100644 index b7514be9..00000000 --- a/smeem-api/src/main/java/com/smeem/SmemeServerRenewalApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.smeem; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SmemeServerRenewalApplication { - - public static void main(String[] args) { - SpringApplication.run(SmemeServerRenewalApplication.class, args); - } - -} diff --git a/smeem-api/src/main/java/com/smeem/api/SmemeServerRenewalApplication.java b/smeem-api/src/main/java/com/smeem/api/SmemeServerRenewalApplication.java new file mode 100644 index 00000000..8806c4d2 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/SmemeServerRenewalApplication.java @@ -0,0 +1,19 @@ +package com.smeem.api; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; + +@SpringBootApplication +@ComponentScan(basePackages = {"com.smeem.common", "com.smeem.api", "com.smeem.domain", "com.smeem.external"}) +@EnableJpaRepositories(basePackages = {"com.smeem.domain"}) +@EntityScan(basePackages = {"com.smeem.domain"}) +public class SmemeServerRenewalApplication { + + public static void main(String[] args) { + SpringApplication.run(SmemeServerRenewalApplication.class, args); + } + +} diff --git a/smeem-api/src/main/java/com/smeem/auth/controller/AuthController.java b/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java similarity index 78% rename from smeem-api/src/main/java/com/smeem/auth/controller/AuthController.java rename to smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java index dfb3903f..f2da4c16 100644 --- a/smeem-api/src/main/java/com/smeem/auth/controller/AuthController.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java @@ -1,10 +1,12 @@ -package com.smeem.auth.controller; - -import com.smeme.server.dto.auth.SignInRequestDTO; -import com.smeme.server.dto.auth.SignInResponseDTO; -import com.smeem.auth.controller.dto.response.token.TokenResponseDTO; -import com.smeme.server.service.auth.AuthService; -import com.smeme.server.util.ApiResponse; +package com.smeem.api.auth.controller; + +import com.smeem.api.auth.controller.dto.request.SignInRequestDTO; +import com.smeem.api.auth.controller.dto.response.SignInResponseDTO; +import com.smeem.api.auth.controller.dto.response.token.TokenResponseDTO; +import com.smeem.api.auth.service.AuthService; +import com.smeem.api.common.ApiResponse; +import com.smeem.common.code.ResponseMessage; +import com.smeem.common.util.Util; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -13,9 +15,6 @@ import java.security.Principal; import java.security.spec.InvalidKeySpecException; -import static com.smeme.server.util.ApiResponse.success; -import static com.smeme.server.util.Util.getMemberId; -import static com.smeme.server.util.message.ResponseMessage.*; @RestController @RequiredArgsConstructor diff --git a/smeem-api/src/main/java/com/smeem/auth/controller/dto/request/SignInRequestDTO.java b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/request/SignInRequestDTO.java similarity index 64% rename from smeem-api/src/main/java/com/smeem/auth/controller/dto/request/SignInRequestDTO.java rename to smeem-api/src/main/java/com/smeem/api/auth/controller/dto/request/SignInRequestDTO.java index 4242f337..c9970fe2 100644 --- a/smeem-api/src/main/java/com/smeem/auth/controller/dto/request/SignInRequestDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/request/SignInRequestDTO.java @@ -1,7 +1,7 @@ -package com.smeem.auth.controller.dto.request; +package com.smeem.api.auth.controller.dto.request; import com.fasterxml.jackson.annotation.JsonProperty; -import com.smeme.server.model.SocialType; +import com.smeem.domain.member.model.SocialType; public record SignInRequestDTO( @JsonProperty("social") diff --git a/smeem-api/src/main/java/com/smeem/auth/controller/dto/response/SignInResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponseDTO.java similarity index 78% rename from smeem-api/src/main/java/com/smeem/auth/controller/dto/response/SignInResponseDTO.java rename to smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponseDTO.java index 732e4940..0ff30b98 100644 --- a/smeem-api/src/main/java/com/smeem/auth/controller/dto/response/SignInResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponseDTO.java @@ -1,7 +1,7 @@ -package com.smeem.auth.controller.dto.response; +package com.smeem.api.auth.controller.dto.response; -import com.smeem.auth.controller.dto.response.token.TokenVO; +import com.smeem.api.auth.controller.dto.response.token.TokenVO; import lombok.Builder; diff --git a/smeem-api/src/main/java/com/smeem/auth/controller/dto/response/token/TokenResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenResponseDTO.java similarity index 82% rename from smeem-api/src/main/java/com/smeem/auth/controller/dto/response/token/TokenResponseDTO.java rename to smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenResponseDTO.java index 1c8ba32c..76f14668 100644 --- a/smeem-api/src/main/java/com/smeem/auth/controller/dto/response/token/TokenResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenResponseDTO.java @@ -1,4 +1,4 @@ -package com.smeem.auth.controller.dto.response.token; +package com.smeem.api.auth.controller.dto.response.token; import lombok.Builder; diff --git a/smeem-api/src/main/java/com/smeem/auth/controller/dto/response/token/TokenVO.java b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenVO.java similarity index 77% rename from smeem-api/src/main/java/com/smeem/auth/controller/dto/response/token/TokenVO.java rename to smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenVO.java index 7fbc4786..0278ffde 100644 --- a/smeem-api/src/main/java/com/smeem/auth/controller/dto/response/token/TokenVO.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenVO.java @@ -1,4 +1,4 @@ -package com.smeem.auth.controller.dto.response.token; +package com.smeem.api.auth.controller.dto.response.token; public record TokenVO(String accessToken, String refreshToken) { diff --git a/smeem-api/src/main/java/com/smeem/auth/jwt/CustomJwtAuthenticationEntryPoint.java b/smeem-api/src/main/java/com/smeem/api/auth/jwt/CustomJwtAuthenticationEntryPoint.java similarity index 78% rename from smeem-api/src/main/java/com/smeem/auth/jwt/CustomJwtAuthenticationEntryPoint.java rename to smeem-api/src/main/java/com/smeem/api/auth/jwt/CustomJwtAuthenticationEntryPoint.java index 071ba79a..7ea8c59a 100644 --- a/smeem-api/src/main/java/com/smeem/auth/jwt/CustomJwtAuthenticationEntryPoint.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/jwt/CustomJwtAuthenticationEntryPoint.java @@ -1,18 +1,18 @@ -package com.smeem.auth.jwt; +package com.smeem.api.auth.jwt; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.springframework.http.MediaType; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.stereotype.Component; import java.io.IOException; -import static com.smeme.server.util.ApiResponse.fail; -import static com.smeme.server.util.message.ErrorMessage.INVALID_TOKEN; -import static jakarta.servlet.http.HttpServletResponse.SC_UNAUTHORIZED; -import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import static com.smeem.api.common.ApiResponse.fail; +import static com.smeem.common.code.ErrorMessage.INVALID_TOKEN; + @Component public class CustomJwtAuthenticationEntryPoint implements AuthenticationEntryPoint { diff --git a/smeem-api/src/main/java/com/smeem/auth/jwt/JwtAuthenticationFilter.java b/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtAuthenticationFilter.java similarity index 92% rename from smeem-api/src/main/java/com/smeem/auth/jwt/JwtAuthenticationFilter.java rename to smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtAuthenticationFilter.java index ffd8785f..64c31e5e 100644 --- a/smeem-api/src/main/java/com/smeem/auth/jwt/JwtAuthenticationFilter.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtAuthenticationFilter.java @@ -1,4 +1,4 @@ -package com.smeem.auth.jwt; +package com.smeem.api.auth.jwt; import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; @@ -11,12 +11,13 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; import org.springframework.web.filter.OncePerRequestFilter; import java.io.IOException; -import static com.smeem.auth.jwt.JwtValidationType.*; -import static org.springframework.util.StringUtils.hasText; +import static com.smeem.api.auth.jwt.JwtValidationType.VALID_JWT; + @Slf4j @Component diff --git a/smeem-api/src/main/java/com/smeem/auth/jwt/JwtTokenProvider.java b/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtTokenProvider.java similarity index 90% rename from smeem-api/src/main/java/com/smeem/auth/jwt/JwtTokenProvider.java rename to smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtTokenProvider.java index b0459fc4..98be515b 100644 --- a/smeem-api/src/main/java/com/smeem/auth/jwt/JwtTokenProvider.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtTokenProvider.java @@ -1,19 +1,19 @@ -package com.smeem.auth.jwt; +package com.smeem.api.auth.jwt; -import com.smeme.server.config.ValueConfig; +import com.smeem.common.config.ValueConfig; import io.jsonwebtoken.*; -import lombok.*; +import io.jsonwebtoken.security.Keys; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import lombok.val; import org.springframework.security.core.Authentication; import org.springframework.stereotype.Component; import javax.crypto.SecretKey; import java.util.Date; -import static com.smeem.auth.jwt.JwtValidationType.*; -import static io.jsonwebtoken.Header.*; -import static io.jsonwebtoken.security.Keys.hmacShaKeyFor; +import static com.smeem.api.auth.jwt.JwtValidationType.*; import static java.util.Base64.getEncoder; @Slf4j diff --git a/smeem-api/src/main/java/com/smeem/auth/jwt/JwtValidationType.java b/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtValidationType.java similarity index 83% rename from smeem-api/src/main/java/com/smeem/auth/jwt/JwtValidationType.java rename to smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtValidationType.java index eba30954..7960630b 100644 --- a/smeem-api/src/main/java/com/smeem/auth/jwt/JwtValidationType.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtValidationType.java @@ -1,4 +1,4 @@ -package com.smeem.auth.jwt; +package com.smeem.api.auth.jwt; public enum JwtValidationType { VALID_JWT, diff --git a/smeem-api/src/main/java/com/smeem/auth/jwt/UserAuthentication.java b/smeem-api/src/main/java/com/smeem/api/auth/jwt/UserAuthentication.java similarity index 93% rename from smeem-api/src/main/java/com/smeem/auth/jwt/UserAuthentication.java rename to smeem-api/src/main/java/com/smeem/api/auth/jwt/UserAuthentication.java index d271686a..e1029740 100644 --- a/smeem-api/src/main/java/com/smeem/auth/jwt/UserAuthentication.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/jwt/UserAuthentication.java @@ -1,4 +1,4 @@ -package com.smeem.auth.jwt; +package com.smeem.api.auth.jwt; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; diff --git a/smeem-api/src/main/java/com/smeem/auth/service/AuthService.java b/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java similarity index 79% rename from smeem-api/src/main/java/com/smeem/auth/service/AuthService.java rename to smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java index b480efcb..6dc040cc 100644 --- a/smeem-api/src/main/java/com/smeem/auth/service/AuthService.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java @@ -1,29 +1,32 @@ -package com.smeem.auth.service; - -import com.smeme.server.config.jwt.JwtTokenProvider; -import com.smeme.server.config.jwt.UserAuthentication; -import com.smeme.server.dto.auth.SignInRequestDTO; -import com.smeme.server.dto.auth.SignInResponseDTO; -import com.smeem.auth.controller.dto.response.token.TokenResponseDTO; -import com.smeem.auth.controller.dto.response.token.TokenVO; -import com.smeme.server.model.LangType; -import com.smeme.server.model.Member; -import com.smeme.server.model.SocialType; -import com.smeme.server.repository.MemberRepository; -import com.smeme.server.service.DiaryService; -import com.smeme.server.service.MemberBadgeService; -import com.smeme.server.service.TrainingTimeService; +package com.smeem.api.auth.service; + +import com.smeem.api.auth.controller.dto.request.SignInRequestDTO; +import com.smeem.api.auth.controller.dto.response.SignInResponseDTO; +import com.smeem.api.auth.controller.dto.response.token.TokenResponseDTO; +import com.smeem.api.auth.controller.dto.response.token.TokenVO; +import com.smeem.api.auth.jwt.JwtTokenProvider; + + +import com.smeem.api.auth.jwt.UserAuthentication; +import com.smeem.api.diary.service.DiaryService; +import com.smeem.api.member.service.MemberBadgeService; +import com.smeem.api.member.service.TrainingTimeService; +import com.smeem.common.code.ErrorMessage; +import com.smeem.domain.member.model.LangType; +import com.smeem.domain.member.model.Member; +import com.smeem.domain.member.model.SocialType; +import com.smeem.domain.member.repository.MemberRepository; +import com.smeem.external.apple.AppleSignInService; +import com.smeem.external.kakao.KakaoSignInService; import lombok.RequiredArgsConstructor; import org.springframework.security.core.Authentication; -import org.springframework.security.oauth2.server.resource.InvalidBearerTokenException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.security.NoSuchAlgorithmException; import java.security.spec.InvalidKeySpecException; -import static com.smeme.server.util.message.ErrorMessage.*; -import static java.util.Objects.*; +import static java.util.Objects.nonNull; @Service @RequiredArgsConstructor @@ -123,11 +126,14 @@ private boolean isMemberBySocialAndSocialId(SocialType socialType, String social return memberRepository.existsBySocialAndSocialId(socialType, socialId); } + // TODO : Custom Exception 처리 private String login(SocialType socialType, String socialAccessToken) throws NoSuchAlgorithmException, InvalidKeySpecException { return switch (socialType.toString()) { case "APPLE" -> appleSignInService.getAppleData(socialAccessToken); case "KAKAO" -> kakaoSignInService.getKakaoData(socialAccessToken); - default -> throw new InvalidBearerTokenException(ErrorMessage.INVALID_TOKEN.getMessage()); + + // TODO : Change to Custom Exception + default -> throw new RuntimeException(ErrorMessage.INVALID_TOKEN.getMessage()); }; } } diff --git a/smeem-api/src/main/java/com/smeem/badge/controller/BadgeController.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java similarity index 67% rename from smeem-api/src/main/java/com/smeem/badge/controller/BadgeController.java rename to smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java index 6660b3da..4317d287 100644 --- a/smeem-api/src/main/java/com/smeem/badge/controller/BadgeController.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java @@ -1,8 +1,10 @@ -package com.smeem.badge.controller; +package com.smeem.api.badge.controller; -import com.smeme.server.dto.badge.BadgeListResponseDTO; -import com.smeme.server.service.BadgeService; -import com.smeme.server.util.ApiResponse; +import com.smeem.api.badge.controller.dto.response.BadgeListResponseDTO; +import com.smeem.api.badge.service.BadgeService; +import com.smeem.api.common.ApiResponse; +import com.smeem.common.code.ResponseMessage; +import com.smeem.common.util.Util; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -11,10 +13,6 @@ import java.security.Principal; -import static com.smeme.server.util.ApiResponse.success; -import static com.smeme.server.util.Util.getMemberId; -import static com.smeme.server.util.message.ResponseMessage.SUCCESS_GET_BADGES; - @RestController @RequiredArgsConstructor @RequestMapping("/api/v2/members/badges") diff --git a/smeem-api/src/main/java/com/smeem/badge/controller/dto/response/AcquiredBadgeResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/AcquiredBadgeResponseDTO.java similarity index 76% rename from smeem-api/src/main/java/com/smeem/badge/controller/dto/response/AcquiredBadgeResponseDTO.java rename to smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/AcquiredBadgeResponseDTO.java index 52931ea5..fbb04bab 100644 --- a/smeem-api/src/main/java/com/smeem/badge/controller/dto/response/AcquiredBadgeResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/AcquiredBadgeResponseDTO.java @@ -1,7 +1,7 @@ -package com.smeem.badge.controller.dto.response; +package com.smeem.api.badge.controller.dto.response; -import com.smeme.server.model.badge.Badge; -import com.smeme.server.model.badge.BadgeType; +import com.smeem.domain.badge.model.Badge; +import com.smeem.domain.badge.model.BadgeType; import lombok.AccessLevel; import lombok.Builder; diff --git a/smeem-api/src/main/java/com/smeem/badge/controller/dto/response/BadgeListResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponseDTO.java similarity index 92% rename from smeem-api/src/main/java/com/smeem/badge/controller/dto/response/BadgeListResponseDTO.java rename to smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponseDTO.java index b611cf9c..f735aeca 100644 --- a/smeem-api/src/main/java/com/smeem/badge/controller/dto/response/BadgeListResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponseDTO.java @@ -1,8 +1,8 @@ -package com.smeem.badge.controller.dto.response; +package com.smeem.api.badge.controller.dto.response; -import com.smeme.server.model.badge.Badge; -import com.smeme.server.model.badge.BadgeType; -import com.smeme.server.model.badge.MemberBadge; +import com.smeem.domain.badge.model.Badge; +import com.smeem.domain.badge.model.BadgeType; +import com.smeem.domain.member.model.MemberBadge; import lombok.*; import java.util.List; diff --git a/smeem-api/src/main/java/com/smeem/badge/controller/dto/response/BadgeResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponseDTO.java similarity index 77% rename from smeem-api/src/main/java/com/smeem/badge/controller/dto/response/BadgeResponseDTO.java rename to smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponseDTO.java index ba83729f..6b7f7c4d 100644 --- a/smeem-api/src/main/java/com/smeem/badge/controller/dto/response/BadgeResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponseDTO.java @@ -1,6 +1,6 @@ -package com.smeem.badge.controller.dto.response; +package com.smeem.api.badge.controller.dto.response; -import com.smeme.server.model.badge.Badge; +import com.smeem.domain.badge.model.Badge; import lombok.Builder; @Builder diff --git a/smeem-api/src/main/java/com/smeem/badge/service/BadgeService.java b/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java similarity index 73% rename from smeem-api/src/main/java/com/smeem/badge/service/BadgeService.java rename to smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java index e379f7e0..e3070591 100644 --- a/smeem-api/src/main/java/com/smeem/badge/service/BadgeService.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java @@ -1,14 +1,17 @@ -package com.smeem.badge.service; - -import com.smeme.server.dto.badge.BadgeListResponseDTO; -import com.smeme.server.model.Member; -import com.smeme.server.model.badge.Badge; -import com.smeme.server.model.badge.BadgeType; -import com.smeme.server.model.badge.MemberBadge; -import com.smeme.server.repository.badge.BadgeRepository; -import com.smeme.server.repository.badge.MemberBadgeRepository; +package com.smeem.api.badge.service; + + +import com.smeem.api.badge.controller.dto.response.BadgeListResponseDTO; +import com.smeem.common.code.ErrorMessage; +import com.smeem.domain.badge.model.Badge; +import com.smeem.domain.badge.model.BadgeType; +import com.smeem.domain.badge.repository.BadgeRepository; +import com.smeem.domain.member.model.Member; +import com.smeem.domain.member.model.MemberBadge; +import com.smeem.domain.member.repository.MemberBadgeRepository; import jakarta.persistence.EntityNotFoundException; -import lombok.*; +import lombok.RequiredArgsConstructor; +import lombok.val; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -17,8 +20,6 @@ import java.util.List; import java.util.Map; -import static com.smeme.server.util.message.ErrorMessage.INVALID_BADGE; - @Service @RequiredArgsConstructor @Transactional(readOnly = true) @@ -49,7 +50,7 @@ public void saveMemberBadge(Member member, Badge badge) { memberBadgeRepository.save(new MemberBadge(member, badge)); } - protected Badge get(Long id) { + public Badge get(Long id) { return badgeRepository.findById(id) .orElseThrow(() -> new EntityNotFoundException(ErrorMessage.INVALID_BADGE.getMessage())); } diff --git a/smeem-api/src/main/java/com/smeem/common/ApiResponse.java b/smeem-api/src/main/java/com/smeem/api/common/ApiResponse.java similarity index 97% rename from smeem-api/src/main/java/com/smeem/common/ApiResponse.java rename to smeem-api/src/main/java/com/smeem/api/common/ApiResponse.java index f8d71754..96691126 100644 --- a/smeem-api/src/main/java/com/smeem/common/ApiResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/common/ApiResponse.java @@ -1,4 +1,4 @@ -package com.smeem.common; +package com.smeem.api.common; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; diff --git a/smeem-common/src/main/java/com/smeem/config/SecurityConfig.java b/smeem-api/src/main/java/com/smeem/api/config/SecurityConfig.java similarity index 92% rename from smeem-common/src/main/java/com/smeem/config/SecurityConfig.java rename to smeem-api/src/main/java/com/smeem/api/config/SecurityConfig.java index 2b93f648..72041c1a 100644 --- a/smeem-common/src/main/java/com/smeem/config/SecurityConfig.java +++ b/smeem-api/src/main/java/com/smeem/api/config/SecurityConfig.java @@ -1,7 +1,7 @@ -package com.smeem.config; +package com.smeem.api.config; -import com.smeme.server.config.jwt.CustomJwtAuthenticationEntryPoint; -import com.smeme.server.config.jwt.JwtAuthenticationFilter; +import com.smeem.api.auth.jwt.CustomJwtAuthenticationEntryPoint; +import com.smeem.api.auth.jwt.JwtAuthenticationFilter; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -22,8 +22,8 @@ public class SecurityConfig { private final CustomJwtAuthenticationEntryPoint customJwtAuthenticationEntryPoint; private static final String[] AUTH_WHITELIST = { - "/api/v2/com.smeem.auth", - "/api/v2/com.smeem.test", + "/api/v2/auth", + "/api/v2/test", "/api/beta/token", "/error", "/favicon.ico", @@ -40,7 +40,7 @@ public class SecurityConfig { }; @Bean - @Profile("dev") + @Profile({"dev", "local"}) public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { return http .csrf().disable() diff --git a/smeem-common/src/main/java/com/smeem/config/SwaggerConfig.java b/smeem-api/src/main/java/com/smeem/api/config/SwaggerConfig.java similarity index 97% rename from smeem-common/src/main/java/com/smeem/config/SwaggerConfig.java rename to smeem-api/src/main/java/com/smeem/api/config/SwaggerConfig.java index 4f3d6889..94e9a683 100644 --- a/smeem-common/src/main/java/com/smeem/config/SwaggerConfig.java +++ b/smeem-api/src/main/java/com/smeem/api/config/SwaggerConfig.java @@ -1,4 +1,4 @@ -package com.smeem.config; +package com.smeem.api.config; import io.swagger.v3.oas.annotations.enums.SecuritySchemeIn; diff --git a/smeem-api/src/main/java/com/smeem/diary/controller/DiaryController.java b/smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java similarity index 82% rename from smeem-api/src/main/java/com/smeem/diary/controller/DiaryController.java rename to smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java index 7fe9e9b3..51720de2 100644 --- a/smeem-api/src/main/java/com/smeem/diary/controller/DiaryController.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java @@ -1,12 +1,16 @@ -package com.smeem.diary.controller; +package com.smeem.api.diary.controller; -import static com.smeme.server.util.ApiResponse.success; -import static com.smeme.server.util.Util.getMemberId; -import static com.smeme.server.util.Util.getURI; -import static com.smeme.server.util.message.ResponseMessage.*; import java.security.Principal; +import com.smeem.api.common.ApiResponse; +import com.smeem.api.diary.controller.dto.request.DiaryRequestDTO; +import com.smeem.api.diary.controller.dto.response.CreatedDiaryResponseDTO; +import com.smeem.api.diary.controller.dto.response.DiariesResponseDTO; +import com.smeem.api.diary.controller.dto.response.DiaryResponseDTO; +import com.smeem.api.diary.service.DiaryService; +import com.smeem.common.code.ResponseMessage; +import com.smeem.common.util.Util; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -18,12 +22,6 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.smeme.server.dto.diary.CreatedDiaryResponseDTO; -import com.smeme.server.dto.diary.DiariesResponseDTO; -import com.smeme.server.dto.diary.DiaryRequestDTO; -import com.smeme.server.dto.diary.DiaryResponseDTO; -import com.smeme.server.service.DiaryService; -import com.smeme.server.util.ApiResponse; import lombok.RequiredArgsConstructor; diff --git a/smeem-api/src/main/java/com/smeem/diary/controller/dto/request/DiaryRequestDTO.java b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryRequestDTO.java similarity index 70% rename from smeem-api/src/main/java/com/smeem/diary/controller/dto/request/DiaryRequestDTO.java rename to smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryRequestDTO.java index bb40ed81..b4a5805a 100644 --- a/smeem-api/src/main/java/com/smeem/diary/controller/dto/request/DiaryRequestDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryRequestDTO.java @@ -1,4 +1,4 @@ -package com.smeem.diary.controller.dto.request; +package com.smeem.api.diary.controller.dto.request; import lombok.NonNull; diff --git a/smeem-api/src/main/java/com/smeem/diary/controller/dto/response/CreatedDiaryResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/CreatedDiaryResponseDTO.java similarity index 66% rename from smeem-api/src/main/java/com/smeem/diary/controller/dto/response/CreatedDiaryResponseDTO.java rename to smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/CreatedDiaryResponseDTO.java index 5b6cd745..320247e6 100644 --- a/smeem-api/src/main/java/com/smeem/diary/controller/dto/response/CreatedDiaryResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/CreatedDiaryResponseDTO.java @@ -1,9 +1,9 @@ -package com.smeem.diary.controller.dto.response; +package com.smeem.api.diary.controller.dto.response; -import java.util.List; +import com.smeem.api.badge.controller.dto.response.AcquiredBadgeResponseDTO; +import com.smeem.domain.badge.model.Badge; -import com.smeme.server.dto.badge.AcquiredBadgeResponseDTO; -import com.smeme.server.model.badge.Badge; +import java.util.List; public record CreatedDiaryResponseDTO( Long diaryId, diff --git a/smeem-api/src/main/java/com/smeem/diary/controller/dto/response/DiariesResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiariesResponseDTO.java similarity index 81% rename from smeem-api/src/main/java/com/smeem/diary/controller/dto/response/DiariesResponseDTO.java rename to smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiariesResponseDTO.java index 3e8187a5..4f1654c8 100644 --- a/smeem-api/src/main/java/com/smeem/diary/controller/dto/response/DiariesResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiariesResponseDTO.java @@ -1,10 +1,10 @@ -package com.smeem.diary.controller.dto.response; +package com.smeem.api.diary.controller.dto.response; -import java.util.List; +import com.smeem.common.util.Util; +import com.smeem.domain.diary.model.Diary; -import com.smeme.server.model.Diary; +import java.util.List; -import static com.smeme.server.util.Util.dateToString; public record DiariesResponseDTO( List diaries, diff --git a/smeem-api/src/main/java/com/smeem/diary/controller/dto/response/DiaryResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryResponseDTO.java similarity index 83% rename from smeem-api/src/main/java/com/smeem/diary/controller/dto/response/DiaryResponseDTO.java rename to smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryResponseDTO.java index e5fbebe4..a8f7eab9 100644 --- a/smeem-api/src/main/java/com/smeem/diary/controller/dto/response/DiaryResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryResponseDTO.java @@ -1,10 +1,11 @@ -package com.smeem.diary.controller.dto.response; +package com.smeem.api.diary.controller.dto.response; + -import static com.smeme.server.util.Util.dateToString; import static java.util.Objects.*; -import com.smeme.server.model.Diary; +import com.smeem.common.util.Util; +import com.smeem.domain.diary.model.Diary; import lombok.AccessLevel; import lombok.Builder; diff --git a/smeem-api/src/main/java/com/smeem/diary/service/DiaryService.java b/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryService.java similarity index 80% rename from smeem-api/src/main/java/com/smeem/diary/service/DiaryService.java rename to smeem-api/src/main/java/com/smeem/api/diary/service/DiaryService.java index 410ff31c..970907d8 100644 --- a/smeem-api/src/main/java/com/smeem/diary/service/DiaryService.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryService.java @@ -1,33 +1,35 @@ -package com.smeem.diary.service; - -import static com.smeme.server.util.Util.stringToDate; -import static com.smeme.server.util.message.ErrorMessage.*; -import static java.lang.Integer.parseInt; -import static java.time.LocalDateTime.now; -import static java.util.Objects.*; +package com.smeem.api.diary.service; + + +import com.smeem.api.badge.service.BadgeService; +import com.smeem.api.diary.controller.dto.request.DiaryRequestDTO; +import com.smeem.api.diary.controller.dto.response.CreatedDiaryResponseDTO; +import com.smeem.api.diary.controller.dto.response.DiariesResponseDTO; +import com.smeem.api.diary.controller.dto.response.DiaryResponseDTO; +import com.smeem.api.member.service.MemberService; +import com.smeem.api.topic.service.TopicService; +import com.smeem.common.code.ErrorMessage; +import com.smeem.common.config.ValueConfig; +import com.smeem.common.util.Util; +import com.smeem.domain.badge.model.Badge; +import com.smeem.domain.diary.model.DeletedDiary; +import com.smeem.domain.diary.model.Diary; +import com.smeem.domain.diary.repository.DeletedDiaryRepository; +import com.smeem.domain.diary.repository.DiaryRepository; +import com.smeem.domain.member.model.Member; +import com.smeem.domain.topic.model.Topic; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; import java.time.LocalDateTime; -import java.util.*; +import java.util.ArrayList; +import java.util.List; -import com.smeme.server.config.ValueConfig; -import com.smeme.server.model.DeletedDiary; -import com.smeme.server.repository.diary.DeletedDiaryRepository; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import com.smeme.server.dto.diary.CreatedDiaryResponseDTO; -import com.smeme.server.dto.diary.DiariesResponseDTO; -import com.smeme.server.dto.diary.DiaryRequestDTO; -import com.smeme.server.dto.diary.DiaryResponseDTO; -import com.smeme.server.model.Diary; -import com.smeme.server.model.Member; -import com.smeme.server.model.badge.Badge; -import com.smeme.server.model.topic.Topic; -import com.smeme.server.repository.diary.DiaryRepository; - -import jakarta.persistence.EntityNotFoundException; -import lombok.RequiredArgsConstructor; +import static java.lang.Integer.parseInt; +import static java.time.LocalDateTime.now; +import static java.util.Objects.nonNull; @Service @RequiredArgsConstructor @@ -119,9 +121,9 @@ public List getAllByMemberId(Long memberId) { return diaryRepository.findAllByMemberId(memberId); } - protected Diary get(Long id) { + public Diary get(Long id) { return diaryRepository.findById(id) - .orElseThrow(() -> new EntityNotFoundException(ErrorMessage.INVALID_DIARY.getMessage())); + .orElseThrow(() -> new RuntimeException(ErrorMessage.INVALID_DIARY.getMessage())); } private List obtainBadges(Member member, LocalDateTime createdAt) { diff --git a/smeem-api/src/main/java/com/smeem/goal/controller/GoalController.java b/smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java similarity index 72% rename from smeem-api/src/main/java/com/smeem/goal/controller/GoalController.java rename to smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java index cd565c18..3d6eb0a5 100644 --- a/smeem-api/src/main/java/com/smeem/goal/controller/GoalController.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java @@ -1,20 +1,18 @@ -package com.smeem.goal.controller; +package com.smeem.api.goal.controller; -import static com.smeme.server.util.ApiResponse.success; -import static com.smeme.server.util.message.ResponseMessage.*; +import com.smeem.api.common.ApiResponse; +import com.smeem.api.goal.controller.dto.response.GoalResponseDTO; +import com.smeem.api.goal.controller.dto.response.GoalsResponseDTO; +import com.smeem.api.goal.service.GoalService; +import com.smeem.common.code.ResponseMessage; +import com.smeem.domain.goal.model.GoalType; 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.RestController; -import com.smeme.server.dto.goal.GoalResponseDTO; -import com.smeme.server.dto.goal.GoalsResponseDTO; -import com.smeme.server.model.goal.GoalType; -import com.smeme.server.service.GoalService; -import com.smeme.server.util.ApiResponse; - import lombok.RequiredArgsConstructor; @RestController diff --git a/smeem-api/src/main/java/com/smeem/goal/controller/dto/response/GoalResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalResponseDTO.java similarity index 76% rename from smeem-api/src/main/java/com/smeem/goal/controller/dto/response/GoalResponseDTO.java rename to smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalResponseDTO.java index 3487d14d..d47dc18e 100644 --- a/smeem-api/src/main/java/com/smeem/goal/controller/dto/response/GoalResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalResponseDTO.java @@ -1,6 +1,7 @@ -package com.smeem.goal.controller.dto.response; +package com.smeem.api.goal.controller.dto.response; -import com.smeme.server.model.goal.Goal; + +import com.smeem.domain.goal.model.Goal; public record GoalResponseDTO( String name, diff --git a/smeem-api/src/main/java/com/smeem/goal/controller/dto/response/GoalsResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalsResponseDTO.java similarity index 83% rename from smeem-api/src/main/java/com/smeem/goal/controller/dto/response/GoalsResponseDTO.java rename to smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalsResponseDTO.java index f6dbed93..c975f15f 100644 --- a/smeem-api/src/main/java/com/smeem/goal/controller/dto/response/GoalsResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalsResponseDTO.java @@ -1,8 +1,10 @@ -package com.smeem.goal.controller.dto.response; +package com.smeem.api.goal.controller.dto.response; + +import com.smeem.domain.goal.model.GoalType; import java.util.List; -import com.smeme.server.model.goal.GoalType; + public record GoalsResponseDTO( List goals diff --git a/smeem-api/src/main/java/com/smeem/goal/service/GoalService.java b/smeem-api/src/main/java/com/smeem/api/goal/service/GoalService.java similarity index 70% rename from smeem-api/src/main/java/com/smeem/goal/service/GoalService.java rename to smeem-api/src/main/java/com/smeem/api/goal/service/GoalService.java index 4b688ac4..ec298028 100644 --- a/smeem-api/src/main/java/com/smeem/goal/service/GoalService.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/service/GoalService.java @@ -1,17 +1,17 @@ -package com.smeem.goal.service; +package com.smeem.api.goal.service; -import static com.smeme.server.util.message.ErrorMessage.*; import java.util.List; +import com.smeem.api.goal.controller.dto.response.GoalResponseDTO; +import com.smeem.api.goal.controller.dto.response.GoalsResponseDTO; +import com.smeem.common.code.ErrorMessage; +import com.smeem.domain.goal.model.Goal; +import com.smeem.domain.goal.model.GoalType; +import com.smeem.domain.goal.repository.GoalRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.smeme.server.dto.goal.GoalResponseDTO; -import com.smeme.server.dto.goal.GoalsResponseDTO; -import com.smeme.server.model.goal.Goal; -import com.smeme.server.model.goal.GoalType; -import com.smeme.server.repository.goal.GoalRepository; import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; diff --git a/smeem-api/src/main/java/com/smeem/member/controller/MemberController.java b/smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java similarity index 76% rename from smeem-api/src/main/java/com/smeem/member/controller/MemberController.java rename to smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java index 8e416d4b..bbe3fa26 100644 --- a/smeem-api/src/main/java/com/smeem/member/controller/MemberController.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java @@ -1,20 +1,25 @@ -package com.smeem.member.controller; - -import com.smeme.server.dto.member.*; -import com.smeme.server.service.MemberService; -import com.smeme.server.util.ApiResponse; +package com.smeem.api.member.controller; + + +import com.smeem.api.common.ApiResponse; +import com.smeem.api.member.controller.dto.request.MemberPlanUpdateRequestDTO; +import com.smeem.api.member.controller.dto.request.MemberPushUpdateRequestDTO; +import com.smeem.api.member.controller.dto.request.MemberUpdateRequestDTO; +import com.smeem.api.member.controller.dto.response.MemberGetResponseDTO; +import com.smeem.api.member.controller.dto.response.MemberNameResponseDTO; +import com.smeem.api.member.controller.dto.response.MemberUpdateResponseDTO; +import com.smeem.api.member.service.MemberService; +import com.smeem.common.code.ResponseMessage; +import com.smeem.common.util.Util; import io.swagger.v3.oas.annotations.Parameter; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; -import com.smeem.member.service.MemberService; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.security.Principal; -import static com.smeme.server.util.ApiResponse.success; -import static com.smeme.server.util.Util.getMemberId; -import static com.smeme.server.util.message.ResponseMessage.*; + @RestController @RequiredArgsConstructor diff --git a/smeem-api/src/main/java/com/smeem/member/controller/dto/UsernameValidator.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/UsernameValidator.java similarity index 93% rename from smeem-api/src/main/java/com/smeem/member/controller/dto/UsernameValidator.java rename to smeem-api/src/main/java/com/smeem/api/member/controller/dto/UsernameValidator.java index 5d3172b8..622b59a2 100644 --- a/smeem-api/src/main/java/com/smeem/member/controller/dto/UsernameValidator.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/UsernameValidator.java @@ -1,4 +1,4 @@ -package com.smeem.member.controller.dto; +package com.smeem.api.member.controller.dto; import jakarta.validation.ConstraintValidator; import jakarta.validation.ConstraintValidatorContext; diff --git a/smeem-api/src/main/java/com/smeem/member/controller/dto/ValidUsername.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/ValidUsername.java similarity index 87% rename from smeem-api/src/main/java/com/smeem/member/controller/dto/ValidUsername.java rename to smeem-api/src/main/java/com/smeem/api/member/controller/dto/ValidUsername.java index 7f6add25..6ca432b1 100644 --- a/smeem-api/src/main/java/com/smeem/member/controller/dto/ValidUsername.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/ValidUsername.java @@ -1,4 +1,4 @@ -package com.smeem.member.controller.dto; +package com.smeem.api.member.controller.dto; import jakarta.validation.Constraint; diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPlanUpdateRequestDTO.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPlanUpdateRequestDTO.java new file mode 100644 index 00000000..effff809 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPlanUpdateRequestDTO.java @@ -0,0 +1,11 @@ +package com.smeem.api.member.controller.dto.request; + + +import com.smeem.domain.goal.model.GoalType; + +public record MemberPlanUpdateRequestDTO( + GoalType target, + TrainingTimeRequestDTO trainingTime, + Boolean hasAlarm +) { +} diff --git a/smeem-api/src/main/java/com/smeem/member/controller/dto/request/MemberPushUpdateRequestDTO.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPushUpdateRequestDTO.java similarity index 58% rename from smeem-api/src/main/java/com/smeem/member/controller/dto/request/MemberPushUpdateRequestDTO.java rename to smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPushUpdateRequestDTO.java index 41e657c7..156d540c 100644 --- a/smeem-api/src/main/java/com/smeem/member/controller/dto/request/MemberPushUpdateRequestDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPushUpdateRequestDTO.java @@ -1,4 +1,4 @@ -package com.smeem.member.controller.dto.request; +package com.smeem.api.member.controller.dto.request; public record MemberPushUpdateRequestDTO( boolean hasAlarm diff --git a/smeem-api/src/main/java/com/smeem/member/controller/dto/request/MemberUpdateRequestDTO.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberUpdateRequestDTO.java similarity index 52% rename from smeem-api/src/main/java/com/smeem/member/controller/dto/request/MemberUpdateRequestDTO.java rename to smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberUpdateRequestDTO.java index 9bff04db..ba2abf40 100644 --- a/smeem-api/src/main/java/com/smeem/member/controller/dto/request/MemberUpdateRequestDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberUpdateRequestDTO.java @@ -1,6 +1,7 @@ -package com.smeem.member.controller.dto.request; +package com.smeem.api.member.controller.dto.request; -import com.smeem.member.controller.dto.ValidUsername; + +import com.smeem.api.member.controller.dto.ValidUsername; public record MemberUpdateRequestDTO( @ValidUsername diff --git a/smeem-api/src/main/java/com/smeem/member/controller/dto/request/TrainingTimeRequestDTO.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/TrainingTimeRequestDTO.java similarity index 79% rename from smeem-api/src/main/java/com/smeem/member/controller/dto/request/TrainingTimeRequestDTO.java rename to smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/TrainingTimeRequestDTO.java index d55139ab..21596a88 100644 --- a/smeem-api/src/main/java/com/smeem/member/controller/dto/request/TrainingTimeRequestDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/TrainingTimeRequestDTO.java @@ -1,4 +1,4 @@ -package com.smeem.member.controller.dto.request; +package com.smeem.api.member.controller.dto.request; import jakarta.validation.constraints.NotNull; diff --git a/smeem-api/src/main/java/com/smeem/member/controller/dto/response/MemberGetResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponseDTO.java similarity index 75% rename from smeem-api/src/main/java/com/smeem/member/controller/dto/response/MemberGetResponseDTO.java rename to smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponseDTO.java index e0dd171b..839e8e09 100644 --- a/smeem-api/src/main/java/com/smeem/member/controller/dto/response/MemberGetResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponseDTO.java @@ -1,9 +1,9 @@ -package com.smeem.member.controller.dto.response; +package com.smeem.api.member.controller.dto.response; -import com.smeme.server.dto.badge.BadgeResponseDTO; -import com.smeme.server.dto.goal.GoalResponseDTO; -import com.smeme.server.dto.training.TrainingTimeResponseDTO; -import com.smeme.server.model.Member; + +import com.smeem.api.badge.controller.dto.response.BadgeResponseDTO; +import com.smeem.api.goal.controller.dto.response.GoalResponseDTO; +import com.smeem.domain.member.model.Member; public record MemberGetResponseDTO( String username, diff --git a/smeem-api/src/main/java/com/smeem/member/controller/dto/response/MemberNameResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponseDTO.java similarity index 55% rename from smeem-api/src/main/java/com/smeem/member/controller/dto/response/MemberNameResponseDTO.java rename to smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponseDTO.java index 1dcfd287..36dc2b17 100644 --- a/smeem-api/src/main/java/com/smeem/member/controller/dto/response/MemberNameResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponseDTO.java @@ -1,4 +1,4 @@ -package com.smeem.member.controller.dto.response; +package com.smeem.api.member.controller.dto.response; public record MemberNameResponseDTO( boolean isExist diff --git a/smeem-api/src/main/java/com/smeem/member/controller/dto/response/MemberUpdateResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberUpdateResponseDTO.java similarity index 62% rename from smeem-api/src/main/java/com/smeem/member/controller/dto/response/MemberUpdateResponseDTO.java rename to smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberUpdateResponseDTO.java index a635d955..f40262c7 100644 --- a/smeem-api/src/main/java/com/smeem/member/controller/dto/response/MemberUpdateResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberUpdateResponseDTO.java @@ -1,7 +1,8 @@ -package com.smeem.member.controller.dto.response; +package com.smeem.api.member.controller.dto.response; -import com.smeme.server.dto.badge.AcquiredBadgeResponseDTO; -import com.smeme.server.model.badge.Badge; + +import com.smeem.api.badge.controller.dto.response.AcquiredBadgeResponseDTO; +import com.smeem.domain.badge.model.Badge; import java.util.List; diff --git a/smeem-api/src/main/java/com/smeem/member/controller/dto/response/TrainingTimeResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponseDTO.java similarity index 80% rename from smeem-api/src/main/java/com/smeem/member/controller/dto/response/TrainingTimeResponseDTO.java rename to smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponseDTO.java index 10d5fe00..b52a03c5 100644 --- a/smeem-api/src/main/java/com/smeem/member/controller/dto/response/TrainingTimeResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponseDTO.java @@ -1,4 +1,4 @@ -package com.smeem.member.controller.dto.response; +package com.smeem.api.member.controller.dto.response; public record TrainingTimeResponseDTO(String day, int hour, int minute) { public static TrainingTimeResponseDTO of(String day, int hour, int minute) { diff --git a/smeem-api/src/main/java/com/smeem/member/service/MemberBadgeService.java b/smeem-api/src/main/java/com/smeem/api/member/service/MemberBadgeService.java similarity index 76% rename from smeem-api/src/main/java/com/smeem/member/service/MemberBadgeService.java rename to smeem-api/src/main/java/com/smeem/api/member/service/MemberBadgeService.java index 3a35a69c..c4a948ca 100644 --- a/smeem-api/src/main/java/com/smeem/member/service/MemberBadgeService.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/MemberBadgeService.java @@ -1,10 +1,11 @@ -package com.smeem.member.service; +package com.smeem.api.member.service; -import com.smeme.server.model.Member; -import com.smeme.server.model.badge.Badge; -import com.smeme.server.model.badge.MemberBadge; -import com.smeme.server.repository.badge.MemberBadgeRepository; -import com.smeme.server.util.message.ErrorMessage; + +import com.smeem.common.code.ErrorMessage; +import com.smeem.domain.badge.model.Badge; +import com.smeem.domain.member.model.Member; +import com.smeem.domain.member.model.MemberBadge; +import com.smeem.domain.member.repository.MemberBadgeRepository; import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/smeem-api/src/main/java/com/smeem/member/service/MemberService.java b/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java similarity index 79% rename from smeem-api/src/main/java/com/smeem/member/service/MemberService.java rename to smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java index fbf81db5..eac83229 100644 --- a/smeem-api/src/main/java/com/smeem/member/service/MemberService.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java @@ -1,16 +1,24 @@ -package com.smeem.member.service; - -import com.smeme.server.config.ValueConfig; -import com.smeme.server.dto.badge.BadgeResponseDTO; -import com.smeme.server.dto.goal.GoalResponseDTO; -import com.smeme.server.dto.member.*; -import com.smeme.server.dto.training.TrainingTimeResponseDTO; -import com.smeme.server.model.Member; -import com.smeme.server.model.badge.Badge; -import com.smeme.server.model.training.DayType; -import com.smeme.server.model.training.TrainingTime; -import com.smeme.server.repository.MemberRepository; -import com.smeme.server.util.message.ErrorMessage; +package com.smeem.api.member.service; + + +import com.smeem.api.badge.controller.dto.response.BadgeResponseDTO; +import com.smeem.api.badge.service.BadgeService; +import com.smeem.api.goal.controller.dto.response.GoalResponseDTO; +import com.smeem.api.goal.service.GoalService; +import com.smeem.api.member.controller.dto.request.MemberPlanUpdateRequestDTO; +import com.smeem.api.member.controller.dto.request.MemberPushUpdateRequestDTO; +import com.smeem.api.member.controller.dto.request.MemberUpdateRequestDTO; +import com.smeem.api.member.controller.dto.response.MemberGetResponseDTO; +import com.smeem.api.member.controller.dto.response.MemberNameResponseDTO; +import com.smeem.api.member.controller.dto.response.MemberUpdateResponseDTO; +import com.smeem.api.member.controller.dto.response.TrainingTimeResponseDTO; +import com.smeem.common.code.ErrorMessage; +import com.smeem.common.config.ValueConfig; +import com.smeem.domain.badge.model.Badge; +import com.smeem.domain.member.model.Member; +import com.smeem.domain.member.repository.MemberRepository; +import com.smeem.domain.training.model.DayType; +import com.smeem.domain.training.model.TrainingTime; import jakarta.persistence.EntityExistsException; import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; @@ -19,6 +27,7 @@ import org.springframework.util.StringUtils; import java.util.ArrayList; + import java.util.List; import java.util.stream.Collectors; @@ -104,9 +113,9 @@ public MemberNameResponseDTO checkDuplicatedName(String name) { return new MemberNameResponseDTO(isExist); } - protected Member get(Long id) { + public Member get(Long id) { return memberRepository.findById(id) - .orElseThrow(() -> new EntityNotFoundException(ErrorMessage.EMPTY_MEMBER.getMessage())); + .orElseThrow(() -> new RuntimeException(ErrorMessage.EMPTY_MEMBER.getMessage())); } private void updateTrainingTime(Member member, MemberPlanUpdateRequestDTO request) { diff --git a/smeem-api/src/main/java/com/smeem/member/service/TrainingTimeService.java b/smeem-api/src/main/java/com/smeem/api/member/service/TrainingTimeService.java similarity index 80% rename from smeem-api/src/main/java/com/smeem/member/service/TrainingTimeService.java rename to smeem-api/src/main/java/com/smeem/api/member/service/TrainingTimeService.java index 445eaab5..5f37f240 100644 --- a/smeem-api/src/main/java/com/smeem/member/service/TrainingTimeService.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/TrainingTimeService.java @@ -1,13 +1,15 @@ -package com.smeem.member.service; +package com.smeem.api.member.service; -import com.smeme.server.model.Member; -import com.smeme.server.model.training.TrainingTime; -import com.smeme.server.repository.trainingTime.TrainingTimeRepository; + +import com.smeem.domain.member.model.Member; +import com.smeem.domain.training.model.TrainingTime; +import com.smeem.domain.training.repository.TrainingTimeRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import java.util.List; + @Service @RequiredArgsConstructor public class TrainingTimeService { diff --git a/smeem-api/src/main/java/com/smeem/test/controller/TestController.java b/smeem-api/src/main/java/com/smeem/api/test/TestController.java similarity index 69% rename from smeem-api/src/main/java/com/smeem/test/controller/TestController.java rename to smeem-api/src/main/java/com/smeem/api/test/TestController.java index 2433ffbe..dec3edef 100644 --- a/smeem-api/src/main/java/com/smeem/test/controller/TestController.java +++ b/smeem-api/src/main/java/com/smeem/api/test/TestController.java @@ -1,24 +1,26 @@ -package com.smeem.test.controller; +package com.smeem.api.test; + -import static com.smeme.server.util.ApiResponse.*; import java.security.Principal; -import com.smeme.server.config.ValueConfig; + +import com.smeem.api.common.ApiResponse; +import com.smeem.common.config.ValueConfig; +import com.smeem.external.firebase.MessageService; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.smeme.server.service.MessageService; -import com.smeme.server.util.ApiResponse; + import io.swagger.v3.oas.annotations.Parameter; import lombok.RequiredArgsConstructor; @RestController @RequiredArgsConstructor -@RequestMapping("/api/v2/com.smeem.test") +@RequestMapping("/api/v2/test") public class TestController { private final MessageService messageService; @@ -31,7 +33,7 @@ public ResponseEntity test() { @GetMapping("/alarm") public ResponseEntity alarmTest(@Parameter(hidden = true) Principal principal) { - messageService.pushTest(valueConfig.getMESSAGE_TITLE(), valueConfig.getMESSAGE_BODY(), Long.valueOf(principal.getName())); + // messageService.pushTest(valueConfig.getMESSAGE_TITLE(), valueConfig.getMESSAGE_BODY(), Long.valueOf(principal.getName())); return ResponseEntity.ok(ApiResponse.success("푸시 알림 전송 성공")); } } diff --git a/smeem-api/src/main/java/com/smeem/topic/controller/TopicController.java b/smeem-api/src/main/java/com/smeem/api/topic/controller/TopicController.java similarity index 67% rename from smeem-api/src/main/java/com/smeem/topic/controller/TopicController.java rename to smeem-api/src/main/java/com/smeem/api/topic/controller/TopicController.java index c61aeb8c..985e5b79 100644 --- a/smeem-api/src/main/java/com/smeem/topic/controller/TopicController.java +++ b/smeem-api/src/main/java/com/smeem/api/topic/controller/TopicController.java @@ -1,19 +1,20 @@ -package com.smeem.topic.controller; +package com.smeem.api.topic.controller; -import static com.smeme.server.util.ApiResponse.success; -import static com.smeme.server.util.message.ResponseMessage.*; + +import com.smeem.api.common.ApiResponse; +import com.smeem.api.topic.controller.dto.response.TopicResponseDTO; +import com.smeem.api.topic.service.TopicService; +import com.smeem.common.code.ResponseMessage; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.smeme.server.dto.topic.TopicResponseDTO; -import com.smeme.server.service.TopicService; -import com.smeme.server.util.ApiResponse; + import lombok.RequiredArgsConstructor; -import com.smeem.topic.service.TopicService; + @RestController @RequiredArgsConstructor diff --git a/smeem-api/src/main/java/com/smeem/topic/controller/dto/response/TopicResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/topic/controller/dto/response/TopicResponseDTO.java similarity index 69% rename from smeem-api/src/main/java/com/smeem/topic/controller/dto/response/TopicResponseDTO.java rename to smeem-api/src/main/java/com/smeem/api/topic/controller/dto/response/TopicResponseDTO.java index 5a0f253d..11f06ab1 100644 --- a/smeem-api/src/main/java/com/smeem/topic/controller/dto/response/TopicResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/topic/controller/dto/response/TopicResponseDTO.java @@ -1,6 +1,7 @@ -package com.smeem.topic.controller.dto.response; +package com.smeem.api.topic.controller.dto.response; -import com.smeme.server.model.topic.Topic; + +import com.smeem.domain.topic.model.Topic; public record TopicResponseDTO( Long topicId, diff --git a/smeem-api/src/main/java/com/smeem/topic/service/TopicService.java b/smeem-api/src/main/java/com/smeem/api/topic/service/TopicService.java similarity index 71% rename from smeem-api/src/main/java/com/smeem/topic/service/TopicService.java rename to smeem-api/src/main/java/com/smeem/api/topic/service/TopicService.java index ab2065ac..bef3f652 100644 --- a/smeem-api/src/main/java/com/smeem/topic/service/TopicService.java +++ b/smeem-api/src/main/java/com/smeem/api/topic/service/TopicService.java @@ -1,16 +1,16 @@ -package com.smeem.topic.service; +package com.smeem.api.topic.service; +import com.smeem.api.topic.controller.dto.response.TopicResponseDTO; +import com.smeem.common.code.ErrorMessage; +import com.smeem.domain.topic.model.Topic; +import com.smeem.domain.topic.repository.TopicRepository; import jakarta.persistence.EntityNotFoundException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.smeme.server.dto.topic.TopicResponseDTO; -import com.smeme.server.model.topic.Topic; -import com.smeme.server.repository.topic.TopicRepository; import lombok.RequiredArgsConstructor; -import static com.smeme.server.util.message.ErrorMessage.INVALID_TOPIC; import static java.util.Objects.nonNull; @Service @@ -25,7 +25,7 @@ public TopicResponseDTO getRandom() { return TopicResponseDTO.of(topic); } - protected Topic get(Long id) { + public Topic get(Long id) { return nonNull(id) ? topicRepository.findById(id) .orElseThrow(() -> new EntityNotFoundException(ErrorMessage.INVALID_TOPIC.getMessage())) diff --git a/smeem-api/src/main/java/com/smeem/member/controller/dto/request/MemberPlanUpdateRequestDTO.java b/smeem-api/src/main/java/com/smeem/member/controller/dto/request/MemberPlanUpdateRequestDTO.java deleted file mode 100644 index 19ceeee5..00000000 --- a/smeem-api/src/main/java/com/smeem/member/controller/dto/request/MemberPlanUpdateRequestDTO.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.smeem.member.controller.dto.request; - -import com.smeme.server.dto.training.TrainingTimeRequestDTO; -import com.smeme.server.model.goal.GoalType; - -public record MemberPlanUpdateRequestDTO( - GoalType target, - TrainingTimeRequestDTO trainingTime, - Boolean hasAlarm -) { -} diff --git a/smeem-api/src/main/resources/application-local.yml b/smeem-api/src/main/resources/application-local.yml new file mode 100644 index 00000000..871b38a6 --- /dev/null +++ b/smeem-api/src/main/resources/application-local.yml @@ -0,0 +1,51 @@ +spring: + config: + import: application-secret.yml + activate: + on-profile: local + datasource: + driver-class-name: org.h2.Driver + url : jdbc:h2:mem:testdb + username: sa + password: + jpa: + hibernate: + ddl-auto: create + properties: + hibernate: + format_sql: true + default_batch_fetch_size: 1000 + auto_quote_keyword: true + +logging.level: + org.hibernate.SQL: debug + +fcm: + file_path: smeem_fcm.json + url: ${FCM.URL} + google_api: https://www.googleapis.com/auth/cloud-platform + smeem_title: "오늘의 영어 훈련, 딱 5분 걸려요!" + smeem_body: "지금 눌러서 일기 쓰기 ✍️" + cron_expression: "-" + +jwt: + secret: ${JWT.SECRET} + KAKAO_URL: https://kapi.kakao.com/v2/user/me + APPLE_URL: https://appleid.apple.com/auth/keys + ACCESS_TOKEN_EXPIRED: 7200000 + REFRESH_TOKEN_EXPIRED: 1209600000 + +badge: + welcome-badge-id: ${WELCOME_BADGE_ID} + +springdoc: + default-consumes-media-type: application/json;charset=UTF-8 + default-produces-media-type: application/json;charset=UTF-8 + swagger-ui: + url: /docs/open-api-3.0.1.json + path: /swagger + +smeem: + duration: + expired: ${SMEEM.DURATION.EXPIRED} + remind: ${SMEEM.DURATION.REMIND} \ No newline at end of file diff --git a/smeem-api/src/test/java/com/smeem/controller/MemberControllerTest.java b/smeem-api/src/test/java/com/smeem/controller/MemberControllerTest.java index ab36ff4d..2f4811d4 100644 --- a/smeem-api/src/test/java/com/smeem/controller/MemberControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/controller/MemberControllerTest.java @@ -2,6 +2,7 @@ import com.epages.restdocs.apispec.ResourceSnippetParameters; +import com.smeem.api.member.controller.MemberController; import com.smeem.fixture.member.MemberFixture; import lombok.val; import org.junit.jupiter.api.DisplayName; @@ -13,10 +14,9 @@ import java.security.Principal; import static com.epages.restdocs.apispec.ResourceDocumentation.resource; -import static com.smeme.server.util.message.ResponseMessage.SUCCESS_UPDATE_USER_PLAN; + import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; -import static com.smeme.server.util.ApiResponse.success; -import static com.smeme.server.util.message.ResponseMessage.SUCCESS_UPDATE_USER_PUSH; + import static org.mockito.Mockito.when; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*; @@ -173,7 +173,7 @@ void success_checkDuplicatedName() throws Exception { ) .build(); // when - when(memberController.checkDuplicatedName("com.smeem.test")) + when(memberController.checkDuplicatedName("test")) .thenReturn(ResponseEntity.ok(success("닉네임 중복 체크 성공"))); // then diff --git a/smeem-batch/build.gradle b/smeem-batch/build.gradle index 3a1f9c05..d8ce4c44 100644 --- a/smeem-batch/build.gradle +++ b/smeem-batch/build.gradle @@ -1,19 +1,6 @@ -plugins { - id 'java' -} - -group = 'com.smeme' -version = '0.0.1-SNAPSHOT' - -repositories { - mavenCentral() -} - dependencies { - testImplementation platform('org.junit:junit-bom:5.9.1') - testImplementation 'org.junit.jupiter:junit-jupiter' -} + implementation project(":smeem-common") + implementation project(":smeem-domain") -test { - useJUnitPlatform() + implementation 'org.springframework.boot:spring-boot-starter-web' } \ No newline at end of file diff --git a/smeem-batch/src/main/java/com/smeem/scheduler/DiaryScheduler.java b/smeem-batch/src/main/java/com/smeem/batch/scheduler/DiaryScheduler.java similarity index 86% rename from smeem-batch/src/main/java/com/smeem/scheduler/DiaryScheduler.java rename to smeem-batch/src/main/java/com/smeem/batch/scheduler/DiaryScheduler.java index fe65d116..f5a75734 100644 --- a/smeem-batch/src/main/java/com/smeem/scheduler/DiaryScheduler.java +++ b/smeem-batch/src/main/java/com/smeem/batch/scheduler/DiaryScheduler.java @@ -1,6 +1,5 @@ -package com.smeem.scheduler; +package com.smeem.batch.scheduler; -import com.smeme.server.service.DiaryService; import lombok.RequiredArgsConstructor; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; diff --git a/smeem-batch/src/main/java/com/smeem/scheduler/MessageScheduler.java b/smeem-batch/src/main/java/com/smeem/batch/scheduler/MessageScheduler.java similarity index 63% rename from smeem-batch/src/main/java/com/smeem/scheduler/MessageScheduler.java rename to smeem-batch/src/main/java/com/smeem/batch/scheduler/MessageScheduler.java index 50415ea9..1e887929 100644 --- a/smeem-batch/src/main/java/com/smeem/scheduler/MessageScheduler.java +++ b/smeem-batch/src/main/java/com/smeem/batch/scheduler/MessageScheduler.java @@ -1,7 +1,6 @@ -package com.smeem.scheduler; +package com.smeem.batch.scheduler; -import com.smeme.server.config.ValueConfig; -import com.smeme.server.service.MessageService; +import com.smeem.common.config.ValueConfig; import lombok.RequiredArgsConstructor; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; @@ -13,12 +12,12 @@ @EnableScheduling @RequiredArgsConstructor public class MessageScheduler { - private final MessageService messageService; +// private final MessageService messageService; private final ValueConfig valueConfig; @Scheduled(cron = "${fcm.cron_expression}") public void pushMessage() throws InterruptedException { Thread.sleep(1000); - messageService.pushMessageForTrainingTime(LocalDateTime.now(), valueConfig.getMESSAGE_TITLE(), valueConfig.getMESSAGE_BODY()); +// messageService.pushMessageForTrainingTime(LocalDateTime.now(), valueConfig.getMESSAGE_TITLE(), valueConfig.getMESSAGE_BODY()); } } diff --git a/smeem-common/build.gradle b/smeem-common/build.gradle index 3a1f9c05..e76e2f06 100644 --- a/smeem-common/build.gradle +++ b/smeem-common/build.gradle @@ -1,19 +1,9 @@ -plugins { - id 'java' -} +jar { enabled = true } -group = 'com.smeme' -version = '0.0.1-SNAPSHOT' - -repositories { - mavenCentral() -} +bootJar { enabled = false } dependencies { - testImplementation platform('org.junit:junit-bom:5.9.1') - testImplementation 'org.junit.jupiter:junit-jupiter' -} + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-security' -test { - useJUnitPlatform() } \ No newline at end of file diff --git a/smeem-common/src/main/java/com/smeem/advicer/ErrorHandler.java b/smeem-common/src/main/java/com/smeem/advicer/ErrorHandler.java deleted file mode 100644 index eb8bc500..00000000 --- a/smeem-common/src/main/java/com/smeem/advicer/ErrorHandler.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.smeem.advicer; - -import static com.smeme.server.util.ApiResponse.fail; -import static org.springframework.http.HttpStatus.*; - -import java.io.IOException; -import java.util.NoSuchElementException; - -import jakarta.persistence.EntityExistsException; -import jakarta.validation.ConstraintViolationException; -import org.springframework.data.crossstore.ChangeSetPersister; -import org.springframework.http.ResponseEntity; -import org.springframework.security.oauth2.server.resource.InvalidBearerTokenException; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.RestControllerAdvice; - -import com.smeme.server.util.ApiResponse; - -import jakarta.persistence.EntityNotFoundException; - -@RestControllerAdvice -public class ErrorHandler { - - @ExceptionHandler(EntityNotFoundException.class) - public ResponseEntity entityNotFoundException(EntityNotFoundException ex) { - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ApiResponse.fail(ex.getMessage())); - } - - @ExceptionHandler(ChangeSetPersister.NotFoundException.class) - public ResponseEntity notFoundException(ChangeSetPersister.NotFoundException ex) { - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ApiResponse.fail(ex.getMessage())); - } - - @ExceptionHandler(NoSuchElementException.class) - public ResponseEntity noSuchElementException(NoSuchElementException ex) { - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ApiResponse.fail(ex.getMessage())); - } - - @ExceptionHandler(IllegalArgumentException.class) - public ResponseEntity illegalArgumentException(IllegalArgumentException ex) { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.fail(ex.getMessage())); - } - - @ExceptionHandler(ConstraintViolationException.class) - public ResponseEntity constraintViolationException(ConstraintViolationException ex) { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.fail(ex.getMessage())); - } - - @ExceptionHandler(EntityExistsException.class) - public ResponseEntity entityExistsException(EntityExistsException ex) { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.fail(ex.getMessage())); - } - - @ExceptionHandler(InvalidBearerTokenException.class) - public ResponseEntity invalidBearerTokenException(InvalidBearerTokenException ex) { - return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(ApiResponse.fail(ex.getMessage())); - } - - @ExceptionHandler(IOException.class) - public ResponseEntity ioException(IOException ex) { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ApiResponse.fail(ex.getMessage())); - } - - @ExceptionHandler(IllegalStateException.class) - public ResponseEntity illegalStateException(IllegalStateException ex) { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.fail(ex.getMessage())); - } -} diff --git a/smeem-common/src/main/java/com/smeem/common/advicer/ErrorHandler.java b/smeem-common/src/main/java/com/smeem/common/advicer/ErrorHandler.java new file mode 100644 index 00000000..e0d98e6d --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/advicer/ErrorHandler.java @@ -0,0 +1,61 @@ +package com.smeem.common.advicer; + + +import java.io.IOException; +import java.util.NoSuchElementException; + + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + + + +@RestControllerAdvice +public class ErrorHandler { + +// @ExceptionHandler(EntityNotFoundException.class) +// public ResponseEntity entityNotFoundException(EntityNotFoundException ex) { +// return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ApiResponse.fail(ex.getMessage())); +// } +// +// @ExceptionHandler(ChangeSetPersister.NotFoundException.class) +// public ResponseEntity notFoundException(ChangeSetPersister.NotFoundException ex) { +// return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ApiResponse.fail(ex.getMessage())); +// } +// +// @ExceptionHandler(NoSuchElementException.class) +// public ResponseEntity noSuchElementException(NoSuchElementException ex) { +// return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ApiResponse.fail(ex.getMessage())); +// } +// +// @ExceptionHandler(IllegalArgumentException.class) +// public ResponseEntity illegalArgumentException(IllegalArgumentException ex) { +// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.fail(ex.getMessage())); +// } +// +// @ExceptionHandler(ConstraintViolationException.class) +// public ResponseEntity constraintViolationException(ConstraintViolationException ex) { +// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.fail(ex.getMessage())); +// } +// +// @ExceptionHandler(EntityExistsException.class) +// public ResponseEntity entityExistsException(EntityExistsException ex) { +// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.fail(ex.getMessage())); +// } +// +// @ExceptionHandler(InvalidBearerTokenException.class) +// public ResponseEntity invalidBearerTokenException(InvalidBearerTokenException ex) { +// return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(ApiResponse.fail(ex.getMessage())); +// } +// +// @ExceptionHandler(IOException.class) +// public ResponseEntity ioException(IOException ex) { +// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ApiResponse.fail(ex.getMessage())); +// } +// +// @ExceptionHandler(IllegalStateException.class) +// public ResponseEntity illegalStateException(IllegalStateException ex) { +// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.fail(ex.getMessage())); +// } +} diff --git a/smeem-common/src/main/java/com/smeem/code/ErrorMessage.java b/smeem-common/src/main/java/com/smeem/common/code/ErrorMessage.java similarity index 98% rename from smeem-common/src/main/java/com/smeem/code/ErrorMessage.java rename to smeem-common/src/main/java/com/smeem/common/code/ErrorMessage.java index 52a4fe3c..44331f39 100644 --- a/smeem-common/src/main/java/com/smeem/code/ErrorMessage.java +++ b/smeem-common/src/main/java/com/smeem/common/code/ErrorMessage.java @@ -1,4 +1,4 @@ -package com.smeem.code; +package com.smeem.common.code; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/smeem-common/src/main/java/com/smeem/code/ResponseMessage.java b/smeem-common/src/main/java/com/smeem/common/code/ResponseMessage.java similarity index 98% rename from smeem-common/src/main/java/com/smeem/code/ResponseMessage.java rename to smeem-common/src/main/java/com/smeem/common/code/ResponseMessage.java index da3b9b35..4cc9996f 100644 --- a/smeem-common/src/main/java/com/smeem/code/ResponseMessage.java +++ b/smeem-common/src/main/java/com/smeem/common/code/ResponseMessage.java @@ -1,4 +1,4 @@ -package com.smeem.code; +package com.smeem.common.code; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/smeem-common/src/main/java/com/smeem/config/RestTemplateConfig.java b/smeem-common/src/main/java/com/smeem/common/config/RestTemplateConfig.java similarity index 90% rename from smeem-common/src/main/java/com/smeem/config/RestTemplateConfig.java rename to smeem-common/src/main/java/com/smeem/common/config/RestTemplateConfig.java index f3c26ab5..af97ffa2 100644 --- a/smeem-common/src/main/java/com/smeem/config/RestTemplateConfig.java +++ b/smeem-common/src/main/java/com/smeem/common/config/RestTemplateConfig.java @@ -1,4 +1,4 @@ -package com.smeem.config; +package com.smeem.common.config; import org.springframework.context.annotation.Bean; diff --git a/smeem-common/src/main/java/com/smeem/config/TimezoneConfig.java b/smeem-common/src/main/java/com/smeem/common/config/TimezoneConfig.java similarity index 77% rename from smeem-common/src/main/java/com/smeem/config/TimezoneConfig.java rename to smeem-common/src/main/java/com/smeem/common/config/TimezoneConfig.java index 01d97685..03c8ccad 100644 --- a/smeem-common/src/main/java/com/smeem/config/TimezoneConfig.java +++ b/smeem-common/src/main/java/com/smeem/common/config/TimezoneConfig.java @@ -1,9 +1,9 @@ -package com.smeem.config; +package com.smeem.common.config; import java.util.TimeZone; -import javax.annotation.PostConstruct; +import jakarta.annotation.PostConstruct; import org.springframework.context.annotation.Configuration; @Configuration diff --git a/smeem-common/src/main/java/com/smeem/config/ValueConfig.java b/smeem-common/src/main/java/com/smeem/common/config/ValueConfig.java similarity index 90% rename from smeem-common/src/main/java/com/smeem/config/ValueConfig.java rename to smeem-common/src/main/java/com/smeem/common/config/ValueConfig.java index b91512c2..55b275e1 100644 --- a/smeem-common/src/main/java/com/smeem/config/ValueConfig.java +++ b/smeem-common/src/main/java/com/smeem/common/config/ValueConfig.java @@ -1,10 +1,10 @@ -package com.smeem.config; +package com.smeem.common.config; +import jakarta.annotation.PostConstruct; import lombok.Getter; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; -import javax.annotation.PostConstruct; import java.nio.charset.StandardCharsets; import java.util.Base64; @@ -24,7 +24,7 @@ public class ValueConfig { @Value("${jwt.APPLE_URL}") private String APPLE_URL; - @Value("${com.smeem.badge.welcome-com.smeem.badge-id}") + @Value("${WELCOME_BADGE_ID}") private Long WELCOME_BADGE_ID; @Value("${jwt.KAKAO_URL}") diff --git a/smeem-common/src/main/java/com/smeem/util/Util.java b/smeem-common/src/main/java/com/smeem/common/util/Util.java similarity index 92% rename from smeem-common/src/main/java/com/smeem/util/Util.java rename to smeem-common/src/main/java/com/smeem/common/util/Util.java index a65f67e7..513d39f8 100644 --- a/smeem-common/src/main/java/com/smeem/util/Util.java +++ b/smeem-common/src/main/java/com/smeem/common/util/Util.java @@ -1,6 +1,6 @@ -package com.smeem.util; +package com.smeem.common.util; -import static com.smeme.server.util.message.ErrorMessage.*; +import static com.smeem.common.code.ErrorMessage.EMPTY_ACCESS_TOKEN; import static java.util.Objects.*; import java.net.URI; diff --git a/smeem-domain/build.gradle b/smeem-domain/build.gradle index 3a1f9c05..c528a2da 100644 --- a/smeem-domain/build.gradle +++ b/smeem-domain/build.gradle @@ -1,19 +1,21 @@ -plugins { - id 'java' -} +bootJar { enabled = false } +jar { enabled = true } -group = 'com.smeme' -version = '0.0.1-SNAPSHOT' - -repositories { - mavenCentral() -} dependencies { - testImplementation platform('org.junit:junit-bom:5.9.1') - testImplementation 'org.junit.jupiter:junit-jupiter' -} -test { - useJUnitPlatform() + implementation project(":smeem-common") + + // jpa + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + + // QueryDSL + implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta' + annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta" + annotationProcessor "jakarta.annotation:jakarta.annotation-api" + annotationProcessor "jakarta.persistence:jakarta.persistence-api" + + // DB + runtimeOnly 'com.h2database:h2' + runtimeOnly 'org.postgresql:postgresql' } \ No newline at end of file diff --git a/smeem-domain/src/main/java/com/smeem/badge/model/Badge.java b/smeem-domain/src/main/java/com/smeem/domain/badge/model/Badge.java similarity index 57% rename from smeem-domain/src/main/java/com/smeem/badge/model/Badge.java rename to smeem-domain/src/main/java/com/smeem/domain/badge/model/Badge.java index 1589e22a..a92f739f 100644 --- a/smeem-domain/src/main/java/com/smeem/badge/model/Badge.java +++ b/smeem-domain/src/main/java/com/smeem/domain/badge/model/Badge.java @@ -1,12 +1,7 @@ -package com.smeem.badge.model; +package com.smeem.domain.badge.model; -import static jakarta.persistence.GenerationType.*; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; +import jakarta.persistence.*; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/smeem-domain/src/main/java/com/smeem/badge/model/BadgeType.java b/smeem-domain/src/main/java/com/smeem/domain/badge/model/BadgeType.java similarity index 87% rename from smeem-domain/src/main/java/com/smeem/badge/model/BadgeType.java rename to smeem-domain/src/main/java/com/smeem/domain/badge/model/BadgeType.java index e64bc196..1ea6b171 100644 --- a/smeem-domain/src/main/java/com/smeem/badge/model/BadgeType.java +++ b/smeem-domain/src/main/java/com/smeem/domain/badge/model/BadgeType.java @@ -1,4 +1,4 @@ -package com.smeem.badge.model; +package com.smeem.domain.badge.model; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/smeem-domain/src/main/java/com/smeem/badge/repository/BadgeCustomRepository.java b/smeem-domain/src/main/java/com/smeem/domain/badge/repository/BadgeCustomRepository.java similarity index 54% rename from smeem-domain/src/main/java/com/smeem/badge/repository/BadgeCustomRepository.java rename to smeem-domain/src/main/java/com/smeem/domain/badge/repository/BadgeCustomRepository.java index 3e075c30..ecac4d33 100644 --- a/smeem-domain/src/main/java/com/smeem/badge/repository/BadgeCustomRepository.java +++ b/smeem-domain/src/main/java/com/smeem/domain/badge/repository/BadgeCustomRepository.java @@ -1,6 +1,7 @@ -package com.smeem.badge.repository; +package com.smeem.domain.badge.repository; -import com.smeme.server.model.badge.Badge; + +import com.smeem.domain.badge.model.Badge; import java.util.List; diff --git a/smeem-domain/src/main/java/com/smeem/badge/repository/BadgeRepository.java b/smeem-domain/src/main/java/com/smeem/domain/badge/repository/BadgeRepository.java similarity index 64% rename from smeem-domain/src/main/java/com/smeem/badge/repository/BadgeRepository.java rename to smeem-domain/src/main/java/com/smeem/domain/badge/repository/BadgeRepository.java index 09a95618..050b6c9f 100644 --- a/smeem-domain/src/main/java/com/smeem/badge/repository/BadgeRepository.java +++ b/smeem-domain/src/main/java/com/smeem/domain/badge/repository/BadgeRepository.java @@ -1,6 +1,7 @@ -package com.smeem.badge.repository; +package com.smeem.domain.badge.repository; -import com.smeme.server.model.badge.Badge; + +import com.smeem.domain.badge.model.Badge; import org.springframework.data.jpa.repository.JpaRepository; public interface BadgeRepository extends JpaRepository, BadgeCustomRepository { diff --git a/smeem-domain/src/main/java/com/smeem/badge/repository/BadgeRepositoryImpl.java b/smeem-domain/src/main/java/com/smeem/domain/badge/repository/BadgeRepositoryImpl.java similarity index 78% rename from smeem-domain/src/main/java/com/smeem/badge/repository/BadgeRepositoryImpl.java rename to smeem-domain/src/main/java/com/smeem/domain/badge/repository/BadgeRepositoryImpl.java index e84d9357..c8f257c6 100644 --- a/smeem-domain/src/main/java/com/smeem/badge/repository/BadgeRepositoryImpl.java +++ b/smeem-domain/src/main/java/com/smeem/domain/badge/repository/BadgeRepositoryImpl.java @@ -1,12 +1,13 @@ -package com.smeem.badge.repository; +package com.smeem.domain.badge.repository; import com.querydsl.jpa.impl.JPAQueryFactory; -import com.smeme.server.model.badge.Badge; +import com.smeem.domain.badge.model.Badge; +import com.smeem.domain.badge.model.QBadge; import lombok.*; import org.springframework.stereotype.Repository; + import java.util.List; -import static com.smeme.server.model.badge.QBadge.badge; @Repository @RequiredArgsConstructor diff --git a/smeem-common/src/main/java/com/smeem/config/JpaAuditingConfig.java b/smeem-domain/src/main/java/com/smeem/domain/config/JpaAuditingConfig.java similarity index 86% rename from smeem-common/src/main/java/com/smeem/config/JpaAuditingConfig.java rename to smeem-domain/src/main/java/com/smeem/domain/config/JpaAuditingConfig.java index d32530f4..40a49d41 100644 --- a/smeem-common/src/main/java/com/smeem/config/JpaAuditingConfig.java +++ b/smeem-domain/src/main/java/com/smeem/domain/config/JpaAuditingConfig.java @@ -1,4 +1,4 @@ -package com.smeem.config; +package com.smeem.domain.config; import org.springframework.context.annotation.Configuration; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; diff --git a/smeem-common/src/main/java/com/smeem/config/JpaQueryFactoryConfig.java b/smeem-domain/src/main/java/com/smeem/domain/config/JpaQueryFactoryConfig.java similarity index 91% rename from smeem-common/src/main/java/com/smeem/config/JpaQueryFactoryConfig.java rename to smeem-domain/src/main/java/com/smeem/domain/config/JpaQueryFactoryConfig.java index 0cad9a16..431630cc 100644 --- a/smeem-common/src/main/java/com/smeem/config/JpaQueryFactoryConfig.java +++ b/smeem-domain/src/main/java/com/smeem/domain/config/JpaQueryFactoryConfig.java @@ -1,4 +1,4 @@ -package com.smeem.config; +package com.smeem.domain.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/smeem-domain/src/main/java/com/smeem/diary/model/DeletedDiary.java b/smeem-domain/src/main/java/com/smeem/domain/diary/model/DeletedDiary.java similarity index 86% rename from smeem-domain/src/main/java/com/smeem/diary/model/DeletedDiary.java rename to smeem-domain/src/main/java/com/smeem/domain/diary/model/DeletedDiary.java index 5cc94aa8..9a68b45e 100644 --- a/smeem-domain/src/main/java/com/smeem/diary/model/DeletedDiary.java +++ b/smeem-domain/src/main/java/com/smeem/domain/diary/model/DeletedDiary.java @@ -1,15 +1,14 @@ -package com.smeem.diary.model; +package com.smeem.domain.diary.model; -import com.smeme.server.model.topic.Topic; +import com.smeem.domain.member.model.LangType; +import com.smeem.domain.member.model.Member; +import com.smeem.domain.topic.model.Topic; import jakarta.persistence.*; import lombok.Getter; import lombok.NoArgsConstructor; import java.time.LocalDateTime; -import static jakarta.persistence.FetchType.LAZY; -import static jakarta.persistence.GenerationType.IDENTITY; - @Entity @Getter @NoArgsConstructor diff --git a/smeem-domain/src/main/java/com/smeem/diary/model/Diary.java b/smeem-domain/src/main/java/com/smeem/domain/diary/model/Diary.java similarity index 89% rename from smeem-domain/src/main/java/com/smeem/diary/model/Diary.java rename to smeem-domain/src/main/java/com/smeem/domain/diary/model/Diary.java index 1b1cf121..5250def2 100644 --- a/smeem-domain/src/main/java/com/smeem/diary/model/Diary.java +++ b/smeem-domain/src/main/java/com/smeem/domain/diary/model/Diary.java @@ -1,10 +1,13 @@ -package com.smeem.diary.model; +package com.smeem.domain.diary.model; + -import static com.smeme.server.util.Util.getStartOfDay; -import static jakarta.persistence.FetchType.*; -import static jakarta.persistence.GenerationType.*; import static java.util.Objects.nonNull; +import com.smeem.common.util.Util; +import com.smeem.domain.member.model.LangType; +import com.smeem.domain.member.model.Member; +import com.smeem.domain.model.BaseTimeEntity; +import com.smeem.domain.topic.model.Topic; import jakarta.persistence.*; import lombok.Builder; import lombok.Getter; @@ -12,7 +15,7 @@ import java.time.LocalDateTime; -import com.smeme.server.model.topic.Topic; + @Entity @NoArgsConstructor diff --git a/smeem-domain/src/main/java/com/smeem/diary/repository/DeletedDiaryRepository.java b/smeem-domain/src/main/java/com/smeem/domain/diary/repository/DeletedDiaryRepository.java similarity index 66% rename from smeem-domain/src/main/java/com/smeem/diary/repository/DeletedDiaryRepository.java rename to smeem-domain/src/main/java/com/smeem/domain/diary/repository/DeletedDiaryRepository.java index f7ba0835..02eb2caf 100644 --- a/smeem-domain/src/main/java/com/smeem/diary/repository/DeletedDiaryRepository.java +++ b/smeem-domain/src/main/java/com/smeem/domain/diary/repository/DeletedDiaryRepository.java @@ -1,7 +1,8 @@ -package com.smeem.diary.repository; +package com.smeem.domain.diary.repository; -import com.smeme.server.model.DeletedDiary; -import com.smeme.server.model.Member; + +import com.smeem.domain.diary.model.DeletedDiary; +import com.smeem.domain.member.model.Member; import org.springframework.data.jpa.repository.JpaRepository; import java.time.LocalDateTime; diff --git a/smeem-domain/src/main/java/com/smeem/diary/repository/DiaryRepository.java b/smeem-domain/src/main/java/com/smeem/domain/diary/repository/DiaryRepository.java similarity index 66% rename from smeem-domain/src/main/java/com/smeem/diary/repository/DiaryRepository.java rename to smeem-domain/src/main/java/com/smeem/domain/diary/repository/DiaryRepository.java index 70f551e0..6d50ac5e 100644 --- a/smeem-domain/src/main/java/com/smeem/diary/repository/DiaryRepository.java +++ b/smeem-domain/src/main/java/com/smeem/domain/diary/repository/DiaryRepository.java @@ -1,9 +1,9 @@ -package com.smeem.diary.repository; +package com.smeem.domain.diary.repository; -import com.smeme.server.model.Member; -import org.springframework.data.jpa.repository.JpaRepository; -import com.smeme.server.model.Diary; +import com.smeem.domain.diary.model.Diary; +import com.smeem.domain.member.model.Member; +import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; diff --git a/smeem-domain/src/main/java/com/smeem/goal/model/Goal.java b/smeem-domain/src/main/java/com/smeem/domain/goal/model/Goal.java similarity index 71% rename from smeem-domain/src/main/java/com/smeem/goal/model/Goal.java rename to smeem-domain/src/main/java/com/smeem/domain/goal/model/Goal.java index 481ea7d3..5b184ffc 100644 --- a/smeem-domain/src/main/java/com/smeem/goal/model/Goal.java +++ b/smeem-domain/src/main/java/com/smeem/domain/goal/model/Goal.java @@ -1,13 +1,8 @@ -package com.smeem.goal.model; +package com.smeem.domain.goal.model; import static jakarta.persistence.GenerationType.*; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; +import jakarta.persistence.*; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/smeem-domain/src/main/java/com/smeem/goal/model/GoalType.java b/smeem-domain/src/main/java/com/smeem/domain/goal/model/GoalType.java similarity index 90% rename from smeem-domain/src/main/java/com/smeem/goal/model/GoalType.java rename to smeem-domain/src/main/java/com/smeem/domain/goal/model/GoalType.java index 6f537ee1..b231ec80 100644 --- a/smeem-domain/src/main/java/com/smeem/goal/model/GoalType.java +++ b/smeem-domain/src/main/java/com/smeem/domain/goal/model/GoalType.java @@ -1,4 +1,4 @@ -package com.smeem.goal.model; +package com.smeem.domain.goal.model; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/smeem-domain/src/main/java/com/smeem/goal/repository/GoalRepository.java b/smeem-domain/src/main/java/com/smeem/domain/goal/repository/GoalRepository.java similarity index 62% rename from smeem-domain/src/main/java/com/smeem/goal/repository/GoalRepository.java rename to smeem-domain/src/main/java/com/smeem/domain/goal/repository/GoalRepository.java index ad51a4e5..64c921e2 100644 --- a/smeem-domain/src/main/java/com/smeem/goal/repository/GoalRepository.java +++ b/smeem-domain/src/main/java/com/smeem/domain/goal/repository/GoalRepository.java @@ -1,7 +1,8 @@ -package com.smeem.goal.repository; +package com.smeem.domain.goal.repository; -import com.smeme.server.model.goal.Goal; -import com.smeme.server.model.goal.GoalType; + +import com.smeem.domain.goal.model.Goal; +import com.smeem.domain.goal.model.GoalType; import org.springframework.data.jpa.repository.JpaRepository; import java.util.Optional; diff --git a/smeem-domain/src/main/java/com/smeem/domain/member/model/LangType.java b/smeem-domain/src/main/java/com/smeem/domain/member/model/LangType.java new file mode 100644 index 00000000..da7de0dd --- /dev/null +++ b/smeem-domain/src/main/java/com/smeem/domain/member/model/LangType.java @@ -0,0 +1,5 @@ +package com.smeem.domain.member.model; + +public enum LangType { + en +} diff --git a/smeem-domain/src/main/java/com/smeem/member/model/Member.java b/smeem-domain/src/main/java/com/smeem/domain/member/model/Member.java similarity index 91% rename from smeem-domain/src/main/java/com/smeem/member/model/Member.java rename to smeem-domain/src/main/java/com/smeem/domain/member/model/Member.java index 6e5a157e..27480caa 100644 --- a/smeem-domain/src/main/java/com/smeem/member/model/Member.java +++ b/smeem-domain/src/main/java/com/smeem/domain/member/model/Member.java @@ -1,9 +1,12 @@ -package com.smeem.member.model; +package com.smeem.domain.member.model; -import static jakarta.persistence.GenerationType.*; import static java.time.LocalDateTime.now; -import com.smeme.server.model.badge.Badge; +import com.smeem.domain.badge.model.Badge; +import com.smeem.domain.diary.model.Diary; +import com.smeem.domain.goal.model.GoalType; +import com.smeem.domain.model.BaseTimeEntity; +import com.smeem.domain.training.model.TrainingTime; import jakarta.persistence.*; import lombok.Builder; import lombok.Getter; @@ -13,9 +16,6 @@ import java.util.ArrayList; import java.util.List; -import com.smeme.server.model.badge.MemberBadge; -import com.smeme.server.model.training.TrainingTime; -import com.smeme.server.model.goal.GoalType; @Entity @NoArgsConstructor diff --git a/smeem-domain/src/main/java/com/smeem/member/model/MemberBadge.java b/smeem-domain/src/main/java/com/smeem/domain/member/model/MemberBadge.java similarity index 64% rename from smeem-domain/src/main/java/com/smeem/member/model/MemberBadge.java rename to smeem-domain/src/main/java/com/smeem/domain/member/model/MemberBadge.java index 2f5f8d08..608af956 100644 --- a/smeem-domain/src/main/java/com/smeem/member/model/MemberBadge.java +++ b/smeem-domain/src/main/java/com/smeem/domain/member/model/MemberBadge.java @@ -1,19 +1,11 @@ -package com.smeem.member.model; +package com.smeem.domain.member.model; -import static jakarta.persistence.FetchType.*; -import static jakarta.persistence.GenerationType.*; import static java.util.Objects.*; -import com.smeem.badge.model.Badge; -import com.smeme.server.model.BaseTimeEntity; -import com.smeme.server.model.Member; +import com.smeem.domain.badge.model.Badge; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; +import com.smeem.domain.model.BaseTimeEntity; +import jakarta.persistence.*; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/smeem-domain/src/main/java/com/smeem/member/model/SocialType.java b/smeem-domain/src/main/java/com/smeem/domain/member/model/SocialType.java similarity index 60% rename from smeem-domain/src/main/java/com/smeem/member/model/SocialType.java rename to smeem-domain/src/main/java/com/smeem/domain/member/model/SocialType.java index d014ce1b..0f3da844 100644 --- a/smeem-domain/src/main/java/com/smeem/member/model/SocialType.java +++ b/smeem-domain/src/main/java/com/smeem/domain/member/model/SocialType.java @@ -1,4 +1,4 @@ -package com.smeem.member.model; +package com.smeem.domain.member.model; public enum SocialType { KAKAO, diff --git a/smeem-domain/src/main/java/com/smeem/member/repository/MemberBadgeRepository.java b/smeem-domain/src/main/java/com/smeem/domain/member/repository/MemberBadgeRepository.java similarity index 78% rename from smeem-domain/src/main/java/com/smeem/member/repository/MemberBadgeRepository.java rename to smeem-domain/src/main/java/com/smeem/domain/member/repository/MemberBadgeRepository.java index 4fb85e9b..309f7ae1 100644 --- a/smeem-domain/src/main/java/com/smeem/member/repository/MemberBadgeRepository.java +++ b/smeem-domain/src/main/java/com/smeem/domain/member/repository/MemberBadgeRepository.java @@ -1,5 +1,6 @@ -package com.smeem.member.repository; -import com.smeme.server.model.badge.MemberBadge; +package com.smeem.domain.member.repository; + +import com.smeem.domain.member.model.MemberBadge; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; diff --git a/smeem-domain/src/main/java/com/smeem/member/repository/MemberRepository.java b/smeem-domain/src/main/java/com/smeem/domain/member/repository/MemberRepository.java similarity index 73% rename from smeem-domain/src/main/java/com/smeem/member/repository/MemberRepository.java rename to smeem-domain/src/main/java/com/smeem/domain/member/repository/MemberRepository.java index 76111b75..6700d4a8 100644 --- a/smeem-domain/src/main/java/com/smeem/member/repository/MemberRepository.java +++ b/smeem-domain/src/main/java/com/smeem/domain/member/repository/MemberRepository.java @@ -1,8 +1,10 @@ -package com.smeem.member.repository; +package com.smeem.domain.member.repository; -import com.smeme.server.model.Member; -import com.smeme.server.model.SocialType; + + +import com.smeem.domain.member.model.Member; +import com.smeem.domain.member.model.SocialType; import org.springframework.data.jpa.repository.JpaRepository; import java.util.Optional; diff --git a/smeem-domain/src/main/java/com/smeem/common/model/BaseTimeEntity.java b/smeem-domain/src/main/java/com/smeem/domain/model/BaseTimeEntity.java similarity index 81% rename from smeem-domain/src/main/java/com/smeem/common/model/BaseTimeEntity.java rename to smeem-domain/src/main/java/com/smeem/domain/model/BaseTimeEntity.java index 78a3262b..e5c0b44a 100644 --- a/smeem-domain/src/main/java/com/smeem/common/model/BaseTimeEntity.java +++ b/smeem-domain/src/main/java/com/smeem/domain/model/BaseTimeEntity.java @@ -1,4 +1,4 @@ -package com.smeem.common.model; +package com.smeem.domain.model; import jakarta.persistence.EntityListeners; import jakarta.persistence.MappedSuperclass; @@ -15,8 +15,8 @@ public abstract class BaseTimeEntity { @CreatedDate - protected LocalDateTime createdAt; + public LocalDateTime createdAt; @LastModifiedDate - protected LocalDateTime updatedAt; + public LocalDateTime updatedAt; } diff --git a/smeem-domain/src/main/java/com/smeem/topic/model/Category.java b/smeem-domain/src/main/java/com/smeem/domain/topic/model/Category.java similarity index 87% rename from smeem-domain/src/main/java/com/smeem/topic/model/Category.java rename to smeem-domain/src/main/java/com/smeem/domain/topic/model/Category.java index 2dc2ed08..f97a946c 100644 --- a/smeem-domain/src/main/java/com/smeem/topic/model/Category.java +++ b/smeem-domain/src/main/java/com/smeem/domain/topic/model/Category.java @@ -1,4 +1,4 @@ -package com.smeem.topic.model; +package com.smeem.domain.topic.model; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/smeem-domain/src/main/java/com/smeem/topic/model/Topic.java b/smeem-domain/src/main/java/com/smeem/domain/topic/model/Topic.java similarity index 93% rename from smeem-domain/src/main/java/com/smeem/topic/model/Topic.java rename to smeem-domain/src/main/java/com/smeem/domain/topic/model/Topic.java index 51957c50..62760415 100644 --- a/smeem-domain/src/main/java/com/smeem/topic/model/Topic.java +++ b/smeem-domain/src/main/java/com/smeem/domain/topic/model/Topic.java @@ -1,4 +1,4 @@ -package com.smeem.topic.model; +package com.smeem.domain.topic.model; import static jakarta.persistence.GenerationType.*; diff --git a/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicCustomRepository.java b/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicCustomRepository.java new file mode 100644 index 00000000..95c3ba73 --- /dev/null +++ b/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicCustomRepository.java @@ -0,0 +1,8 @@ +package com.smeem.domain.topic.repository; + + +import com.smeem.domain.topic.model.Topic; + +public interface TopicCustomRepository { + Topic getRandom(); +} diff --git a/smeem-domain/src/main/java/com/smeem/topic/repository/TopicRepository.java b/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicRepository.java similarity index 65% rename from smeem-domain/src/main/java/com/smeem/topic/repository/TopicRepository.java rename to smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicRepository.java index e3cf09dc..b162992f 100644 --- a/smeem-domain/src/main/java/com/smeem/topic/repository/TopicRepository.java +++ b/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicRepository.java @@ -1,8 +1,8 @@ -package com.smeem.topic.repository; +package com.smeem.domain.topic.repository; -import org.springframework.data.jpa.repository.JpaRepository; -import com.smeme.server.model.topic.Topic; +import com.smeem.domain.topic.model.Topic; +import org.springframework.data.jpa.repository.JpaRepository; public interface TopicRepository extends JpaRepository, TopicCustomRepository { } diff --git a/smeem-domain/src/main/java/com/smeem/topic/repository/TopicRepositoryImpl.java b/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicRepositoryImpl.java similarity index 74% rename from smeem-domain/src/main/java/com/smeem/topic/repository/TopicRepositoryImpl.java rename to smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicRepositoryImpl.java index 7ff83f52..4e941a70 100644 --- a/smeem-domain/src/main/java/com/smeem/topic/repository/TopicRepositoryImpl.java +++ b/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicRepositoryImpl.java @@ -1,12 +1,12 @@ -package com.smeem.topic.repository; +package com.smeem.domain.topic.repository; -import static com.querydsl.core.types.dsl.NumberExpression.*; -import static com.smeme.server.model.topic.QTopic.*; +import com.querydsl.core.types.dsl.NumberExpression; +import com.smeem.domain.topic.model.QTopic; +import com.smeem.domain.topic.model.Topic; import org.springframework.stereotype.Repository; import com.querydsl.jpa.impl.JPAQueryFactory; -import com.smeme.server.model.topic.Topic; import lombok.RequiredArgsConstructor; diff --git a/smeem-domain/src/main/java/com/smeem/training/model/DayType.java b/smeem-domain/src/main/java/com/smeem/domain/training/model/DayType.java similarity index 86% rename from smeem-domain/src/main/java/com/smeem/training/model/DayType.java rename to smeem-domain/src/main/java/com/smeem/domain/training/model/DayType.java index 83adc8b1..fb744fe8 100644 --- a/smeem-domain/src/main/java/com/smeem/training/model/DayType.java +++ b/smeem-domain/src/main/java/com/smeem/domain/training/model/DayType.java @@ -1,4 +1,4 @@ -package com.smeem.training.model; +package com.smeem.domain.training.model; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/smeem-domain/src/main/java/com/smeem/training/model/TrainingTime.java b/smeem-domain/src/main/java/com/smeem/domain/training/model/TrainingTime.java similarity index 53% rename from smeem-domain/src/main/java/com/smeem/training/model/TrainingTime.java rename to smeem-domain/src/main/java/com/smeem/domain/training/model/TrainingTime.java index 199d0471..4fa1205f 100644 --- a/smeem-domain/src/main/java/com/smeem/training/model/TrainingTime.java +++ b/smeem-domain/src/main/java/com/smeem/domain/training/model/TrainingTime.java @@ -1,20 +1,10 @@ -package com.smeem.training.model; +package com.smeem.domain.training.model; -import static jakarta.persistence.FetchType.*; -import static jakarta.persistence.GenerationType.*; import static java.util.Objects.*; -import com.smeme.server.model.Member; - -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import jakarta.validation.constraints.Max; -import jakarta.validation.constraints.Min; + +import com.smeem.domain.member.model.Member; +import jakarta.persistence.*; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -31,12 +21,14 @@ public class TrainingTime { @Enumerated(value = EnumType.STRING) private DayType day; - @Min(value = 1, message = "시(hour)는 1 이상이어야 합니다.") - @Max(value = 24, message = "시(hour)는 24 이하여야 합니다.") + // TODO : validation -> 생성자에 validation method 직접 구현 + // @Min(value = 1, message = "시(hour)는 1 이상이어야 합니다.") + // @Max(value = 24, message = "시(hour)는 24 이하여야 합니다.") private int hour; - @Min(value = 0, message = "분(minute)은 0 이상이어야 합니다.") - @Max(value = 59, message = "분(minute)은 59 이하이어야 합니다.") + // TODO : validation -> 생성자에 validation method 직접 구현 + // @Min(value = 0, message = "분(minute)은 0 이상이어야 합니다.") + // @Max(value = 59, message = "분(minute)은 59 이하이어야 합니다.") private int minute; @ManyToOne(fetch = FetchType.LAZY) @@ -58,4 +50,4 @@ private void setMember(Member member) { this.member = member; member.getTrainingTimes().add(this); } -} +} \ No newline at end of file diff --git a/smeem-domain/src/main/java/com/smeem/training/repository/TrainingTimeCustomRepository.java b/smeem-domain/src/main/java/com/smeem/domain/training/repository/TrainingTimeCustomRepository.java similarity index 64% rename from smeem-domain/src/main/java/com/smeem/training/repository/TrainingTimeCustomRepository.java rename to smeem-domain/src/main/java/com/smeem/domain/training/repository/TrainingTimeCustomRepository.java index 68b6734c..f7429223 100644 --- a/smeem-domain/src/main/java/com/smeem/training/repository/TrainingTimeCustomRepository.java +++ b/smeem-domain/src/main/java/com/smeem/domain/training/repository/TrainingTimeCustomRepository.java @@ -1,9 +1,10 @@ -package com.smeem.training.repository; +package com.smeem.domain.training.repository; + +import com.smeem.domain.training.model.TrainingTime; import java.time.LocalDateTime; import java.util.List; -import com.smeme.server.model.training.TrainingTime; public interface TrainingTimeCustomRepository { List getTrainingTimeForPushAlarm(LocalDateTime now); diff --git a/smeem-domain/src/main/java/com/smeem/training/repository/TrainingTimeRepository.java b/smeem-domain/src/main/java/com/smeem/domain/training/repository/TrainingTimeRepository.java similarity index 68% rename from smeem-domain/src/main/java/com/smeem/training/repository/TrainingTimeRepository.java rename to smeem-domain/src/main/java/com/smeem/domain/training/repository/TrainingTimeRepository.java index 3b3000eb..207c1353 100644 --- a/smeem-domain/src/main/java/com/smeem/training/repository/TrainingTimeRepository.java +++ b/smeem-domain/src/main/java/com/smeem/domain/training/repository/TrainingTimeRepository.java @@ -1,9 +1,9 @@ -package com.smeem.training.repository; +package com.smeem.domain.training.repository; -import com.smeme.server.model.Member; -import org.springframework.data.jpa.repository.JpaRepository; -import com.smeme.server.model.training.TrainingTime; +import com.smeem.domain.member.model.Member; +import com.smeem.domain.training.model.TrainingTime; +import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; diff --git a/smeem-domain/src/main/java/com/smeem/training/repository/TrainingTimeRepositoryImpl.java b/smeem-domain/src/main/java/com/smeem/domain/training/repository/TrainingTimeRepositoryImpl.java similarity index 79% rename from smeem-domain/src/main/java/com/smeem/training/repository/TrainingTimeRepositoryImpl.java rename to smeem-domain/src/main/java/com/smeem/domain/training/repository/TrainingTimeRepositoryImpl.java index 95aa5d23..68872179 100644 --- a/smeem-domain/src/main/java/com/smeem/training/repository/TrainingTimeRepositoryImpl.java +++ b/smeem-domain/src/main/java/com/smeem/domain/training/repository/TrainingTimeRepositoryImpl.java @@ -1,18 +1,19 @@ -package com.smeem.training.repository; +package com.smeem.domain.training.repository; + +import static com.smeem.domain.training.model.DayType.*; -import static com.smeme.server.model.QMember.*; -import static com.smeme.server.model.training.DayType.*; -import static com.smeme.server.model.training.QTrainingTime.*; -import static com.smeme.server.util.message.ErrorMessage.*; import java.time.LocalDateTime; import java.util.List; +import com.smeem.common.code.ErrorMessage; +import com.smeem.domain.member.model.QMember; +import com.smeem.domain.training.model.DayType; +import com.smeem.domain.training.model.QTrainingTime; +import com.smeem.domain.training.model.TrainingTime; import org.springframework.stereotype.Repository; import com.querydsl.jpa.impl.JPAQueryFactory; -import com.smeme.server.model.training.DayType; -import com.smeme.server.model.training.TrainingTime; import lombok.RequiredArgsConstructor; diff --git a/smeem-domain/src/main/java/com/smeem/member/model/LangType.java b/smeem-domain/src/main/java/com/smeem/member/model/LangType.java deleted file mode 100644 index 9880fce4..00000000 --- a/smeem-domain/src/main/java/com/smeem/member/model/LangType.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.smeem.member.model; - -public enum LangType { - en -} diff --git a/smeem-domain/src/main/java/com/smeem/topic/repository/TopicCustomRepository.java b/smeem-domain/src/main/java/com/smeem/topic/repository/TopicCustomRepository.java deleted file mode 100644 index 88f7a871..00000000 --- a/smeem-domain/src/main/java/com/smeem/topic/repository/TopicCustomRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.smeem.topic.repository; - -import com.smeme.server.model.topic.Topic; - -public interface TopicCustomRepository { - Topic getRandom(); -} diff --git a/smeem-external/build.gradle b/smeem-external/build.gradle index 3a1f9c05..94a1383d 100644 --- a/smeem-external/build.gradle +++ b/smeem-external/build.gradle @@ -1,19 +1,17 @@ -plugins { - id 'java' -} +dependencies { + implementation project(':smeem-common') -group = 'com.smeme' -version = '0.0.1-SNAPSHOT' + implementation 'org.springframework.boot:spring-boot-starter-web' -repositories { - mavenCentral() -} + implementation 'com.google.code.gson:gson:2.10.1' + implementation 'javax.xml.bind:jaxb-api:2.4.0-b180830.0359' -dependencies { - testImplementation platform('org.junit:junit-bom:5.9.1') - testImplementation 'org.junit.jupiter:junit-jupiter' -} + // fcm + implementation 'com.google.firebase:firebase-admin:9.1.1' + implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.2.2' -test { - useJUnitPlatform() + // JWT + implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.5' + implementation group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.5' + implementation group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.5' } \ No newline at end of file diff --git a/smeem-external/src/main/java/com/smeem/apple/AppleSignInService.java b/smeem-external/src/main/java/com/smeem/external/apple/AppleSignInService.java similarity index 88% rename from smeem-external/src/main/java/com/smeem/apple/AppleSignInService.java rename to smeem-external/src/main/java/com/smeem/external/apple/AppleSignInService.java index 2647d42f..ff72e4ef 100644 --- a/smeem-external/src/main/java/com/smeem/apple/AppleSignInService.java +++ b/smeem-external/src/main/java/com/smeem/external/apple/AppleSignInService.java @@ -1,13 +1,14 @@ -package com.smeem.apple; +package com.smeem.external.apple; import com.google.gson.*; -import com.smeme.server.config.ValueConfig; -import com.smeme.server.config.jwt.RestTemplateConfig; +import com.smeem.common.config.RestTemplateConfig; +import com.smeem.common.config.ValueConfig; + import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpMethod; -import org.springframework.stereotype.Service; +import org.springframework.stereotype.Component; import java.io.BufferedReader; import java.io.IOException; @@ -24,13 +25,13 @@ import java.util.Objects; @RequiredArgsConstructor -@Service +@Component public class AppleSignInService { private final ValueConfig valueConfig; private final RestTemplateConfig restTemplateConfig; - protected JsonArray getApplePublicKeys() { + public JsonArray getApplePublicKeys() { try { URL url = new URL(valueConfig.getAPPLE_URL()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); @@ -51,7 +52,7 @@ protected JsonArray getApplePublicKeys() { } } - protected PublicKey makePublicKey(String accessToken, JsonArray publicKeyList) throws NoSuchAlgorithmException, InvalidKeySpecException { + public PublicKey makePublicKey(String accessToken, JsonArray publicKeyList) throws NoSuchAlgorithmException, InvalidKeySpecException { JsonObject selectedObject = null; String[] decodeArray = accessToken.split("\\."); @@ -78,7 +79,7 @@ protected PublicKey makePublicKey(String accessToken, JsonArray publicKeyList) t return getPublicKey(selectedObject); } - protected String getAppleData(String socialAccessToken) throws NoSuchAlgorithmException, InvalidKeySpecException { + public String getAppleData(String socialAccessToken) throws NoSuchAlgorithmException, InvalidKeySpecException { JsonArray publicKeyList = getApplePublicKeys(); PublicKey publicKey = makePublicKey(socialAccessToken, publicKeyList); diff --git a/smeem-external/src/main/java/com/smeem/firebase/MessageDTO.java b/smeem-external/src/main/java/com/smeem/external/firebase/MessageDTO.java similarity index 93% rename from smeem-external/src/main/java/com/smeem/firebase/MessageDTO.java rename to smeem-external/src/main/java/com/smeem/external/firebase/MessageDTO.java index 7f391a3f..a666be27 100644 --- a/smeem-external/src/main/java/com/smeem/firebase/MessageDTO.java +++ b/smeem-external/src/main/java/com/smeem/external/firebase/MessageDTO.java @@ -1,4 +1,4 @@ -package com.smeem.firebase; +package com.smeem.external.firebase; import lombok.Builder; diff --git a/smeem-external/src/main/java/com/smeem/external/firebase/MessageService.java b/smeem-external/src/main/java/com/smeem/external/firebase/MessageService.java new file mode 100644 index 00000000..482f70d3 --- /dev/null +++ b/smeem-external/src/main/java/com/smeem/external/firebase/MessageService.java @@ -0,0 +1,74 @@ +package com.smeem.external.firebase; + + +import java.io.IOException; +import java.time.LocalDateTime; +import java.util.List; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import org.springframework.core.io.ClassPathResource; +import org.springframework.stereotype.Service; + +import com.google.auth.oauth2.GoogleCredentials; + +import lombok.RequiredArgsConstructor; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; + +@Service +@RequiredArgsConstructor +//@Transactional(readOnly = true) +public class MessageService { +// +// private final ObjectMapper objectMapper; +// private final TrainingTimeRepository trainingTimeRepository; +// private final MemberRepository memberRepository; +// private final ValueConfig valueConfig; +// +// public void pushMessageForTrainingTime(LocalDateTime now, String title, String body) { +// trainingTimeRepository.getTrainingTimeForPushAlarm(now) +// .forEach(trainingTime -> pushMessage(trainingTime.getMember().getFcmToken(), title, body)); +// } +// +// public void pushTest(String title, String body, Long memberId) { +// Member member = memberRepository.findById(memberId) +// .orElseThrow(() -> new EntityNotFoundException(ErrorMessage.INVALID_MEMBER.getMessage())); +// pushMessage(member.getFcmToken(), title, body); +// } +// +// private void pushMessage(String targetToken, String title, String body) { +// try { +// String message = makeMessage(targetToken, title, body); +// RequestBody requestBody = RequestBody.create(message, MediaType.get("application/json; charset=utf-8")); +// +// Request request = new Request.Builder() +// .url(valueConfig.getFIREBASE_API_URI()) +// .post(requestBody) +// .addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + getAccessToken()) +// .addHeader("Accept", "application/json; UTF-8") +// .build(); +// +// OkHttpClient client = new OkHttpClient(); +// client.newCall(request).execute(); +// } catch (Exception e) { +// throw new RuntimeException(e); +// } +// } +// +// private String makeMessage(String targetToken, String title, String body) throws JsonProcessingException { +// MessageDTO message = MessageDTO.of(targetToken, title, body); +// return objectMapper.writeValueAsString(message); +// } +// +// private String getAccessToken() throws IOException { +// GoogleCredentials googleCredentials = GoogleCredentials +// .fromStream(new ClassPathResource(valueConfig.getFIREBASE_CONFIG_PATH()).getInputStream()) +// .createScoped(List.of(valueConfig.getGOOGLE_API_URI())); +// googleCredentials.refreshIfExpired(); +// return googleCredentials.getAccessToken().getTokenValue(); +// } +} diff --git a/smeem-external/src/main/java/com/smeem/kakao/KakaoSignInService.java b/smeem-external/src/main/java/com/smeem/external/kakao/KakaoSignInService.java similarity index 88% rename from smeem-external/src/main/java/com/smeem/kakao/KakaoSignInService.java rename to smeem-external/src/main/java/com/smeem/external/kakao/KakaoSignInService.java index bf196f8c..02d21632 100644 --- a/smeem-external/src/main/java/com/smeem/kakao/KakaoSignInService.java +++ b/smeem-external/src/main/java/com/smeem/external/kakao/KakaoSignInService.java @@ -1,8 +1,8 @@ -package com.smeem.kakao; +package com.smeem.external.kakao; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.JsonArray; -import com.smeme.server.config.ValueConfig; +import com.smeem.common.config.ValueConfig; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -18,7 +18,7 @@ public class KakaoSignInService { private final ValueConfig valueConfig; - protected String getKakaoData(String accessToken) { + public String getKakaoData(String accessToken) { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", accessToken); diff --git a/smeem-external/src/main/java/com/smeem/firebase/MessageService.java b/smeem-external/src/main/java/com/smeem/firebase/MessageService.java deleted file mode 100644 index e9043c17..00000000 --- a/smeem-external/src/main/java/com/smeem/firebase/MessageService.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.smeem.firebase; - -import static org.springframework.http.HttpHeaders.*; - -import java.io.IOException; -import java.time.LocalDateTime; -import java.util.List; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; - -import com.smeme.server.config.ValueConfig; -import org.springframework.core.io.ClassPathResource; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import com.google.auth.oauth2.GoogleCredentials; -import com.smeme.server.dto.message.MessageDTO; -import com.smeme.server.model.Member; -import com.smeme.server.repository.MemberRepository; -import com.smeme.server.repository.trainingTime.TrainingTimeRepository; -import com.smeme.server.util.message.ErrorMessage; - -import jakarta.persistence.EntityNotFoundException; -import lombok.RequiredArgsConstructor; -import okhttp3.MediaType; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.RequestBody; - -@Service -@RequiredArgsConstructor -@Transactional(readOnly = true) -public class MessageService { - - private final ObjectMapper objectMapper; - private final TrainingTimeRepository trainingTimeRepository; - private final MemberRepository memberRepository; - private final ValueConfig valueConfig; - - public void pushMessageForTrainingTime(LocalDateTime now, String title, String body) { - trainingTimeRepository.getTrainingTimeForPushAlarm(now) - .forEach(trainingTime -> pushMessage(trainingTime.getMember().getFcmToken(), title, body)); - } - - public void pushTest(String title, String body, Long memberId) { - Member member = memberRepository.findById(memberId) - .orElseThrow(() -> new EntityNotFoundException(ErrorMessage.INVALID_MEMBER.getMessage())); - pushMessage(member.getFcmToken(), title, body); - } - - private void pushMessage(String targetToken, String title, String body) { - try { - String message = makeMessage(targetToken, title, body); - RequestBody requestBody = RequestBody.create(message, MediaType.get("application/json; charset=utf-8")); - - Request request = new Request.Builder() - .url(valueConfig.getFIREBASE_API_URI()) - .post(requestBody) - .addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + getAccessToken()) - .addHeader("Accept", "application/json; UTF-8") - .build(); - - OkHttpClient client = new OkHttpClient(); - client.newCall(request).execute(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - private String makeMessage(String targetToken, String title, String body) throws JsonProcessingException { - MessageDTO message = MessageDTO.of(targetToken, title, body); - return objectMapper.writeValueAsString(message); - } - - private String getAccessToken() throws IOException { - GoogleCredentials googleCredentials = GoogleCredentials - .fromStream(new ClassPathResource(valueConfig.getFIREBASE_CONFIG_PATH()).getInputStream()) - .createScoped(List.of(valueConfig.getGOOGLE_API_URI())); - googleCredentials.refreshIfExpired(); - return googleCredentials.getAccessToken().getTokenValue(); - } -} From caecdcb4e5f5f00137072b54812d37b2e6e5a2cd Mon Sep 17 00:00:00 2001 From: unanchoi Date: Wed, 7 Feb 2024 00:59:01 +0900 Subject: [PATCH 16/86] =?UTF-8?q?Refactor:=20Test=20Directory=20Package=20?= =?UTF-8?q?=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smeem/{ => api}/controller/AuthControllerTest.java | 4 ++-- .../smeem/{ => api}/controller/BadgeControllerTest.java | 4 ++-- .../smeem/{ => api}/controller/BaseControllerTest.java | 2 +- .../smeem/{ => api}/controller/DiaryControllerTest.java | 2 +- .../smeem/{ => api}/controller/GoalControllerTest.java | 2 +- .../smeem/{ => api}/controller/MemberControllerTest.java | 4 ++-- .../smeem/{ => api}/controller/TestControllerTest.java | 2 +- .../smeem/{ => api}/controller/TopicControllerTest.java | 2 +- .../com/smeem/{ => api}/fixture/auth/AuthFixture.java | 2 +- .../com/smeem/{ => api}/fixture/badge/BadgeFixture.java | 7 +------ .../com/smeem/{ => api}/fixture/diary/DiaryFixture.java | 6 +++--- .../com/smeem/{ => api}/fixture/goal/GoalFixture.java | 2 +- .../com/smeem/{ => api}/fixture/member/MemberFixture.java | 8 ++++---- .../smeem/api/fixture/memberbadge/MemberBadgeFixture.java | 4 ++++ .../com/smeem/{ => api}/fixture/topic/TopicFixture.java | 2 +- .../fixture/trainingtime/TrainingTimeFixture.java | 4 ++-- .../com/smeem/fixture/memberbadge/MemberBadgeFixture.java | 4 ---- 17 files changed, 28 insertions(+), 33 deletions(-) rename smeem-api/src/test/java/com/smeem/{ => api}/controller/AuthControllerTest.java (99%) rename smeem-api/src/test/java/com/smeem/{ => api}/controller/BadgeControllerTest.java (97%) rename smeem-api/src/test/java/com/smeem/{ => api}/controller/BaseControllerTest.java (98%) rename smeem-api/src/test/java/com/smeem/{ => api}/controller/DiaryControllerTest.java (99%) rename smeem-api/src/test/java/com/smeem/{ => api}/controller/GoalControllerTest.java (99%) rename smeem-api/src/test/java/com/smeem/{ => api}/controller/MemberControllerTest.java (99%) rename smeem-api/src/test/java/com/smeem/{ => api}/controller/TestControllerTest.java (98%) rename smeem-api/src/test/java/com/smeem/{ => api}/controller/TopicControllerTest.java (99%) rename smeem-api/src/test/java/com/smeem/{ => api}/fixture/auth/AuthFixture.java (97%) rename smeem-api/src/test/java/com/smeem/{ => api}/fixture/badge/BadgeFixture.java (86%) rename smeem-api/src/test/java/com/smeem/{ => api}/fixture/diary/DiaryFixture.java (82%) rename smeem-api/src/test/java/com/smeem/{ => api}/fixture/goal/GoalFixture.java (95%) rename smeem-api/src/test/java/com/smeem/{ => api}/fixture/member/MemberFixture.java (90%) create mode 100644 smeem-api/src/test/java/com/smeem/api/fixture/memberbadge/MemberBadgeFixture.java rename smeem-api/src/test/java/com/smeem/{ => api}/fixture/topic/TopicFixture.java (94%) rename smeem-api/src/test/java/com/smeem/{ => api}/fixture/trainingtime/TrainingTimeFixture.java (91%) delete mode 100644 smeem-api/src/test/java/com/smeem/fixture/memberbadge/MemberBadgeFixture.java diff --git a/smeem-api/src/test/java/com/smeem/controller/AuthControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/AuthControllerTest.java similarity index 99% rename from smeem-api/src/test/java/com/smeem/controller/AuthControllerTest.java rename to smeem-api/src/test/java/com/smeem/api/controller/AuthControllerTest.java index 937c25b8..9e97f155 100644 --- a/smeem-api/src/test/java/com/smeem/controller/AuthControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/AuthControllerTest.java @@ -1,8 +1,8 @@ -package com.smeem.controller; +package com.smeem.api.controller; import com.epages.restdocs.apispec.ResourceSnippetParameters; -import com.smeem.fixture.auth.AuthFixture; +import com.smeem.api.fixture.auth.AuthFixture; import lombok.val; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/smeem-api/src/test/java/com/smeem/controller/BadgeControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/BadgeControllerTest.java similarity index 97% rename from smeem-api/src/test/java/com/smeem/controller/BadgeControllerTest.java rename to smeem-api/src/test/java/com/smeem/api/controller/BadgeControllerTest.java index 3d6ecf99..d5645fce 100644 --- a/smeem-api/src/test/java/com/smeem/controller/BadgeControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/BadgeControllerTest.java @@ -1,7 +1,7 @@ -package com.smeem.controller; +package com.smeem.api.controller; import com.epages.restdocs.apispec.ResourceSnippetParameters; -import com.smeem.fixture.badge.BadgeFixture; +import com.smeem.api.fixture.badge.BadgeFixture; import lombok.val; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/smeem-api/src/test/java/com/smeem/controller/BaseControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/BaseControllerTest.java similarity index 98% rename from smeem-api/src/test/java/com/smeem/controller/BaseControllerTest.java rename to smeem-api/src/test/java/com/smeem/api/controller/BaseControllerTest.java index 566ee875..0eec52af 100644 --- a/smeem-api/src/test/java/com/smeem/controller/BaseControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/BaseControllerTest.java @@ -1,4 +1,4 @@ -package com.smeem.controller; +package com.smeem.api.controller; import com.fasterxml.jackson.databind.ObjectMapper; import com.smeme.server.config.jwt.CustomJwtAuthenticationEntryPoint; diff --git a/smeem-api/src/test/java/com/smeem/controller/DiaryControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java similarity index 99% rename from smeem-api/src/test/java/com/smeem/controller/DiaryControllerTest.java rename to smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java index 381ac61d..632749f3 100644 --- a/smeem-api/src/test/java/com/smeem/controller/DiaryControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java @@ -1,4 +1,4 @@ -package com.smeem.controller; +package com.smeem.api.controller; import com.epages.restdocs.apispec.ResourceSnippetParameters; import com.smeme.server.dto.badge.AcquiredBadgeResponseDTO; diff --git a/smeem-api/src/test/java/com/smeem/controller/GoalControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java similarity index 99% rename from smeem-api/src/test/java/com/smeem/controller/GoalControllerTest.java rename to smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java index 7a81d5cf..476c6d53 100644 --- a/smeem-api/src/test/java/com/smeem/controller/GoalControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java @@ -1,4 +1,4 @@ -package com.smeem.controller; +package com.smeem.api.controller; import com.epages.restdocs.apispec.ResourceSnippetParameters; import com.smeme.server.dto.goal.GoalResponseDTO; diff --git a/smeem-api/src/test/java/com/smeem/controller/MemberControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/MemberControllerTest.java similarity index 99% rename from smeem-api/src/test/java/com/smeem/controller/MemberControllerTest.java rename to smeem-api/src/test/java/com/smeem/api/controller/MemberControllerTest.java index 2f4811d4..f742bcdc 100644 --- a/smeem-api/src/test/java/com/smeem/controller/MemberControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/MemberControllerTest.java @@ -1,9 +1,9 @@ -package com.smeem.controller; +package com.smeem.api.controller; import com.epages.restdocs.apispec.ResourceSnippetParameters; import com.smeem.api.member.controller.MemberController; -import com.smeem.fixture.member.MemberFixture; +import com.smeem.api.fixture.member.MemberFixture; import lombok.val; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/smeem-api/src/test/java/com/smeem/controller/TestControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/TestControllerTest.java similarity index 98% rename from smeem-api/src/test/java/com/smeem/controller/TestControllerTest.java rename to smeem-api/src/test/java/com/smeem/api/controller/TestControllerTest.java index 60a621bd..58073e60 100644 --- a/smeem-api/src/test/java/com/smeem/controller/TestControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/TestControllerTest.java @@ -1,4 +1,4 @@ -package com.smeem.controller; +package com.smeem.api.controller; import com.epages.restdocs.apispec.ResourceSnippetParameters; import com.smeme.server.util.ApiResponse; diff --git a/smeem-api/src/test/java/com/smeem/controller/TopicControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java similarity index 99% rename from smeem-api/src/test/java/com/smeem/controller/TopicControllerTest.java rename to smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java index 232fa67d..514ab386 100644 --- a/smeem-api/src/test/java/com/smeem/controller/TopicControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java @@ -1,4 +1,4 @@ -package com.smeem.controller; +package com.smeem.api.controller; import com.epages.restdocs.apispec.ResourceSnippetParameters; import com.smeme.server.dto.topic.TopicResponseDTO; diff --git a/smeem-api/src/test/java/com/smeem/fixture/auth/AuthFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/auth/AuthFixture.java similarity index 97% rename from smeem-api/src/test/java/com/smeem/fixture/auth/AuthFixture.java rename to smeem-api/src/test/java/com/smeem/api/fixture/auth/AuthFixture.java index c902d81b..383fc3a4 100644 --- a/smeem-api/src/test/java/com/smeem/fixture/auth/AuthFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/auth/AuthFixture.java @@ -1,4 +1,4 @@ -package com.smeem.fixture.auth; +package com.smeem.api.fixture.auth; import com.smeme.server.dto.auth.SignInRequestDTO; import com.smeme.server.dto.auth.SignInResponseDTO; diff --git a/smeem-api/src/test/java/com/smeem/fixture/badge/BadgeFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/badge/BadgeFixture.java similarity index 86% rename from smeem-api/src/test/java/com/smeem/fixture/badge/BadgeFixture.java rename to smeem-api/src/test/java/com/smeem/api/fixture/badge/BadgeFixture.java index 14b27091..33671a61 100644 --- a/smeem-api/src/test/java/com/smeem/fixture/badge/BadgeFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/badge/BadgeFixture.java @@ -1,9 +1,4 @@ -package com.smeem.fixture.badge; - -import com.smeme.server.dto.badge.BadgeListResponseDTO; -import com.smeme.server.dto.badge.BadgeListResponseDTO.BadgeTypeResponseDTO; -import com.smeme.server.dto.badge.BadgeResponseDTO; -import com.smeme.server.model.badge.BadgeType; +package com.smeem.api.fixture.badge; import java.util.List; import java.util.stream.Stream; diff --git a/smeem-api/src/test/java/com/smeem/fixture/diary/DiaryFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/diary/DiaryFixture.java similarity index 82% rename from smeem-api/src/test/java/com/smeem/fixture/diary/DiaryFixture.java rename to smeem-api/src/test/java/com/smeem/api/fixture/diary/DiaryFixture.java index 34a4091e..5f63d4a0 100644 --- a/smeem-api/src/test/java/com/smeem/fixture/diary/DiaryFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/diary/DiaryFixture.java @@ -1,7 +1,7 @@ -package com.smeem.fixture.diary; +package com.smeem.api.fixture.diary; -import com.smeem.fixture.member.MemberFixture; -import com.smeem.fixture.topic.TopicFixture; +import com.smeem.api.fixture.member.MemberFixture; +import com.smeem.api.fixture.topic.TopicFixture; import com.smeme.server.model.Diary; import com.smeme.server.model.LangType; diff --git a/smeem-api/src/test/java/com/smeem/fixture/goal/GoalFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/goal/GoalFixture.java similarity index 95% rename from smeem-api/src/test/java/com/smeem/fixture/goal/GoalFixture.java rename to smeem-api/src/test/java/com/smeem/api/fixture/goal/GoalFixture.java index e7c5694f..9352ce94 100644 --- a/smeem-api/src/test/java/com/smeem/fixture/goal/GoalFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/goal/GoalFixture.java @@ -1,4 +1,4 @@ -package com.smeem.fixture.goal; +package com.smeem.api.fixture.goal; import com.smeme.server.dto.goal.GoalResponseDTO; import com.smeme.server.model.goal.Goal; diff --git a/smeem-api/src/test/java/com/smeem/fixture/member/MemberFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/member/MemberFixture.java similarity index 90% rename from smeem-api/src/test/java/com/smeem/fixture/member/MemberFixture.java rename to smeem-api/src/test/java/com/smeem/api/fixture/member/MemberFixture.java index e66fb8c6..ae6be95a 100644 --- a/smeem-api/src/test/java/com/smeem/fixture/member/MemberFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/member/MemberFixture.java @@ -1,8 +1,8 @@ -package com.smeem.fixture.member; +package com.smeem.api.fixture.member; -import com.smeem.fixture.badge.BadgeFixture; -import com.smeem.fixture.goal.GoalFixture; -import com.smeem.fixture.trainingtime.TrainingTimeFixture; +import com.smeem.api.fixture.goal.GoalFixture; +import com.smeem.api.fixture.badge.BadgeFixture; +import com.smeem.api.fixture.trainingtime.TrainingTimeFixture; import com.smeme.server.model.LangType; import com.smeme.server.model.Member; import com.smeme.server.model.SocialType; diff --git a/smeem-api/src/test/java/com/smeem/api/fixture/memberbadge/MemberBadgeFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/memberbadge/MemberBadgeFixture.java new file mode 100644 index 00000000..e52cb105 --- /dev/null +++ b/smeem-api/src/test/java/com/smeem/api/fixture/memberbadge/MemberBadgeFixture.java @@ -0,0 +1,4 @@ +package com.smeem.api.fixture.memberbadge; + +public class MemberBadgeFixture { +} diff --git a/smeem-api/src/test/java/com/smeem/fixture/topic/TopicFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/topic/TopicFixture.java similarity index 94% rename from smeem-api/src/test/java/com/smeem/fixture/topic/TopicFixture.java rename to smeem-api/src/test/java/com/smeem/api/fixture/topic/TopicFixture.java index dec46c0b..28899f17 100644 --- a/smeem-api/src/test/java/com/smeem/fixture/topic/TopicFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/topic/TopicFixture.java @@ -1,4 +1,4 @@ -package com.smeem.fixture.topic; +package com.smeem.api.fixture.topic; import com.smeme.server.dto.topic.TopicResponseDTO; import com.smeme.server.model.topic.Category; diff --git a/smeem-api/src/test/java/com/smeem/fixture/trainingtime/TrainingTimeFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/trainingtime/TrainingTimeFixture.java similarity index 91% rename from smeem-api/src/test/java/com/smeem/fixture/trainingtime/TrainingTimeFixture.java rename to smeem-api/src/test/java/com/smeem/api/fixture/trainingtime/TrainingTimeFixture.java index 8a2b0b68..33ef600f 100644 --- a/smeem-api/src/test/java/com/smeem/fixture/trainingtime/TrainingTimeFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/trainingtime/TrainingTimeFixture.java @@ -1,8 +1,8 @@ -package com.smeem.fixture.trainingtime; +package com.smeem.api.fixture.trainingtime; +import com.smeem.api.fixture.member.MemberFixture; import com.smeme.server.dto.training.TrainingTimeRequestDTO; import com.smeme.server.dto.training.TrainingTimeResponseDTO; -import com.smeem.fixture.member.MemberFixture; import com.smeme.server.model.training.DayType; import com.smeme.server.model.training.TrainingTime; diff --git a/smeem-api/src/test/java/com/smeem/fixture/memberbadge/MemberBadgeFixture.java b/smeem-api/src/test/java/com/smeem/fixture/memberbadge/MemberBadgeFixture.java deleted file mode 100644 index 0a9b2488..00000000 --- a/smeem-api/src/test/java/com/smeem/fixture/memberbadge/MemberBadgeFixture.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.smeem.fixture.memberbadge; - -public class MemberBadgeFixture { -} From c80dc5d7ab95a20ce39aa8a2b79d7e3fb5f197b3 Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 7 Feb 2024 01:47:06 +0900 Subject: [PATCH 17/86] =?UTF-8?q?[ADD]=20Success=20Code=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smeem/common/code/ResponseMessage.java | 53 ------------------- .../common/code/success/AuthSuccessCode.java | 23 ++++++++ .../common/code/success/BadgeSuccessCode.java | 21 ++++++++ .../common/code/success/DiarySuccessCode.java | 30 +++++++++++ .../common/code/success/GoalSuccessCode.java | 22 ++++++++ .../code/success/MemberSuccessCode.java | 25 +++++++++ .../code/success/MessageSuccessCode.java | 21 ++++++++ .../common/code/success/SuccessCode.java | 8 +++ .../common/code/success/TokenSuccessCode.java | 21 ++++++++ .../common/code/success/TopicSuccessCode.java | 21 ++++++++ 10 files changed, 192 insertions(+), 53 deletions(-) delete mode 100644 smeem-common/src/main/java/com/smeem/common/code/ResponseMessage.java create mode 100644 smeem-common/src/main/java/com/smeem/common/code/success/AuthSuccessCode.java create mode 100644 smeem-common/src/main/java/com/smeem/common/code/success/BadgeSuccessCode.java create mode 100644 smeem-common/src/main/java/com/smeem/common/code/success/DiarySuccessCode.java create mode 100644 smeem-common/src/main/java/com/smeem/common/code/success/GoalSuccessCode.java create mode 100644 smeem-common/src/main/java/com/smeem/common/code/success/MemberSuccessCode.java create mode 100644 smeem-common/src/main/java/com/smeem/common/code/success/MessageSuccessCode.java create mode 100644 smeem-common/src/main/java/com/smeem/common/code/success/SuccessCode.java create mode 100644 smeem-common/src/main/java/com/smeem/common/code/success/TokenSuccessCode.java create mode 100644 smeem-common/src/main/java/com/smeem/common/code/success/TopicSuccessCode.java diff --git a/smeem-common/src/main/java/com/smeem/common/code/ResponseMessage.java b/smeem-common/src/main/java/com/smeem/common/code/ResponseMessage.java deleted file mode 100644 index 4cc9996f..00000000 --- a/smeem-common/src/main/java/com/smeem/common/code/ResponseMessage.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.smeem.common.code; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -@AllArgsConstructor -@Getter -public enum ResponseMessage { - // com.smeem.diary - SUCCESS_CREATE_DIARY("일기 생성 성공"), - SUCCESS_GET_DIARY("일기 상세 조회 성공"), - SUCCESS_UPDATE_DAIRY("일기 수정 성공"), - SUCCESS_DELETE_DIARY("일기 삭제 성공"), - SUCCESS_GET_DIARIES("일기 리스트 조회 성공"), - - // com.smeem.topic - SUCCESS_GET_RANDOM_TOPIC("랜덤 주제 조회 성공"), - - // badges - SUCCESS_GET_BADGES("뱃지 리스트 조회 성공"), - - // correction - SUCCESS_CREATE_CORRECTION("일기 첨삭 성공"), - SUCCESS_DELETE_CORRECTION("첨삭 삭제 성공"), - SUCCESS_UPDATE_CORRECTION("첨삭 수정 성공"), - - // com.smeem.member - SUCCESS_UPDATE_USERNAME("닉네임 변경 성공"), - SUCCESS_GET_USER("회원 정보 조회 성공"), - SUCCESS_UPDATE_USER_PLAN("회원 학습 계획 업데이트 성공"), - SUCCESS_CHECK_DUPLICATED_NAME("닉네임 중복 검사 성공"), - SUCCESS_UPDATE_USER_PUSH("회원 푸시알람 동의여부 업데이트 성공"), - - // message - SUCCESS_PUSH_MESSAGE("푸시알람 요청 성공"), - - // oauth - SUCCESS_SIGNIN("소셜로그인 성공"), - SUCCESS_SIGNOUT("로그아웃 성공"), - SUCCESS_WITHDRAW("회원 탈퇴 성공"), - - // jwt - SUCCESS_ISSUE_TOKEN("토큰 발급 성공"), - - // beta - SUCCESS_BETA_AUTH_TOKEN("임시토큰 발급 성공"), - - // com.smeem.goal - SUCCESS_GET_GOALS("학습 목표 리스트 조회 성공"), - SUCCESS_GET_GOAL("학습 목표 조회 성공"); - - private final String message; -} diff --git a/smeem-common/src/main/java/com/smeem/common/code/success/AuthSuccessCode.java b/smeem-common/src/main/java/com/smeem/common/code/success/AuthSuccessCode.java new file mode 100644 index 00000000..821130f7 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/code/success/AuthSuccessCode.java @@ -0,0 +1,23 @@ +package com.smeem.common.code.success; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.OK; + +@RequiredArgsConstructor +@Getter +public enum AuthSuccessCode implements SuccessCode { + + /** + * 200 Ok + */ + SUCCESS_SIGNIN(OK, "소셜로그인 성공"), + SUCCESS_SIGNOUT(OK, "로그아웃 성공"), + SUCCESS_WITHDRAW(OK, "회원 탈퇴 성공"), + ; + + private final HttpStatus status; + private final String message; +} diff --git a/smeem-common/src/main/java/com/smeem/common/code/success/BadgeSuccessCode.java b/smeem-common/src/main/java/com/smeem/common/code/success/BadgeSuccessCode.java new file mode 100644 index 00000000..d6a11437 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/code/success/BadgeSuccessCode.java @@ -0,0 +1,21 @@ +package com.smeem.common.code.success; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.OK; + +@RequiredArgsConstructor +@Getter +public enum BadgeSuccessCode implements SuccessCode { + + /** + * 200 Ok + */ + SUCCESS_GET_BADGES(OK, "뱃지 리스트 조회 성공"), + ; + + private final HttpStatus status; + private final String message; +} diff --git a/smeem-common/src/main/java/com/smeem/common/code/success/DiarySuccessCode.java b/smeem-common/src/main/java/com/smeem/common/code/success/DiarySuccessCode.java new file mode 100644 index 00000000..7472d777 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/code/success/DiarySuccessCode.java @@ -0,0 +1,30 @@ +package com.smeem.common.code.success; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.OK; + +@RequiredArgsConstructor +@Getter +public enum DiarySuccessCode implements SuccessCode { + + /** + * 200 Ok + */ + SUCCESS_GET_DIARY(OK, "일기 상세 조회 성공"), + SUCCESS_UPDATE_DAIRY(OK, "일기 수정 성공"), + SUCCESS_DELETE_DIARY(OK, "일기 삭제 성공"), + SUCCESS_GET_DIARIES(OK, "일기 리스트 조회 성공"), + + /** + * 201 Created + */ + SUCCESS_CREATE_DIARY(CREATED, "일기 생성 성공"), + ; + + private final HttpStatus status; + private final String message; +} diff --git a/smeem-common/src/main/java/com/smeem/common/code/success/GoalSuccessCode.java b/smeem-common/src/main/java/com/smeem/common/code/success/GoalSuccessCode.java new file mode 100644 index 00000000..46848ce3 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/code/success/GoalSuccessCode.java @@ -0,0 +1,22 @@ +package com.smeem.common.code.success; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.OK; + +@RequiredArgsConstructor +@Getter +public enum GoalSuccessCode implements SuccessCode { + + /** + * 200 Ok + */ + SUCCESS_GET_GOALS(OK, "학습 목표 리스트 조회 성공"), + SUCCESS_GET_GOAL(OK, "학습 목표 조회 성공"); + ; + + private final HttpStatus status; + private final String message; +} diff --git a/smeem-common/src/main/java/com/smeem/common/code/success/MemberSuccessCode.java b/smeem-common/src/main/java/com/smeem/common/code/success/MemberSuccessCode.java new file mode 100644 index 00000000..93de7853 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/code/success/MemberSuccessCode.java @@ -0,0 +1,25 @@ +package com.smeem.common.code.success; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.OK; + +@RequiredArgsConstructor +@Getter +public enum MemberSuccessCode implements SuccessCode { + + /** + * 200 Ok + */ + SUCCESS_UPDATE_USERNAME(OK, "닉네임 변경 성공"), + SUCCESS_GET_USER(OK, "회원 정보 조회 성공"), + SUCCESS_UPDATE_USER_PLAN(OK, "회원 학습 계획 업데이트 성공"), + SUCCESS_CHECK_DUPLICATED_NAME(OK, "닉네임 중복 검사 성공"), + SUCCESS_UPDATE_USER_PUSH(OK, "회원 푸시알람 동의여부 업데이트 성공"), + ; + + private final HttpStatus status; + private final String message; +} diff --git a/smeem-common/src/main/java/com/smeem/common/code/success/MessageSuccessCode.java b/smeem-common/src/main/java/com/smeem/common/code/success/MessageSuccessCode.java new file mode 100644 index 00000000..23687531 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/code/success/MessageSuccessCode.java @@ -0,0 +1,21 @@ +package com.smeem.common.code.success; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.OK; + +@RequiredArgsConstructor +@Getter +public enum MessageSuccessCode implements SuccessCode { + + /** + * 200 Ok + */ + SUCCESS_PUSH_MESSAGE(OK, "푸시알람 요청 성공"), + ; + + private final HttpStatus status; + private final String message; +} diff --git a/smeem-common/src/main/java/com/smeem/common/code/success/SuccessCode.java b/smeem-common/src/main/java/com/smeem/common/code/success/SuccessCode.java new file mode 100644 index 00000000..2e9b6286 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/code/success/SuccessCode.java @@ -0,0 +1,8 @@ +package com.smeem.common.code.success; + +import org.springframework.http.HttpStatus; + +public interface SuccessCode { + HttpStatus getStatus(); + String getMessage(); +} diff --git a/smeem-common/src/main/java/com/smeem/common/code/success/TokenSuccessCode.java b/smeem-common/src/main/java/com/smeem/common/code/success/TokenSuccessCode.java new file mode 100644 index 00000000..06de450d --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/code/success/TokenSuccessCode.java @@ -0,0 +1,21 @@ +package com.smeem.common.code.success; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.OK; + +@RequiredArgsConstructor +@Getter +public enum TokenSuccessCode implements SuccessCode { + + /** + * 200 Ok + */ + SUCCESS_ISSUE_TOKEN(OK, "토큰 발급 성공"), + ; + + private final HttpStatus status; + private final String message; +} diff --git a/smeem-common/src/main/java/com/smeem/common/code/success/TopicSuccessCode.java b/smeem-common/src/main/java/com/smeem/common/code/success/TopicSuccessCode.java new file mode 100644 index 00000000..1c07140d --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/code/success/TopicSuccessCode.java @@ -0,0 +1,21 @@ +package com.smeem.common.code.success; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.OK; + +@RequiredArgsConstructor +@Getter +public enum TopicSuccessCode implements SuccessCode { + + /** + * 200 Ok + */ + SUCCESS_GET_RANDOM_TOPIC(OK, "랜덤 주제 조회 성공"), + ; + + private final HttpStatus status; + private final String message; +} From fcf8110f3eedd75b69487daf483b70b7f279de03 Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 7 Feb 2024 01:47:35 +0900 Subject: [PATCH 18/86] =?UTF-8?q?[REFACTOR]=20API=20=EA=B3=B5=ED=86=B5=20R?= =?UTF-8?q?esponse=20DTO=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/smeem/api/common/ApiResponse.java | 40 ------------------- .../com/smeem/api/common/ApiResponseUtil.java | 25 ++++++++++++ .../com/smeem/api/common/BaseResponse.java | 33 +++++++++++++++ 3 files changed, 58 insertions(+), 40 deletions(-) delete mode 100644 smeem-api/src/main/java/com/smeem/api/common/ApiResponse.java create mode 100644 smeem-api/src/main/java/com/smeem/api/common/ApiResponseUtil.java create mode 100644 smeem-api/src/main/java/com/smeem/api/common/BaseResponse.java diff --git a/smeem-api/src/main/java/com/smeem/api/common/ApiResponse.java b/smeem-api/src/main/java/com/smeem/api/common/ApiResponse.java deleted file mode 100644 index 96691126..00000000 --- a/smeem-api/src/main/java/com/smeem/api/common/ApiResponse.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.smeem.api.common; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Builder; -import lombok.NonNull; - -@Schema(description = "API 요청 응답 DTO") -@Builder -public record ApiResponse( - @Schema(description = "성공 여부") - boolean success, - @Schema(description = "응답 메세지") - @NonNull - String message, - @Schema(description = " 응답 데이터 || Null") - Object data -) { - - public static ApiResponse success(String message, Object data) { - return ApiResponse.builder() - .success(true) - .message(message) - .data(data) - .build(); - } - - public static ApiResponse success(String message) { - return ApiResponse.builder() - .success(true) - .message(message) - .build(); - } - - public static ApiResponse fail(String message) { - return ApiResponse.builder() - .success(false) - .message(message) - .build(); - } -} diff --git a/smeem-api/src/main/java/com/smeem/api/common/ApiResponseUtil.java b/smeem-api/src/main/java/com/smeem/api/common/ApiResponseUtil.java new file mode 100644 index 00000000..75564362 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/common/ApiResponseUtil.java @@ -0,0 +1,25 @@ +package com.smeem.api.common; + +import com.smeem.common.code.success.SuccessCode; +import org.springframework.http.ResponseEntity; + +public interface ApiResponseUtil { + + static ResponseEntity> success(SuccessCode code, T data) { + return ResponseEntity + .status(code.getStatus()) + .body(BaseResponse.of(code.getMessage(), data)); + } + + static ResponseEntity> success(SuccessCode code) { + return ResponseEntity + .status(code.getStatus()) + .body(BaseResponse.of(true, code.getMessage())); + } + +// static ResponseEntity> failure(FailureCode code) { +// return ResponseEntity +// .status(code.getStatus()) +// .body(BaseResponse.of(false, code.getMessage())); +// } +} diff --git a/smeem-api/src/main/java/com/smeem/api/common/BaseResponse.java b/smeem-api/src/main/java/com/smeem/api/common/BaseResponse.java new file mode 100644 index 00000000..3ddd319d --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/common/BaseResponse.java @@ -0,0 +1,33 @@ +package com.smeem.api.common; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Builder; + +import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL; +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +@AllArgsConstructor(access = PRIVATE) +public record BaseResponse( + boolean success, + String message, + @JsonInclude(value = NON_NULL) + T data +) { + + public static BaseResponse of(String message, T data) { + return BaseResponse.builder() + .success(true) + .message(message) + .data(data) + .build(); + } + + public static BaseResponse of(boolean isSuccess, String message) { + return BaseResponse.builder() + .success(isSuccess) + .message(message) + .build(); + } +} From 390612c2e0ff3f7f509d226cdef080bd9ad47964 Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 7 Feb 2024 01:48:17 +0900 Subject: [PATCH 19/86] =?UTF-8?q?[FIX]=20Auth=20:=20Success=20Code=20?= =?UTF-8?q?=EB=B0=8F=20DTO=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/auth/controller/AuthController.java | 24 ++++++++++--------- .../api/controller/AuthControllerTest.java | 16 ++++++------- .../smeem/api/fixture/auth/AuthFixture.java | 10 ++++---- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java b/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java index f2da4c16..3c197fba 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java @@ -4,8 +4,8 @@ import com.smeem.api.auth.controller.dto.response.SignInResponseDTO; import com.smeem.api.auth.controller.dto.response.token.TokenResponseDTO; import com.smeem.api.auth.service.AuthService; -import com.smeem.api.common.ApiResponse; -import com.smeem.common.code.ResponseMessage; +import com.smeem.api.common.ApiResponseUtil; +import com.smeem.api.common.BaseResponse; import com.smeem.common.util.Util; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -15,36 +15,38 @@ import java.security.Principal; import java.security.spec.InvalidKeySpecException; +import static com.smeem.common.code.success.AuthSuccessCode.*; +import static com.smeem.common.code.success.TokenSuccessCode.SUCCESS_ISSUE_TOKEN; @RestController @RequiredArgsConstructor -@RequestMapping("api/v2/com.smeem.auth") +@RequestMapping("api/v2/auth") public class AuthController { private final AuthService authService; @PostMapping - public ResponseEntity signIn(@RequestHeader("Authorization") String socialAccessToken, @RequestBody SignInRequestDTO request + public ResponseEntity> signIn(@RequestHeader("Authorization") String socialAccessToken, @RequestBody SignInRequestDTO request ) throws NoSuchAlgorithmException, InvalidKeySpecException { SignInResponseDTO response = authService.signIn(socialAccessToken, request); - return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_SIGNIN.getMessage(), response)); + return ApiResponseUtil.success(SUCCESS_SIGNIN, response); } @PostMapping("/token") - public ResponseEntity reissueToken(Principal principal) { + public ResponseEntity> reissueToken(Principal principal) { TokenResponseDTO response = authService.issueToken(Util.getMemberId(principal)); - return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_ISSUE_TOKEN.getMessage(), response)); + return ApiResponseUtil.success(SUCCESS_ISSUE_TOKEN, response); } @PostMapping("/sign-out") - public ResponseEntity signOut(Principal principal) { + public ResponseEntity> signOut(Principal principal) { authService.signOut(Util.getMemberId(principal)); - return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_SIGNOUT.getMessage())); + return ApiResponseUtil.success(SUCCESS_SIGNOUT); } @DeleteMapping - public ResponseEntity withDrawl(Principal principal) { + public ResponseEntity> withDrawl(Principal principal) { authService.withdraw(Util.getMemberId(principal)); - return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_WITHDRAW.getMessage())); + return ApiResponseUtil.success(SUCCESS_WITHDRAW); } } diff --git a/smeem-api/src/test/java/com/smeem/api/controller/AuthControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/AuthControllerTest.java index 9e97f155..adff384d 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/AuthControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/AuthControllerTest.java @@ -1,20 +1,20 @@ package com.smeem.api.controller; - import com.epages.restdocs.apispec.ResourceSnippetParameters; +import com.smeem.api.auth.controller.AuthController; +import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.fixture.auth.AuthFixture; import lombok.val; 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.ResponseEntity; import java.security.Principal; import static com.epages.restdocs.apispec.ResourceDocumentation.resource; -import static com.smeme.server.util.ApiResponse.success; -import static com.smeme.server.util.message.ResponseMessage.*; +import static com.smeem.common.code.success.AuthSuccessCode.*; +import static com.smeem.common.code.success.TokenSuccessCode.SUCCESS_ISSUE_TOKEN; import static org.mockito.Mockito.when; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; @@ -66,7 +66,7 @@ void success_signIn() throws Exception { ) .build(); // when - val result = ResponseEntity.ok(success(SUCCESS_SIGNIN.getMessage(), AuthFixture.createSignInResponseDTO())); + val result = ApiResponseUtil.success(SUCCESS_SIGNIN, AuthFixture.createSignInResponseDTO()); when(authController.signIn(SOCIAL_ACCESS_TOKEN , AuthFixture.createSignInRequestDTO())) .thenReturn(result); @@ -102,7 +102,7 @@ void success_reissueToken() throws Exception { ) .build(); // when - val result = ResponseEntity.ok(success(SUCCESS_ISSUE_TOKEN.getMessage(), AuthFixture.createTokenResponseDTO())); + val result = ApiResponseUtil.success(SUCCESS_ISSUE_TOKEN, AuthFixture.createTokenResponseDTO()); when(authController.reissueToken(principal)).thenReturn(result); @@ -132,7 +132,7 @@ void success_signOut() throws Exception { ) .build(); // when - val result = ResponseEntity.ok(success(SUCCESS_SIGNOUT.getMessage())); + val result = ApiResponseUtil.success(SUCCESS_SIGNOUT); when(authController.signOut(principal)).thenReturn(result); @@ -160,7 +160,7 @@ void success_withDrawl() throws Exception{ ) .build(); // when - val result = ResponseEntity.ok(success(SUCCESS_WITHDRAW.getMessage())); + val result = ApiResponseUtil.success(SUCCESS_WITHDRAW); when(authController.withDrawl(principal)).thenReturn(result); diff --git a/smeem-api/src/test/java/com/smeem/api/fixture/auth/AuthFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/auth/AuthFixture.java index 383fc3a4..16c4bfcf 100644 --- a/smeem-api/src/test/java/com/smeem/api/fixture/auth/AuthFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/auth/AuthFixture.java @@ -1,10 +1,10 @@ package com.smeem.api.fixture.auth; -import com.smeme.server.dto.auth.SignInRequestDTO; -import com.smeme.server.dto.auth.SignInResponseDTO; -import com.smeem.auth.controller.dto.response.token.TokenResponseDTO; -import com.smeem.auth.controller.dto.response.token.TokenVO; -import com.smeme.server.model.SocialType; +import com.smeem.api.auth.controller.dto.request.SignInRequestDTO; +import com.smeem.api.auth.controller.dto.response.SignInResponseDTO; +import com.smeem.api.auth.controller.dto.response.token.TokenResponseDTO; +import com.smeem.api.auth.controller.dto.response.token.TokenVO; +import com.smeem.domain.member.model.SocialType; public class AuthFixture { From f7da888ae5b6927cf2a2c339c0cc2765c286581d Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 7 Feb 2024 01:59:10 +0900 Subject: [PATCH 20/86] =?UTF-8?q?[FIX]=20Badge=20:=20Success=20Code=20?= =?UTF-8?q?=EB=B0=8F=20DTO=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smeem/api/badge/controller/BadgeController.java | 10 ++++++---- .../com/smeem/api/controller/BadgeControllerTest.java | 11 +++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java index 4317d287..301e992a 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java @@ -2,8 +2,8 @@ import com.smeem.api.badge.controller.dto.response.BadgeListResponseDTO; import com.smeem.api.badge.service.BadgeService; -import com.smeem.api.common.ApiResponse; -import com.smeem.common.code.ResponseMessage; +import com.smeem.api.common.ApiResponseUtil; +import com.smeem.api.common.BaseResponse; import com.smeem.common.util.Util; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -13,6 +13,8 @@ import java.security.Principal; +import static com.smeem.common.code.success.BadgeSuccessCode.SUCCESS_GET_BADGES; + @RestController @RequiredArgsConstructor @RequestMapping("/api/v2/members/badges") @@ -21,9 +23,9 @@ public class BadgeController { private final BadgeService badgeService; @GetMapping - public ResponseEntity getBadgeList(Principal principal) { + public ResponseEntity> getBadgeList(Principal principal) { BadgeListResponseDTO response = badgeService.getBadgeList(Util.getMemberId(principal)); - return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_GET_BADGES.getMessage(), response)); + return ApiResponseUtil.success(SUCCESS_GET_BADGES, response); } } diff --git a/smeem-api/src/test/java/com/smeem/api/controller/BadgeControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/BadgeControllerTest.java index d5645fce..09ebd6df 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/BadgeControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/BadgeControllerTest.java @@ -1,19 +1,19 @@ package com.smeem.api.controller; import com.epages.restdocs.apispec.ResourceSnippetParameters; +import com.smeem.api.badge.controller.BadgeController; +import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.fixture.badge.BadgeFixture; import lombok.val; 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.ResponseEntity; import java.security.Principal; import static com.epages.restdocs.apispec.ResourceDocumentation.resource; -import static com.smeme.server.util.ApiResponse.success; -import static com.smeme.server.util.message.ResponseMessage.SUCCESS_GET_BADGES; +import static com.smeem.common.code.success.BadgeSuccessCode.SUCCESS_GET_BADGES; import static org.mockito.Mockito.when; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; @@ -56,10 +56,9 @@ void success_getBadgesList() throws Exception { ) .build(); // when - val result = ResponseEntity.ok(success(SUCCESS_GET_BADGES.getMessage(), BadgeFixture.createBadgeListResponseDTO())); + val result = ApiResponseUtil.success(SUCCESS_GET_BADGES, BadgeFixture.createBadgeListResponseDTO()); - when(badgeController.getBadgeList(principal)) - .thenReturn(result); + when(badgeController.getBadgeList(principal)).thenReturn(result); mockMvc.perform(get(DEFAULT_URL) From c2b6f400059d9e5bfd7dd3ced727c9e07ca85503 Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 7 Feb 2024 02:09:07 +0900 Subject: [PATCH 21/86] =?UTF-8?q?[FIX]=20Diary=20:=20Success=20Code=20?= =?UTF-8?q?=EB=B0=8F=20DTO=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/smeem/api/common/ApiResponseUtil.java | 13 +++++-- .../api/diary/controller/DiaryController.java | 30 ++++++++-------- .../api/controller/DiaryControllerTest.java | 36 ++++++++++--------- 3 files changed, 46 insertions(+), 33 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/common/ApiResponseUtil.java b/smeem-api/src/main/java/com/smeem/api/common/ApiResponseUtil.java index 75564362..5f881b16 100644 --- a/smeem-api/src/main/java/com/smeem/api/common/ApiResponseUtil.java +++ b/smeem-api/src/main/java/com/smeem/api/common/ApiResponseUtil.java @@ -3,18 +3,27 @@ import com.smeem.common.code.success.SuccessCode; import org.springframework.http.ResponseEntity; +import java.net.URI; + public interface ApiResponseUtil { + static ResponseEntity> success(SuccessCode code) { + return ResponseEntity + .status(code.getStatus()) + .body(BaseResponse.of(true, code.getMessage())); + } + static ResponseEntity> success(SuccessCode code, T data) { return ResponseEntity .status(code.getStatus()) .body(BaseResponse.of(code.getMessage(), data)); } - static ResponseEntity> success(SuccessCode code) { + static ResponseEntity> success(SuccessCode code, URI uri, T data) { return ResponseEntity .status(code.getStatus()) - .body(BaseResponse.of(true, code.getMessage())); + .location(uri) + .body(BaseResponse.of(code.getMessage(), data)); } // static ResponseEntity> failure(FailureCode code) { diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java b/smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java index 51720de2..1ea239e9 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java @@ -3,14 +3,15 @@ import java.security.Principal; -import com.smeem.api.common.ApiResponse; +import com.smeem.api.common.ApiResponseUtil; +import com.smeem.api.common.BaseResponse; import com.smeem.api.diary.controller.dto.request.DiaryRequestDTO; import com.smeem.api.diary.controller.dto.response.CreatedDiaryResponseDTO; import com.smeem.api.diary.controller.dto.response.DiariesResponseDTO; import com.smeem.api.diary.controller.dto.response.DiaryResponseDTO; import com.smeem.api.diary.service.DiaryService; -import com.smeem.common.code.ResponseMessage; import com.smeem.common.util.Util; +import lombok.val; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -25,6 +26,8 @@ import lombok.RequiredArgsConstructor; +import static com.smeem.common.code.success.DiarySuccessCode.*; + @RestController @RequiredArgsConstructor @RequestMapping("/api/v2/diaries") @@ -32,38 +35,37 @@ public class DiaryController { private final DiaryService diaryService; @PostMapping - public ResponseEntity save(Principal principal, @RequestBody DiaryRequestDTO request) { + public ResponseEntity> save(Principal principal, @RequestBody DiaryRequestDTO request) { CreatedDiaryResponseDTO response = diaryService.save(Util.getMemberId(principal), request); - return ResponseEntity - .created(Util.getURI(response.diaryId())) - .body(ApiResponse.success(ResponseMessage.SUCCESS_CREATE_DIARY.getMessage(), response)); + val uri = Util.getURI("/{diaryId}", response.diaryId()); + return ApiResponseUtil.success(SUCCESS_CREATE_DIARY, uri, response); } @GetMapping("/{diaryId}") - public ResponseEntity getDetail(@PathVariable Long diaryId) { + public ResponseEntity> getDetail(@PathVariable Long diaryId) { DiaryResponseDTO response = diaryService.getDetail(diaryId); - return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_GET_DIARY.getMessage(), response)); + return ApiResponseUtil.success(SUCCESS_GET_DIARY, response); } @PatchMapping("/{diaryId}") - public ResponseEntity update(@PathVariable Long diaryId, @RequestBody DiaryRequestDTO request) { + public ResponseEntity> update(@PathVariable Long diaryId, @RequestBody DiaryRequestDTO request) { diaryService.update(diaryId, request); - return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_UPDATE_DAIRY.getMessage())); + return ApiResponseUtil.success(SUCCESS_UPDATE_DAIRY); } @DeleteMapping("/{diaryId}") - public ResponseEntity delete(@PathVariable Long diaryId) { + public ResponseEntity> delete(@PathVariable Long diaryId) { diaryService.delete(diaryId); - return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_DELETE_DIARY.getMessage())); + return ApiResponseUtil.success(SUCCESS_DELETE_DIARY); } @GetMapping - public ResponseEntity getDiaries( + public ResponseEntity> getDiaries( Principal principal, @RequestParam(name = "start") String startDate, @RequestParam(name = "end") String endDate ) { DiariesResponseDTO response = diaryService.getDiaries(Util.getMemberId(principal), startDate, endDate); - return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_GET_DIARIES.getMessage(), response)); + return ApiResponseUtil.success(SUCCESS_GET_DIARIES, response); } } diff --git a/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java index 632749f3..1b9bd7c5 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java @@ -1,14 +1,16 @@ package com.smeem.api.controller; import com.epages.restdocs.apispec.ResourceSnippetParameters; -import com.smeme.server.dto.badge.AcquiredBadgeResponseDTO; -import com.smeme.server.dto.diary.CreatedDiaryResponseDTO; -import com.smeme.server.dto.diary.DiariesResponseDTO; -import com.smeme.server.dto.diary.DiariesResponseDTO.DiaryDTO; -import com.smeme.server.dto.diary.DiaryRequestDTO; -import com.smeme.server.dto.diary.DiaryResponseDTO; -import com.smeme.server.model.badge.BadgeType; -import com.smeme.server.util.ApiResponse; +import com.smeem.api.badge.controller.dto.response.AcquiredBadgeResponseDTO; +import com.smeem.api.common.ApiResponseUtil; +import com.smeem.api.common.BaseResponse; +import com.smeem.api.diary.controller.DiaryController; +import com.smeem.api.diary.controller.dto.request.DiaryRequestDTO; +import com.smeem.api.diary.controller.dto.response.CreatedDiaryResponseDTO; +import com.smeem.api.diary.controller.dto.response.DiariesResponseDTO; +import com.smeem.api.diary.controller.dto.response.DiariesResponseDTO.DiaryDTO; +import com.smeem.api.diary.controller.dto.response.DiaryResponseDTO; +import lombok.val; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; @@ -24,7 +26,8 @@ import java.util.stream.Stream; import static com.epages.restdocs.apispec.ResourceDocumentation.resource; -import static com.smeme.server.util.ApiResponse.success; +import static com.smeem.common.code.success.DiarySuccessCode.*; +import static com.smeem.domain.badge.model.BadgeType.EVENT; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.when; import static org.springframework.http.MediaType.APPLICATION_JSON; @@ -55,9 +58,8 @@ void success_create_diary() throws Exception { // given DiaryRequestDTO request = new DiaryRequestDTO("Hello SMEEM!", 1L); CreatedDiaryResponseDTO response = new CreatedDiaryResponseDTO(1L, acquiredBadges()); - ResponseEntity result = ResponseEntity - .created(URI.create("localhost:8080/api/v2/diaries/1")) - .body(success("일기 작성 성공", response)); + val uri = URI.create("localhost:8080/api/v2/diaries/1"); + ResponseEntity> result = ApiResponseUtil.success(SUCCESS_CREATE_DIARY, uri, response); // when when(diaryController.save(principal, request)).thenReturn(result); @@ -108,7 +110,7 @@ void success_get_diary() throws Exception { "I want to go Bla Bla ...", "2023-08-19 14:00", "스미무"); - ResponseEntity result = ResponseEntity.ok(success("일기 조회 성공", response)); + ResponseEntity> result = ApiResponseUtil.success(SUCCESS_GET_DIARY, response); // when when(diaryController.getDetail(anyLong())).thenReturn(result); @@ -150,7 +152,7 @@ void success_update_diary() throws Exception { // given Long diaryId = 1L; DiaryRequestDTO request = new DiaryRequestDTO("Hello SMEEM!!", 1L); - ResponseEntity result = ResponseEntity.ok(success("일기 수정 성공")); + ResponseEntity> result = ApiResponseUtil.success(SUCCESS_UPDATE_DAIRY); // when when(diaryController.update(diaryId, request)).thenReturn(result); @@ -190,7 +192,7 @@ void success_update_diary() throws Exception { void success_delete_diary() throws Exception { // given Long diaryId = 1L; - ResponseEntity result = ResponseEntity.ok(success("일기 삭제 성공")); + ResponseEntity> result = ApiResponseUtil.success(SUCCESS_DELETE_DIARY); // when when(diaryController.delete(diaryId)).thenReturn(result); @@ -225,7 +227,7 @@ void success_delete_diary() throws Exception { void success_get_diaries() throws Exception { // given DiariesResponseDTO response = new DiariesResponseDTO(diaries(), true); - ResponseEntity result = ResponseEntity.ok(success("일기 리스트 조회 성공", response)); + ResponseEntity> result = ApiResponseUtil.success(SUCCESS_GET_DIARIES, response); MultiValueMap queries = new LinkedMultiValueMap<>(); String startDate = "2023-08-18 00:00"; @@ -275,7 +277,7 @@ private List acquiredBadges() { } private AcquiredBadgeResponseDTO acquiredBadge() { - return new AcquiredBadgeResponseDTO("뱃지 이름", "com.smeem.badge-image-url", BadgeType.EVENT); + return new AcquiredBadgeResponseDTO("뱃지 이름", "com.smeem.badge-image-url", EVENT); } private List diaries() { From 5a1cca2dddd743bc7146e8ad5035ad735034598c Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 7 Feb 2024 02:09:15 +0900 Subject: [PATCH 22/86] =?UTF-8?q?[FIX]=20Diary=20:=20Success=20Code=20?= =?UTF-8?q?=EB=B0=8F=20DTO=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smeem-common/src/main/java/com/smeem/common/util/Util.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/smeem-common/src/main/java/com/smeem/common/util/Util.java b/smeem-common/src/main/java/com/smeem/common/util/Util.java index 513d39f8..6e7b8de3 100644 --- a/smeem-common/src/main/java/com/smeem/common/util/Util.java +++ b/smeem-common/src/main/java/com/smeem/common/util/Util.java @@ -19,11 +19,11 @@ public static Long getMemberId(Principal principal) { return Long.valueOf(principal.getName()); } - public static URI getURI(Long diaryId) { + public static URI getURI(String path, long id) { return ServletUriComponentsBuilder .fromCurrentRequest() - .path("/{diaryId}") - .buildAndExpand(diaryId) + .path(path) + .buildAndExpand(id) .toUri(); } From e779e426084bffc3b78cae3505e22c83717af770 Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 7 Feb 2024 02:11:49 +0900 Subject: [PATCH 23/86] =?UTF-8?q?[FIX]=20Goal=20:=20Success=20Code=20?= =?UTF-8?q?=EB=B0=8F=20DTO=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/goal/controller/GoalController.java | 15 ++++++---- .../api/controller/GoalControllerTest.java | 29 ++++++++++--------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java b/smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java index 3d6eb0a5..4e850afc 100644 --- a/smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java @@ -1,11 +1,11 @@ package com.smeem.api.goal.controller; -import com.smeem.api.common.ApiResponse; +import com.smeem.api.common.ApiResponseUtil; +import com.smeem.api.common.BaseResponse; import com.smeem.api.goal.controller.dto.response.GoalResponseDTO; import com.smeem.api.goal.controller.dto.response.GoalsResponseDTO; import com.smeem.api.goal.service.GoalService; -import com.smeem.common.code.ResponseMessage; import com.smeem.domain.goal.model.GoalType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -15,6 +15,9 @@ import lombok.RequiredArgsConstructor; +import static com.smeem.common.code.success.GoalSuccessCode.SUCCESS_GET_GOAL; +import static com.smeem.common.code.success.GoalSuccessCode.SUCCESS_GET_GOALS; + @RestController @RequiredArgsConstructor @RequestMapping("/api/v2/goals") @@ -23,14 +26,14 @@ public class GoalController { private final GoalService goalService; @GetMapping - public ResponseEntity getAll() { + public ResponseEntity> getAll() { GoalsResponseDTO response = goalService.getAll(); - return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_GET_GOALS.getMessage(), response)); + return ApiResponseUtil.success(SUCCESS_GET_GOALS, response); } @GetMapping("/{type}") - public ResponseEntity getByType(@PathVariable GoalType type) { + public ResponseEntity> getByType(@PathVariable GoalType type) { GoalResponseDTO response = goalService.getByType(type); - return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_GET_GOAL.getMessage(), response)); + return ApiResponseUtil.success(SUCCESS_GET_GOAL, response); } } diff --git a/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java index 476c6d53..1322e2a5 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java @@ -1,23 +1,26 @@ package com.smeem.api.controller; import com.epages.restdocs.apispec.ResourceSnippetParameters; -import com.smeme.server.dto.goal.GoalResponseDTO; -import com.smeme.server.dto.goal.GoalsResponseDTO; -import com.smeme.server.dto.goal.GoalsResponseDTO.GoalResponseVO; -import com.smeme.server.model.goal.GoalType; -import com.smeme.server.util.ApiResponse; +import com.smeem.api.common.ApiResponseUtil; +import com.smeem.api.goal.controller.GoalController; +import com.smeem.api.goal.controller.dto.response.GoalResponseDTO; +import com.smeem.api.goal.controller.dto.response.GoalsResponseDTO; +import com.smeem.api.goal.controller.dto.response.GoalsResponseDTO.GoalResponseVO; +import com.smeem.domain.goal.model.GoalType; +import lombok.val; 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.ResponseEntity; import java.security.Principal; import java.util.ArrayList; import java.util.List; import static com.epages.restdocs.apispec.ResourceDocumentation.resource; -import static com.smeme.server.util.ApiResponse.success; +import static com.smeem.common.code.success.GoalSuccessCode.SUCCESS_GET_GOAL; +import static com.smeem.common.code.success.GoalSuccessCode.SUCCESS_GET_GOALS; +import static com.smeem.domain.goal.model.GoalType.APPLY; import static org.mockito.Mockito.when; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; @@ -44,8 +47,8 @@ class GoalControllerTest extends BaseControllerTest { @DisplayName("전체 학습 목표 조회 테스트") void success_get_goals_test() throws Exception { // given - GoalsResponseDTO response = new GoalsResponseDTO(goals()); - ResponseEntity result = ResponseEntity.ok(success("전체 학습 목표 조회 성공", response)); + val response = new GoalsResponseDTO(goals()); + val result = ApiResponseUtil.success(SUCCESS_GET_GOALS, response); // when when(goalController.getAll()).thenReturn(result); @@ -79,12 +82,12 @@ void success_get_goals_test() throws Exception { @DisplayName("학습 목표 조회 테스트") void success_get_goal_test() throws Exception { // given - GoalType type = GoalType.APPLY; - GoalResponseDTO response = new GoalResponseDTO( + GoalType type = APPLY; + val response = new GoalResponseDTO( "현지 언어 체득", "주 5회 이상 오늘 하루를 돌아보는 일기 작성하기", "사전 없이 일기 완성\nsmeem 연속 일기 배지 획득"); - ResponseEntity result = ResponseEntity.ok(success("학습 목표 조회 성공", response)); + val result = ApiResponseUtil.success(SUCCESS_GET_GOAL, response); // when when(goalController.getByType(type)).thenReturn(result); @@ -120,7 +123,7 @@ void success_get_goal_test() throws Exception { private List goals() { List goals = new ArrayList<>(); for (int i = 0; i < 2; i++) { - goals.add(new GoalResponseVO(GoalType.APPLY.name(), "현지 언어 체득" + (i + 1))); + goals.add(new GoalResponseVO(APPLY.name(), "현지 언어 체득" + (i + 1))); } return goals; } From 2d96bd75fcad143b55410dee702bda432104fb1b Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 7 Feb 2024 02:16:47 +0900 Subject: [PATCH 24/86] =?UTF-8?q?[FIX]=20Member=20:=20Success=20Code=20?= =?UTF-8?q?=EB=B0=8F=20DTO=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/MemberController.java | 27 +++++++++---------- .../api/controller/MemberControllerTest.java | 13 ++++----- .../smeem/api/fixture/badge/BadgeFixture.java | 9 ++++++- .../smeem/api/fixture/goal/GoalFixture.java | 10 ++++--- .../api/fixture/member/MemberFixture.java | 26 +++++++++++------- 5 files changed, 51 insertions(+), 34 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java b/smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java index bbe3fa26..7c4c01d4 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java @@ -1,7 +1,7 @@ package com.smeem.api.member.controller; - -import com.smeem.api.common.ApiResponse; +import com.smeem.api.common.ApiResponseUtil; +import com.smeem.api.common.BaseResponse; import com.smeem.api.member.controller.dto.request.MemberPlanUpdateRequestDTO; import com.smeem.api.member.controller.dto.request.MemberPushUpdateRequestDTO; import com.smeem.api.member.controller.dto.request.MemberUpdateRequestDTO; @@ -9,7 +9,6 @@ import com.smeem.api.member.controller.dto.response.MemberNameResponseDTO; import com.smeem.api.member.controller.dto.response.MemberUpdateResponseDTO; import com.smeem.api.member.service.MemberService; -import com.smeem.common.code.ResponseMessage; import com.smeem.common.util.Util; import io.swagger.v3.oas.annotations.Parameter; import jakarta.validation.Valid; @@ -19,7 +18,7 @@ import java.security.Principal; - +import static com.smeem.common.code.success.MemberSuccessCode.*; @RestController @RequiredArgsConstructor @@ -29,33 +28,33 @@ public class MemberController { private final MemberService memberService; @PatchMapping - public ResponseEntity updateProfile(Principal principal, @RequestBody MemberUpdateRequestDTO request) { + public ResponseEntity> updateProfile(Principal principal, @RequestBody MemberUpdateRequestDTO request) { MemberUpdateResponseDTO response = memberService.updateMember(Util.getMemberId(principal), request); - return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_UPDATE_USERNAME.getMessage(), response)); + return ApiResponseUtil.success(SUCCESS_UPDATE_USERNAME, response); } @GetMapping("/me") - public ResponseEntity getProfile(Principal principal) { + public ResponseEntity> getProfile(Principal principal) { MemberGetResponseDTO response = memberService.getProfile(Util.getMemberId(principal)); - return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_GET_USER.getMessage(), response)); + return ApiResponseUtil.success(SUCCESS_GET_USER, response); } @PatchMapping("/plan") - public ResponseEntity updateUserPlan(Principal principal, @Valid @RequestBody MemberPlanUpdateRequestDTO request) { + public ResponseEntity> updateUserPlan(Principal principal, @Valid @RequestBody MemberPlanUpdateRequestDTO request) { memberService.updateMemberPlan(Util.getMemberId(principal), request); - return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_UPDATE_USER_PLAN.getMessage())); + return ApiResponseUtil.success(SUCCESS_UPDATE_USER_PLAN); } @GetMapping("/nickname/check") - public ResponseEntity checkDuplicatedName(@Parameter(description = "유저 닉네임") @RequestParam String name) { + public ResponseEntity> checkDuplicatedName(@Parameter(description = "유저 닉네임") @RequestParam String name) { MemberNameResponseDTO response = memberService.checkDuplicatedName(name); - return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_CHECK_DUPLICATED_NAME.getMessage(), response)); + return ApiResponseUtil.success(SUCCESS_CHECK_DUPLICATED_NAME, response); } @PatchMapping("/push") - public ResponseEntity updateUserPush(Principal principal, @RequestBody MemberPushUpdateRequestDTO request) { + public ResponseEntity> updateUserPush(Principal principal, @RequestBody MemberPushUpdateRequestDTO request) { memberService.updateHasAlarm(Util.getMemberId(principal), request); - return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_UPDATE_USER_PUSH.getMessage())); + return ApiResponseUtil.success(SUCCESS_UPDATE_USER_PUSH); } } diff --git a/smeem-api/src/test/java/com/smeem/api/controller/MemberControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/MemberControllerTest.java index f742bcdc..197878ea 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/MemberControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/MemberControllerTest.java @@ -2,6 +2,7 @@ import com.epages.restdocs.apispec.ResourceSnippetParameters; +import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.member.controller.MemberController; import com.smeem.api.fixture.member.MemberFixture; import lombok.val; @@ -9,12 +10,12 @@ 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.ResponseEntity; import java.security.Principal; import static com.epages.restdocs.apispec.ResourceDocumentation.resource; +import static com.smeem.common.code.success.MemberSuccessCode.*; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; import static org.mockito.Mockito.when; @@ -66,7 +67,7 @@ void success_updateProfile() throws Exception { ) .build(); - val response = ResponseEntity.ok(success("유저 프로필 업데이트 성공", MemberFixture.createMemberGetResponseDTO())); + val response = ApiResponseUtil.success(SUCCESS_UPDATE_USERNAME, resources); when(memberController.updateProfile(principal, MemberFixture.createMemberUpdateRequestDTO())) .thenReturn(response); @@ -112,7 +113,7 @@ void success_getProfile() throws Exception { fieldWithPath("data.com.smeem.badge.imageUrl").type(STRING).description("뱃지 이미지") ) .build(); - val result = ResponseEntity.ok(success("사용자 정보 조회 성공", MemberFixture.createMemberGetResponseDTO())); + val result = ApiResponseUtil.success(SUCCESS_GET_USER, resources); when(memberController.getProfile(principal)) .thenReturn(result); @@ -141,7 +142,7 @@ void success_updateUserPlan() throws Exception { fieldWithPath("data").type(NULL).description("응답 데이터") ) .build(); - val result = ResponseEntity.ok(success(SUCCESS_UPDATE_USER_PLAN.getMessage())); + val result = ApiResponseUtil.success(SUCCESS_UPDATE_USER_PLAN); when(memberController.updateUserPlan(principal, MemberFixture.createMemberPlanUpdateRequestDTO())) .thenReturn(result); @@ -174,7 +175,7 @@ void success_checkDuplicatedName() throws Exception { .build(); // when when(memberController.checkDuplicatedName("test")) - .thenReturn(ResponseEntity.ok(success("닉네임 중복 체크 성공"))); + .thenReturn(ApiResponseUtil.success(SUCCESS_CHECK_DUPLICATED_NAME, resources)); // then mockMvc.perform(get(DEFAULT_URL + "/nickname/check") @@ -206,7 +207,7 @@ void success_updateUserPush() throws Exception { .build(); // when when(memberController.updateUserPush(principal, MemberFixture.createMemberPushUpdateRequestDTO())) - .thenReturn(ResponseEntity.ok(success(SUCCESS_UPDATE_USER_PUSH.getMessage()))); + .thenReturn(ApiResponseUtil.success(SUCCESS_UPDATE_USER_PUSH)); mockMvc.perform(patch(DEFAULT_URL + "/push") diff --git a/smeem-api/src/test/java/com/smeem/api/fixture/badge/BadgeFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/badge/BadgeFixture.java index 33671a61..e6ebd711 100644 --- a/smeem-api/src/test/java/com/smeem/api/fixture/badge/BadgeFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/badge/BadgeFixture.java @@ -1,13 +1,20 @@ package com.smeem.api.fixture.badge; +import com.smeem.api.badge.controller.dto.response.BadgeListResponseDTO; +import com.smeem.api.badge.controller.dto.response.BadgeListResponseDTO.BadgeTypeResponseDTO; +import com.smeem.api.badge.controller.dto.response.BadgeResponseDTO; +import com.smeem.domain.badge.model.BadgeType; + import java.util.List; import java.util.stream.Stream; +import static com.smeem.domain.badge.model.BadgeType.COMBO; + public class BadgeFixture { private static final String BADGE_NAME = "연속 3일 일기 뱃지"; private static final Long BADGE_ID = 1L; - private static final BadgeType BADGE_TYPE = BadgeType.COMBO; + private static final BadgeType BADGE_TYPE = COMBO; private static final String BADGE_IMAGE_URL = "https://m.s3.ap-northeast-2.amazonaws.com/badge/streak.png"; public static BadgeResponseDTO createBadgeResponseDTO() { diff --git a/smeem-api/src/test/java/com/smeem/api/fixture/goal/GoalFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/goal/GoalFixture.java index 9352ce94..1cabb621 100644 --- a/smeem-api/src/test/java/com/smeem/api/fixture/goal/GoalFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/goal/GoalFixture.java @@ -1,12 +1,14 @@ package com.smeem.api.fixture.goal; -import com.smeme.server.dto.goal.GoalResponseDTO; -import com.smeme.server.model.goal.Goal; -import com.smeme.server.model.goal.GoalType; +import com.smeem.api.goal.controller.dto.response.GoalResponseDTO; +import com.smeem.domain.goal.model.Goal; +import com.smeem.domain.goal.model.GoalType; + +import static com.smeem.domain.goal.model.GoalType.DEVELOP; public class GoalFixture { - private static final GoalType GOAL_TYPE = GoalType.DEVELOP; + private static final GoalType GOAL_TYPE = DEVELOP; private static final String GOAL_WAY = "주 5회 이상 오늘 하루를 돌아보는 일기 작성하기"; private static final String GOAL_DETAIL = "사전 없이 일기 완성\nsmeem 연속 일기 배지 획득"; diff --git a/smeem-api/src/test/java/com/smeem/api/fixture/member/MemberFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/member/MemberFixture.java index ae6be95a..eb7b70c2 100644 --- a/smeem-api/src/test/java/com/smeem/api/fixture/member/MemberFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/member/MemberFixture.java @@ -3,30 +3,38 @@ import com.smeem.api.fixture.goal.GoalFixture; import com.smeem.api.fixture.badge.BadgeFixture; import com.smeem.api.fixture.trainingtime.TrainingTimeFixture; -import com.smeme.server.model.LangType; -import com.smeme.server.model.Member; -import com.smeme.server.model.SocialType; -import com.smeme.server.model.goal.GoalType; +import com.smeem.api.member.controller.dto.request.MemberPlanUpdateRequestDTO; +import com.smeem.api.member.controller.dto.request.MemberPushUpdateRequestDTO; +import com.smeem.api.member.controller.dto.request.MemberUpdateRequestDTO; +import com.smeem.api.member.controller.dto.response.MemberGetResponseDTO; +import com.smeem.domain.goal.model.GoalType; +import com.smeem.domain.member.model.LangType; +import com.smeem.domain.member.model.Member; +import com.smeem.domain.member.model.SocialType; import lombok.val; +import static com.smeem.domain.goal.model.GoalType.DEVELOP; +import static com.smeem.domain.member.model.LangType.en; +import static com.smeem.domain.member.model.SocialType.KAKAO; + public class MemberFixture { private static final String MEMBER_USERNAME = "홍길동"; - private static final SocialType MEMBER_SOCIAL = SocialType.KAKAO; + private static final SocialType MEMBER_SOCIAL = KAKAO; private static final String MEMBER_SOCIAL_ID = "123456789"; private static final String MEMBER_FCM_TOKEN = "fcm_token"; - private static final LangType TARGET_LANG = LangType.en; + private static final LangType TARGET_LANG = en; private static final boolean HAS_ALARM = true; public static Member createMember() { - val member = Member.builder() + val member = Member.builder() .social(MEMBER_SOCIAL) .socialId(MEMBER_SOCIAL_ID) .targetLang(TARGET_LANG) .fcmToken(MEMBER_FCM_TOKEN) .build(); - member.updateGoal(GoalType.DEVELOP); + member.updateGoal(DEVELOP); return member; } @@ -45,7 +53,7 @@ public static MemberUpdateRequestDTO createMemberUpdateRequestDTO() { public static MemberPlanUpdateRequestDTO createMemberPlanUpdateRequestDTO() { return new MemberPlanUpdateRequestDTO( - GoalType.DEVELOP, + DEVELOP, TrainingTimeFixture.createTrainingTimeRequestDTO(), HAS_ALARM ); From 3750165b2c57d46cfe0fcd1e200719b13963cb1d Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 7 Feb 2024 02:19:44 +0900 Subject: [PATCH 25/86] =?UTF-8?q?[FIX]=20Test=20:=20Success=20Code=20?= =?UTF-8?q?=EB=B0=8F=20DTO=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/smeem/api/test/TestController.java | 19 ++++++++-------- .../api/controller/TestControllerTest.java | 7 +++--- .../common/code/success/TestSuccessCode.java | 22 +++++++++++++++++++ 3 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 smeem-common/src/main/java/com/smeem/common/code/success/TestSuccessCode.java diff --git a/smeem-api/src/main/java/com/smeem/api/test/TestController.java b/smeem-api/src/main/java/com/smeem/api/test/TestController.java index dec3edef..0eb2e35a 100644 --- a/smeem-api/src/main/java/com/smeem/api/test/TestController.java +++ b/smeem-api/src/main/java/com/smeem/api/test/TestController.java @@ -1,11 +1,9 @@ package com.smeem.api.test; - - import java.security.Principal; - -import com.smeem.api.common.ApiResponse; +import com.smeem.api.common.ApiResponseUtil; +import com.smeem.api.common.BaseResponse; import com.smeem.common.config.ValueConfig; import com.smeem.external.firebase.MessageService; import org.springframework.http.ResponseEntity; @@ -13,11 +11,12 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; - - import io.swagger.v3.oas.annotations.Parameter; import lombok.RequiredArgsConstructor; +import static com.smeem.common.code.success.TestSuccessCode.SUCCESS_SEND_PUSH_ALARM; +import static com.smeem.common.code.success.TestSuccessCode.SUCCESS_SERVER_CONNECT; + @RestController @RequiredArgsConstructor @RequestMapping("/api/v2/test") @@ -27,13 +26,13 @@ public class TestController { private final ValueConfig valueConfig; @GetMapping - public ResponseEntity test() { - return ResponseEntity.ok(ApiResponse.success("server connect")); + public ResponseEntity> test() { + return ApiResponseUtil.success(SUCCESS_SERVER_CONNECT); } @GetMapping("/alarm") - public ResponseEntity alarmTest(@Parameter(hidden = true) Principal principal) { + public ResponseEntity> alarmTest(@Parameter(hidden = true) Principal principal) { // messageService.pushTest(valueConfig.getMESSAGE_TITLE(), valueConfig.getMESSAGE_BODY(), Long.valueOf(principal.getName())); - return ResponseEntity.ok(ApiResponse.success("푸시 알림 전송 성공")); + return ApiResponseUtil.success(SUCCESS_SEND_PUSH_ALARM); } } diff --git a/smeem-api/src/test/java/com/smeem/api/controller/TestControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/TestControllerTest.java index 58073e60..c26093f1 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/TestControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/TestControllerTest.java @@ -1,13 +1,13 @@ package com.smeem.api.controller; import com.epages.restdocs.apispec.ResourceSnippetParameters; -import com.smeme.server.util.ApiResponse; +import com.smeem.api.common.ApiResponseUtil; +import com.smeem.api.test.TestController; 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.http.ResponseEntity; import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; import org.springframework.restdocs.payload.JsonFieldType; @@ -15,6 +15,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import static com.epages.restdocs.apispec.ResourceDocumentation.resource; +import static com.smeem.common.code.success.TestSuccessCode.SUCCESS_SERVER_CONNECT; import static org.mockito.Mockito.when; import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; @@ -34,7 +35,7 @@ void success_test() throws Exception { //given when(testController.test()) - .thenReturn(ResponseEntity.ok(ApiResponse.success("server connect", null))); + .thenReturn(ApiResponseUtil.success(SUCCESS_SERVER_CONNECT)); //then ResultActions resultActions = mockMvc.perform( diff --git a/smeem-common/src/main/java/com/smeem/common/code/success/TestSuccessCode.java b/smeem-common/src/main/java/com/smeem/common/code/success/TestSuccessCode.java new file mode 100644 index 00000000..ade59c14 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/code/success/TestSuccessCode.java @@ -0,0 +1,22 @@ +package com.smeem.common.code.success; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.OK; + +@RequiredArgsConstructor +@Getter +public enum TestSuccessCode implements SuccessCode { + + /** + * 200 Ok + */ + SUCCESS_SERVER_CONNECT(OK, "서버 연결 성공"), + SUCCESS_SEND_PUSH_ALARM(OK, "푸시 알람 전송 성공"), + ; + + private final HttpStatus status; + private final String message; +} From edb1c5ac6c3c5c79dc36e86ddc5d17590194b26b Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 7 Feb 2024 02:21:19 +0900 Subject: [PATCH 26/86] =?UTF-8?q?[FIX]=20Topic=20:=20Success=20Code=20?= =?UTF-8?q?=EB=B0=8F=20DTO=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smeem/api/topic/controller/TopicController.java | 13 +++++-------- .../smeem/api/controller/TopicControllerTest.java | 11 ++++++----- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/topic/controller/TopicController.java b/smeem-api/src/main/java/com/smeem/api/topic/controller/TopicController.java index 985e5b79..a445b2e2 100644 --- a/smeem-api/src/main/java/com/smeem/api/topic/controller/TopicController.java +++ b/smeem-api/src/main/java/com/smeem/api/topic/controller/TopicController.java @@ -1,20 +1,17 @@ package com.smeem.api.topic.controller; - - -import com.smeem.api.common.ApiResponse; +import com.smeem.api.common.ApiResponseUtil; +import com.smeem.api.common.BaseResponse; import com.smeem.api.topic.controller.dto.response.TopicResponseDTO; import com.smeem.api.topic.service.TopicService; -import com.smeem.common.code.ResponseMessage; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; - - import lombok.RequiredArgsConstructor; +import static com.smeem.common.code.success.TopicSuccessCode.SUCCESS_GET_RANDOM_TOPIC; @RestController @RequiredArgsConstructor @@ -24,8 +21,8 @@ public class TopicController { private final TopicService topicService; @GetMapping("/random") - public ResponseEntity getRandom() { + public ResponseEntity> getRandom() { TopicResponseDTO response = topicService.getRandom(); - return ResponseEntity.ok(ApiResponse.success(ResponseMessage.SUCCESS_GET_RANDOM_TOPIC.getMessage(), response)); + return ApiResponseUtil.success(SUCCESS_GET_RANDOM_TOPIC, response); } } diff --git a/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java index 514ab386..297b546f 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java @@ -1,18 +1,19 @@ package com.smeem.api.controller; import com.epages.restdocs.apispec.ResourceSnippetParameters; -import com.smeme.server.dto.topic.TopicResponseDTO; -import com.smeme.server.util.ApiResponse; +import com.smeem.api.common.ApiResponseUtil; +import com.smeem.api.topic.controller.TopicController; +import com.smeem.api.topic.controller.dto.response.TopicResponseDTO; +import lombok.val; 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.ResponseEntity; import java.security.Principal; import static com.epages.restdocs.apispec.ResourceDocumentation.resource; -import static com.smeme.server.util.ApiResponse.success; +import static com.smeem.common.code.success.TopicSuccessCode.SUCCESS_GET_RANDOM_TOPIC; import static org.mockito.Mockito.when; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; @@ -40,7 +41,7 @@ class TopicControllerTest extends BaseControllerTest { void success_get_random_topic_test() throws Exception { // given TopicResponseDTO response = new TopicResponseDTO(1L, "가보고 싶은 해외 여행 지가 있다면 소개해 주세요!"); - ResponseEntity result = ResponseEntity.ok(success("랜덤 주제 조회 성공", response)); + val result = ApiResponseUtil.success(SUCCESS_GET_RANDOM_TOPIC, response); // when when(topicController.getRandom()).thenReturn(result); From 1bf276ad9d4676245843b4b25c8bb88ef0c5a728 Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 7 Feb 2024 02:21:32 +0900 Subject: [PATCH 27/86] =?UTF-8?q?[FIX]=20Member=20:=20Success=20Code=20?= =?UTF-8?q?=EB=B0=8F=20DTO=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fixture/trainingtime/TrainingTimeFixture.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/smeem-api/src/test/java/com/smeem/api/fixture/trainingtime/TrainingTimeFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/trainingtime/TrainingTimeFixture.java index 33ef600f..2d2fc365 100644 --- a/smeem-api/src/test/java/com/smeem/api/fixture/trainingtime/TrainingTimeFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/trainingtime/TrainingTimeFixture.java @@ -1,14 +1,16 @@ package com.smeem.api.fixture.trainingtime; import com.smeem.api.fixture.member.MemberFixture; -import com.smeme.server.dto.training.TrainingTimeRequestDTO; -import com.smeme.server.dto.training.TrainingTimeResponseDTO; -import com.smeme.server.model.training.DayType; -import com.smeme.server.model.training.TrainingTime; +import com.smeem.api.member.controller.dto.request.TrainingTimeRequestDTO; +import com.smeem.api.member.controller.dto.response.TrainingTimeResponseDTO; +import com.smeem.domain.training.model.DayType; +import com.smeem.domain.training.model.TrainingTime; + +import static com.smeem.domain.training.model.DayType.MON; public class TrainingTimeFixture { - private static final DayType DAY_TYPE = DayType.MON; + private static final DayType DAY_TYPE = MON; private static final int HOUR = 10; private static final int MINUTE = 30; From b2103dfdd1738343b115a899dd32e3f346d4635d Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 7 Feb 2024 14:00:37 +0900 Subject: [PATCH 28/86] =?UTF-8?q?[ADD]=20Failure=20Code=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/smeem/common/code/ErrorMessage.java | 48 ------------------- .../common/code/failure/AlarmFailureCode.java | 22 +++++++++ .../common/code/failure/AuthFailureCode.java | 24 ++++++++++ .../common/code/failure/BadgeFailureCode.java | 23 +++++++++ .../common/code/failure/DiaryFailureCode.java | 28 +++++++++++ .../common/code/failure/FailureCode.java | 8 ++++ .../common/code/failure/GoalFailureCode.java | 21 ++++++++ .../code/failure/MemberFailureCode.java | 28 +++++++++++ .../common/code/failure/TopicFailureCode.java | 22 +++++++++ .../code/failure/TrainingTimeFailureCode.java | 23 +++++++++ 10 files changed, 199 insertions(+), 48 deletions(-) delete mode 100644 smeem-common/src/main/java/com/smeem/common/code/ErrorMessage.java create mode 100644 smeem-common/src/main/java/com/smeem/common/code/failure/AlarmFailureCode.java create mode 100644 smeem-common/src/main/java/com/smeem/common/code/failure/AuthFailureCode.java create mode 100644 smeem-common/src/main/java/com/smeem/common/code/failure/BadgeFailureCode.java create mode 100644 smeem-common/src/main/java/com/smeem/common/code/failure/DiaryFailureCode.java create mode 100644 smeem-common/src/main/java/com/smeem/common/code/failure/FailureCode.java create mode 100644 smeem-common/src/main/java/com/smeem/common/code/failure/GoalFailureCode.java create mode 100644 smeem-common/src/main/java/com/smeem/common/code/failure/MemberFailureCode.java create mode 100644 smeem-common/src/main/java/com/smeem/common/code/failure/TopicFailureCode.java create mode 100644 smeem-common/src/main/java/com/smeem/common/code/failure/TrainingTimeFailureCode.java diff --git a/smeem-common/src/main/java/com/smeem/common/code/ErrorMessage.java b/smeem-common/src/main/java/com/smeem/common/code/ErrorMessage.java deleted file mode 100644 index 44331f39..00000000 --- a/smeem-common/src/main/java/com/smeem/common/code/ErrorMessage.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.smeem.common.code; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public enum ErrorMessage { - - // com.smeem.auth - EMPTY_ACCESS_TOKEN("액세스 토큰이 없습니다."), - EMPTY_REFRESH_TOKEN("리프레시 토큰이 없습니다"), - INVALID_TOKEN("유효하지 않은 토큰입니다"), - MESSAGE_UNAUTHORIZED("유효하지 않은 토큰"), - - // com.smeem.member - EMPTY_MEMBER("존재하지 않는 회원입니다."), - DUPLICATE_USERNAME("이미 존재하는 닉네임입니다."), - INVALID_MEMBER("유효하지 않은 회원입니다."), - INVALID_USERNAME("유효하지 않은 닉네임입니다."), - - // com.smeem.diary - EXIST_TODAY_DIARY("일기는 하루에 한 번씩 작성할 수 있습니다."), - INVALID_DIARY("유효하지 않은 일기입니다."), - DELETED_DIARY("삭제된 일기입니다."), - - // correction - INVALID_CORRECTION("유효하지 않은 첨삭입니다."), - - // com.smeem.topic - INVALID_TOPIC("유효하지 않은 랜덤주제입니다."), - - // Push Alarm - INVALID_DAY_OF_WEEK("유효하지 않은 요일 값입니다."), - - // Training Time - EMPTY_TRAINING_TIME("존재하지 않는 학습계획 입니다."), - NOT_SET_TRAINING_TIME("학습계획이 설정되지 않았습니다."), - - // com.smeem.badge - INVALID_BADGE("유효하지 않은 뱃지입니다."), - EMPTY_BADGE("존재하지 않는 뱃지입니다."), - - // com.smeem.goal - EMPTY_GOAL("존재하지 않는 목표입니다."); - - private final String message; -} diff --git a/smeem-common/src/main/java/com/smeem/common/code/failure/AlarmFailureCode.java b/smeem-common/src/main/java/com/smeem/common/code/failure/AlarmFailureCode.java new file mode 100644 index 00000000..82129d63 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/code/failure/AlarmFailureCode.java @@ -0,0 +1,22 @@ +package com.smeem.common.code.failure; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.BAD_REQUEST; +import static org.springframework.http.HttpStatus.NOT_FOUND; + +@RequiredArgsConstructor +@Getter +public enum AlarmFailureCode implements FailureCode { + + /** + * 400 BAD REQUEST + */ + INVALID_DAY_OF_WEEK(BAD_REQUEST, "유효하지 않은 요일 값입니다."), + ; + + private final HttpStatus status; + private final String message; +} diff --git a/smeem-common/src/main/java/com/smeem/common/code/failure/AuthFailureCode.java b/smeem-common/src/main/java/com/smeem/common/code/failure/AuthFailureCode.java new file mode 100644 index 00000000..d72f5847 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/code/failure/AuthFailureCode.java @@ -0,0 +1,24 @@ +package com.smeem.common.code.failure; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.UNAUTHORIZED; + +@RequiredArgsConstructor +@Getter +public enum AuthFailureCode implements FailureCode { + + /** + * 401 UNAUTHORIZED + */ + EMPTY_ACCESS_TOKEN(UNAUTHORIZED, "액세스 토큰이 없습니다."), + EMPTY_REFRESH_TOKEN(UNAUTHORIZED, "리프레시 토큰이 없습니다"), + INVALID_TOKEN(UNAUTHORIZED, "유효하지 않은 토큰입니다"), + MESSAGE_UNAUTHORIZED(UNAUTHORIZED, "유효하지 않은 토큰"), + ; + + private final HttpStatus status; + private final String message; +} diff --git a/smeem-common/src/main/java/com/smeem/common/code/failure/BadgeFailureCode.java b/smeem-common/src/main/java/com/smeem/common/code/failure/BadgeFailureCode.java new file mode 100644 index 00000000..2a693cb6 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/code/failure/BadgeFailureCode.java @@ -0,0 +1,23 @@ +package com.smeem.common.code.failure; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.BAD_REQUEST; +import static org.springframework.http.HttpStatus.NOT_FOUND; + +@RequiredArgsConstructor +@Getter +public enum BadgeFailureCode implements FailureCode { + + /** + * 404 NOT FOUND + */ + INVALID_BADGE(NOT_FOUND, "유효하지 않은 뱃지입니다."), + EMPTY_BADGE(NOT_FOUND, "존재하지 않는 뱃지입니다."), + ; + + private final HttpStatus status; + private final String message; +} diff --git a/smeem-common/src/main/java/com/smeem/common/code/failure/DiaryFailureCode.java b/smeem-common/src/main/java/com/smeem/common/code/failure/DiaryFailureCode.java new file mode 100644 index 00000000..2dcea08b --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/code/failure/DiaryFailureCode.java @@ -0,0 +1,28 @@ +package com.smeem.common.code.failure; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.BAD_REQUEST; +import static org.springframework.http.HttpStatus.NOT_FOUND; + +@RequiredArgsConstructor +@Getter +public enum DiaryFailureCode implements FailureCode { + + /** + * 400 BAD REQUEST + */ + EXIST_TODAY_DIARY(BAD_REQUEST, "일기는 하루에 한 번씩 작성할 수 있습니다."), + + /** + * 404 NOT FOUND + */ + INVALID_DIARY(NOT_FOUND, "유효하지 않은 일기입니다."), + DELETED_DIARY(NOT_FOUND, "삭제된 일기입니다."), + ; + + private final HttpStatus status; + private final String message; +} diff --git a/smeem-common/src/main/java/com/smeem/common/code/failure/FailureCode.java b/smeem-common/src/main/java/com/smeem/common/code/failure/FailureCode.java new file mode 100644 index 00000000..e02006c5 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/code/failure/FailureCode.java @@ -0,0 +1,8 @@ +package com.smeem.common.code.failure; + +import org.springframework.http.HttpStatus; + +public interface FailureCode { + HttpStatus getStatus(); + String getMessage(); +} diff --git a/smeem-common/src/main/java/com/smeem/common/code/failure/GoalFailureCode.java b/smeem-common/src/main/java/com/smeem/common/code/failure/GoalFailureCode.java new file mode 100644 index 00000000..5d504da2 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/code/failure/GoalFailureCode.java @@ -0,0 +1,21 @@ +package com.smeem.common.code.failure; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.NOT_FOUND; + +@RequiredArgsConstructor +@Getter +public enum GoalFailureCode implements FailureCode { + + /** + * 404 NOT FOUND + */ + EMPTY_GOAL(NOT_FOUND, "존재하지 않는 목표입니다."), + ; + + private final HttpStatus status; + private final String message; +} diff --git a/smeem-common/src/main/java/com/smeem/common/code/failure/MemberFailureCode.java b/smeem-common/src/main/java/com/smeem/common/code/failure/MemberFailureCode.java new file mode 100644 index 00000000..236530a2 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/code/failure/MemberFailureCode.java @@ -0,0 +1,28 @@ +package com.smeem.common.code.failure; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.*; + +@RequiredArgsConstructor +@Getter +public enum MemberFailureCode implements FailureCode { + + /** + * 400 BAD REQUEST + */ + DUPLICATE_USERNAME(BAD_REQUEST, "이미 존재하는 닉네임입니다."), + INVALID_USERNAME(BAD_REQUEST, "유효하지 않은 닉네임입니다."), + + /** + * 404 NOT FOUND + */ + EMPTY_MEMBER(NOT_FOUND, "존재하지 않는 회원입니다."), + INVALID_MEMBER(NOT_FOUND, "유효하지 않은 회원입니다."), + ; + + private final HttpStatus status; + private final String message; +} diff --git a/smeem-common/src/main/java/com/smeem/common/code/failure/TopicFailureCode.java b/smeem-common/src/main/java/com/smeem/common/code/failure/TopicFailureCode.java new file mode 100644 index 00000000..d7b3cb60 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/code/failure/TopicFailureCode.java @@ -0,0 +1,22 @@ +package com.smeem.common.code.failure; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.BAD_REQUEST; +import static org.springframework.http.HttpStatus.NOT_FOUND; + +@RequiredArgsConstructor +@Getter +public enum TopicFailureCode implements FailureCode { + + /** + * 404 NOT FOUND + */ + INVALID_TOPIC(NOT_FOUND, "유효하지 않은 랜덤주제입니다."), + ; + + private final HttpStatus status; + private final String message; +} diff --git a/smeem-common/src/main/java/com/smeem/common/code/failure/TrainingTimeFailureCode.java b/smeem-common/src/main/java/com/smeem/common/code/failure/TrainingTimeFailureCode.java new file mode 100644 index 00000000..6bca69c4 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/code/failure/TrainingTimeFailureCode.java @@ -0,0 +1,23 @@ +package com.smeem.common.code.failure; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.BAD_REQUEST; +import static org.springframework.http.HttpStatus.NOT_FOUND; + +@RequiredArgsConstructor +@Getter +public enum TrainingTimeFailureCode implements FailureCode { + + /** + * 404 NOT FOUND + */ + EMPTY_TRAINING_TIME(NOT_FOUND, "존재하지 않는 학습계획 입니다."), + NOT_SET_TRAINING_TIME(NOT_FOUND, "학습계획이 설정되지 않았습니다."), + ; + + private final HttpStatus status; + private final String message; +} From 4bba734d27ba73b8cbf97a758f58f008ce56652b Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 7 Feb 2024 14:02:39 +0900 Subject: [PATCH 29/86] =?UTF-8?q?[ADD]=20Failure=20Code=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9=20=ED=98=95=ED=83=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/smeem/api/common/ApiResponseUtil.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/common/ApiResponseUtil.java b/smeem-api/src/main/java/com/smeem/api/common/ApiResponseUtil.java index 5f881b16..9aa8512d 100644 --- a/smeem-api/src/main/java/com/smeem/api/common/ApiResponseUtil.java +++ b/smeem-api/src/main/java/com/smeem/api/common/ApiResponseUtil.java @@ -1,5 +1,6 @@ package com.smeem.api.common; +import com.smeem.common.code.failure.FailureCode; import com.smeem.common.code.success.SuccessCode; import org.springframework.http.ResponseEntity; @@ -26,9 +27,9 @@ static ResponseEntity> success(SuccessCode code, URI uri, T .body(BaseResponse.of(code.getMessage(), data)); } -// static ResponseEntity> failure(FailureCode code) { -// return ResponseEntity -// .status(code.getStatus()) -// .body(BaseResponse.of(false, code.getMessage())); -// } + static ResponseEntity> failure(FailureCode code) { + return ResponseEntity + .status(code.getStatus()) + .body(BaseResponse.of(true, code.getMessage())); + } } From 8c171cfa78661560a958a794bc5e9212b1a339cc Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 7 Feb 2024 14:43:46 +0900 Subject: [PATCH 30/86] =?UTF-8?q?[ADD]=20=EC=98=88=EC=99=B8=20=EC=BB=A4?= =?UTF-8?q?=EC=8A=A4=ED=85=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomJwtAuthenticationEntryPoint.java | 13 ++-- .../smeem/api/auth/service/AuthService.java | 11 ++-- .../smeem/api/badge/service/BadgeService.java | 8 +-- .../api/common/advicer/ErrorHandler.java | 52 ++++++++++++++++ .../smeem/api/diary/service/DiaryService.java | 8 ++- .../smeem/api/goal/service/GoalService.java | 8 +-- .../member/service/MemberBadgeService.java | 7 ++- .../api/member/service/MemberService.java | 15 ++--- .../smeem/api/topic/service/TopicService.java | 6 +- .../smeem/common/advicer/ErrorHandler.java | 61 ------------------- .../common/code/failure/AlarmFailureCode.java | 22 ------- .../common/code/failure/AuthFailureCode.java | 3 +- .../common/code/failure/BadgeFailureCode.java | 1 - .../common/code/failure/DiaryFailureCode.java | 1 - .../common/code/failure/TopicFailureCode.java | 1 - .../code/failure/TrainingTimeFailureCode.java | 5 ++ .../common/exception/AppleException.java | 15 +++++ .../common/exception/BadgeException.java | 16 +++++ .../common/exception/DiaryException.java | 17 ++++++ .../smeem/common/exception/GoalException.java | 17 ++++++ .../common/exception/MemberException.java | 17 ++++++ .../common/exception/TokenException.java | 16 +++++ .../common/exception/TopicException.java | 16 +++++ .../exception/TrainingTimeException.java | 16 +++++ .../main/java/com/smeem/common/util/Util.java | 5 +- .../TrainingTimeRepositoryImpl.java | 24 ++++---- .../external/apple/AppleSignInService.java | 7 ++- 27 files changed, 252 insertions(+), 136 deletions(-) create mode 100644 smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java delete mode 100644 smeem-common/src/main/java/com/smeem/common/advicer/ErrorHandler.java delete mode 100644 smeem-common/src/main/java/com/smeem/common/code/failure/AlarmFailureCode.java create mode 100644 smeem-common/src/main/java/com/smeem/common/exception/AppleException.java create mode 100644 smeem-common/src/main/java/com/smeem/common/exception/BadgeException.java create mode 100644 smeem-common/src/main/java/com/smeem/common/exception/DiaryException.java create mode 100644 smeem-common/src/main/java/com/smeem/common/exception/GoalException.java create mode 100644 smeem-common/src/main/java/com/smeem/common/exception/MemberException.java create mode 100644 smeem-common/src/main/java/com/smeem/common/exception/TokenException.java create mode 100644 smeem-common/src/main/java/com/smeem/common/exception/TopicException.java create mode 100644 smeem-common/src/main/java/com/smeem/common/exception/TrainingTimeException.java diff --git a/smeem-api/src/main/java/com/smeem/api/auth/jwt/CustomJwtAuthenticationEntryPoint.java b/smeem-api/src/main/java/com/smeem/api/auth/jwt/CustomJwtAuthenticationEntryPoint.java index 7ea8c59a..df4e1499 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/jwt/CustomJwtAuthenticationEntryPoint.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/jwt/CustomJwtAuthenticationEntryPoint.java @@ -1,18 +1,19 @@ package com.smeem.api.auth.jwt; import com.fasterxml.jackson.databind.ObjectMapper; +import com.smeem.api.common.ApiResponseUtil; +import com.smeem.api.common.BaseResponse; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.stereotype.Component; import java.io.IOException; -import static com.smeem.api.common.ApiResponse.fail; -import static com.smeem.common.code.ErrorMessage.INVALID_TOKEN; - +import static com.smeem.common.code.failure.AuthFailureCode.INVALID_TOKEN; @Component public class CustomJwtAuthenticationEntryPoint implements AuthenticationEntryPoint { @@ -28,6 +29,10 @@ private void setResponse(HttpServletResponse response) throws IOException { response.setCharacterEncoding("UTF-8"); response.setContentType(MediaType.APPLICATION_JSON_VALUE); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); - response.getWriter().println(objectMapper.writeValueAsString(fail(INVALID_TOKEN.getMessage()))); + response.getWriter().println(objectMapper.writeValueAsString(getFailureResponse())); + } + + private ResponseEntity> getFailureResponse() { + return ApiResponseUtil.failure(INVALID_TOKEN); } } diff --git a/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java b/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java index 6dc040cc..92748687 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java @@ -11,7 +11,8 @@ import com.smeem.api.diary.service.DiaryService; import com.smeem.api.member.service.MemberBadgeService; import com.smeem.api.member.service.TrainingTimeService; -import com.smeem.common.code.ErrorMessage; +import com.smeem.common.exception.MemberException; +import com.smeem.common.exception.TokenException; import com.smeem.domain.member.model.LangType; import com.smeem.domain.member.model.Member; import com.smeem.domain.member.model.SocialType; @@ -26,6 +27,8 @@ import java.security.NoSuchAlgorithmException; import java.security.spec.InvalidKeySpecException; +import static com.smeem.common.code.failure.AuthFailureCode.INVALID_TOKEN; +import static com.smeem.common.code.failure.MemberFailureCode.INVALID_MEMBER; import static java.util.Objects.nonNull; @Service @@ -114,12 +117,12 @@ private TokenVO generateToken(Authentication authentication) { private Member get(Long memberId) { return memberRepository.findById(memberId) - .orElseThrow(() -> new RuntimeException(ErrorMessage.INVALID_MEMBER.getMessage())); + .orElseThrow(() -> new MemberException(INVALID_MEMBER)); } private Member getMemberBySocialAndSocialId(SocialType socialType, String socialId) { return memberRepository.findBySocialAndSocialId(socialType, socialId) - .orElseThrow(() -> new RuntimeException(ErrorMessage.INVALID_MEMBER.getMessage())); + .orElseThrow(() -> new MemberException(INVALID_MEMBER)); } private boolean isMemberBySocialAndSocialId(SocialType socialType, String socialId) { @@ -133,7 +136,7 @@ private String login(SocialType socialType, String socialAccessToken) throws NoS case "KAKAO" -> kakaoSignInService.getKakaoData(socialAccessToken); // TODO : Change to Custom Exception - default -> throw new RuntimeException(ErrorMessage.INVALID_TOKEN.getMessage()); + default -> throw new TokenException(INVALID_TOKEN); }; } } diff --git a/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java b/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java index e3070591..eb8d499e 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java @@ -1,15 +1,13 @@ package com.smeem.api.badge.service; - import com.smeem.api.badge.controller.dto.response.BadgeListResponseDTO; -import com.smeem.common.code.ErrorMessage; +import com.smeem.common.exception.BadgeException; import com.smeem.domain.badge.model.Badge; import com.smeem.domain.badge.model.BadgeType; import com.smeem.domain.badge.repository.BadgeRepository; import com.smeem.domain.member.model.Member; import com.smeem.domain.member.model.MemberBadge; import com.smeem.domain.member.repository.MemberBadgeRepository; -import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; import lombok.val; import org.springframework.stereotype.Service; @@ -20,6 +18,8 @@ import java.util.List; import java.util.Map; +import static com.smeem.common.code.failure.BadgeFailureCode.INVALID_BADGE; + @Service @RequiredArgsConstructor @Transactional(readOnly = true) @@ -52,6 +52,6 @@ public void saveMemberBadge(Member member, Badge badge) { public Badge get(Long id) { return badgeRepository.findById(id) - .orElseThrow(() -> new EntityNotFoundException(ErrorMessage.INVALID_BADGE.getMessage())); + .orElseThrow(() -> new BadgeException(INVALID_BADGE)); } } diff --git a/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java b/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java new file mode 100644 index 00000000..f6320340 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java @@ -0,0 +1,52 @@ +package com.smeem.api.common.advicer; + +import com.smeem.api.common.ApiResponseUtil; +import com.smeem.api.common.BaseResponse; +import com.smeem.common.exception.*; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@RestControllerAdvice +public class ErrorHandler { + + @ExceptionHandler(TrainingTimeException.class) + public ResponseEntity> trainingTimeException(TrainingTimeException exception) { + return ApiResponseUtil.failure(exception.getFailureCode()); + } + + @ExceptionHandler(TokenException.class) + public ResponseEntity> tokenException(TokenException exception) { + return ApiResponseUtil.failure(exception.getFailureCode()); + } + + @ExceptionHandler(BadgeException.class) + public ResponseEntity> badgeException(BadgeException exception) { + return ApiResponseUtil.failure(exception.getFailureCode()); + } + + @ExceptionHandler(DiaryException.class) + public ResponseEntity> diaryException(DiaryException exception) { + return ApiResponseUtil.failure(exception.getFailureCode()); + } + + @ExceptionHandler(MemberException.class) + public ResponseEntity> memberException(MemberException exception) { + return ApiResponseUtil.failure(exception.getFailureCode()); + } + + @ExceptionHandler(GoalException.class) + public ResponseEntity> goalException(GoalException exception) { + return ApiResponseUtil.failure(exception.getFailureCode()); + } + + @ExceptionHandler(TopicException.class) + public ResponseEntity> topicException(TopicException exception) { + return ApiResponseUtil.failure(exception.getFailureCode()); + } + + @ExceptionHandler(AppleException.class) + public ResponseEntity> appleException(AppleException exception) { + return ApiResponseUtil.failure(exception.getFailureCode()); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryService.java b/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryService.java index 970907d8..8cd79ae3 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryService.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryService.java @@ -8,8 +8,8 @@ import com.smeem.api.diary.controller.dto.response.DiaryResponseDTO; import com.smeem.api.member.service.MemberService; import com.smeem.api.topic.service.TopicService; -import com.smeem.common.code.ErrorMessage; import com.smeem.common.config.ValueConfig; +import com.smeem.common.exception.DiaryException; import com.smeem.common.util.Util; import com.smeem.domain.badge.model.Badge; import com.smeem.domain.diary.model.DeletedDiary; @@ -27,6 +27,8 @@ import java.util.ArrayList; import java.util.List; +import static com.smeem.common.code.failure.DiaryFailureCode.EXIST_TODAY_DIARY; +import static com.smeem.common.code.failure.DiaryFailureCode.INVALID_DIARY; import static java.lang.Integer.parseInt; import static java.time.LocalDateTime.now; import static java.util.Objects.nonNull; @@ -50,7 +52,7 @@ public CreatedDiaryResponseDTO save(Long memberId, DiaryRequestDTO request) { Member member = memberService.get(memberId); if (member.wroteDiaryToday()) { - throw new IllegalStateException(ErrorMessage.EXIST_TODAY_DIARY.getMessage()); + throw new DiaryException(EXIST_TODAY_DIARY); } Topic topic = topicService.get(request.topicId()); @@ -123,7 +125,7 @@ public List getAllByMemberId(Long memberId) { public Diary get(Long id) { return diaryRepository.findById(id) - .orElseThrow(() -> new RuntimeException(ErrorMessage.INVALID_DIARY.getMessage())); + .orElseThrow(() -> new DiaryException(INVALID_DIARY)); } private List obtainBadges(Member member, LocalDateTime createdAt) { diff --git a/smeem-api/src/main/java/com/smeem/api/goal/service/GoalService.java b/smeem-api/src/main/java/com/smeem/api/goal/service/GoalService.java index ec298028..071b3ba7 100644 --- a/smeem-api/src/main/java/com/smeem/api/goal/service/GoalService.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/service/GoalService.java @@ -5,17 +5,17 @@ import com.smeem.api.goal.controller.dto.response.GoalResponseDTO; import com.smeem.api.goal.controller.dto.response.GoalsResponseDTO; -import com.smeem.common.code.ErrorMessage; +import com.smeem.common.exception.GoalException; import com.smeem.domain.goal.model.Goal; import com.smeem.domain.goal.model.GoalType; import com.smeem.domain.goal.repository.GoalRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; - -import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; +import static com.smeem.common.code.failure.GoalFailureCode.EMPTY_GOAL; + @Service @RequiredArgsConstructor @Transactional(readOnly = true) @@ -30,7 +30,7 @@ public GoalsResponseDTO getAll() { public GoalResponseDTO getByType(GoalType goalType) { Goal goal = goalRepository.findOneByType(goalType) - .orElseThrow(() -> new EntityNotFoundException(ErrorMessage.EMPTY_GOAL.getMessage())); + .orElseThrow(() -> new GoalException(EMPTY_GOAL)); return new GoalResponseDTO(goal.getType().getDescription(), goal.getWay(), goal.getDetail()); } } diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/MemberBadgeService.java b/smeem-api/src/main/java/com/smeem/api/member/service/MemberBadgeService.java index c4a948ca..be04f287 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/MemberBadgeService.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/MemberBadgeService.java @@ -1,15 +1,16 @@ package com.smeem.api.member.service; -import com.smeem.common.code.ErrorMessage; +import com.smeem.common.exception.BadgeException; import com.smeem.domain.badge.model.Badge; import com.smeem.domain.member.model.Member; import com.smeem.domain.member.model.MemberBadge; import com.smeem.domain.member.repository.MemberBadgeRepository; -import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import static com.smeem.common.code.failure.BadgeFailureCode.EMPTY_BADGE; + @Service @RequiredArgsConstructor public class MemberBadgeService { @@ -30,6 +31,6 @@ public void deleteAllByMember(Member member) { protected Badge getBadgeByMemberId(Long memberId) { return memberBadgeRepository.findFirstByMemberIdOrderByCreatedAtDesc(memberId).orElseThrow( - () -> new EntityNotFoundException(ErrorMessage.EMPTY_BADGE.getMessage())).getBadge(); + () -> new BadgeException(EMPTY_BADGE)).getBadge(); } } diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java b/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java index eac83229..cf033bd5 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java @@ -12,15 +12,14 @@ import com.smeem.api.member.controller.dto.response.MemberNameResponseDTO; import com.smeem.api.member.controller.dto.response.MemberUpdateResponseDTO; import com.smeem.api.member.controller.dto.response.TrainingTimeResponseDTO; -import com.smeem.common.code.ErrorMessage; import com.smeem.common.config.ValueConfig; +import com.smeem.common.exception.MemberException; +import com.smeem.common.exception.TrainingTimeException; import com.smeem.domain.badge.model.Badge; import com.smeem.domain.member.model.Member; import com.smeem.domain.member.repository.MemberRepository; import com.smeem.domain.training.model.DayType; import com.smeem.domain.training.model.TrainingTime; -import jakarta.persistence.EntityExistsException; -import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -31,10 +30,12 @@ import java.util.List; import java.util.stream.Collectors; +import static com.smeem.common.code.failure.MemberFailureCode.DUPLICATE_USERNAME; +import static com.smeem.common.code.failure.MemberFailureCode.EMPTY_MEMBER; +import static com.smeem.common.code.failure.TrainingTimeFailureCode.NOT_SET_TRAINING_TIME; import static java.util.Objects.isNull; import static java.util.Objects.nonNull; - @Service @Transactional(readOnly = true) @RequiredArgsConstructor @@ -115,7 +116,7 @@ public MemberNameResponseDTO checkDuplicatedName(String name) { public Member get(Long id) { return memberRepository.findById(id) - .orElseThrow(() -> new RuntimeException(ErrorMessage.EMPTY_MEMBER.getMessage())); + .orElseThrow(() -> new MemberException(EMPTY_MEMBER)); } private void updateTrainingTime(Member member, MemberPlanUpdateRequestDTO request) { @@ -138,7 +139,7 @@ private String[] parseDay(String day) { private TrainingTime getOneTrainingTime(List trainingTimes) { return trainingTimes.stream().findFirst().orElseThrow( - () -> new EntityNotFoundException(ErrorMessage.NOT_SET_TRAINING_TIME.getMessage())); + () -> new TrainingTimeException(NOT_SET_TRAINING_TIME)); } private String getDays(List trainingTimeList) { @@ -150,7 +151,7 @@ private String getDays(List trainingTimeList) { private void checkMemberDuplicate(String username) { if (memberRepository.existsByUsername(username)) { - throw new EntityExistsException(ErrorMessage.DUPLICATE_USERNAME.getMessage()); + throw new MemberException(DUPLICATE_USERNAME); } } } \ No newline at end of file diff --git a/smeem-api/src/main/java/com/smeem/api/topic/service/TopicService.java b/smeem-api/src/main/java/com/smeem/api/topic/service/TopicService.java index bef3f652..c1746839 100644 --- a/smeem-api/src/main/java/com/smeem/api/topic/service/TopicService.java +++ b/smeem-api/src/main/java/com/smeem/api/topic/service/TopicService.java @@ -1,16 +1,16 @@ package com.smeem.api.topic.service; import com.smeem.api.topic.controller.dto.response.TopicResponseDTO; -import com.smeem.common.code.ErrorMessage; +import com.smeem.common.exception.TopicException; import com.smeem.domain.topic.model.Topic; import com.smeem.domain.topic.repository.TopicRepository; -import jakarta.persistence.EntityNotFoundException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import lombok.RequiredArgsConstructor; +import static com.smeem.common.code.failure.TopicFailureCode.INVALID_TOPIC; import static java.util.Objects.nonNull; @Service @@ -28,7 +28,7 @@ public TopicResponseDTO getRandom() { public Topic get(Long id) { return nonNull(id) ? topicRepository.findById(id) - .orElseThrow(() -> new EntityNotFoundException(ErrorMessage.INVALID_TOPIC.getMessage())) + .orElseThrow(() -> new TopicException(INVALID_TOPIC)) : null; } } diff --git a/smeem-common/src/main/java/com/smeem/common/advicer/ErrorHandler.java b/smeem-common/src/main/java/com/smeem/common/advicer/ErrorHandler.java deleted file mode 100644 index e0d98e6d..00000000 --- a/smeem-common/src/main/java/com/smeem/common/advicer/ErrorHandler.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.smeem.common.advicer; - - -import java.io.IOException; -import java.util.NoSuchElementException; - - -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.RestControllerAdvice; - - - -@RestControllerAdvice -public class ErrorHandler { - -// @ExceptionHandler(EntityNotFoundException.class) -// public ResponseEntity entityNotFoundException(EntityNotFoundException ex) { -// return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ApiResponse.fail(ex.getMessage())); -// } -// -// @ExceptionHandler(ChangeSetPersister.NotFoundException.class) -// public ResponseEntity notFoundException(ChangeSetPersister.NotFoundException ex) { -// return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ApiResponse.fail(ex.getMessage())); -// } -// -// @ExceptionHandler(NoSuchElementException.class) -// public ResponseEntity noSuchElementException(NoSuchElementException ex) { -// return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ApiResponse.fail(ex.getMessage())); -// } -// -// @ExceptionHandler(IllegalArgumentException.class) -// public ResponseEntity illegalArgumentException(IllegalArgumentException ex) { -// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.fail(ex.getMessage())); -// } -// -// @ExceptionHandler(ConstraintViolationException.class) -// public ResponseEntity constraintViolationException(ConstraintViolationException ex) { -// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.fail(ex.getMessage())); -// } -// -// @ExceptionHandler(EntityExistsException.class) -// public ResponseEntity entityExistsException(EntityExistsException ex) { -// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.fail(ex.getMessage())); -// } -// -// @ExceptionHandler(InvalidBearerTokenException.class) -// public ResponseEntity invalidBearerTokenException(InvalidBearerTokenException ex) { -// return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(ApiResponse.fail(ex.getMessage())); -// } -// -// @ExceptionHandler(IOException.class) -// public ResponseEntity ioException(IOException ex) { -// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ApiResponse.fail(ex.getMessage())); -// } -// -// @ExceptionHandler(IllegalStateException.class) -// public ResponseEntity illegalStateException(IllegalStateException ex) { -// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.fail(ex.getMessage())); -// } -} diff --git a/smeem-common/src/main/java/com/smeem/common/code/failure/AlarmFailureCode.java b/smeem-common/src/main/java/com/smeem/common/code/failure/AlarmFailureCode.java deleted file mode 100644 index 82129d63..00000000 --- a/smeem-common/src/main/java/com/smeem/common/code/failure/AlarmFailureCode.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.smeem.common.code.failure; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; - -import static org.springframework.http.HttpStatus.BAD_REQUEST; -import static org.springframework.http.HttpStatus.NOT_FOUND; - -@RequiredArgsConstructor -@Getter -public enum AlarmFailureCode implements FailureCode { - - /** - * 400 BAD REQUEST - */ - INVALID_DAY_OF_WEEK(BAD_REQUEST, "유효하지 않은 요일 값입니다."), - ; - - private final HttpStatus status; - private final String message; -} diff --git a/smeem-common/src/main/java/com/smeem/common/code/failure/AuthFailureCode.java b/smeem-common/src/main/java/com/smeem/common/code/failure/AuthFailureCode.java index d72f5847..e1d3a6fc 100644 --- a/smeem-common/src/main/java/com/smeem/common/code/failure/AuthFailureCode.java +++ b/smeem-common/src/main/java/com/smeem/common/code/failure/AuthFailureCode.java @@ -14,9 +14,8 @@ public enum AuthFailureCode implements FailureCode { * 401 UNAUTHORIZED */ EMPTY_ACCESS_TOKEN(UNAUTHORIZED, "액세스 토큰이 없습니다."), - EMPTY_REFRESH_TOKEN(UNAUTHORIZED, "리프레시 토큰이 없습니다"), INVALID_TOKEN(UNAUTHORIZED, "유효하지 않은 토큰입니다"), - MESSAGE_UNAUTHORIZED(UNAUTHORIZED, "유효하지 않은 토큰"), + INVALID_APPLE_TOKEN(UNAUTHORIZED, "유효하지 않은 애플 토큰입니다.") ; private final HttpStatus status; diff --git a/smeem-common/src/main/java/com/smeem/common/code/failure/BadgeFailureCode.java b/smeem-common/src/main/java/com/smeem/common/code/failure/BadgeFailureCode.java index 2a693cb6..67506b29 100644 --- a/smeem-common/src/main/java/com/smeem/common/code/failure/BadgeFailureCode.java +++ b/smeem-common/src/main/java/com/smeem/common/code/failure/BadgeFailureCode.java @@ -4,7 +4,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; -import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.NOT_FOUND; @RequiredArgsConstructor diff --git a/smeem-common/src/main/java/com/smeem/common/code/failure/DiaryFailureCode.java b/smeem-common/src/main/java/com/smeem/common/code/failure/DiaryFailureCode.java index 2dcea08b..9789a799 100644 --- a/smeem-common/src/main/java/com/smeem/common/code/failure/DiaryFailureCode.java +++ b/smeem-common/src/main/java/com/smeem/common/code/failure/DiaryFailureCode.java @@ -20,7 +20,6 @@ public enum DiaryFailureCode implements FailureCode { * 404 NOT FOUND */ INVALID_DIARY(NOT_FOUND, "유효하지 않은 일기입니다."), - DELETED_DIARY(NOT_FOUND, "삭제된 일기입니다."), ; private final HttpStatus status; diff --git a/smeem-common/src/main/java/com/smeem/common/code/failure/TopicFailureCode.java b/smeem-common/src/main/java/com/smeem/common/code/failure/TopicFailureCode.java index d7b3cb60..c0e223de 100644 --- a/smeem-common/src/main/java/com/smeem/common/code/failure/TopicFailureCode.java +++ b/smeem-common/src/main/java/com/smeem/common/code/failure/TopicFailureCode.java @@ -4,7 +4,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; -import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.NOT_FOUND; @RequiredArgsConstructor diff --git a/smeem-common/src/main/java/com/smeem/common/code/failure/TrainingTimeFailureCode.java b/smeem-common/src/main/java/com/smeem/common/code/failure/TrainingTimeFailureCode.java index 6bca69c4..245077f5 100644 --- a/smeem-common/src/main/java/com/smeem/common/code/failure/TrainingTimeFailureCode.java +++ b/smeem-common/src/main/java/com/smeem/common/code/failure/TrainingTimeFailureCode.java @@ -11,6 +11,11 @@ @Getter public enum TrainingTimeFailureCode implements FailureCode { + /** + * 400 BAD REQUEST + */ + INVALID_DAY_OF_WEEK(BAD_REQUEST, "유효하지 않은 요일 값입니다."), + /** * 404 NOT FOUND */ diff --git a/smeem-common/src/main/java/com/smeem/common/exception/AppleException.java b/smeem-common/src/main/java/com/smeem/common/exception/AppleException.java new file mode 100644 index 00000000..88880184 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/exception/AppleException.java @@ -0,0 +1,15 @@ +package com.smeem.common.exception; + +import com.smeem.common.code.failure.FailureCode; +import lombok.Getter; + +@Getter +public class AppleException extends RuntimeException { + + private final FailureCode failureCode; + + public AppleException(FailureCode failureCode) { + super("[AppleException] : " + failureCode.getMessage()); + this.failureCode = failureCode; + } +} diff --git a/smeem-common/src/main/java/com/smeem/common/exception/BadgeException.java b/smeem-common/src/main/java/com/smeem/common/exception/BadgeException.java new file mode 100644 index 00000000..c168d142 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/exception/BadgeException.java @@ -0,0 +1,16 @@ +package com.smeem.common.exception; + +import com.smeem.common.code.failure.BadgeFailureCode; +import com.smeem.common.code.failure.FailureCode; +import lombok.Getter; + +@Getter +public class BadgeException extends RuntimeException { + + private final FailureCode failureCode; + + public BadgeException(BadgeFailureCode failureCode) { + super("[BadgeException] : " + failureCode.getMessage()); + this.failureCode = failureCode; + } +} diff --git a/smeem-common/src/main/java/com/smeem/common/exception/DiaryException.java b/smeem-common/src/main/java/com/smeem/common/exception/DiaryException.java new file mode 100644 index 00000000..42c229e4 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/exception/DiaryException.java @@ -0,0 +1,17 @@ +package com.smeem.common.exception; + + +import com.smeem.common.code.failure.DiaryFailureCode; +import com.smeem.common.code.failure.FailureCode; +import lombok.Getter; + +@Getter +public class DiaryException extends RuntimeException { + + private final FailureCode failureCode; + + public DiaryException(DiaryFailureCode failureCode) { + super("[DiaryException] : " + failureCode.getMessage()); + this.failureCode = failureCode; + } +} diff --git a/smeem-common/src/main/java/com/smeem/common/exception/GoalException.java b/smeem-common/src/main/java/com/smeem/common/exception/GoalException.java new file mode 100644 index 00000000..d9d9e1aa --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/exception/GoalException.java @@ -0,0 +1,17 @@ +package com.smeem.common.exception; + + +import com.smeem.common.code.failure.FailureCode; +import com.smeem.common.code.failure.GoalFailureCode; +import lombok.Getter; + +@Getter +public class GoalException extends RuntimeException { + + private final FailureCode failureCode; + + public GoalException(GoalFailureCode failureCode) { + super("[GoalException] : " + failureCode.getMessage()); + this.failureCode = failureCode; + } +} diff --git a/smeem-common/src/main/java/com/smeem/common/exception/MemberException.java b/smeem-common/src/main/java/com/smeem/common/exception/MemberException.java new file mode 100644 index 00000000..05e1e5bd --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/exception/MemberException.java @@ -0,0 +1,17 @@ +package com.smeem.common.exception; + + +import com.smeem.common.code.failure.FailureCode; +import com.smeem.common.code.failure.MemberFailureCode; +import lombok.Getter; + +@Getter +public class MemberException extends RuntimeException { + + private final FailureCode failureCode; + + public MemberException(MemberFailureCode failureCode) { + super("[MemberException] : " + failureCode.getMessage()); + this.failureCode = failureCode; + } +} diff --git a/smeem-common/src/main/java/com/smeem/common/exception/TokenException.java b/smeem-common/src/main/java/com/smeem/common/exception/TokenException.java new file mode 100644 index 00000000..bf091bd8 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/exception/TokenException.java @@ -0,0 +1,16 @@ +package com.smeem.common.exception; + +import com.smeem.common.code.failure.AuthFailureCode; +import com.smeem.common.code.failure.FailureCode; +import lombok.Getter; + +@Getter +public class TokenException extends SecurityException { + + private final FailureCode failureCode; + + public TokenException(AuthFailureCode failureCode) { + super("[TokenException] : " + failureCode.getMessage()); + this.failureCode = failureCode; + } +} diff --git a/smeem-common/src/main/java/com/smeem/common/exception/TopicException.java b/smeem-common/src/main/java/com/smeem/common/exception/TopicException.java new file mode 100644 index 00000000..c969240e --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/exception/TopicException.java @@ -0,0 +1,16 @@ +package com.smeem.common.exception; + +import com.smeem.common.code.failure.FailureCode; +import com.smeem.common.code.failure.TopicFailureCode; +import lombok.Getter; + +@Getter +public class TopicException extends RuntimeException { + + private final FailureCode failureCode; + + public TopicException(TopicFailureCode failureCode) { + super("[TopicException] : " + failureCode.getMessage()); + this.failureCode = failureCode; + } +} diff --git a/smeem-common/src/main/java/com/smeem/common/exception/TrainingTimeException.java b/smeem-common/src/main/java/com/smeem/common/exception/TrainingTimeException.java new file mode 100644 index 00000000..3edcd8ac --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/exception/TrainingTimeException.java @@ -0,0 +1,16 @@ +package com.smeem.common.exception; + +import com.smeem.common.code.failure.FailureCode; +import com.smeem.common.code.failure.TrainingTimeFailureCode; +import lombok.Getter; + +@Getter +public class TrainingTimeException extends RuntimeException { + + private final FailureCode failureCode; + + public TrainingTimeException(TrainingTimeFailureCode failureCode) { + super("[TrainingTimeException] : " + failureCode.getMessage()); + this.failureCode = failureCode; + } +} diff --git a/smeem-common/src/main/java/com/smeem/common/util/Util.java b/smeem-common/src/main/java/com/smeem/common/util/Util.java index 6e7b8de3..35ce197a 100644 --- a/smeem-common/src/main/java/com/smeem/common/util/Util.java +++ b/smeem-common/src/main/java/com/smeem/common/util/Util.java @@ -1,6 +1,6 @@ package com.smeem.common.util; -import static com.smeem.common.code.ErrorMessage.EMPTY_ACCESS_TOKEN; +import static com.smeem.common.code.failure.AuthFailureCode.EMPTY_ACCESS_TOKEN; import static java.util.Objects.*; import java.net.URI; @@ -8,13 +8,14 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import com.smeem.common.exception.TokenException; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; public class Util { public static Long getMemberId(Principal principal) { if (isNull(principal)) { - throw new SecurityException(EMPTY_ACCESS_TOKEN.getMessage()); + throw new TokenException(EMPTY_ACCESS_TOKEN); } return Long.valueOf(principal.getName()); } diff --git a/smeem-domain/src/main/java/com/smeem/domain/training/repository/TrainingTimeRepositoryImpl.java b/smeem-domain/src/main/java/com/smeem/domain/training/repository/TrainingTimeRepositoryImpl.java index 68872179..3eaaa22b 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/training/repository/TrainingTimeRepositoryImpl.java +++ b/smeem-domain/src/main/java/com/smeem/domain/training/repository/TrainingTimeRepositoryImpl.java @@ -1,15 +1,15 @@ package com.smeem.domain.training.repository; +import static com.smeem.common.code.failure.TrainingTimeFailureCode.INVALID_DAY_OF_WEEK; +import static com.smeem.domain.member.model.QMember.member; import static com.smeem.domain.training.model.DayType.*; - +import static com.smeem.domain.training.model.QTrainingTime.trainingTime; import java.time.LocalDateTime; import java.util.List; -import com.smeem.common.code.ErrorMessage; -import com.smeem.domain.member.model.QMember; +import com.smeem.common.exception.TrainingTimeException; import com.smeem.domain.training.model.DayType; -import com.smeem.domain.training.model.QTrainingTime; import com.smeem.domain.training.model.TrainingTime; import org.springframework.stereotype.Repository; @@ -26,14 +26,14 @@ public class TrainingTimeRepositoryImpl implements TrainingTimeCustomRepository @Override public List getTrainingTimeForPushAlarm(LocalDateTime now) { return queryFactory - .select(QTrainingTime.trainingTime) - .from(QTrainingTime.trainingTime) - .join(QTrainingTime.trainingTime.member, QMember.member).fetchJoin() + .select(trainingTime) + .from(trainingTime) + .join(trainingTime.member, member).fetchJoin() .where( - QTrainingTime.trainingTime.day.eq(getDayType(now.getDayOfWeek().getValue())), - QTrainingTime.trainingTime.hour.eq(now.getHour()), - QTrainingTime.trainingTime.minute.eq(now.getMinute()), - QMember.member.hasPushAlarm.eq(true) + trainingTime.day.eq(getDayType(now.getDayOfWeek().getValue())), + trainingTime.hour.eq(now.getHour()), + trainingTime.minute.eq(now.getMinute()), + member.hasPushAlarm.eq(true) ) .fetch(); } @@ -47,7 +47,7 @@ private DayType getDayType(int dayValue) { case 5 -> FRI; case 6 -> SAT; case 7 -> SUN; - default -> throw new RuntimeException(ErrorMessage.INVALID_DAY_OF_WEEK.getMessage()); + default -> throw new TrainingTimeException(INVALID_DAY_OF_WEEK); }; } } diff --git a/smeem-external/src/main/java/com/smeem/external/apple/AppleSignInService.java b/smeem-external/src/main/java/com/smeem/external/apple/AppleSignInService.java index ff72e4ef..e6091b4a 100644 --- a/smeem-external/src/main/java/com/smeem/external/apple/AppleSignInService.java +++ b/smeem-external/src/main/java/com/smeem/external/apple/AppleSignInService.java @@ -4,6 +4,7 @@ import com.smeem.common.config.RestTemplateConfig; import com.smeem.common.config.ValueConfig; +import com.smeem.common.exception.AppleException; import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; import lombok.RequiredArgsConstructor; @@ -24,6 +25,8 @@ import java.util.Base64; import java.util.Objects; +import static com.smeem.common.code.failure.AuthFailureCode.INVALID_APPLE_TOKEN; + @RequiredArgsConstructor @Component public class AppleSignInService { @@ -47,8 +50,8 @@ public JsonArray getApplePublicKeys() { JsonObject keys = (JsonObject) JsonParser.parseString(result.toString()); return (JsonArray) keys.get("keys"); - } catch (IOException e) { - throw new RuntimeException(e); + } catch (IOException exception) { + throw new AppleException(INVALID_APPLE_TOKEN); } } From 1e902493ddff9e00c5d3fdd0320c36007ce149f6 Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 7 Feb 2024 15:37:57 +0900 Subject: [PATCH 31/86] =?UTF-8?q?[REFACTOR]=20batch=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/smeem/api/common/BaseResponse.java | 2 - .../api/common/advicer/ErrorHandler.java | 5 ++ .../smeem/api/diary/service/DiaryService.java | 12 --- .../com/smeem/api/test/TestController.java | 8 +- .../java/com/smeem/api/test/TestService.java | 27 +++++++ smeem-batch/build.gradle | 4 + .../smeem/batch/scheduler/DiaryScheduler.java | 21 +++++- .../batch/scheduler/MessageScheduler.java | 24 +++++- .../common/code/failure/FcmFailureCode.java | 22 ++++++ .../smeem/common/exception/FcmException.java | 16 ++++ .../smeem/external/firebase/FcmService.java | 69 +++++++++++++++++ .../external/firebase/MessageService.java | 74 ------------------- 12 files changed, 188 insertions(+), 96 deletions(-) create mode 100644 smeem-api/src/main/java/com/smeem/api/test/TestService.java create mode 100644 smeem-common/src/main/java/com/smeem/common/code/failure/FcmFailureCode.java create mode 100644 smeem-common/src/main/java/com/smeem/common/exception/FcmException.java create mode 100644 smeem-external/src/main/java/com/smeem/external/firebase/FcmService.java delete mode 100644 smeem-external/src/main/java/com/smeem/external/firebase/MessageService.java diff --git a/smeem-api/src/main/java/com/smeem/api/common/BaseResponse.java b/smeem-api/src/main/java/com/smeem/api/common/BaseResponse.java index 3ddd319d..b72b470f 100644 --- a/smeem-api/src/main/java/com/smeem/api/common/BaseResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/common/BaseResponse.java @@ -1,14 +1,12 @@ package com.smeem.api.common; import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.AllArgsConstructor; import lombok.Builder; import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL; import static lombok.AccessLevel.PRIVATE; @Builder(access = PRIVATE) -@AllArgsConstructor(access = PRIVATE) public record BaseResponse( boolean success, String message, diff --git a/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java b/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java index f6320340..f4bbbe1f 100644 --- a/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java +++ b/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java @@ -49,4 +49,9 @@ public ResponseEntity> topicException(TopicException exception) public ResponseEntity> appleException(AppleException exception) { return ApiResponseUtil.failure(exception.getFailureCode()); } + + @ExceptionHandler(FcmException.class) + public ResponseEntity> fcmException(FcmException exception) { + return ApiResponseUtil.failure(exception.getFailureCode()); + } } diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryService.java b/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryService.java index 8cd79ae3..9914d6ee 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryService.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryService.java @@ -22,7 +22,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.time.LocalDate; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -102,17 +101,6 @@ public DiariesResponseDTO getDiaries(Long memberId, String startDate, String end return DiariesResponseDTO.of(diaries, hasRemind); } - @Transactional - public void deleteExpiredDiary() { - LocalDateTime expiryDate = getExpiryDate(); - deletedDiaryRepository.deleteByUpdatedAtBefore(expiryDate); - } - - private LocalDateTime getExpiryDate() { - int expiredDay = parseInt(valueConfig.getDURATION_EXPIRED()) - 1; - return LocalDate.now().minusDays(expiredDay).atStartOfDay(); - } - @Transactional public void deleteAllByMember(Member member) { diaryRepository.deleteAllByMember(member); diff --git a/smeem-api/src/main/java/com/smeem/api/test/TestController.java b/smeem-api/src/main/java/com/smeem/api/test/TestController.java index 0eb2e35a..5f1cd7f5 100644 --- a/smeem-api/src/main/java/com/smeem/api/test/TestController.java +++ b/smeem-api/src/main/java/com/smeem/api/test/TestController.java @@ -5,7 +5,7 @@ import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; import com.smeem.common.config.ValueConfig; -import com.smeem.external.firebase.MessageService; +import lombok.val; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -22,7 +22,7 @@ @RequestMapping("/api/v2/test") public class TestController { - private final MessageService messageService; + private final TestService testService; private final ValueConfig valueConfig; @GetMapping @@ -32,7 +32,9 @@ public ResponseEntity> test() { @GetMapping("/alarm") public ResponseEntity> alarmTest(@Parameter(hidden = true) Principal principal) { - // messageService.pushTest(valueConfig.getMESSAGE_TITLE(), valueConfig.getMESSAGE_BODY(), Long.valueOf(principal.getName())); + val title = valueConfig.getMESSAGE_TITLE(); + val body = valueConfig.getMESSAGE_BODY(); + testService.pushTest(title, body, Long.valueOf(principal.getName())); return ApiResponseUtil.success(SUCCESS_SEND_PUSH_ALARM); } } diff --git a/smeem-api/src/main/java/com/smeem/api/test/TestService.java b/smeem-api/src/main/java/com/smeem/api/test/TestService.java new file mode 100644 index 00000000..974d887e --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/test/TestService.java @@ -0,0 +1,27 @@ +package com.smeem.api.test; + + +import com.smeem.common.exception.MemberException; +import com.smeem.domain.member.model.Member; +import com.smeem.domain.member.repository.MemberRepository; +import com.smeem.external.firebase.FcmService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import static com.smeem.common.code.failure.MemberFailureCode.*; + +@Service +@Transactional(readOnly = true) +@RequiredArgsConstructor +public class TestService { + + private final MemberRepository memberRepository; + private final FcmService fcmService; + + public void pushTest(String title, String body, Long memberId) { + Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new MemberException(INVALID_MEMBER)); + fcmService.pushMessage(member.getFcmToken(), title, body); + } +} \ No newline at end of file diff --git a/smeem-batch/build.gradle b/smeem-batch/build.gradle index d8ce4c44..c0d69595 100644 --- a/smeem-batch/build.gradle +++ b/smeem-batch/build.gradle @@ -1,6 +1,10 @@ dependencies { implementation project(":smeem-common") implementation project(":smeem-domain") + implementation project(":smeem-external") implementation 'org.springframework.boot:spring-boot-starter-web' + + // jpa + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' } \ No newline at end of file diff --git a/smeem-batch/src/main/java/com/smeem/batch/scheduler/DiaryScheduler.java b/smeem-batch/src/main/java/com/smeem/batch/scheduler/DiaryScheduler.java index f5a75734..a2b6c5bc 100644 --- a/smeem-batch/src/main/java/com/smeem/batch/scheduler/DiaryScheduler.java +++ b/smeem-batch/src/main/java/com/smeem/batch/scheduler/DiaryScheduler.java @@ -1,18 +1,35 @@ package com.smeem.batch.scheduler; +import com.smeem.common.config.ValueConfig; +import com.smeem.domain.diary.repository.DeletedDiaryRepository; import lombok.RequiredArgsConstructor; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +import static java.lang.Integer.parseInt; @Component @EnableScheduling @RequiredArgsConstructor public class DiaryScheduler { - private final DiaryService diaryService; + + private final DeletedDiaryRepository deletedDiaryRepository; + private final ValueConfig valueConfig; @Scheduled(cron = "0 0 0 * * *") + @Transactional public void deleteExpiredDiaries() { - diaryService.deleteExpiredDiary(); + LocalDateTime expiryDate = getExpiryDate(); + deletedDiaryRepository.deleteByUpdatedAtBefore(expiryDate); + } + + private LocalDateTime getExpiryDate() { + int expiredDay = parseInt(valueConfig.getDURATION_EXPIRED()) - 1; + return LocalDate.now().minusDays(expiredDay).atStartOfDay(); } } diff --git a/smeem-batch/src/main/java/com/smeem/batch/scheduler/MessageScheduler.java b/smeem-batch/src/main/java/com/smeem/batch/scheduler/MessageScheduler.java index 1e887929..97be9bb9 100644 --- a/smeem-batch/src/main/java/com/smeem/batch/scheduler/MessageScheduler.java +++ b/smeem-batch/src/main/java/com/smeem/batch/scheduler/MessageScheduler.java @@ -1,10 +1,16 @@ package com.smeem.batch.scheduler; + import com.smeem.common.config.ValueConfig; +import com.smeem.domain.training.model.TrainingTime; +import com.smeem.domain.training.repository.TrainingTimeRepository; +import com.smeem.external.firebase.FcmService; import lombok.RequiredArgsConstructor; +import lombok.val; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; @@ -12,12 +18,24 @@ @EnableScheduling @RequiredArgsConstructor public class MessageScheduler { -// private final MessageService messageService; + + private final FcmService fcmService; + private final TrainingTimeRepository trainingTimeRepository; private final ValueConfig valueConfig; @Scheduled(cron = "${fcm.cron_expression}") - public void pushMessage() throws InterruptedException { + @Transactional(readOnly = true) + public void pushMessagesForTrainingTime() throws InterruptedException { Thread.sleep(1000); -// messageService.pushMessageForTrainingTime(LocalDateTime.now(), valueConfig.getMESSAGE_TITLE(), valueConfig.getMESSAGE_BODY()); + + val trainingTimes = trainingTimeRepository.getTrainingTimeForPushAlarm(LocalDateTime.now()); + trainingTimes.forEach(this::pushMessageForTrainingTime); + } + + private void pushMessageForTrainingTime(TrainingTime trainingTime) { + val fcmToken = trainingTime.getMember().getFcmToken(); + val messageTitle = valueConfig.getMESSAGE_TITLE(); + val messageBody = valueConfig.getMESSAGE_BODY(); + fcmService.pushMessage(fcmToken, messageTitle, messageBody); } } diff --git a/smeem-common/src/main/java/com/smeem/common/code/failure/FcmFailureCode.java b/smeem-common/src/main/java/com/smeem/common/code/failure/FcmFailureCode.java new file mode 100644 index 00000000..d4c0b900 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/code/failure/FcmFailureCode.java @@ -0,0 +1,22 @@ +package com.smeem.common.code.failure; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.BAD_REQUEST; + +@RequiredArgsConstructor +@Getter +public enum FcmFailureCode implements FailureCode { + + /** + * 400 BAD REQUEST + */ + INVALID_REQUEST_PATTERN(BAD_REQUEST, "잘못된 요청 형식입니다."), + INVALID_REQUEST_MESSAGE(BAD_REQUEST, "잘못된 fcm 요청입니다."), + ; + + private final HttpStatus status; + private final String message; +} diff --git a/smeem-common/src/main/java/com/smeem/common/exception/FcmException.java b/smeem-common/src/main/java/com/smeem/common/exception/FcmException.java new file mode 100644 index 00000000..6460e776 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/exception/FcmException.java @@ -0,0 +1,16 @@ +package com.smeem.common.exception; + +import com.smeem.common.code.failure.FailureCode; +import com.smeem.common.code.failure.FcmFailureCode; +import lombok.Getter; + +@Getter +public class FcmException extends RuntimeException { + + private final FailureCode failureCode; + + public FcmException(FcmFailureCode failureCode) { + super("[FcmException] : " + failureCode.getMessage()); + this.failureCode = failureCode; + } +} diff --git a/smeem-external/src/main/java/com/smeem/external/firebase/FcmService.java b/smeem-external/src/main/java/com/smeem/external/firebase/FcmService.java new file mode 100644 index 00000000..b70bc583 --- /dev/null +++ b/smeem-external/src/main/java/com/smeem/external/firebase/FcmService.java @@ -0,0 +1,69 @@ +package com.smeem.external.firebase; + + +import java.io.IOException; +import java.util.List; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import com.smeem.common.config.ValueConfig; +import com.smeem.common.exception.FcmException; +import org.springframework.core.io.ClassPathResource; +import org.springframework.stereotype.Service; + +import com.google.auth.oauth2.GoogleCredentials; + +import lombok.RequiredArgsConstructor; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; + +import static com.smeem.common.code.failure.FcmFailureCode.INVALID_REQUEST_MESSAGE; +import static com.smeem.common.code.failure.FcmFailureCode.INVALID_REQUEST_PATTERN; +import static org.springframework.http.HttpHeaders.AUTHORIZATION; + +@Service +@RequiredArgsConstructor +public class FcmService { + + private final ObjectMapper objectMapper; + private final ValueConfig valueConfig; + + public void pushMessage(String targetToken, String title, String body) { + try { + String message = makeMessage(targetToken, title, body); + RequestBody requestBody = RequestBody.create(message, MediaType.get("application/json; charset=utf-8")); + + Request request = new Request.Builder() + .url(valueConfig.getFIREBASE_API_URI()) + .post(requestBody) + .addHeader(AUTHORIZATION, "Bearer " + getAccessToken()) + .addHeader("Accept", "application/json; UTF-8") + .build(); + + OkHttpClient client = new OkHttpClient(); + client.newCall(request).execute(); + } catch (Exception exception) { + throw new FcmException(INVALID_REQUEST_MESSAGE); + } + } + + private String makeMessage(String targetToken, String title, String body) { + try { + MessageDTO message = MessageDTO.of(targetToken, title, body); + return objectMapper.writeValueAsString(message); + } catch (JsonProcessingException exception) { + throw new FcmException(INVALID_REQUEST_PATTERN); + } + } + + private String getAccessToken() throws IOException { + GoogleCredentials googleCredentials = GoogleCredentials + .fromStream(new ClassPathResource(valueConfig.getFIREBASE_CONFIG_PATH()).getInputStream()) + .createScoped(List.of(valueConfig.getGOOGLE_API_URI())); + googleCredentials.refreshIfExpired(); + return googleCredentials.getAccessToken().getTokenValue(); + } +} diff --git a/smeem-external/src/main/java/com/smeem/external/firebase/MessageService.java b/smeem-external/src/main/java/com/smeem/external/firebase/MessageService.java deleted file mode 100644 index 482f70d3..00000000 --- a/smeem-external/src/main/java/com/smeem/external/firebase/MessageService.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.smeem.external.firebase; - - -import java.io.IOException; -import java.time.LocalDateTime; -import java.util.List; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; - -import org.springframework.core.io.ClassPathResource; -import org.springframework.stereotype.Service; - -import com.google.auth.oauth2.GoogleCredentials; - -import lombok.RequiredArgsConstructor; -import okhttp3.MediaType; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.RequestBody; - -@Service -@RequiredArgsConstructor -//@Transactional(readOnly = true) -public class MessageService { -// -// private final ObjectMapper objectMapper; -// private final TrainingTimeRepository trainingTimeRepository; -// private final MemberRepository memberRepository; -// private final ValueConfig valueConfig; -// -// public void pushMessageForTrainingTime(LocalDateTime now, String title, String body) { -// trainingTimeRepository.getTrainingTimeForPushAlarm(now) -// .forEach(trainingTime -> pushMessage(trainingTime.getMember().getFcmToken(), title, body)); -// } -// -// public void pushTest(String title, String body, Long memberId) { -// Member member = memberRepository.findById(memberId) -// .orElseThrow(() -> new EntityNotFoundException(ErrorMessage.INVALID_MEMBER.getMessage())); -// pushMessage(member.getFcmToken(), title, body); -// } -// -// private void pushMessage(String targetToken, String title, String body) { -// try { -// String message = makeMessage(targetToken, title, body); -// RequestBody requestBody = RequestBody.create(message, MediaType.get("application/json; charset=utf-8")); -// -// Request request = new Request.Builder() -// .url(valueConfig.getFIREBASE_API_URI()) -// .post(requestBody) -// .addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + getAccessToken()) -// .addHeader("Accept", "application/json; UTF-8") -// .build(); -// -// OkHttpClient client = new OkHttpClient(); -// client.newCall(request).execute(); -// } catch (Exception e) { -// throw new RuntimeException(e); -// } -// } -// -// private String makeMessage(String targetToken, String title, String body) throws JsonProcessingException { -// MessageDTO message = MessageDTO.of(targetToken, title, body); -// return objectMapper.writeValueAsString(message); -// } -// -// private String getAccessToken() throws IOException { -// GoogleCredentials googleCredentials = GoogleCredentials -// .fromStream(new ClassPathResource(valueConfig.getFIREBASE_CONFIG_PATH()).getInputStream()) -// .createScoped(List.of(valueConfig.getGOOGLE_API_URI())); -// googleCredentials.refreshIfExpired(); -// return googleCredentials.getAccessToken().getTokenValue(); -// } -} From 3c614a33d8b205350b6bc935479a12ee88b676e4 Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 7 Feb 2024 20:30:23 +0900 Subject: [PATCH 32/86] =?UTF-8?q?[FIX]=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/smeem/api/controller/BaseControllerTest.java | 4 ++-- .../java/com/smeem/api/fixture/diary/DiaryFixture.java | 9 ++++++--- .../java/com/smeem/api/fixture/topic/TopicFixture.java | 7 ++++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/smeem-api/src/test/java/com/smeem/api/controller/BaseControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/BaseControllerTest.java index 0eec52af..a1777e42 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/BaseControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/BaseControllerTest.java @@ -1,8 +1,8 @@ package com.smeem.api.controller; import com.fasterxml.jackson.databind.ObjectMapper; -import com.smeme.server.config.jwt.CustomJwtAuthenticationEntryPoint; -import com.smeme.server.config.jwt.JwtTokenProvider; +import com.smeem.api.auth.jwt.CustomJwtAuthenticationEntryPoint; +import com.smeem.api.auth.jwt.JwtTokenProvider; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/smeem-api/src/test/java/com/smeem/api/fixture/diary/DiaryFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/diary/DiaryFixture.java index 5f63d4a0..ff42cfbe 100644 --- a/smeem-api/src/test/java/com/smeem/api/fixture/diary/DiaryFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/diary/DiaryFixture.java @@ -1,14 +1,17 @@ package com.smeem.api.fixture.diary; + import com.smeem.api.fixture.member.MemberFixture; import com.smeem.api.fixture.topic.TopicFixture; -import com.smeme.server.model.Diary; -import com.smeme.server.model.LangType; +import com.smeem.domain.diary.model.Diary; +import com.smeem.domain.member.model.LangType; + +import static com.smeem.domain.member.model.LangType.en; public class DiaryFixture { private static final Long DIARY_ID = 1L; private static final String DIARY_CONTENT = ""; - private static final LangType DIARY_LANG = LangType.en; + private static final LangType DIARY_LANG = en; private static final Boolean DIARY_IS_DELETED = false; private static final Boolean DIARY_IS_PUBLIC = true; diff --git a/smeem-api/src/test/java/com/smeem/api/fixture/topic/TopicFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/topic/TopicFixture.java index 28899f17..773985f8 100644 --- a/smeem-api/src/test/java/com/smeem/api/fixture/topic/TopicFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/topic/TopicFixture.java @@ -1,8 +1,9 @@ package com.smeem.api.fixture.topic; -import com.smeme.server.dto.topic.TopicResponseDTO; -import com.smeme.server.model.topic.Category; -import com.smeme.server.model.topic.Topic; + +import com.smeem.api.topic.controller.dto.response.TopicResponseDTO; +import com.smeem.domain.topic.model.Category; +import com.smeem.domain.topic.model.Topic; public class TopicFixture { From a84afb0aaf33268a247c2587d5caa4dc3d287865 Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 7 Feb 2024 20:39:11 +0900 Subject: [PATCH 33/86] =?UTF-8?q?[FIX]=20script=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EB=82=B4=20=EA=B2=BD=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-dev.yml | 7 ++++--- .github/workflows/cd-prod.yml | 7 ++++--- .github/workflows/ci.yml | 7 ++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/cd-dev.yml b/.github/workflows/cd-dev.yml index 0539f471..505921be 100644 --- a/.github/workflows/cd-dev.yml +++ b/.github/workflows/cd-dev.yml @@ -22,9 +22,10 @@ jobs: - name: Create application-secret.yml run: | pwd - touch src/main/resources/application-secret.yml - echo "${{ secrets.APPLICATION_SECRET_YML }}" >> src/main/resources/application-secret.yml - cat src/main/resources/application-secret.yml + cd ./smeem-api/src/main/resources + touch ./application-secret.yml + echo "${{ secrets.APPLICATION_SECRET_YML }}" >> ./application-secret.yml + cat ./application-secret.yml - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 diff --git a/.github/workflows/cd-prod.yml b/.github/workflows/cd-prod.yml index bf9bdb4d..e7be3a63 100644 --- a/.github/workflows/cd-prod.yml +++ b/.github/workflows/cd-prod.yml @@ -22,9 +22,10 @@ jobs: - name: Create application-secret.yml run: | pwd - touch src/main/resources/application-secret.yml - echo "${{ secrets.APPLICATION_SECRET_YML }}" >> src/main/resources/application-secret.yml - cat src/main/resources/application-secret.yml + cd ./smeem-api/src/main/resources + touch ./application-secret.yml + echo "${{ secrets.APPLICATION_SECRET_YML }}" >> ./application-secret.yml + cat ./application-secret.yml - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 99d7e680..82a57d7b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,9 +22,10 @@ jobs: - name: Create application-secret.yml run: | pwd - touch src/main/resources/application-secret.yml - echo "${{ secrets.APPLICATION_SECRET_YML }}" >> src/main/resources/application-secret.yml - cat src/main/resources/application-secret.yml + cd ./smeem-api/src/main/resources + touch ./application-secret.yml + echo "${{ secrets.APPLICATION_SECRET_YML }}" >> ./application-secret.yml + cat ./application-secret.yml - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 From dfb52bfcb25fdd2ed8939ac0126f13fdf75d58cd Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 9 Feb 2024 16:57:33 +0900 Subject: [PATCH 34/86] =?UTF-8?q?[TEST]=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=84=EC=8B=9C=20=EC=A4=91=EB=8B=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smeem-api/build.gradle | 34 +- .../resources/static/docs/open-api-3.0.1.json | 1113 +---------------- .../SmemeServerRenewalApplicationTests.java | 7 - .../api/controller/AuthControllerTest.java | 20 +- .../api/controller/BadgeControllerTest.java | 6 +- .../api/controller/BaseControllerTest.java | 8 +- .../api/controller/DiaryControllerTest.java | 24 +- .../api/controller/GoalControllerTest.java | 12 +- .../api/controller/MemberControllerTest.java | 24 +- .../api/controller/TestControllerTest.java | 8 +- .../api/controller/TopicControllerTest.java | 8 +- 11 files changed, 70 insertions(+), 1194 deletions(-) delete mode 100644 smeem-api/src/test/java/com/smeem/SmemeServerRenewalApplicationTests.java diff --git a/smeem-api/build.gradle b/smeem-api/build.gradle index 31f950ff..4400c8c3 100644 --- a/smeem-api/build.gradle +++ b/smeem-api/build.gradle @@ -22,35 +22,35 @@ dependencies { implementation group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.5' implementation group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.5' - // Swagger & RestDocs testImplementation "com.epages:restdocs-api-spec-mockmvc:0.18.2" testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2' +// implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0' } swaggerSources { sample { - setInputFile(file("${project.buildDir}/api-spec/openapi3.yaml")) + setInputFile(file("build/api-spec/openapi3.yaml")) } } openapi3 { - server('http://localhost:8080') - title = 'restdocs-swagger API Documentation' - description = 'Spring REST Docs with SwaggerUI.' - version = '0.0.1' - format = 'yaml' + server = "http://localhost:8080" + title = "SMEEM API Documentation" + description = "Spring REST Docs with SwaggerUI." + version = "0.0.1" + outputFileNamePrefix = 'open-api-3.0.1' + format = 'json' + outputDirectory = 'build/resources/main/static/docs' } - - ext { set('snippetsDir', file("build/generated-snippets")) } -tasks.withType(GenerateSwaggerUI) { +tasks.withType(GenerateSwaggerUI).configureEach { dependsOn 'openapi3' copy { from "build/resources/main/static/docs" @@ -59,16 +59,6 @@ tasks.withType(GenerateSwaggerUI) { } bootJar { - dependsOn(':openapi3') -} -// bootJar 실행 전, copySwaggerUI 를 실행하도록 설정 -openapi3 { - server = "http://localhost:8080" - title = "smeme api documentation" - description = "Spring REST Docs with SwaggerUI." - version = "0.0.1" - outputFileNamePrefix = 'open-api-3.0.1' - format = 'json' - - outputDirectory = 'build/resources/main/static/docs' +// enabled = true + dependsOn('openapi3') } diff --git a/smeem-api/src/main/resources/static/docs/open-api-3.0.1.json b/smeem-api/src/main/resources/static/docs/open-api-3.0.1.json index 38cf2d04..e71bebc4 100644 --- a/smeem-api/src/main/resources/static/docs/open-api-3.0.1.json +++ b/smeem-api/src/main/resources/static/docs/open-api-3.0.1.json @@ -1,7 +1,7 @@ { "openapi" : "3.0.1", "info" : { - "title" : "smeme api documentation", + "title" : "SMEEM API Documentation", "description" : "Spring REST Docs with SwaggerUI.", "version" : "0.0.1" }, @@ -9,1115 +9,8 @@ "url" : "http://localhost:8080" } ], "tags" : [ ], - "paths" : { - "/api/v2/auth" : { - "post" : { - "tags" : [ "Auth" ], - "summary" : "소셜로그인", - "description" : "소셜로그인", - "operationId" : "소셜로그인 Example", - "parameters" : [ { - "name" : "Authorization", - "in" : "header", - "description" : "소셜 로그인 토큰", - "required" : true, - "schema" : { - "type" : "string" - }, - "example" : "TEST SOCIAL_ACCESS_TOKEN" - } ], - "requestBody" : { - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-auth702405657" - }, - "examples" : { - "소셜로그인 Example" : { - "value" : "{\n \"social\" : \"KAKAO\",\n \"fcmToken\" : \"testfcmtoken\"\n}" - } - } - } - } - }, - "responses" : { - "200" : { - "description" : "200", - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-auth1857992220" - }, - "examples" : { - "소셜로그인 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"소셜로그인 성공\",\n \"data\" : {\n \"accessToken\" : \"testaccesstoken\",\n \"refreshToken\" : \"testrefreshtoken\",\n \"isRegistered\" : true,\n \"hasPlan\" : true\n }\n}" - } - } - } - } - } - } - }, - "delete" : { - "tags" : [ "Auth" ], - "summary" : "회원탈퇴 API", - "description" : "회원탈퇴 API", - "operationId" : "회원탈퇴 Example", - "responses" : { - "200" : { - "description" : "200", - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-auth594740350" - }, - "examples" : { - "회원탈퇴 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"회원 탈퇴 성공\",\n \"data\" : null\n}" - } - } - } - } - } - } - } - }, - "/api/v2/diaries" : { - "get" : { - "tags" : [ "Diary" ], - "summary" : "일기 리스트 조회", - "description" : "일기 리스트 조회", - "operationId" : "일기 리스트 조회 성공 Example", - "parameters" : [ { - "name" : "start", - "in" : "query", - "description" : "범위 시작 날짜(yyyy-MM-dd HH:mm)", - "required" : true, - "schema" : { - "type" : "string" - } - }, { - "name" : "end", - "in" : "query", - "description" : "범위 끝 날짜(yyyy-MM-dd HH:mm)", - "required" : true, - "schema" : { - "type" : "string" - } - } ], - "responses" : { - "200" : { - "description" : "200", - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-diaries1551664804" - }, - "examples" : { - "일기 리스트 조회 성공 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"일기 리스트 조회 성공\",\n \"data\" : {\n \"diaries\" : [ {\n \"diaryId\" : 1,\n \"content\" : \"Hello SMEEM1\",\n \"createdAt\" : \"2023-08-20 14:00\"\n }, {\n \"diaryId\" : 2,\n \"content\" : \"Hello SMEEM2\",\n \"createdAt\" : \"2023-08-21 14:00\"\n } ],\n \"has30Past\" : true\n }\n}" - } - } - } - } - } - } - }, - "post" : { - "tags" : [ "Diary" ], - "summary" : "일기 작성", - "description" : "일기 작성", - "operationId" : "일기 작성 성공 Example", - "requestBody" : { - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-diaries-1124915790" - }, - "examples" : { - "일기 작성 성공 Example" : { - "value" : "{\n \"content\" : \"Hello SMEEM!\",\n \"topicId\" : 1\n}" - } - } - } - } - }, - "responses" : { - "201" : { - "description" : "201", - "headers" : { - "Location" : { - "description" : "생성된 일기 조회 URI", - "schema" : { - "type" : "string" - } - } - }, - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-diaries-609397821" - }, - "examples" : { - "일기 작성 성공 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"일기 작성 성공\",\n \"data\" : {\n \"diaryId\" : 1,\n \"badges\" : [ {\n \"name\" : \"뱃지 이름\",\n \"imageUrl\" : \"badge-image-url\",\n \"type\" : \"EVENT\"\n }, {\n \"name\" : \"뱃지 이름\",\n \"imageUrl\" : \"badge-image-url\",\n \"type\" : \"EVENT\"\n }, {\n \"name\" : \"뱃지 이름\",\n \"imageUrl\" : \"badge-image-url\",\n \"type\" : \"EVENT\"\n }, {\n \"name\" : \"뱃지 이름\",\n \"imageUrl\" : \"badge-image-url\",\n \"type\" : \"EVENT\"\n }, {\n \"name\" : \"뱃지 이름\",\n \"imageUrl\" : \"badge-image-url\",\n \"type\" : \"EVENT\"\n } ]\n }\n}" - } - } - } - } - } - } - } - }, - "/api/v2/goals" : { - "get" : { - "tags" : [ "Goal" ], - "summary" : "전체 학습 목표 조회", - "description" : "전체 학습 목표 조회", - "operationId" : "전체 학습 목표 조회 성공 Example", - "responses" : { - "200" : { - "description" : "200", - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-goals-1163689825" - }, - "examples" : { - "전체 학습 목표 조회 성공 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"전체 학습 목표 조회 성공\",\n \"data\" : {\n \"goals\" : [ {\n \"goalType\" : \"APPLY\",\n \"name\" : \"현지 언어 체득1\"\n }, {\n \"goalType\" : \"APPLY\",\n \"name\" : \"현지 언어 체득2\"\n } ]\n }\n}" - } - } - } - } - } - } - } - }, - "/api/v2/members" : { - "patch" : { - "tags" : [ "Member" ], - "summary" : "유저 프로필 업데이트", - "description" : "유저 프로필 업데이트", - "operationId" : "유저 프로필 업데이트 성공 Example", - "requestBody" : { - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-members486549215" - }, - "examples" : { - "유저 프로필 업데이트 성공 Example" : { - "value" : "{\n \"username\" : \"홍길동\",\n \"termAccepted\" : true\n}" - } - } - } - } - }, - "responses" : { - "200" : { - "description" : "200", - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-members1042223039" - }, - "examples" : { - "유저 프로필 업데이트 성공 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"유저 프로필 업데이트 성공\",\n \"data\" : {\n \"username\" : null,\n \"target\" : \"자기계발\",\n \"way\" : \"주 5회 이상 오늘 하루를 돌아보는 일기 작성하기\",\n \"detail\" : \"사전 없이 일기 완성\\nsmeem 연속 일기 배지 획득\",\n \"targetLang\" : \"en\",\n \"hasPushAlarm\" : false,\n \"trainingTime\" : {\n \"day\" : \"MON\",\n \"hour\" : 10,\n \"minute\" : 30\n },\n \"badge\" : {\n \"id\" : 1,\n \"name\" : \"연속 3일 일기 뱃지\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://m.s3.ap-northeast-2.amazonaws.com/badge/streak.png\"\n }\n }\n}" - } - } - } - } - } - } - } - }, - "/api/v2/test" : { - "get" : { - "tags" : [ "api" ], - "summary" : "서버 연결 테스트", - "description" : "서버 연결 테스트", - "operationId" : "test-docs", - "responses" : { - "200" : { - "description" : "200", - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-auth594740350" - }, - "examples" : { - "test-docs" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"server connect\",\n \"data\" : null\n}" - } - } - } - } - } - } - } - }, - "/api/v2/auth/sign-out" : { - "post" : { - "tags" : [ "Auth" ], - "summary" : "로그아웃 API", - "description" : "로그아웃 API", - "operationId" : "로그아웃 Example", - "responses" : { - "200" : { - "description" : "200", - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-auth594740350" - }, - "examples" : { - "로그아웃 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"로그아웃 성공\",\n \"data\" : null\n}" - } - } - } - } - } - } - } - }, - "/api/v2/auth/token" : { - "post" : { - "tags" : [ "Auth" ], - "summary" : "토큰재발급 API", - "description" : "토큰재발급 API", - "operationId" : "토큰재발급 Example", - "responses" : { - "200" : { - "description" : "200", - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-auth-token622381957" - }, - "examples" : { - "토큰재발급 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"토큰 발급 성공\",\n \"data\" : {\n \"accessToken\" : \"testaccesstoken\",\n \"refreshToken\" : \"testrefreshtoken\"\n }\n}" - } - } - } - } - } - } - } - }, - "/api/v2/diaries/{diaryId}" : { - "get" : { - "tags" : [ "Diary" ], - "summary" : "일기 조회", - "description" : "일기 조회", - "operationId" : "일기 조회 성공 Example", - "parameters" : [ { - "name" : "diaryId", - "in" : "path", - "description" : "일기 id", - "required" : true, - "schema" : { - "type" : "string" - } - } ], - "responses" : { - "200" : { - "description" : "200", - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-diaries-diaryId-1777546585" - }, - "examples" : { - "일기 조회 성공 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"일기 조회 성공\",\n \"data\" : {\n \"diaryId\" : 1,\n \"topic\" : \"가보고 싶은 해외 여행 지가 있다면 소개해 주세요!\",\n \"content\" : \"I want to go Bla Bla ...\",\n \"createdAt\" : \"2023-08-19 14:00\",\n \"username\" : \"스미무\"\n }\n}" - } - } - } - } - } - } - }, - "delete" : { - "tags" : [ "Diary" ], - "summary" : "일기 삭제", - "description" : "일기 삭제", - "operationId" : "일기 삭제 성공 Example", - "parameters" : [ { - "name" : "diaryId", - "in" : "path", - "description" : "일기 id", - "required" : true, - "schema" : { - "type" : "string" - } - } ], - "responses" : { - "200" : { - "description" : "200", - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-auth594740350" - }, - "examples" : { - "일기 삭제 성공 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"일기 삭제 성공\",\n \"data\" : null\n}" - } - } - } - } - } - } - }, - "patch" : { - "tags" : [ "Diary" ], - "summary" : "일기 수정", - "description" : "일기 수정", - "operationId" : "일기 수정 성공 Example", - "parameters" : [ { - "name" : "diaryId", - "in" : "path", - "description" : "일기 id", - "required" : true, - "schema" : { - "type" : "string" - } - } ], - "requestBody" : { - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-diaries-diaryId1231150871" - }, - "examples" : { - "일기 수정 성공 Example" : { - "value" : "{\n \"content\" : \"Hello SMEEM!!\",\n \"topicId\" : 1\n}" - } - } - } - } - }, - "responses" : { - "200" : { - "description" : "200", - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-auth594740350" - }, - "examples" : { - "일기 수정 성공 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"일기 수정 성공\",\n \"data\" : null\n}" - } - } - } - } - } - } - } - }, - "/api/v2/goals/{type}" : { - "get" : { - "tags" : [ "Goal" ], - "summary" : "전체 학습 목표 조회", - "description" : "전체 학습 목표 조회", - "operationId" : "학습 목표 조회 성공 Example", - "parameters" : [ { - "name" : "type", - "in" : "path", - "description" : "학습 목표 ENUM 값", - "required" : true, - "schema" : { - "type" : "string" - } - } ], - "responses" : { - "200" : { - "description" : "200", - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-goals-type1705313935" - }, - "examples" : { - "학습 목표 조회 성공 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"학습 목표 조회 성공\",\n \"data\" : {\n \"name\" : \"현지 언어 체득\",\n \"way\" : \"주 5회 이상 오늘 하루를 돌아보는 일기 작성하기\",\n \"detail\" : \"사전 없이 일기 완성\\nsmeem 연속 일기 배지 획득\"\n }\n}" - } - } - } - } - } - } - } - }, - "/api/v2/members/badges" : { - "get" : { - "tags" : [ "Badge" ], - "summary" : "뱃지 목록 조회", - "description" : "뱃지 목록 조회", - "operationId" : "뱃지 목록 조회 Example", - "responses" : { - "200" : { - "description" : "200", - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-members-badges1884183897" - }, - "examples" : { - "뱃지 목록 조회 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"뱃지 리스트 조회 성공\",\n \"data\" : {\n \"badgeTypes\" : [ {\n \"badgeType\" : \"COMBO\",\n \"badgeTypeName\" : \"연속 3일 일기 뱃지\",\n \"badges\" : [ {\n \"name\" : \"연속 3일 일기 뱃지1\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지2\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지3\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지4\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지5\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n } ]\n }, {\n \"badgeType\" : \"COMBO\",\n \"badgeTypeName\" : \"연속 3일 일기 뱃지\",\n \"badges\" : [ {\n \"name\" : \"연속 3일 일기 뱃지1\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지2\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지3\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지4\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지5\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n } ]\n }, {\n \"badgeType\" : \"COMBO\",\n \"badgeTypeName\" : \"연속 3일 일기 뱃지\",\n \"badges\" : [ {\n \"name\" : \"연속 3일 일기 뱃지1\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지2\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지3\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지4\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지5\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n } ]\n }, {\n \"badgeType\" : \"COMBO\",\n \"badgeTypeName\" : \"연속 3일 일기 뱃지\",\n \"badges\" : [ {\n \"name\" : \"연속 3일 일기 뱃지1\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지2\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지3\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지4\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지5\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n } ]\n }, {\n \"badgeType\" : \"COMBO\",\n \"badgeTypeName\" : \"연속 3일 일기 뱃지\",\n \"badges\" : [ {\n \"name\" : \"연속 3일 일기 뱃지1\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지2\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지3\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지4\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n }, {\n \"name\" : \"연속 3일 일기 뱃지5\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://...\"\n } ]\n } ]\n }\n}" - } - } - } - } - } - } - } - }, - "/api/v2/members/me" : { - "get" : { - "tags" : [ "Member" ], - "summary" : "사용자 정보 조회", - "description" : "사용자 정보 조회", - "operationId" : "사용자 정보 조회 성공 Example", - "responses" : { - "200" : { - "description" : "200", - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-members1042223039" - }, - "examples" : { - "사용자 정보 조회 성공 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"사용자 정보 조회 성공\",\n \"data\" : {\n \"username\" : null,\n \"target\" : \"자기계발\",\n \"way\" : \"주 5회 이상 오늘 하루를 돌아보는 일기 작성하기\",\n \"detail\" : \"사전 없이 일기 완성\\nsmeem 연속 일기 배지 획득\",\n \"targetLang\" : \"en\",\n \"hasPushAlarm\" : false,\n \"trainingTime\" : {\n \"day\" : \"MON\",\n \"hour\" : 10,\n \"minute\" : 30\n },\n \"badge\" : {\n \"id\" : 1,\n \"name\" : \"연속 3일 일기 뱃지\",\n \"type\" : \"COMBO\",\n \"imageUrl\" : \"https://m.s3.ap-northeast-2.amazonaws.com/badge/streak.png\"\n }\n }\n}" - } - } - } - } - } - } - } - }, - "/api/v2/members/plan" : { - "patch" : { - "tags" : [ "Member" ], - "summary" : "사용자 수정 API", - "description" : "사용자 수정 API", - "operationId" : "사용자 정보 수정 성공 Example", - "requestBody" : { - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-members486549215" - }, - "examples" : { - "사용자 정보 수정 성공 Example" : { - "value" : "{\n \"target\" : \"DEVELOP\",\n \"trainingTime\" : {\n \"day\" : \"MON\",\n \"hour\" : 10,\n \"minute\" : 30\n },\n \"hasAlarm\" : true\n}" - } - } - } - } - }, - "responses" : { - "200" : { - "description" : "200", - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-auth594740350" - }, - "examples" : { - "사용자 정보 수정 성공 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"회원 학습 계획 업데이트 성공\",\n \"data\" : null\n}" - } - } - } - } - } - } - } - }, - "/api/v2/members/push" : { - "patch" : { - "tags" : [ "Member" ], - "summary" : "푸시 알림 동의여부 수정", - "description" : "푸시 알림 동의여부 수정", - "operationId" : "푸시 알림 동의여부 성공 Example", - "requestBody" : { - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-members-push-1005876473" - }, - "examples" : { - "푸시 알림 동의여부 성공 Example" : { - "value" : "{\n \"hasAlarm\" : true\n}" - } - } - } - } - }, - "responses" : { - "200" : { - "description" : "200", - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-auth594740350" - }, - "examples" : { - "푸시 알림 동의여부 성공 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"회원 푸시알람 동의여부 업데이트 성공\",\n \"data\" : null\n}" - } - } - } - } - } - } - } - }, - "/api/v2/topics/random" : { - "get" : { - "tags" : [ "Topic" ], - "summary" : "랜덤 주제 조회", - "description" : "랜덤 주제 조회", - "operationId" : "랜덤 주제 조회 성공 Example", - "responses" : { - "200" : { - "description" : "200", - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-topics-random459952356" - }, - "examples" : { - "랜덤 주제 조회 성공 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"랜덤 주제 조회 성공\",\n \"data\" : {\n \"topicId\" : 1,\n \"content\" : \"가보고 싶은 해외 여행 지가 있다면 소개해 주세요!\"\n }\n}" - } - } - } - } - } - } - } - }, - "/api/v2/members/nickname/check" : { - "get" : { - "tags" : [ "Member" ], - "summary" : "닉네임 중복 체크", - "description" : "닉네임 중복 체크", - "operationId" : "닉네임 중복 체크 성공 Example", - "responses" : { - "200" : { - "description" : "200", - "content" : { - "application/json;charset=UTF-8" : { - "schema" : { - "$ref" : "#/components/schemas/api-v2-auth594740350" - }, - "examples" : { - "닉네임 중복 체크 성공 Example" : { - "value" : "{\n \"success\" : true,\n \"message\" : \"닉네임 중복 체크 성공\",\n \"data\" : null\n}" - } - } - } - } - } - } - } - } - }, + "paths" : { }, "components" : { - "schemas" : { - "api-v2-members1042223039" : { - "type" : "object", - "properties" : { - "data" : { - "type" : "object", - "properties" : { - "badge" : { - "type" : "object", - "properties" : { - "imageUrl" : { - "type" : "string", - "description" : "뱃지 이미지" - }, - "name" : { - "type" : "string", - "description" : "뱃지 이름" - }, - "id" : { - "type" : "number", - "description" : "뱃지 아이디" - }, - "type" : { - "type" : "string", - "description" : "뱃지 설명" - } - }, - "description" : "뱃지" - }, - "targetLang" : { - "type" : "string", - "description" : "목표 언어" - }, - "trainingTime" : { - "type" : "object", - "properties" : { - "hour" : { - "type" : "number", - "description" : "학습 시간" - }, - "day" : { - "type" : "string", - "description" : "학습 요일" - }, - "minute" : { - "type" : "number", - "description" : "학습 분" - } - }, - "description" : "학습 시간" - }, - "hasPushAlarm" : { - "type" : "boolean", - "description" : "푸시 알림 여부" - }, - "detail" : { - "type" : "string", - "description" : "목표 달성 방법" - }, - "way" : { - "type" : "string", - "description" : "목표 달성 방법" - }, - "target" : { - "type" : "string", - "description" : "학습목표" - } - }, - "description" : "응답 데이터" - }, - "success" : { - "type" : "boolean", - "description" : "응답 성공 여부" - }, - "message" : { - "type" : "string", - "description" : "응답 메시지" - } - } - }, - "api-v2-diaries-1124915790" : { - "type" : "object", - "properties" : { - "topicId" : { - "type" : "number", - "description" : "랜덤 주제 id(8~54) or null" - }, - "content" : { - "type" : "string", - "description" : "일기 내용" - } - } - }, - "api-v2-auth1857992220" : { - "type" : "object", - "properties" : { - "data" : { - "type" : "object", - "properties" : { - "isRegistered" : { - "type" : "boolean", - "description" : "서비스 등록 여부" - }, - "hasPlan" : { - "type" : "boolean", - "description" : "학습 계획 설정 여부" - }, - "accessToken" : { - "type" : "string", - "description" : "서비스 액세스 토큰" - }, - "refreshToken" : { - "type" : "string", - "description" : "서비스 리프레시 토큰" - } - }, - "description" : "응답 데이터" - }, - "success" : { - "type" : "boolean", - "description" : "응답 성공 여부" - }, - "message" : { - "type" : "string", - "description" : "응답 메시지" - } - } - }, - "api-v2-auth702405657" : { - "type" : "object", - "properties" : { - "social" : { - "type" : "string", - "description" : "소셜로그인 타입" - }, - "fcmToken" : { - "type" : "string", - "description" : "FCM Token" - } - } - }, - "api-v2-goals-type1705313935" : { - "type" : "object", - "properties" : { - "data" : { - "type" : "object", - "properties" : { - "name" : { - "type" : "string", - "description" : "학습 목표 이름" - }, - "detail" : { - "type" : "string", - "description" : "학습 목표 내용" - }, - "way" : { - "type" : "string", - "description" : "학습 목표 방식" - } - }, - "description" : "응답 데이터" - }, - "success" : { - "type" : "boolean", - "description" : "응답 성공 여부" - }, - "message" : { - "type" : "string", - "description" : "응답 메시지" - } - } - }, - "api-v2-diaries-diaryId-1777546585" : { - "type" : "object", - "properties" : { - "data" : { - "type" : "object", - "properties" : { - "createdAt" : { - "type" : "string", - "description" : "작성 날짜" - }, - "diaryId" : { - "type" : "number", - "description" : "일기 id" - }, - "topic" : { - "type" : "string", - "description" : "랜덤 주제" - }, - "content" : { - "type" : "string", - "description" : "일기 내용" - }, - "username" : { - "type" : "string", - "description" : "작성자 이름" - } - }, - "description" : "응답 데이터" - }, - "success" : { - "type" : "boolean", - "description" : "응답 성공 여부" - }, - "message" : { - "type" : "string", - "description" : "응답 메시지" - } - } - }, - "api-v2-members-push-1005876473" : { - "type" : "object", - "properties" : { - "hasAlarm" : { - "type" : "boolean", - "description" : "푸시 알림 동의여부" - } - } - }, - "api-v2-auth594740350" : { - "type" : "object", - "properties" : { - "success" : { - "type" : "boolean", - "description" : "응답 성공 여부" - }, - "message" : { - "type" : "string", - "description" : "응답 메시지" - } - } - }, - "api-v2-diaries-609397821" : { - "type" : "object", - "properties" : { - "data" : { - "type" : "object", - "properties" : { - "badges" : { - "type" : "array", - "description" : "획득한 뱃지 리스트", - "items" : { - "type" : "object", - "properties" : { - "imageUrl" : { - "type" : "string", - "description" : "뱃지 이미지 url" - }, - "name" : { - "type" : "string", - "description" : "뱃지 이름" - }, - "type" : { - "type" : "string", - "description" : "뱃지 타입" - } - } - } - }, - "diaryId" : { - "type" : "number", - "description" : "생성한 일기 id" - } - }, - "description" : "응답 데이터" - }, - "success" : { - "type" : "boolean", - "description" : "응답 성공 여부" - }, - "message" : { - "type" : "string", - "description" : "응답 메시지" - } - } - }, - "api-v2-topics-random459952356" : { - "type" : "object", - "properties" : { - "data" : { - "type" : "object", - "properties" : { - "topicId" : { - "type" : "number", - "description" : "랜덤 주제 id" - }, - "content" : { - "type" : "string", - "description" : "랜덤 주제 내용" - } - }, - "description" : "응답 데이터" - }, - "success" : { - "type" : "boolean", - "description" : "응답 성공 여부" - }, - "message" : { - "type" : "string", - "description" : "응답 메시지" - } - } - }, - "api-v2-diaries-diaryId1231150871" : { - "type" : "object", - "properties" : { - "topicId" : { - "type" : "number", - "description" : "랜덤 주제 id" - }, - "content" : { - "type" : "string", - "description" : "수정할 일기 내용" - } - } - }, - "api-v2-members-badges1884183897" : { - "type" : "object", - "properties" : { - "data" : { - "type" : "object", - "properties" : { - "badgeTypes" : { - "type" : "array", - "description" : "뱃지 타입 목록", - "items" : { - "type" : "object", - "properties" : { - "badges" : { - "type" : "array", - "description" : "타입별 뱃지 리스트", - "items" : { - "type" : "object", - "properties" : { - "imageUrl" : { - "type" : "string", - "description" : "뱃지 이미지 URL" - }, - "name" : { - "type" : "string", - "description" : "뱃지 이름" - }, - "type" : { - "type" : "string", - "description" : "뱃지 타입" - } - } - } - }, - "badgeType" : { - "type" : "string", - "description" : "뱃지 타입" - }, - "badgeTypeName" : { - "type" : "string", - "description" : "뱃지 타입 이름" - } - } - } - } - }, - "description" : "응답 데이터" - }, - "success" : { - "type" : "boolean", - "description" : "응답 성공 여부" - }, - "message" : { - "type" : "string", - "description" : "응답 메시지" - } - } - }, - "api-v2-diaries1551664804" : { - "type" : "object", - "properties" : { - "data" : { - "type" : "object", - "properties" : { - "has30Past" : { - "type" : "boolean", - "description" : "30일 전 일기 존재 여부" - }, - "diaries" : { - "type" : "array", - "description" : "일기 정보 리스트", - "items" : { - "type" : "object", - "properties" : { - "createdAt" : { - "type" : "string", - "description" : "일기 작성 일자" - }, - "diaryId" : { - "type" : "number", - "description" : "일기 id" - }, - "content" : { - "type" : "string", - "description" : "일기 내용" - } - } - } - } - }, - "description" : "응답 데이터" - }, - "success" : { - "type" : "boolean", - "description" : "응답 성공 여부" - }, - "message" : { - "type" : "string", - "description" : "응답 메시지" - } - } - }, - "api-v2-goals-1163689825" : { - "type" : "object", - "properties" : { - "data" : { - "type" : "object", - "properties" : { - "goals" : { - "type" : "array", - "description" : "학습 목표 리스트", - "items" : { - "type" : "object", - "properties" : { - "goalType" : { - "type" : "string", - "description" : "학습 목표 ENUM 값" - }, - "name" : { - "type" : "string", - "description" : "학습 목표 이름" - } - } - } - } - }, - "description" : "응답 데이터" - }, - "success" : { - "type" : "boolean", - "description" : "응답 성공 여부" - }, - "message" : { - "type" : "string", - "description" : "응답 메시지" - } - } - }, - "api-v2-auth-token622381957" : { - "type" : "object", - "properties" : { - "data" : { - "type" : "object", - "properties" : { - "accessToken" : { - "type" : "string", - "description" : "서비스 액세스 토큰" - }, - "refreshToken" : { - "type" : "string", - "description" : "서비스 리프레시 토큰" - } - }, - "description" : "응답 데이터" - }, - "success" : { - "type" : "boolean", - "description" : "응답 성공 여부" - }, - "message" : { - "type" : "string", - "description" : "응답 메시지" - } - } - }, - "api-v2-members486549215" : { - "type" : "object" - } - } + "schemas" : { } } } \ No newline at end of file diff --git a/smeem-api/src/test/java/com/smeem/SmemeServerRenewalApplicationTests.java b/smeem-api/src/test/java/com/smeem/SmemeServerRenewalApplicationTests.java deleted file mode 100644 index c283a60a..00000000 --- a/smeem-api/src/test/java/com/smeem/SmemeServerRenewalApplicationTests.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.smeem; - -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class SmemeServerRenewalApplicationTests { -} diff --git a/smeem-api/src/test/java/com/smeem/api/controller/AuthControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/AuthControllerTest.java index adff384d..6019fda8 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/AuthControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/AuthControllerTest.java @@ -26,8 +26,8 @@ import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@DisplayName("AuthController 테스트") -@WebMvcTest(AuthController.class) +//@DisplayName("AuthController 테스트") +//@WebMvcTest(AuthController.class) public class AuthControllerTest extends BaseControllerTest { @MockBean @@ -41,8 +41,8 @@ public class AuthControllerTest extends BaseControllerTest { private static final String SOCIAL_ACCESS_TOKEN = "TEST SOCIAL_ACCESS_TOKEN"; - @DisplayName("소셜로그인 API 성공") - @Test +// @DisplayName("소셜로그인 API 성공") +// @Test void success_signIn() throws Exception { val resources = ResourceSnippetParameters.builder() @@ -87,8 +87,8 @@ void success_signIn() throws Exception { .andExpect(status().isOk()); } - @DisplayName("토큰재발급 API 성공") - @Test +// @DisplayName("토큰재발급 API 성공") +// @Test void success_reissueToken() throws Exception { val resources = ResourceSnippetParameters.builder() .tag(TAG) @@ -119,8 +119,8 @@ void success_reissueToken() throws Exception { .andExpect(status().isOk()); } - @DisplayName("로그아웃 API 성공") - @Test +// @DisplayName("로그아웃 API 성공") +// @Test void success_signOut() throws Exception { val resources = ResourceSnippetParameters.builder() .tag(TAG) @@ -147,8 +147,8 @@ void success_signOut() throws Exception { .andExpect(status().isOk()); } - @DisplayName("회원탈퇴 API 성공") - @Test +// @DisplayName("회원탈퇴 API 성공") +// @Test void success_withDrawl() throws Exception{ val resources = ResourceSnippetParameters.builder() .tag(TAG) diff --git a/smeem-api/src/test/java/com/smeem/api/controller/BadgeControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/BadgeControllerTest.java index 09ebd6df..11ecdad8 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/BadgeControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/BadgeControllerTest.java @@ -24,7 +24,7 @@ import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@DisplayName("BadgeController 테스트") +//@DisplayName("BadgeController 테스트") @WebMvcTest(BadgeController.class) public class BadgeControllerTest extends BaseControllerTest { @@ -36,8 +36,8 @@ public class BadgeControllerTest extends BaseControllerTest { private final String DEFAULT_URL = "/api/v2/members/badges"; private final String TAG = "Badge"; - @DisplayName("뱃지 목록 조회 API 성공") - @Test +// @DisplayName("뱃지 목록 조회 API 성공") +// @Test void success_getBadgesList() throws Exception { val resources = ResourceSnippetParameters.builder() .tag(TAG) diff --git a/smeem-api/src/test/java/com/smeem/api/controller/BaseControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/BaseControllerTest.java index a1777e42..33003338 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/BaseControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/BaseControllerTest.java @@ -20,9 +20,9 @@ import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -@AutoConfigureMockMvc -@AutoConfigureRestDocs -@ExtendWith({RestDocumentationExtension.class}) +//@AutoConfigureMockMvc +//@AutoConfigureRestDocs +//@ExtendWith({RestDocumentationExtension.class}) @WebMvcTest(properties = "spring.config.location=classpath:/application.yml") public abstract class BaseControllerTest { @@ -41,7 +41,7 @@ public abstract class BaseControllerTest { @MockBean private CustomJwtAuthenticationEntryPoint customJwtAuthenticationEntryPoint; - @BeforeEach +// @BeforeEach void setUp(final RestDocumentationContextProvider restDocumentation) { mockMvc = MockMvcBuilders.webAppContextSetup(context) .apply(documentationConfiguration(restDocumentation)) diff --git a/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java index 1b9bd7c5..8f72448b 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java @@ -41,8 +41,8 @@ import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@DisplayName("DiaryController 테스트") -@WebMvcTest(DiaryController.class) +//@DisplayName("DiaryController 테스트") +//@WebMvcTest(DiaryController.class) class DiaryControllerTest extends BaseControllerTest { @MockBean DiaryController diaryController; @@ -52,8 +52,8 @@ class DiaryControllerTest extends BaseControllerTest { private final String DEFAULT_URL = "/api/v2/diaries"; private final String TAG = "Diary"; - @Test - @DisplayName("일기 작성 테스트") +// @Test +// @DisplayName("일기 작성 테스트") void success_create_diary() throws Exception { // given DiaryRequestDTO request = new DiaryRequestDTO("Hello SMEEM!", 1L); @@ -101,8 +101,8 @@ void success_create_diary() throws Exception { .andExpect(status().isCreated()); } - @Test - @DisplayName("일기 조회 테스트") +// @Test +// @DisplayName("일기 조회 테스트") void success_get_diary() throws Exception { // given DiaryResponseDTO response = new DiaryResponseDTO(1L, @@ -146,8 +146,8 @@ void success_get_diary() throws Exception { .andExpect(status().isOk()); } - @Test - @DisplayName("일기 수정 테스트") +// @Test +// @DisplayName("일기 수정 테스트") void success_update_diary() throws Exception { // given Long diaryId = 1L; @@ -187,8 +187,8 @@ void success_update_diary() throws Exception { .andExpect(status().isOk()); } - @Test - @DisplayName("일기 삭제 테스트") +// @Test +// @DisplayName("일기 삭제 테스트") void success_delete_diary() throws Exception { // given Long diaryId = 1L; @@ -222,8 +222,8 @@ void success_delete_diary() throws Exception { .andExpect(status().isOk()); } - @Test - @DisplayName("일기 리스트 조회 테스트") +// @Test +// @DisplayName("일기 리스트 조회 테스트") void success_get_diaries() throws Exception { // given DiariesResponseDTO response = new DiariesResponseDTO(diaries(), true); diff --git a/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java index 1322e2a5..da3519fd 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java @@ -32,8 +32,8 @@ import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@DisplayName("GoalController 테스트") -@WebMvcTest(GoalController.class) +//@DisplayName("GoalController 테스트") +//@WebMvcTest(GoalController.class) class GoalControllerTest extends BaseControllerTest { @MockBean GoalController goalController; @@ -43,8 +43,8 @@ class GoalControllerTest extends BaseControllerTest { private final String DEFAULT_URL = "/api/v2/goals"; private final String TAG = "Goal"; - @Test - @DisplayName("전체 학습 목표 조회 테스트") +// @Test +// @DisplayName("전체 학습 목표 조회 테스트") void success_get_goals_test() throws Exception { // given val response = new GoalsResponseDTO(goals()); @@ -78,8 +78,8 @@ void success_get_goals_test() throws Exception { .andExpect(status().isOk()); } - @Test - @DisplayName("학습 목표 조회 테스트") +// @Test +// @DisplayName("학습 목표 조회 테스트") void success_get_goal_test() throws Exception { // given GoalType type = APPLY; diff --git a/smeem-api/src/test/java/com/smeem/api/controller/MemberControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/MemberControllerTest.java index 197878ea..05d0cca4 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/MemberControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/MemberControllerTest.java @@ -26,8 +26,8 @@ import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@DisplayName("Member Controller Test") -@WebMvcTest(MemberController.class) +//@DisplayName("Member Controller Test") +//@WebMvcTest(MemberController.class) public class MemberControllerTest extends BaseControllerTest { private static final String DEFAULT_URL = "/api/v2/members"; @@ -39,8 +39,8 @@ public class MemberControllerTest extends BaseControllerTest { @MockBean Principal principal; - @Test - @DisplayName("유저 프로필 업데이트 성공") +// @Test +// @DisplayName("유저 프로필 업데이트 성공") void success_updateProfile() throws Exception { val resources = ResourceSnippetParameters.builder() .tag(TAG) @@ -86,8 +86,8 @@ void success_updateProfile() throws Exception { .andExpect(status().isOk()); } - @DisplayName("사용자 정보 조회") - @Test +// @DisplayName("사용자 정보 조회") +// @Test void success_getProfile() throws Exception { val resources = ResourceSnippetParameters.builder() .tag(TAG) @@ -130,8 +130,8 @@ void success_getProfile() throws Exception { .andExpect(status().isOk()); } - @DisplayName("Member 학습계획 수정 API 성공 ") - @Test +// @DisplayName("Member 학습계획 수정 API 성공 ") +// @Test void success_updateUserPlan() throws Exception { val resources = ResourceSnippetParameters.builder() .tag(TAG) @@ -160,8 +160,8 @@ void success_updateUserPlan() throws Exception { .andExpect(status().isOk()); } - @DisplayName("유저 이름 중복체크 API 성공") - @Test +// @DisplayName("유저 이름 중복체크 API 성공") +// @Test void success_checkDuplicatedName() throws Exception { // given val resources = ResourceSnippetParameters.builder() @@ -191,8 +191,8 @@ void success_checkDuplicatedName() throws Exception { .andExpect(status().isOk()); } - @Test - @DisplayName("푸시알림 동의 여부 수정 메소드 테스트") +// @Test +// @DisplayName("푸시알림 동의 여부 수정 메소드 테스트") void success_updateUserPush() throws Exception { // given val resources = ResourceSnippetParameters.builder() diff --git a/smeem-api/src/test/java/com/smeem/api/controller/TestControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/TestControllerTest.java index c26093f1..859499bb 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/TestControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/TestControllerTest.java @@ -20,8 +20,8 @@ import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; -@DisplayName("TestController 테스트") -@WebMvcTest(value = TestController.class) +//@DisplayName("TestController 테스트") +//@WebMvcTest(value = TestController.class) class TestControllerTest extends BaseControllerTest { private static final String DEFAULT_URL = "/api/v2/com.smeem.test"; @@ -29,8 +29,8 @@ class TestControllerTest extends BaseControllerTest { @MockBean TestController testController; - @Test - @DisplayName("서버 연결 테스트") +// @Test +// @DisplayName("서버 연결 테스트") void success_test() throws Exception { //given diff --git a/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java index 297b546f..92fd402b 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java @@ -25,8 +25,8 @@ import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@DisplayName("TopicController 테스트") -@WebMvcTest(TopicController.class) +//@DisplayName("TopicController 테스트") +//@WebMvcTest(TopicController.class) class TopicControllerTest extends BaseControllerTest { @MockBean TopicController topicController; @@ -36,8 +36,8 @@ class TopicControllerTest extends BaseControllerTest { private final String DEFAULT_URL = "/api/v2/topics"; private final String TAG = "Topic"; - @Test - @DisplayName("랜덤 주제 조회 테스트") +// @Test +// @DisplayName("랜덤 주제 조회 테스트") void success_get_random_topic_test() throws Exception { // given TopicResponseDTO response = new TopicResponseDTO(1L, "가보고 싶은 해외 여행 지가 있다면 소개해 주세요!"); From 7f7b4a5d45f97567773ce220f446a628d054d474 Mon Sep 17 00:00:00 2001 From: thguss Date: Mon, 12 Feb 2024 22:01:24 +0900 Subject: [PATCH 35/86] =?UTF-8?q?[REFACTOR]=20Diary=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smeem/api/auth/service/AuthService.java | 4 +- .../smeem/api/badge/service/BadgeService.java | 28 ++- .../api/diary/controller/DiaryController.java | 46 +++-- ...equestDTO.java => DiaryCreateRequest.java} | 2 +- .../dto/request/DiaryModifyRequest.java | 10 ++ .../dto/response/CreatedDiaryResponseDTO.java | 15 -- .../dto/response/DiariesResponseDTO.java | 28 --- .../service/DiaryNonTransactionalService.java | 52 ++++++ .../smeem/api/diary/service/DiaryService.java | 161 ------------------ .../service/DiaryTransactionalService.java | 161 ++++++++++++++++++ .../request/DiaryCreateServiceRequest.java | 22 +++ .../request/DiaryDeleteServiceRequest.java | 17 ++ .../dto/request/DiaryGetServiceRequest.java | 17 ++ .../request/DiaryListGetServiceRequest.java | 24 +++ .../request/DiaryModifyServiceRequest.java | 20 +++ .../response/DiaryCreateServiceResponse.java | 23 +++ .../response/DiaryGetServiceResponse.java} | 13 +- .../response/DiaryListGetServiceResponse.java | 41 +++++ .../api/controller/DiaryControllerTest.java | 38 ++--- .../com/smeem/common/config/ValueConfig.java | 2 +- .../main/java/com/smeem/common/util/Util.java | 14 +- .../com/smeem/domain/diary/model/Diary.java | 50 ++++-- .../com/smeem/domain/member/model/Member.java | 51 ++++-- 23 files changed, 542 insertions(+), 297 deletions(-) rename smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/{DiaryRequestDTO.java => DiaryCreateRequest.java} (81%) create mode 100644 smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryModifyRequest.java delete mode 100644 smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/CreatedDiaryResponseDTO.java delete mode 100644 smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiariesResponseDTO.java create mode 100644 smeem-api/src/main/java/com/smeem/api/diary/service/DiaryNonTransactionalService.java delete mode 100644 smeem-api/src/main/java/com/smeem/api/diary/service/DiaryService.java create mode 100644 smeem-api/src/main/java/com/smeem/api/diary/service/DiaryTransactionalService.java create mode 100644 smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryCreateServiceRequest.java create mode 100644 smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryDeleteServiceRequest.java create mode 100644 smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryGetServiceRequest.java create mode 100644 smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryListGetServiceRequest.java create mode 100644 smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryModifyServiceRequest.java create mode 100644 smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryCreateServiceResponse.java rename smeem-api/src/main/java/com/smeem/api/diary/{controller/dto/response/DiaryResponseDTO.java => service/dto/response/DiaryGetServiceResponse.java} (65%) create mode 100644 smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryListGetServiceResponse.java diff --git a/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java b/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java index 92748687..06a0e00e 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java @@ -8,7 +8,7 @@ import com.smeem.api.auth.jwt.UserAuthentication; -import com.smeem.api.diary.service.DiaryService; +import com.smeem.api.diary.service.DiaryTransactionalService; import com.smeem.api.member.service.MemberBadgeService; import com.smeem.api.member.service.TrainingTimeService; import com.smeem.common.exception.MemberException; @@ -48,7 +48,7 @@ public class AuthService { private final AppleSignInService appleSignInService; private final KakaoSignInService kakaoSignInService; private final MemberBadgeService memberBadgeService; - private final DiaryService diaryService; + private final DiaryTransactionalService diaryService; private final TrainingTimeService trainingTimeService; @Transactional diff --git a/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java b/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java index eb8d499e..508f43b4 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java @@ -47,10 +47,34 @@ private void putBadgeMap(Map> badgeMap, Badge badge) { @Transactional public void saveMemberBadge(Member member, Badge badge) { - memberBadgeRepository.save(new MemberBadge(member, badge)); + val memberBadge = MemberBadge.builder() + .member(member) + .badge(badge) + .build(); + memberBadgeRepository.save(memberBadge); } - public Badge get(Long id) { + public Badge getBadgeByCountOfDiary(int diaryCount) { + return switch (diaryCount) { + case 50 -> get(5L); + case 30 -> get(4L); + case 10 -> get(3L); + case 1 -> get(2L); + default -> null; + }; + } + + public Badge getBadgeByComboCountOfDiary(int diaryComboCount) { + return switch (diaryComboCount) { + case 30 -> get(9L); + case 15 -> get(8L); + case 7 -> get(7L); + case 3 -> get(6L); + default -> null; + }; + } + + private Badge get(Long id) { return badgeRepository.findById(id) .orElseThrow(() -> new BadgeException(INVALID_BADGE)); } diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java b/smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java index 1ea239e9..9a1de51f 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java @@ -1,15 +1,14 @@ package com.smeem.api.diary.controller; - import java.security.Principal; import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; -import com.smeem.api.diary.controller.dto.request.DiaryRequestDTO; -import com.smeem.api.diary.controller.dto.response.CreatedDiaryResponseDTO; -import com.smeem.api.diary.controller.dto.response.DiariesResponseDTO; -import com.smeem.api.diary.controller.dto.response.DiaryResponseDTO; -import com.smeem.api.diary.service.DiaryService; +import com.smeem.api.diary.controller.dto.request.DiaryCreateRequest; +import com.smeem.api.diary.controller.dto.request.DiaryModifyRequest; +import com.smeem.api.diary.service.DiaryNonTransactionalService; +import com.smeem.api.diary.service.DiaryTransactionalService; +import com.smeem.api.diary.service.dto.request.*; import com.smeem.common.util.Util; import lombok.val; import org.springframework.http.ResponseEntity; @@ -32,40 +31,51 @@ @RequiredArgsConstructor @RequestMapping("/api/v2/diaries") public class DiaryController { - private final DiaryService diaryService; + + private final DiaryTransactionalService diaryTransactionalService; + private final DiaryNonTransactionalService diaryNonTransactionalService; @PostMapping - public ResponseEntity> save(Principal principal, @RequestBody DiaryRequestDTO request) { - CreatedDiaryResponseDTO response = diaryService.save(Util.getMemberId(principal), request); + public ResponseEntity> createDiary(Principal principal, @RequestBody DiaryCreateRequest request) { + val memberId = Util.getMemberId(principal); + val serviceRequest = DiaryCreateServiceRequest.of(memberId, request); + + val response = diaryTransactionalService.createDiary(serviceRequest); val uri = Util.getURI("/{diaryId}", response.diaryId()); + return ApiResponseUtil.success(SUCCESS_CREATE_DIARY, uri, response); } @GetMapping("/{diaryId}") - public ResponseEntity> getDetail(@PathVariable Long diaryId) { - DiaryResponseDTO response = diaryService.getDetail(diaryId); + public ResponseEntity> getDiaryDetail(@PathVariable long diaryId) { + val serviceRequest = DiaryGetServiceRequest.of(diaryId); + val response = diaryNonTransactionalService.getDiaryDetail(serviceRequest); return ApiResponseUtil.success(SUCCESS_GET_DIARY, response); } @PatchMapping("/{diaryId}") - public ResponseEntity> update(@PathVariable Long diaryId, @RequestBody DiaryRequestDTO request) { - diaryService.update(diaryId, request); + public ResponseEntity> modifyDiary(@PathVariable long diaryId, @RequestBody DiaryModifyRequest request) { + val serviceRequest = DiaryModifyServiceRequest.of(diaryId, request); + diaryTransactionalService.modifyDiary(serviceRequest); return ApiResponseUtil.success(SUCCESS_UPDATE_DAIRY); } @DeleteMapping("/{diaryId}") - public ResponseEntity> delete(@PathVariable Long diaryId) { - diaryService.delete(diaryId); + public ResponseEntity> deleteDiary(@PathVariable long diaryId) { + val serviceRequest = DiaryDeleteServiceRequest.of(diaryId); + diaryTransactionalService.deleteDiary(serviceRequest); return ApiResponseUtil.success(SUCCESS_DELETE_DIARY); } @GetMapping public ResponseEntity> getDiaries( Principal principal, - @RequestParam(name = "start") String startDate, - @RequestParam(name = "end") String endDate + @RequestParam String start, + @RequestParam String end ) { - DiariesResponseDTO response = diaryService.getDiaries(Util.getMemberId(principal), startDate, endDate); + val memberId = Util.getMemberId(principal); + val serviceRequest = DiaryListGetServiceRequest.of(memberId, start, end); + val response = diaryNonTransactionalService.getDiaries(serviceRequest); return ApiResponseUtil.success(SUCCESS_GET_DIARIES, response); } } diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryRequestDTO.java b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryCreateRequest.java similarity index 81% rename from smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryRequestDTO.java rename to smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryCreateRequest.java index b4a5805a..3b4cf852 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryRequestDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryCreateRequest.java @@ -2,7 +2,7 @@ import lombok.NonNull; -public record DiaryRequestDTO( +public record DiaryCreateRequest( @NonNull String content, Long topicId diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryModifyRequest.java b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryModifyRequest.java new file mode 100644 index 00000000..8377c67f --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryModifyRequest.java @@ -0,0 +1,10 @@ +package com.smeem.api.diary.controller.dto.request; + +import lombok.NonNull; + +public record DiaryModifyRequest( + @NonNull + String content, + Long topicId +) { +} diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/CreatedDiaryResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/CreatedDiaryResponseDTO.java deleted file mode 100644 index 320247e6..00000000 --- a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/CreatedDiaryResponseDTO.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.smeem.api.diary.controller.dto.response; - -import com.smeem.api.badge.controller.dto.response.AcquiredBadgeResponseDTO; -import com.smeem.domain.badge.model.Badge; - -import java.util.List; - -public record CreatedDiaryResponseDTO( - Long diaryId, - List badges -) { - public static CreatedDiaryResponseDTO of(Long diaryId, List badges) { - return new CreatedDiaryResponseDTO(diaryId, badges.stream().map(AcquiredBadgeResponseDTO::of).toList()); - } -} diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiariesResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiariesResponseDTO.java deleted file mode 100644 index 4f1654c8..00000000 --- a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiariesResponseDTO.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.smeem.api.diary.controller.dto.response; - -import com.smeem.common.util.Util; -import com.smeem.domain.diary.model.Diary; - -import java.util.List; - - -public record DiariesResponseDTO( - List diaries, - boolean has30Past -) { - public static DiariesResponseDTO of(List diaries, boolean hasRemind) { - return new DiariesResponseDTO(diaries.stream().map(DiaryDTO::of).toList(), hasRemind); - } - - public record DiaryDTO( - Long diaryId, - String content, - String createdAt - ) { - public static DiaryDTO of(Diary diary) { - return new DiaryDTO(diary.getId(), diary.getContent(), Util.dateToString(diary.getCreatedAt())); - } - } -} - - diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryNonTransactionalService.java b/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryNonTransactionalService.java new file mode 100644 index 00000000..486f8cc3 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryNonTransactionalService.java @@ -0,0 +1,52 @@ +package com.smeem.api.diary.service; + +import com.smeem.api.diary.service.dto.response.DiaryListGetServiceResponse; +import com.smeem.api.diary.service.dto.response.DiaryGetServiceResponse; +import com.smeem.api.diary.service.dto.request.DiaryGetServiceRequest; +import com.smeem.api.diary.service.dto.request.DiaryListGetServiceRequest; +import com.smeem.common.config.ValueConfig; +import com.smeem.common.exception.DiaryException; +import com.smeem.common.exception.MemberException; +import com.smeem.domain.diary.model.Diary; +import com.smeem.domain.diary.repository.DiaryRepository; +import com.smeem.domain.member.model.Member; +import com.smeem.domain.member.repository.MemberRepository; +import lombok.RequiredArgsConstructor; +import lombok.val; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import static com.smeem.common.code.failure.DiaryFailureCode.INVALID_DIARY; +import static com.smeem.common.code.failure.MemberFailureCode.INVALID_MEMBER; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class DiaryNonTransactionalService { + + private final DiaryRepository diaryRepository; + private final MemberRepository memberRepository; + + private final ValueConfig valueConfig; + + public DiaryGetServiceResponse getDiaryDetail(DiaryGetServiceRequest request) { + val diary = findDiary(request.diaryId()); + return DiaryGetServiceResponse.of(diary); + } + + private Diary findDiary(long id) { + return diaryRepository.findById(id) + .orElseThrow(() -> new DiaryException(INVALID_DIARY)); + } + + public DiaryListGetServiceResponse getDiaries(DiaryListGetServiceRequest request) { + val member = findMember(request.memberId()); + val diaries = member.getDiariesBetweenDate(request.startDate(), request.endDate()); + return DiaryListGetServiceResponse.of(diaries, member, valueConfig); + } + + private Member findMember(long id) { + return memberRepository.findById(id) + .orElseThrow(() -> new MemberException(INVALID_MEMBER)); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryService.java b/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryService.java deleted file mode 100644 index 9914d6ee..00000000 --- a/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryService.java +++ /dev/null @@ -1,161 +0,0 @@ -package com.smeem.api.diary.service; - - -import com.smeem.api.badge.service.BadgeService; -import com.smeem.api.diary.controller.dto.request.DiaryRequestDTO; -import com.smeem.api.diary.controller.dto.response.CreatedDiaryResponseDTO; -import com.smeem.api.diary.controller.dto.response.DiariesResponseDTO; -import com.smeem.api.diary.controller.dto.response.DiaryResponseDTO; -import com.smeem.api.member.service.MemberService; -import com.smeem.api.topic.service.TopicService; -import com.smeem.common.config.ValueConfig; -import com.smeem.common.exception.DiaryException; -import com.smeem.common.util.Util; -import com.smeem.domain.badge.model.Badge; -import com.smeem.domain.diary.model.DeletedDiary; -import com.smeem.domain.diary.model.Diary; -import com.smeem.domain.diary.repository.DeletedDiaryRepository; -import com.smeem.domain.diary.repository.DiaryRepository; -import com.smeem.domain.member.model.Member; -import com.smeem.domain.topic.model.Topic; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; - -import static com.smeem.common.code.failure.DiaryFailureCode.EXIST_TODAY_DIARY; -import static com.smeem.common.code.failure.DiaryFailureCode.INVALID_DIARY; -import static java.lang.Integer.parseInt; -import static java.time.LocalDateTime.now; -import static java.util.Objects.nonNull; - -@Service -@RequiredArgsConstructor -@Transactional(readOnly = true) -public class DiaryService { - - private final DiaryRepository diaryRepository; - private final DeletedDiaryRepository deletedDiaryRepository; - - private final BadgeService badgeService; - private final TopicService topicService; - private final MemberService memberService; - - private final ValueConfig valueConfig; - - @Transactional - public CreatedDiaryResponseDTO save(Long memberId, DiaryRequestDTO request) { - Member member = memberService.get(memberId); - - if (member.wroteDiaryToday()) { - throw new DiaryException(EXIST_TODAY_DIARY); - } - - Topic topic = topicService.get(request.topicId()); - Diary diary = diaryRepository.save(new Diary(request.content(), topic, member)); - - List badges = obtainBadges(member, diary.getCreatedAt()); - badges.forEach(badge -> badgeService.saveMemberBadge(member, badge)); - - return CreatedDiaryResponseDTO.of(diary.getId(), badges); - } - - public DiaryResponseDTO getDetail(Long id) { - Diary diary = get(id); - return DiaryResponseDTO.of(diary); - } - - @Transactional - public void update(Long id, DiaryRequestDTO request) { - Diary diary = get(id); - diary.updateContent(request.content()); - } - - @Transactional - public void delete(Long id) { - Diary diary = get(id); - copyToDeletedDiary(diary); - delete(diary); - } - - private void copyToDeletedDiary(Diary diary) { - deletedDiaryRepository.save(new DeletedDiary(diary)); - } - - private void delete(Diary diary) { - diary.deleteFromMember(); - diaryRepository.deleteById(diary.getId()); - } - - public DiariesResponseDTO getDiaries(Long memberId, String startDate, String endDate) { - Member member = memberService.get(memberId); - List diaries = member.getDiaries().stream() - .filter(diary -> diary.isBetween(Util.stringToDate(startDate), Util.stringToDate(endDate))) - .toList(); - boolean hasRemind = member.getDiaries().stream() - .anyMatch(diary -> diary.isCreatedAt(now().minusDays(parseInt(valueConfig.getDURATION_REMIND())))); - - return DiariesResponseDTO.of(diaries, hasRemind); - } - - @Transactional - public void deleteAllByMember(Member member) { - diaryRepository.deleteAllByMember(member); - deletedDiaryRepository.deleteByMember(member); - } - - public List getAllByMemberId(Long memberId) { - return diaryRepository.findAllByMemberId(memberId); - } - - public Diary get(Long id) { - return diaryRepository.findById(id) - .orElseThrow(() -> new DiaryException(INVALID_DIARY)); - } - - private List obtainBadges(Member member, LocalDateTime createdAt) { - List badges = new ArrayList<>(); - - Badge countingBadge = obtainCountingBadge(member); - if (nonNull(countingBadge) && member.hasNotBadge(countingBadge)) { - badges.add(countingBadge); - } - - Badge comboBadge = obtainComboBadge(member, createdAt); - if (nonNull(comboBadge) && member.hasNotBadge(comboBadge)) { - badges.add(comboBadge); - } - - return badges; - } - - private Badge obtainCountingBadge(Member member) { - int count = member.getDiaries().stream().toList().size(); - - return switch (count) { - case 50 -> badgeService.get(5L); - case 30 -> badgeService.get(4L); - case 10 -> badgeService.get(3L); - case 1 -> badgeService.get(2L); - default -> null; - }; - } - - private Badge obtainComboBadge(Member member, LocalDateTime createdAt) { - boolean isCombo = member.getDiaries().stream() - .anyMatch(diary -> diary.isCreatedAt(createdAt.minusDays(1))); - - member.updateDiaryCombo(isCombo); - - return switch (member.getDiaryComboCount()) { - case 30 -> badgeService.get(9L); - case 15 -> badgeService.get(8L); - case 7 -> badgeService.get(7L); - case 3 -> badgeService.get(6L); - default -> null; - }; - } -} diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryTransactionalService.java b/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryTransactionalService.java new file mode 100644 index 00000000..312ebf82 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryTransactionalService.java @@ -0,0 +1,161 @@ +package com.smeem.api.diary.service; + +import com.smeem.api.badge.service.BadgeService; +import com.smeem.api.diary.service.dto.request.DiaryDeleteServiceRequest; +import com.smeem.api.diary.service.dto.request.DiaryModifyServiceRequest; +import com.smeem.api.diary.service.dto.response.DiaryCreateServiceResponse; +import com.smeem.api.diary.service.dto.request.DiaryCreateServiceRequest; +import com.smeem.common.exception.DiaryException; +import com.smeem.common.exception.MemberException; +import com.smeem.common.exception.TopicException; +import com.smeem.domain.badge.model.Badge; +import com.smeem.domain.diary.model.DeletedDiary; +import com.smeem.domain.diary.model.Diary; +import com.smeem.domain.diary.repository.DeletedDiaryRepository; +import com.smeem.domain.diary.repository.DiaryRepository; +import com.smeem.domain.member.model.Member; +import com.smeem.domain.member.repository.MemberRepository; +import com.smeem.domain.topic.model.Topic; +import com.smeem.domain.topic.repository.TopicRepository; +import lombok.RequiredArgsConstructor; +import lombok.val; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import static com.smeem.common.code.failure.DiaryFailureCode.EXIST_TODAY_DIARY; +import static com.smeem.common.code.failure.DiaryFailureCode.INVALID_DIARY; +import static com.smeem.common.code.failure.MemberFailureCode.INVALID_MEMBER; +import static com.smeem.common.code.failure.TopicFailureCode.INVALID_TOPIC; +import static java.util.Objects.nonNull; + +@Service +@RequiredArgsConstructor +@Transactional +public class DiaryTransactionalService { + + private final DiaryRepository diaryRepository; + private final DeletedDiaryRepository deletedDiaryRepository; + private final MemberRepository memberRepository; + private final TopicRepository topicRepository; + + private final BadgeService badgeService; + + public DiaryCreateServiceResponse createDiary(final DiaryCreateServiceRequest request) { + val member = getMemberCheckedNoDiaryWrittenToday(request.memberId()); + val savedDiary = saveDiary(request, member); + val acquiredBadges = acquireBadgesByCreatingDiary(member, savedDiary); + return DiaryCreateServiceResponse.of(savedDiary, acquiredBadges); + } + + private Member getMemberCheckedNoDiaryWrittenToday(long memberId) { + val member = findMember(memberId); + if (member.hasDiaryWrittenToday()) { + throw new DiaryException(EXIST_TODAY_DIARY); + } + return member; + } + + private Member findMember(long id) { + return memberRepository.findById(id) + .orElseThrow(() -> new MemberException(INVALID_MEMBER)); + } + + private Diary saveDiary(DiaryCreateServiceRequest request, Member member) { + val diary = getDiaryByTopic(request, member); + return diaryRepository.save(diary); + } + + private Diary getDiaryByTopic(DiaryCreateServiceRequest request, Member member) { + val topicId = request.topicId(); + return Objects.isNull(topicId) + ? getDiaryWithoutTopic(request, member) + : getDiaryWithTopic(request, member); + } + + private Diary getDiaryWithoutTopic(DiaryCreateServiceRequest request, Member member) { + return Diary.builder() + .content(request.content()) + .member(member) + .build(); + } + + private Diary getDiaryWithTopic(DiaryCreateServiceRequest request, Member member) { + val topic = findTopic(request.topicId()); + return Diary.builder() + .content(request.content()) + .topic(topic) + .member(member) + .build(); + } + + private Topic findTopic(long id) { + return topicRepository.findById(id) + .orElseThrow(() -> new TopicException(INVALID_TOPIC)); + } + + private List acquireBadgesByCreatingDiary(Member member, Diary diary) { + val acquiredBadge = acquireBadge(member, diary); + acquiredBadge.forEach(badge -> badgeService.saveMemberBadge(member, badge)); + return acquiredBadge; + } + + private List acquireBadge(Member member, Diary diary) { + val badges = new ArrayList(); + acquireBadgeByCountOfDiary(member, badges); + acquireBadgeByComboCountOfDiary(member, diary, badges); + return badges; + } + + private void acquireBadgeByCountOfDiary(Member member, List badges) { + val countingBadge = badgeService.getBadgeByCountOfDiary(member.getDiaries().size()); + if (checkAcquiredBadge(member, countingBadge)) { + badges.add(countingBadge); + } + } + + private void acquireBadgeByComboCountOfDiary(Member member, Diary diary, List badges) { + member.updateDiaryCombo(diary); + val comboBadge = badgeService.getBadgeByComboCountOfDiary(member.getDiaryComboCount()); + if (checkAcquiredBadge(member, comboBadge)) { + badges.add(comboBadge); + } + } + + private boolean checkAcquiredBadge(Member member, Badge badge) { + return nonNull(badge) && member.hasNotBadge(badge); + } + + public void modifyDiary(DiaryModifyServiceRequest request) { + val diary = findDiary(request.diaryId()); + diary.updateContent(request.content()); + } + + private Diary findDiary(long id) { + return diaryRepository.findById(id) + .orElseThrow(() -> new DiaryException(INVALID_DIARY)); + } + + public void deleteDiary(DiaryDeleteServiceRequest request) { + val diary = findDiary(request.diaryId()); + moveToDeletedDairy(diary); + deleteDiary(diary); + } + + private void moveToDeletedDairy(Diary diary) { + deletedDiaryRepository.save(new DeletedDiary(diary)); + } + + private void deleteDiary(Diary diary) { + diary.deleteFromMember(); + diaryRepository.deleteById(diary.getId()); + } + + public void deleteAllByMember(Member member) { + diaryRepository.deleteAllByMember(member); + deletedDiaryRepository.deleteByMember(member); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryCreateServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryCreateServiceRequest.java new file mode 100644 index 00000000..9d359cb1 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryCreateServiceRequest.java @@ -0,0 +1,22 @@ +package com.smeem.api.diary.service.dto.request; + +import com.smeem.api.diary.controller.dto.request.DiaryCreateRequest; +import lombok.Builder; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record DiaryCreateServiceRequest( + long memberId, + String content, + Long topicId +) { + + public static DiaryCreateServiceRequest of(long memberId, DiaryCreateRequest request) { + return DiaryCreateServiceRequest.builder() + .memberId(memberId) + .content(request.content()) + .topicId(request.topicId()) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryDeleteServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryDeleteServiceRequest.java new file mode 100644 index 00000000..77df3654 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryDeleteServiceRequest.java @@ -0,0 +1,17 @@ +package com.smeem.api.diary.service.dto.request; + +import lombok.Builder; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record DiaryDeleteServiceRequest( + long diaryId +) { + + public static DiaryDeleteServiceRequest of(long diaryId) { + return DiaryDeleteServiceRequest.builder() + .diaryId(diaryId) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryGetServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryGetServiceRequest.java new file mode 100644 index 00000000..22302d2d --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryGetServiceRequest.java @@ -0,0 +1,17 @@ +package com.smeem.api.diary.service.dto.request; + +import lombok.Builder; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record DiaryGetServiceRequest( + long diaryId +) { + + public static DiaryGetServiceRequest of(long diaryId) { + return DiaryGetServiceRequest.builder() + .diaryId(diaryId) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryListGetServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryListGetServiceRequest.java new file mode 100644 index 00000000..cb30bfed --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryListGetServiceRequest.java @@ -0,0 +1,24 @@ +package com.smeem.api.diary.service.dto.request; + +import lombok.Builder; + +import java.time.LocalDate; + +import static java.time.format.DateTimeFormatter.ISO_DATE; +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record DiaryListGetServiceRequest( + long memberId, + LocalDate startDate, + LocalDate endDate +) { + + public static DiaryListGetServiceRequest of(long memberId, String startDate, String endDate) { + return DiaryListGetServiceRequest.builder() + .memberId(memberId) + .startDate(LocalDate.parse(startDate, ISO_DATE)) + .endDate(LocalDate.parse(endDate, ISO_DATE)) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryModifyServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryModifyServiceRequest.java new file mode 100644 index 00000000..58836b7b --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryModifyServiceRequest.java @@ -0,0 +1,20 @@ +package com.smeem.api.diary.service.dto.request; + +import com.smeem.api.diary.controller.dto.request.DiaryModifyRequest; +import lombok.Builder; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record DiaryModifyServiceRequest( + long diaryId, + String content +) { + + public static DiaryModifyServiceRequest of(long diaryId, DiaryModifyRequest request) { + return DiaryModifyServiceRequest.builder() + .diaryId(diaryId) + .content(request.content()) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryCreateServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryCreateServiceResponse.java new file mode 100644 index 00000000..ba117180 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryCreateServiceResponse.java @@ -0,0 +1,23 @@ +package com.smeem.api.diary.service.dto.response; + +import com.smeem.api.badge.controller.dto.response.AcquiredBadgeResponseDTO; +import com.smeem.domain.badge.model.Badge; +import com.smeem.domain.diary.model.Diary; +import lombok.Builder; + +import java.util.List; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record DiaryCreateServiceResponse( + long diaryId, + List badges +) { + public static DiaryCreateServiceResponse of(Diary diary, List badges) { + return DiaryCreateServiceResponse.builder() + .diaryId(diary.getId()) + .badges(badges.stream().map(AcquiredBadgeResponseDTO::of).toList()) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryGetServiceResponse.java similarity index 65% rename from smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryResponseDTO.java rename to smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryGetServiceResponse.java index a8f7eab9..737bfb5b 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryGetServiceResponse.java @@ -1,5 +1,4 @@ -package com.smeem.api.diary.controller.dto.response; - +package com.smeem.api.diary.service.dto.response; import static java.util.Objects.*; @@ -10,19 +9,19 @@ import lombok.Builder; @Builder(access = AccessLevel.PRIVATE) -public record DiaryResponseDTO( - Long diaryId, +public record DiaryGetServiceResponse( + long diaryId, String topic, String content, String createdAt, String username ) { - public static DiaryResponseDTO of(Diary diary) { - return DiaryResponseDTO.builder() + public static DiaryGetServiceResponse of(Diary diary) { + return DiaryGetServiceResponse.builder() .diaryId(diary.getId()) .topic(nonNull(diary.getTopic()) ? diary.getTopic().getContent() : "") .content(diary.getContent()) - .createdAt(Util.dateToString(diary.getCreatedAt())) + .createdAt(Util.transferToLocalDateTime(diary.getCreatedAt())) .username(diary.getMember().getUsername()) .build(); } diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryListGetServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryListGetServiceResponse.java new file mode 100644 index 00000000..9248b106 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryListGetServiceResponse.java @@ -0,0 +1,41 @@ +package com.smeem.api.diary.service.dto.response; + +import com.smeem.common.config.ValueConfig; +import com.smeem.common.util.Util; +import com.smeem.domain.diary.model.Diary; +import com.smeem.domain.member.model.Member; +import lombok.Builder; + +import java.util.List; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record DiaryListGetServiceResponse( + List diaries, + boolean has30Past +) { + public static DiaryListGetServiceResponse of(List diaries, Member member, ValueConfig valueConfig) { + return DiaryListGetServiceResponse.builder() + .diaries(diaries.stream().map(DiaryResponse::of).toList()) + .has30Past(member.hasDiaryWrittenAgo(valueConfig.getDURATION_REMIND())) + .build(); + } + + @Builder(access = PRIVATE) + public record DiaryResponse( + long diaryId, + String content, + String createdAt + ) { + public static DiaryResponse of(Diary diary) { + return DiaryResponse.builder() + .diaryId(diary.getId()) + .content(diary.getContent()) + .createdAt(Util.transferToLocalDateTime(diary.getCreatedAt())) + .build(); + } + } +} + + diff --git a/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java index 8f72448b..68115771 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java @@ -5,15 +5,13 @@ import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; import com.smeem.api.diary.controller.DiaryController; -import com.smeem.api.diary.controller.dto.request.DiaryRequestDTO; -import com.smeem.api.diary.controller.dto.response.CreatedDiaryResponseDTO; -import com.smeem.api.diary.controller.dto.response.DiariesResponseDTO; -import com.smeem.api.diary.controller.dto.response.DiariesResponseDTO.DiaryDTO; -import com.smeem.api.diary.controller.dto.response.DiaryResponseDTO; +import com.smeem.api.diary.controller.dto.request.DiaryCreateRequest; +import com.smeem.api.diary.controller.dto.request.DiaryModifyRequest; +import com.smeem.api.diary.service.dto.response.DiaryCreateServiceResponse; +import com.smeem.api.diary.service.dto.response.DiaryListGetServiceResponse; +import com.smeem.api.diary.service.dto.response.DiaryGetServiceResponse; +import com.smeem.api.diary.service.dto.response.DiaryListGetServiceResponse.DiaryResponse; import lombok.val; -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.ResponseEntity; import org.springframework.util.LinkedMultiValueMap; @@ -56,13 +54,13 @@ class DiaryControllerTest extends BaseControllerTest { // @DisplayName("일기 작성 테스트") void success_create_diary() throws Exception { // given - DiaryRequestDTO request = new DiaryRequestDTO("Hello SMEEM!", 1L); - CreatedDiaryResponseDTO response = new CreatedDiaryResponseDTO(1L, acquiredBadges()); + DiaryCreateRequest request = new DiaryCreateRequest("Hello SMEEM!", 1L); + DiaryCreateServiceResponse response = new DiaryCreateServiceResponse(1L, acquiredBadges()); val uri = URI.create("localhost:8080/api/v2/diaries/1"); ResponseEntity> result = ApiResponseUtil.success(SUCCESS_CREATE_DIARY, uri, response); // when - when(diaryController.save(principal, request)).thenReturn(result); + when(diaryController.createDiary(principal, request)).thenReturn(result); // then mockMvc.perform(post(DEFAULT_URL) @@ -105,7 +103,7 @@ void success_create_diary() throws Exception { // @DisplayName("일기 조회 테스트") void success_get_diary() throws Exception { // given - DiaryResponseDTO response = new DiaryResponseDTO(1L, + DiaryGetServiceResponse response = new DiaryGetServiceResponse(1L, "가보고 싶은 해외 여행 지가 있다면 소개해 주세요!", "I want to go Bla Bla ...", "2023-08-19 14:00", @@ -113,7 +111,7 @@ void success_get_diary() throws Exception { ResponseEntity> result = ApiResponseUtil.success(SUCCESS_GET_DIARY, response); // when - when(diaryController.getDetail(anyLong())).thenReturn(result); + when(diaryController.getDiaryDetail(anyLong())).thenReturn(result); // then mockMvc.perform(get(DEFAULT_URL + "/{diaryId}", 1L) @@ -151,11 +149,11 @@ void success_get_diary() throws Exception { void success_update_diary() throws Exception { // given Long diaryId = 1L; - DiaryRequestDTO request = new DiaryRequestDTO("Hello SMEEM!!", 1L); + DiaryModifyRequest request = new DiaryModifyRequest("Hello SMEEM!!", 1L); ResponseEntity> result = ApiResponseUtil.success(SUCCESS_UPDATE_DAIRY); // when - when(diaryController.update(diaryId, request)).thenReturn(result); + when(diaryController.modifyDiary(diaryId, request)).thenReturn(result); // then mockMvc.perform(patch(DEFAULT_URL + "/{diaryId}", diaryId) @@ -195,7 +193,7 @@ void success_delete_diary() throws Exception { ResponseEntity> result = ApiResponseUtil.success(SUCCESS_DELETE_DIARY); // when - when(diaryController.delete(diaryId)).thenReturn(result); + when(diaryController.deleteDiary(diaryId)).thenReturn(result); // then mockMvc.perform(delete(DEFAULT_URL + "/{diaryId}", diaryId) @@ -226,7 +224,7 @@ void success_delete_diary() throws Exception { // @DisplayName("일기 리스트 조회 테스트") void success_get_diaries() throws Exception { // given - DiariesResponseDTO response = new DiariesResponseDTO(diaries(), true); + DiaryListGetServiceResponse response = new DiaryListGetServiceResponse(diaries(), true); ResponseEntity> result = ApiResponseUtil.success(SUCCESS_GET_DIARIES, response); MultiValueMap queries = new LinkedMultiValueMap<>(); @@ -280,10 +278,10 @@ private AcquiredBadgeResponseDTO acquiredBadge() { return new AcquiredBadgeResponseDTO("뱃지 이름", "com.smeem.badge-image-url", EVENT); } - private List diaries() { - List diaries = new ArrayList<>(); + private List diaries() { + List diaries = new ArrayList<>(); for (int i = 0; i < 2; i++) { - diaries.add(new DiaryDTO((long) (i + 1), "Hello SMEEM" + (i + 1), "2023-08-2" + i + " 14:00")); + diaries.add(new DiaryResponse((long) (i + 1), "Hello SMEEM" + (i + 1), "2023-08-2" + i + " 14:00")); } return diaries; } diff --git a/smeem-common/src/main/java/com/smeem/common/config/ValueConfig.java b/smeem-common/src/main/java/com/smeem/common/config/ValueConfig.java index 55b275e1..cf35da98 100644 --- a/smeem-common/src/main/java/com/smeem/common/config/ValueConfig.java +++ b/smeem-common/src/main/java/com/smeem/common/config/ValueConfig.java @@ -43,7 +43,7 @@ public class ValueConfig { private String DURATION_EXPIRED; @Value("${smeem.duration.remind}") - private String DURATION_REMIND; + private int DURATION_REMIND; @PostConstruct protected void init() { diff --git a/smeem-common/src/main/java/com/smeem/common/util/Util.java b/smeem-common/src/main/java/com/smeem/common/util/Util.java index 35ce197a..429888a6 100644 --- a/smeem-common/src/main/java/com/smeem/common/util/Util.java +++ b/smeem-common/src/main/java/com/smeem/common/util/Util.java @@ -13,11 +13,11 @@ public class Util { - public static Long getMemberId(Principal principal) { + public static long getMemberId(Principal principal) { if (isNull(principal)) { throw new TokenException(EMPTY_ACCESS_TOKEN); } - return Long.valueOf(principal.getName()); + return Long.parseLong(principal.getName()); } public static URI getURI(String path, long id) { @@ -28,15 +28,7 @@ public static URI getURI(String path, long id) { .toUri(); } - public static String dateToString(LocalDateTime date) { + public static String transferToLocalDateTime(LocalDateTime date) { return date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")); } - - public static LocalDateTime stringToDate(String str) { - return LocalDateTime.parse(str + " 00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")); - } - - public static LocalDateTime getStartOfDay(LocalDateTime dateTime) { - return dateTime.toLocalDate().atStartOfDay(); - } } diff --git a/smeem-domain/src/main/java/com/smeem/domain/diary/model/Diary.java b/smeem-domain/src/main/java/com/smeem/domain/diary/model/Diary.java index 5250def2..3ac47975 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/diary/model/Diary.java +++ b/smeem-domain/src/main/java/com/smeem/domain/diary/model/Diary.java @@ -12,7 +12,9 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.val; +import java.time.LocalDate; import java.time.LocalDateTime; @@ -51,7 +53,22 @@ public Diary(String content, Topic topic, Member member) { this.isPublic = true; this.topic = topic; setMember(member); - this.createdAt = LocalDateTime.now(); + } + + @Builder + public Diary(String content, Member member) { + this.content = content; + this.targetLang = member.getTargetLang(); + this.isPublic = true; + setMember(member); + } + + private void setMember(Member member) { + if (nonNull(this.member)) { + this.member.getDiaries().remove(this); + } + this.member = member; + member.getDiaries().add(this); } public void updateContent(String content) { @@ -65,22 +82,27 @@ public void deleteFromMember() { } } - public boolean isCreatedAt(LocalDateTime createdAt) { - return Util.getStartOfDay(this.createdAt).isEqual(Util.getStartOfDay(createdAt)); + public boolean isCreatedAt(LocalDate date) { + return this.createdAt.toLocalDate().equals(date); } - public boolean isBetween(LocalDateTime startAt, LocalDateTime endAt) { - LocalDateTime createdAt = Util.getStartOfDay(this.createdAt); - startAt = Util.getStartOfDay(startAt); - endAt = Util.getStartOfDay(endAt); - return createdAt.equals(startAt) || (createdAt.isAfter(startAt) && createdAt.isBefore(endAt)) || createdAt.equals(endAt); + public boolean isWrittenToday() { + return this.createdAt.toLocalDate().equals(LocalDate.now()); } - private void setMember(Member member) { - if (nonNull(this.member)) { - this.member.getDiaries().remove(this); - } - this.member = member; - member.getDiaries().add(this); + public boolean isWrittenYesterday() { + val yesterday = LocalDate.now().minusDays(1); + return this.createdAt.toLocalDate().equals(yesterday); + } + + public boolean isBetween(LocalDate startDate, LocalDate endDate) { + val createdDate = this.createdAt.toLocalDate(); + return createdDate.equals(startDate) + || (createdDate.isAfter(startDate) && createdDate.isBefore(endDate)) + || createdDate.equals(endDate); + } + + public boolean isCombo() { + return this.member.getDiaries().stream().anyMatch(Diary::isWrittenYesterday); } } diff --git a/smeem-domain/src/main/java/com/smeem/domain/member/model/Member.java b/smeem-domain/src/main/java/com/smeem/domain/member/model/Member.java index 27480caa..01dbb007 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/member/model/Member.java +++ b/smeem-domain/src/main/java/com/smeem/domain/member/model/Member.java @@ -1,7 +1,5 @@ package com.smeem.domain.member.model; -import static java.time.LocalDateTime.now; - import com.smeem.domain.badge.model.Badge; import com.smeem.domain.diary.model.Diary; import com.smeem.domain.goal.model.GoalType; @@ -11,12 +9,13 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.val; -import java.time.LocalDateTime; +import java.time.LocalDate; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; - @Entity @NoArgsConstructor @Getter @@ -93,36 +92,54 @@ public void updateGoal(GoalType goal) { this.goal = goal; } - public boolean wroteDiaryToday() { - return this.diaries.stream() - .anyMatch(diary -> diary.isCreatedAt(now())); + public boolean hasDiaryWrittenToday() { + return this.diaries.stream().anyMatch(Diary::isWrittenToday); } - public void updateDiaryCombo(boolean isCombo) { - this.diaryComboCount = isCombo ? this.diaryComboCount + 1 : 1; + public void updateDiaryCombo(Diary diary) { + this.diaryComboCount = diary.isCombo() ? this.diaryComboCount + 1 : 1; } public void updateDiaryCombo() { - List diaries = this.diaries.stream() - .filter(diary -> !diary.isCreatedAt(now())) - .sorted((a, b) -> b.createdAt.compareTo(a.createdAt)).toList(); + this.diaryComboCount = calculateDiaryComboCount(); + } + + private List getDiariesNotWrittenTodayOrderByCreatedAtDesc() { + return this.diaries.stream() + .filter(diary -> !diary.isWrittenToday()) + .sorted(Comparator.comparing(Diary::getCreatedAt).reversed()) + .toList(); + } - int count = wroteDiaryToday() ? 1 : 0; - LocalDateTime day = now(); + private int calculateDiaryComboCount() { + val diaries = getDiariesNotWrittenTodayOrderByCreatedAtDesc(); + int count = hasDiaryWrittenToday() ? 1 : 0; + LocalDate currentDate = LocalDate.now(); for (Diary diary : diaries) { - day = day.minusDays(1); - if (!diary.isCreatedAt(day)) { + currentDate = currentDate.minusDays(1); + if (!diary.isCreatedAt(currentDate)) { break; } count++; } - this.diaryComboCount = count; + return count; } public boolean hasNotBadge(Badge badge) { return badges.stream().noneMatch(memberBadge -> memberBadge.getBadge().equals(badge)); } + public List getDiariesBetweenDate(LocalDate startDate, LocalDate endDate) { + return this.diaries.stream() + .filter(diary -> diary.isBetween(startDate, endDate)) + .toList(); + } + + public boolean hasDiaryWrittenAgo(int duration) { + val remindDate = LocalDate.now().minusDays(duration); + return this.diaries.stream().anyMatch(diary -> diary.isCreatedAt(remindDate)); + } + } From 3903b8013d44286d7704bf0898b3eac10de710f6 Mon Sep 17 00:00:00 2001 From: thguss Date: Mon, 12 Feb 2024 22:03:19 +0900 Subject: [PATCH 36/86] =?UTF-8?q?[REFACTOR]=20Diary=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smeem/api/diary/controller/DiaryController.java | 4 +--- .../dto/request/DiaryCreateRequest.java | 2 +- .../dto/request/DiaryCreateServiceRequest.java | 3 +-- .../dto/request/DiaryDeleteServiceRequest.java | 2 +- .../dto/request/DiaryGetServiceRequest.java | 2 +- .../dto/request/DiaryListGetServiceRequest.java | 2 +- .../dto/request/DiaryModifyRequest.java | 2 +- .../dto/request/DiaryModifyServiceRequest.java | 3 +-- .../dto/response/DiaryCreateServiceResponse.java | 2 +- .../dto/response/DiaryGetServiceResponse.java | 2 +- .../dto/response/DiaryListGetServiceResponse.java | 2 +- .../diary/service/DiaryNonTransactionalService.java | 8 ++++---- .../api/diary/service/DiaryTransactionalService.java | 8 ++++---- .../smeem/api/controller/DiaryControllerTest.java | 12 ++++++------ 14 files changed, 25 insertions(+), 29 deletions(-) rename smeem-api/src/main/java/com/smeem/api/diary/{controller => }/dto/request/DiaryCreateRequest.java (70%) rename smeem-api/src/main/java/com/smeem/api/diary/{service => }/dto/request/DiaryCreateServiceRequest.java (81%) rename smeem-api/src/main/java/com/smeem/api/diary/{service => }/dto/request/DiaryDeleteServiceRequest.java (87%) rename smeem-api/src/main/java/com/smeem/api/diary/{service => }/dto/request/DiaryGetServiceRequest.java (87%) rename smeem-api/src/main/java/com/smeem/api/diary/{service => }/dto/request/DiaryListGetServiceRequest.java (93%) rename smeem-api/src/main/java/com/smeem/api/diary/{controller => }/dto/request/DiaryModifyRequest.java (70%) rename smeem-api/src/main/java/com/smeem/api/diary/{service => }/dto/request/DiaryModifyServiceRequest.java (78%) rename smeem-api/src/main/java/com/smeem/api/diary/{service => }/dto/response/DiaryCreateServiceResponse.java (93%) rename smeem-api/src/main/java/com/smeem/api/diary/{service => }/dto/response/DiaryGetServiceResponse.java (94%) rename smeem-api/src/main/java/com/smeem/api/diary/{service => }/dto/response/DiaryListGetServiceResponse.java (96%) diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java b/smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java index 9a1de51f..edb7b07e 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java @@ -4,11 +4,9 @@ import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; -import com.smeem.api.diary.controller.dto.request.DiaryCreateRequest; -import com.smeem.api.diary.controller.dto.request.DiaryModifyRequest; +import com.smeem.api.diary.dto.request.*; import com.smeem.api.diary.service.DiaryNonTransactionalService; import com.smeem.api.diary.service.DiaryTransactionalService; -import com.smeem.api.diary.service.dto.request.*; import com.smeem.common.util.Util; import lombok.val; import org.springframework.http.ResponseEntity; diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryCreateRequest.java b/smeem-api/src/main/java/com/smeem/api/diary/dto/request/DiaryCreateRequest.java similarity index 70% rename from smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryCreateRequest.java rename to smeem-api/src/main/java/com/smeem/api/diary/dto/request/DiaryCreateRequest.java index 3b4cf852..2a3a0325 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryCreateRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/dto/request/DiaryCreateRequest.java @@ -1,4 +1,4 @@ -package com.smeem.api.diary.controller.dto.request; +package com.smeem.api.diary.dto.request; import lombok.NonNull; diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryCreateServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/diary/dto/request/DiaryCreateServiceRequest.java similarity index 81% rename from smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryCreateServiceRequest.java rename to smeem-api/src/main/java/com/smeem/api/diary/dto/request/DiaryCreateServiceRequest.java index 9d359cb1..59de3683 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryCreateServiceRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/dto/request/DiaryCreateServiceRequest.java @@ -1,6 +1,5 @@ -package com.smeem.api.diary.service.dto.request; +package com.smeem.api.diary.dto.request; -import com.smeem.api.diary.controller.dto.request.DiaryCreateRequest; import lombok.Builder; import static lombok.AccessLevel.PRIVATE; diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryDeleteServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/diary/dto/request/DiaryDeleteServiceRequest.java similarity index 87% rename from smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryDeleteServiceRequest.java rename to smeem-api/src/main/java/com/smeem/api/diary/dto/request/DiaryDeleteServiceRequest.java index 77df3654..84b2bee3 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryDeleteServiceRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/dto/request/DiaryDeleteServiceRequest.java @@ -1,4 +1,4 @@ -package com.smeem.api.diary.service.dto.request; +package com.smeem.api.diary.dto.request; import lombok.Builder; diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryGetServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/diary/dto/request/DiaryGetServiceRequest.java similarity index 87% rename from smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryGetServiceRequest.java rename to smeem-api/src/main/java/com/smeem/api/diary/dto/request/DiaryGetServiceRequest.java index 22302d2d..d666f75b 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryGetServiceRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/dto/request/DiaryGetServiceRequest.java @@ -1,4 +1,4 @@ -package com.smeem.api.diary.service.dto.request; +package com.smeem.api.diary.dto.request; import lombok.Builder; diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryListGetServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/diary/dto/request/DiaryListGetServiceRequest.java similarity index 93% rename from smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryListGetServiceRequest.java rename to smeem-api/src/main/java/com/smeem/api/diary/dto/request/DiaryListGetServiceRequest.java index cb30bfed..da57ac15 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryListGetServiceRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/dto/request/DiaryListGetServiceRequest.java @@ -1,4 +1,4 @@ -package com.smeem.api.diary.service.dto.request; +package com.smeem.api.diary.dto.request; import lombok.Builder; diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryModifyRequest.java b/smeem-api/src/main/java/com/smeem/api/diary/dto/request/DiaryModifyRequest.java similarity index 70% rename from smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryModifyRequest.java rename to smeem-api/src/main/java/com/smeem/api/diary/dto/request/DiaryModifyRequest.java index 8377c67f..88026d11 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryModifyRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/dto/request/DiaryModifyRequest.java @@ -1,4 +1,4 @@ -package com.smeem.api.diary.controller.dto.request; +package com.smeem.api.diary.dto.request; import lombok.NonNull; diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryModifyServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/diary/dto/request/DiaryModifyServiceRequest.java similarity index 78% rename from smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryModifyServiceRequest.java rename to smeem-api/src/main/java/com/smeem/api/diary/dto/request/DiaryModifyServiceRequest.java index 58836b7b..e21494c4 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryModifyServiceRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/dto/request/DiaryModifyServiceRequest.java @@ -1,6 +1,5 @@ -package com.smeem.api.diary.service.dto.request; +package com.smeem.api.diary.dto.request; -import com.smeem.api.diary.controller.dto.request.DiaryModifyRequest; import lombok.Builder; import static lombok.AccessLevel.PRIVATE; diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryCreateServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/diary/dto/response/DiaryCreateServiceResponse.java similarity index 93% rename from smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryCreateServiceResponse.java rename to smeem-api/src/main/java/com/smeem/api/diary/dto/response/DiaryCreateServiceResponse.java index ba117180..afd04064 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryCreateServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/dto/response/DiaryCreateServiceResponse.java @@ -1,4 +1,4 @@ -package com.smeem.api.diary.service.dto.response; +package com.smeem.api.diary.dto.response; import com.smeem.api.badge.controller.dto.response.AcquiredBadgeResponseDTO; import com.smeem.domain.badge.model.Badge; diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryGetServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/diary/dto/response/DiaryGetServiceResponse.java similarity index 94% rename from smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryGetServiceResponse.java rename to smeem-api/src/main/java/com/smeem/api/diary/dto/response/DiaryGetServiceResponse.java index 737bfb5b..204993c6 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryGetServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/dto/response/DiaryGetServiceResponse.java @@ -1,4 +1,4 @@ -package com.smeem.api.diary.service.dto.response; +package com.smeem.api.diary.dto.response; import static java.util.Objects.*; diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryListGetServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/diary/dto/response/DiaryListGetServiceResponse.java similarity index 96% rename from smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryListGetServiceResponse.java rename to smeem-api/src/main/java/com/smeem/api/diary/dto/response/DiaryListGetServiceResponse.java index 9248b106..57d8f49f 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryListGetServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/dto/response/DiaryListGetServiceResponse.java @@ -1,4 +1,4 @@ -package com.smeem.api.diary.service.dto.response; +package com.smeem.api.diary.dto.response; import com.smeem.common.config.ValueConfig; import com.smeem.common.util.Util; diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryNonTransactionalService.java b/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryNonTransactionalService.java index 486f8cc3..d5f3e9be 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryNonTransactionalService.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryNonTransactionalService.java @@ -1,9 +1,9 @@ package com.smeem.api.diary.service; -import com.smeem.api.diary.service.dto.response.DiaryListGetServiceResponse; -import com.smeem.api.diary.service.dto.response.DiaryGetServiceResponse; -import com.smeem.api.diary.service.dto.request.DiaryGetServiceRequest; -import com.smeem.api.diary.service.dto.request.DiaryListGetServiceRequest; +import com.smeem.api.diary.dto.response.DiaryListGetServiceResponse; +import com.smeem.api.diary.dto.response.DiaryGetServiceResponse; +import com.smeem.api.diary.dto.request.DiaryGetServiceRequest; +import com.smeem.api.diary.dto.request.DiaryListGetServiceRequest; import com.smeem.common.config.ValueConfig; import com.smeem.common.exception.DiaryException; import com.smeem.common.exception.MemberException; diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryTransactionalService.java b/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryTransactionalService.java index 312ebf82..5cf7581b 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryTransactionalService.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryTransactionalService.java @@ -1,10 +1,10 @@ package com.smeem.api.diary.service; import com.smeem.api.badge.service.BadgeService; -import com.smeem.api.diary.service.dto.request.DiaryDeleteServiceRequest; -import com.smeem.api.diary.service.dto.request.DiaryModifyServiceRequest; -import com.smeem.api.diary.service.dto.response.DiaryCreateServiceResponse; -import com.smeem.api.diary.service.dto.request.DiaryCreateServiceRequest; +import com.smeem.api.diary.dto.request.DiaryDeleteServiceRequest; +import com.smeem.api.diary.dto.request.DiaryModifyServiceRequest; +import com.smeem.api.diary.dto.response.DiaryCreateServiceResponse; +import com.smeem.api.diary.dto.request.DiaryCreateServiceRequest; import com.smeem.common.exception.DiaryException; import com.smeem.common.exception.MemberException; import com.smeem.common.exception.TopicException; diff --git a/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java index 68115771..6e05f66c 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java @@ -5,12 +5,12 @@ import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; import com.smeem.api.diary.controller.DiaryController; -import com.smeem.api.diary.controller.dto.request.DiaryCreateRequest; -import com.smeem.api.diary.controller.dto.request.DiaryModifyRequest; -import com.smeem.api.diary.service.dto.response.DiaryCreateServiceResponse; -import com.smeem.api.diary.service.dto.response.DiaryListGetServiceResponse; -import com.smeem.api.diary.service.dto.response.DiaryGetServiceResponse; -import com.smeem.api.diary.service.dto.response.DiaryListGetServiceResponse.DiaryResponse; +import com.smeem.api.diary.dto.request.DiaryCreateRequest; +import com.smeem.api.diary.dto.request.DiaryModifyRequest; +import com.smeem.api.diary.dto.response.DiaryCreateServiceResponse; +import com.smeem.api.diary.dto.response.DiaryListGetServiceResponse; +import com.smeem.api.diary.dto.response.DiaryGetServiceResponse; +import com.smeem.api.diary.dto.response.DiaryListGetServiceResponse.DiaryResponse; import lombok.val; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.ResponseEntity; From 1708f3e6668962e613f95174e714507f61784fb6 Mon Sep 17 00:00:00 2001 From: thguss Date: Mon, 12 Feb 2024 22:09:02 +0900 Subject: [PATCH 37/86] =?UTF-8?q?[REFACTOR]=20Test=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/{ => controller}/TestController.java | 16 ++++++++-------- .../dto/request/TestPushAlarmRequest.java | 17 +++++++++++++++++ .../api/test/{ => service}/TestService.java | 19 +++++++++++++++---- .../api/controller/TestControllerTest.java | 5 +---- 4 files changed, 41 insertions(+), 16 deletions(-) rename smeem-api/src/main/java/com/smeem/api/test/{ => controller}/TestController.java (68%) create mode 100644 smeem-api/src/main/java/com/smeem/api/test/dto/request/TestPushAlarmRequest.java rename smeem-api/src/main/java/com/smeem/api/test/{ => service}/TestService.java (59%) diff --git a/smeem-api/src/main/java/com/smeem/api/test/TestController.java b/smeem-api/src/main/java/com/smeem/api/test/controller/TestController.java similarity index 68% rename from smeem-api/src/main/java/com/smeem/api/test/TestController.java rename to smeem-api/src/main/java/com/smeem/api/test/controller/TestController.java index 5f1cd7f5..5f67a6bf 100644 --- a/smeem-api/src/main/java/com/smeem/api/test/TestController.java +++ b/smeem-api/src/main/java/com/smeem/api/test/controller/TestController.java @@ -1,17 +1,18 @@ -package com.smeem.api.test; +package com.smeem.api.test.controller; import java.security.Principal; import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; -import com.smeem.common.config.ValueConfig; +import com.smeem.api.test.dto.request.TestPushAlarmRequest; +import com.smeem.api.test.service.TestService; +import com.smeem.common.util.Util; import lombok.val; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import io.swagger.v3.oas.annotations.Parameter; import lombok.RequiredArgsConstructor; import static com.smeem.common.code.success.TestSuccessCode.SUCCESS_SEND_PUSH_ALARM; @@ -23,7 +24,6 @@ public class TestController { private final TestService testService; - private final ValueConfig valueConfig; @GetMapping public ResponseEntity> test() { @@ -31,10 +31,10 @@ public ResponseEntity> test() { } @GetMapping("/alarm") - public ResponseEntity> alarmTest(@Parameter(hidden = true) Principal principal) { - val title = valueConfig.getMESSAGE_TITLE(); - val body = valueConfig.getMESSAGE_BODY(); - testService.pushTest(title, body, Long.valueOf(principal.getName())); + public ResponseEntity> alarmTest(Principal principal) { + val memberId = Util.getMemberId(principal); + val serviceRequest = TestPushAlarmRequest.of(memberId); + testService.pushTest(serviceRequest); return ApiResponseUtil.success(SUCCESS_SEND_PUSH_ALARM); } } diff --git a/smeem-api/src/main/java/com/smeem/api/test/dto/request/TestPushAlarmRequest.java b/smeem-api/src/main/java/com/smeem/api/test/dto/request/TestPushAlarmRequest.java new file mode 100644 index 00000000..7e9d45e5 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/test/dto/request/TestPushAlarmRequest.java @@ -0,0 +1,17 @@ +package com.smeem.api.test.dto.request; + +import lombok.Builder; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record TestPushAlarmRequest( + long memberId +) { + + public static TestPushAlarmRequest of(long memberId) { + return TestPushAlarmRequest.builder() + .memberId(memberId) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/test/TestService.java b/smeem-api/src/main/java/com/smeem/api/test/service/TestService.java similarity index 59% rename from smeem-api/src/main/java/com/smeem/api/test/TestService.java rename to smeem-api/src/main/java/com/smeem/api/test/service/TestService.java index 974d887e..bd229c41 100644 --- a/smeem-api/src/main/java/com/smeem/api/test/TestService.java +++ b/smeem-api/src/main/java/com/smeem/api/test/service/TestService.java @@ -1,11 +1,14 @@ -package com.smeem.api.test; +package com.smeem.api.test.service; +import com.smeem.api.test.dto.request.TestPushAlarmRequest; +import com.smeem.common.config.ValueConfig; import com.smeem.common.exception.MemberException; import com.smeem.domain.member.model.Member; import com.smeem.domain.member.repository.MemberRepository; import com.smeem.external.firebase.FcmService; import lombok.RequiredArgsConstructor; +import lombok.val; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -17,11 +20,19 @@ public class TestService { private final MemberRepository memberRepository; + private final FcmService fcmService; + private final ValueConfig valueConfig; - public void pushTest(String title, String body, Long memberId) { - Member member = memberRepository.findById(memberId) - .orElseThrow(() -> new MemberException(INVALID_MEMBER)); + public void pushTest(TestPushAlarmRequest request) { + val member = findMember(request.memberId()); + val title = valueConfig.getMESSAGE_TITLE(); + val body = valueConfig.getMESSAGE_BODY(); fcmService.pushMessage(member.getFcmToken(), title, body); } + + private Member findMember(long id) { + return memberRepository.findById(id) + .orElseThrow(() -> new MemberException(INVALID_MEMBER)); + } } \ No newline at end of file diff --git a/smeem-api/src/test/java/com/smeem/api/controller/TestControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/TestControllerTest.java index 859499bb..22c43242 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/TestControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/TestControllerTest.java @@ -2,10 +2,7 @@ import com.epages.restdocs.apispec.ResourceSnippetParameters; import com.smeem.api.common.ApiResponseUtil; -import com.smeem.api.test.TestController; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import com.smeem.api.test.controller.TestController; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; From 30148bbb4abaea254eb07e9056e250bd507fed2b Mon Sep 17 00:00:00 2001 From: thguss Date: Mon, 12 Feb 2024 22:14:59 +0900 Subject: [PATCH 38/86] =?UTF-8?q?[REFACTOR]=20Topic=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/topic/controller/TopicController.java | 6 ++--- .../dto/response/TopicResponseDTO.java | 13 ----------- .../RandomTopicGetServiceResponse.java | 20 +++++++++++++++++ .../smeem/api/topic/service/TopicService.java | 22 +++++-------------- .../api/controller/TopicControllerTest.java | 9 +++----- .../smeem/api/fixture/topic/TopicFixture.java | 6 ++--- .../repository/TopicCustomRepository.java | 2 +- .../topic/repository/TopicRepositoryImpl.java | 9 ++++---- 8 files changed, 39 insertions(+), 48 deletions(-) delete mode 100644 smeem-api/src/main/java/com/smeem/api/topic/controller/dto/response/TopicResponseDTO.java create mode 100644 smeem-api/src/main/java/com/smeem/api/topic/dto/response/RandomTopicGetServiceResponse.java diff --git a/smeem-api/src/main/java/com/smeem/api/topic/controller/TopicController.java b/smeem-api/src/main/java/com/smeem/api/topic/controller/TopicController.java index a445b2e2..d4260a03 100644 --- a/smeem-api/src/main/java/com/smeem/api/topic/controller/TopicController.java +++ b/smeem-api/src/main/java/com/smeem/api/topic/controller/TopicController.java @@ -2,8 +2,8 @@ import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; -import com.smeem.api.topic.controller.dto.response.TopicResponseDTO; import com.smeem.api.topic.service.TopicService; +import lombok.val; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -21,8 +21,8 @@ public class TopicController { private final TopicService topicService; @GetMapping("/random") - public ResponseEntity> getRandom() { - TopicResponseDTO response = topicService.getRandom(); + public ResponseEntity> getTopicByRandom() { + val response = topicService.getTopicByRandom(); return ApiResponseUtil.success(SUCCESS_GET_RANDOM_TOPIC, response); } } diff --git a/smeem-api/src/main/java/com/smeem/api/topic/controller/dto/response/TopicResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/topic/controller/dto/response/TopicResponseDTO.java deleted file mode 100644 index 11f06ab1..00000000 --- a/smeem-api/src/main/java/com/smeem/api/topic/controller/dto/response/TopicResponseDTO.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.smeem.api.topic.controller.dto.response; - - -import com.smeem.domain.topic.model.Topic; - -public record TopicResponseDTO( - Long topicId, - String content -) { - public static TopicResponseDTO of(Topic topic) { - return new TopicResponseDTO(topic.getId(), topic.getContent()); - } -} diff --git a/smeem-api/src/main/java/com/smeem/api/topic/dto/response/RandomTopicGetServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/topic/dto/response/RandomTopicGetServiceResponse.java new file mode 100644 index 00000000..64c49651 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/topic/dto/response/RandomTopicGetServiceResponse.java @@ -0,0 +1,20 @@ +package com.smeem.api.topic.dto.response; + +import com.smeem.domain.topic.model.Topic; +import lombok.Builder; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record RandomTopicGetServiceResponse( + long topicId, + String content +) { + + public static RandomTopicGetServiceResponse of(Topic topic) { + return RandomTopicGetServiceResponse.builder() + .topicId(topic.getId()) + .content(topic.getContent()) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/topic/service/TopicService.java b/smeem-api/src/main/java/com/smeem/api/topic/service/TopicService.java index c1746839..1596c52c 100644 --- a/smeem-api/src/main/java/com/smeem/api/topic/service/TopicService.java +++ b/smeem-api/src/main/java/com/smeem/api/topic/service/TopicService.java @@ -1,18 +1,13 @@ package com.smeem.api.topic.service; -import com.smeem.api.topic.controller.dto.response.TopicResponseDTO; -import com.smeem.common.exception.TopicException; -import com.smeem.domain.topic.model.Topic; +import com.smeem.api.topic.dto.response.RandomTopicGetServiceResponse; import com.smeem.domain.topic.repository.TopicRepository; +import lombok.val; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; - import lombok.RequiredArgsConstructor; -import static com.smeem.common.code.failure.TopicFailureCode.INVALID_TOPIC; -import static java.util.Objects.nonNull; - @Service @RequiredArgsConstructor @Transactional(readOnly = true) @@ -20,15 +15,8 @@ public class TopicService { private final TopicRepository topicRepository; - public TopicResponseDTO getRandom() { - Topic topic = topicRepository.getRandom(); - return TopicResponseDTO.of(topic); - } - - public Topic get(Long id) { - return nonNull(id) - ? topicRepository.findById(id) - .orElseThrow(() -> new TopicException(INVALID_TOPIC)) - : null; + public RandomTopicGetServiceResponse getTopicByRandom() { + val topic = topicRepository.findByRandom(); + return RandomTopicGetServiceResponse.of(topic); } } diff --git a/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java index 92fd402b..f0c2287a 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java @@ -3,11 +3,8 @@ import com.epages.restdocs.apispec.ResourceSnippetParameters; import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.topic.controller.TopicController; -import com.smeem.api.topic.controller.dto.response.TopicResponseDTO; +import com.smeem.api.topic.dto.response.RandomTopicGetServiceResponse; import lombok.val; -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 java.security.Principal; @@ -40,11 +37,11 @@ class TopicControllerTest extends BaseControllerTest { // @DisplayName("랜덤 주제 조회 테스트") void success_get_random_topic_test() throws Exception { // given - TopicResponseDTO response = new TopicResponseDTO(1L, "가보고 싶은 해외 여행 지가 있다면 소개해 주세요!"); + RandomTopicGetServiceResponse response = new RandomTopicGetServiceResponse(1L, "가보고 싶은 해외 여행 지가 있다면 소개해 주세요!"); val result = ApiResponseUtil.success(SUCCESS_GET_RANDOM_TOPIC, response); // when - when(topicController.getRandom()).thenReturn(result); + when(topicController.getTopicByRandom()).thenReturn(result); // then mockMvc.perform(get(DEFAULT_URL + "/random") diff --git a/smeem-api/src/test/java/com/smeem/api/fixture/topic/TopicFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/topic/TopicFixture.java index 773985f8..5eba7f17 100644 --- a/smeem-api/src/test/java/com/smeem/api/fixture/topic/TopicFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/topic/TopicFixture.java @@ -1,7 +1,7 @@ package com.smeem.api.fixture.topic; -import com.smeem.api.topic.controller.dto.response.TopicResponseDTO; +import com.smeem.api.topic.dto.response.RandomTopicGetServiceResponse; import com.smeem.domain.topic.model.Category; import com.smeem.domain.topic.model.Topic; @@ -18,7 +18,7 @@ public static Topic createTopic() { .build(); } - public static TopicResponseDTO createTopicResponseDTO() { - return TopicResponseDTO.of(createTopic()); + public static RandomTopicGetServiceResponse createTopicResponseDTO() { + return RandomTopicGetServiceResponse.of(createTopic()); } } diff --git a/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicCustomRepository.java b/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicCustomRepository.java index 95c3ba73..a751a53a 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicCustomRepository.java +++ b/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicCustomRepository.java @@ -4,5 +4,5 @@ import com.smeem.domain.topic.model.Topic; public interface TopicCustomRepository { - Topic getRandom(); + Topic findByRandom(); } diff --git a/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicRepositoryImpl.java b/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicRepositoryImpl.java index 4e941a70..eea81fc3 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicRepositoryImpl.java +++ b/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicRepositoryImpl.java @@ -1,8 +1,6 @@ package com.smeem.domain.topic.repository; - import com.querydsl.core.types.dsl.NumberExpression; -import com.smeem.domain.topic.model.QTopic; import com.smeem.domain.topic.model.Topic; import org.springframework.stereotype.Repository; @@ -10,6 +8,8 @@ import lombok.RequiredArgsConstructor; +import static com.smeem.domain.topic.model.QTopic.topic; + @Repository @RequiredArgsConstructor public class TopicRepositoryImpl implements TopicCustomRepository { @@ -17,10 +17,9 @@ public class TopicRepositoryImpl implements TopicCustomRepository { private final JPAQueryFactory queryFactory; @Override - public Topic getRandom() { + public Topic findByRandom() { return queryFactory - .select(QTopic.topic) - .from(QTopic.topic) + .selectFrom(topic) .orderBy(NumberExpression.random().asc()) .limit(1) .fetchFirst(); From 3cee0d1b879253eec5d8301c924e5d25398b3f33 Mon Sep 17 00:00:00 2001 From: thguss Date: Mon, 12 Feb 2024 22:25:42 +0900 Subject: [PATCH 39/86] =?UTF-8?q?[REFACTOR]=20Goal=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smeem/api/badge/service/BadgeService.java | 2 +- .../api/goal/controller/GoalController.java | 14 ++++---- .../dto/response/GoalResponseDTO.java | 19 ----------- .../dto/response/GoalsResponseDTO.java | 24 ------------- .../dto/request/GoalGetServiceRequest.java | 18 ++++++++++ .../dto/response/GoalGetServiceResponse.java | 22 ++++++++++++ .../response/GoalListGetServiceResponse.java | 34 +++++++++++++++++++ .../smeem/api/goal/service/GoalService.java | 23 ++++++++----- .../dto/response/MemberGetResponseDTO.java | 4 +-- .../api/member/service/MemberService.java | 5 +-- .../api/controller/GoalControllerTest.java | 23 ++++++------- .../smeem/api/fixture/goal/GoalFixture.java | 6 ++-- 12 files changed, 114 insertions(+), 80 deletions(-) delete mode 100644 smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalResponseDTO.java delete mode 100644 smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalsResponseDTO.java create mode 100644 smeem-api/src/main/java/com/smeem/api/goal/dto/request/GoalGetServiceRequest.java create mode 100644 smeem-api/src/main/java/com/smeem/api/goal/dto/response/GoalGetServiceResponse.java create mode 100644 smeem-api/src/main/java/com/smeem/api/goal/dto/response/GoalListGetServiceResponse.java diff --git a/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java b/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java index 508f43b4..b4291a69 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java @@ -74,7 +74,7 @@ public Badge getBadgeByComboCountOfDiary(int diaryComboCount) { }; } - private Badge get(Long id) { + public Badge get(Long id) { return badgeRepository.findById(id) .orElseThrow(() -> new BadgeException(INVALID_BADGE)); } diff --git a/smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java b/smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java index 4e850afc..bf43f112 100644 --- a/smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java @@ -1,12 +1,11 @@ package com.smeem.api.goal.controller; - import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; -import com.smeem.api.goal.controller.dto.response.GoalResponseDTO; -import com.smeem.api.goal.controller.dto.response.GoalsResponseDTO; +import com.smeem.api.goal.dto.request.GoalGetServiceRequest; import com.smeem.api.goal.service.GoalService; import com.smeem.domain.goal.model.GoalType; +import lombok.val; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -26,14 +25,15 @@ public class GoalController { private final GoalService goalService; @GetMapping - public ResponseEntity> getAll() { - GoalsResponseDTO response = goalService.getAll(); + public ResponseEntity> getAllGoals() { + val response = goalService.getAllGoals(); return ApiResponseUtil.success(SUCCESS_GET_GOALS, response); } @GetMapping("/{type}") - public ResponseEntity> getByType(@PathVariable GoalType type) { - GoalResponseDTO response = goalService.getByType(type); + public ResponseEntity> getGoalByType(@PathVariable GoalType type) { + val serviceRequest = GoalGetServiceRequest.of(type); + val response = goalService.getByType(serviceRequest); return ApiResponseUtil.success(SUCCESS_GET_GOAL, response); } } diff --git a/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalResponseDTO.java deleted file mode 100644 index d47dc18e..00000000 --- a/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalResponseDTO.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.smeem.api.goal.controller.dto.response; - - -import com.smeem.domain.goal.model.Goal; - -public record GoalResponseDTO( - String name, - String way, - String detail -) { - - public static GoalResponseDTO of(Goal goal) { - return new GoalResponseDTO( - goal.getType().name(), - goal.getWay(), - goal.getDetail() - ); - } -} diff --git a/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalsResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalsResponseDTO.java deleted file mode 100644 index c975f15f..00000000 --- a/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalsResponseDTO.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.smeem.api.goal.controller.dto.response; - -import com.smeem.domain.goal.model.GoalType; - -import java.util.List; - - - -public record GoalsResponseDTO( - List goals -) { - public static GoalsResponseDTO of(List goalTypes) { - return new GoalsResponseDTO(goalTypes.stream().map(GoalResponseVO::of).toList()); - } - - public record GoalResponseVO( - String goalType, - String name - ) { - public static GoalResponseVO of(GoalType goalType) { - return new GoalResponseVO(goalType.name(), goalType.getDescription()); - } - } -} diff --git a/smeem-api/src/main/java/com/smeem/api/goal/dto/request/GoalGetServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/goal/dto/request/GoalGetServiceRequest.java new file mode 100644 index 00000000..5ff97973 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/goal/dto/request/GoalGetServiceRequest.java @@ -0,0 +1,18 @@ +package com.smeem.api.goal.dto.request; + +import com.smeem.domain.goal.model.GoalType; +import lombok.Builder; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record GoalGetServiceRequest( + GoalType goalType +) { + + public static GoalGetServiceRequest of(GoalType goalType) { + return GoalGetServiceRequest.builder() + .goalType(goalType) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/goal/dto/response/GoalGetServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/goal/dto/response/GoalGetServiceResponse.java new file mode 100644 index 00000000..abf0ad49 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/goal/dto/response/GoalGetServiceResponse.java @@ -0,0 +1,22 @@ +package com.smeem.api.goal.dto.response; + +import com.smeem.domain.goal.model.Goal; +import lombok.Builder; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record GoalGetServiceResponse( + String name, + String way, + String detail +) { + + public static GoalGetServiceResponse of(Goal goal) { + return GoalGetServiceResponse.builder() + .name(goal.getType().name()) + .way(goal.getWay()) + .detail(goal.getDetail()) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/goal/dto/response/GoalListGetServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/goal/dto/response/GoalListGetServiceResponse.java new file mode 100644 index 00000000..0bfdd59b --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/goal/dto/response/GoalListGetServiceResponse.java @@ -0,0 +1,34 @@ +package com.smeem.api.goal.dto.response; + +import com.smeem.domain.goal.model.GoalType; +import lombok.Builder; + +import java.util.List; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record GoalListGetServiceResponse( + List goals +) { + + public static GoalListGetServiceResponse of(List goalTypes) { + return GoalListGetServiceResponse.builder() + .goals(goalTypes.stream().map(GoalResponse::of).toList()) + .build(); + } + + @Builder(access = PRIVATE) + public record GoalResponse( + String goalType, + String name + ) { + + public static GoalResponse of(GoalType goalType) { + return GoalResponse.builder() + .goalType(goalType.name()) + .name(goalType.getDescription()) + .build(); + } + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/goal/service/GoalService.java b/smeem-api/src/main/java/com/smeem/api/goal/service/GoalService.java index 071b3ba7..fa5419ad 100644 --- a/smeem-api/src/main/java/com/smeem/api/goal/service/GoalService.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/service/GoalService.java @@ -1,14 +1,15 @@ package com.smeem.api.goal.service; - import java.util.List; -import com.smeem.api.goal.controller.dto.response.GoalResponseDTO; -import com.smeem.api.goal.controller.dto.response.GoalsResponseDTO; +import com.smeem.api.goal.dto.request.GoalGetServiceRequest; +import com.smeem.api.goal.dto.response.GoalGetServiceResponse; +import com.smeem.api.goal.dto.response.GoalListGetServiceResponse; import com.smeem.common.exception.GoalException; import com.smeem.domain.goal.model.Goal; import com.smeem.domain.goal.model.GoalType; import com.smeem.domain.goal.repository.GoalRepository; +import lombok.val; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -23,14 +24,18 @@ public class GoalService { private final GoalRepository goalRepository; - public GoalsResponseDTO getAll() { - List goalTypes = List.of(GoalType.values()); - return GoalsResponseDTO.of(goalTypes); + public GoalListGetServiceResponse getAllGoals() { + val goalTypes = List.of(GoalType.values()); + return GoalListGetServiceResponse.of(goalTypes); + } + + public GoalGetServiceResponse getByType(GoalGetServiceRequest request) { + val goal = findGoal(request.goalType()); + return GoalGetServiceResponse.of(goal); } - public GoalResponseDTO getByType(GoalType goalType) { - Goal goal = goalRepository.findOneByType(goalType) + private Goal findGoal(GoalType type) { + return goalRepository.findOneByType(type) .orElseThrow(() -> new GoalException(EMPTY_GOAL)); - return new GoalResponseDTO(goal.getType().getDescription(), goal.getWay(), goal.getDetail()); } } diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponseDTO.java index 839e8e09..dbb2e67d 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponseDTO.java @@ -2,7 +2,7 @@ import com.smeem.api.badge.controller.dto.response.BadgeResponseDTO; -import com.smeem.api.goal.controller.dto.response.GoalResponseDTO; +import com.smeem.api.goal.dto.response.GoalGetServiceResponse; import com.smeem.domain.member.model.Member; public record MemberGetResponseDTO( @@ -16,7 +16,7 @@ public record MemberGetResponseDTO( BadgeResponseDTO badge ) { - public static MemberGetResponseDTO of(GoalResponseDTO goal, Member member, TrainingTimeResponseDTO trainingTime, BadgeResponseDTO badge) { + public static MemberGetResponseDTO of(GoalGetServiceResponse goal, Member member, TrainingTimeResponseDTO trainingTime, BadgeResponseDTO badge) { return new MemberGetResponseDTO( member.getUsername(), member.getGoal().getDescription(), diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java b/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java index cf033bd5..85a15ad0 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java @@ -3,7 +3,8 @@ import com.smeem.api.badge.controller.dto.response.BadgeResponseDTO; import com.smeem.api.badge.service.BadgeService; -import com.smeem.api.goal.controller.dto.response.GoalResponseDTO; +import com.smeem.api.goal.dto.request.GoalGetServiceRequest; +import com.smeem.api.goal.dto.response.GoalGetServiceResponse; import com.smeem.api.goal.service.GoalService; import com.smeem.api.member.controller.dto.request.MemberPlanUpdateRequestDTO; import com.smeem.api.member.controller.dto.request.MemberPushUpdateRequestDTO; @@ -71,7 +72,7 @@ public MemberUpdateResponseDTO updateMember(Long memberId, MemberUpdateRequestDT public MemberGetResponseDTO getProfile(Long memberId) { Member member = get(memberId); - GoalResponseDTO goal = goalService.getByType(member.getGoal()); + GoalGetServiceResponse goal = goalService.getByType(GoalGetServiceRequest.of(member.getGoal())); List trainingTimes = trainingTimeService.getAllByMember(member); // 기본 시간 설정 diff --git a/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java index da3519fd..990cedcd 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java @@ -3,14 +3,11 @@ import com.epages.restdocs.apispec.ResourceSnippetParameters; import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.goal.controller.GoalController; -import com.smeem.api.goal.controller.dto.response.GoalResponseDTO; -import com.smeem.api.goal.controller.dto.response.GoalsResponseDTO; -import com.smeem.api.goal.controller.dto.response.GoalsResponseDTO.GoalResponseVO; +import com.smeem.api.goal.dto.response.GoalListGetServiceResponse.GoalResponse; +import com.smeem.api.goal.dto.response.GoalGetServiceResponse; +import com.smeem.api.goal.dto.response.GoalListGetServiceResponse; import com.smeem.domain.goal.model.GoalType; import lombok.val; -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 java.security.Principal; @@ -47,11 +44,11 @@ class GoalControllerTest extends BaseControllerTest { // @DisplayName("전체 학습 목표 조회 테스트") void success_get_goals_test() throws Exception { // given - val response = new GoalsResponseDTO(goals()); + val response = new GoalListGetServiceResponse(goals()); val result = ApiResponseUtil.success(SUCCESS_GET_GOALS, response); // when - when(goalController.getAll()).thenReturn(result); + when(goalController.getAllGoals()).thenReturn(result); // then mockMvc.perform(get(DEFAULT_URL) @@ -83,14 +80,14 @@ void success_get_goals_test() throws Exception { void success_get_goal_test() throws Exception { // given GoalType type = APPLY; - val response = new GoalResponseDTO( + val response = new GoalGetServiceResponse( "현지 언어 체득", "주 5회 이상 오늘 하루를 돌아보는 일기 작성하기", "사전 없이 일기 완성\nsmeem 연속 일기 배지 획득"); val result = ApiResponseUtil.success(SUCCESS_GET_GOAL, response); // when - when(goalController.getByType(type)).thenReturn(result); + when(goalController.getGoalByType(type)).thenReturn(result); // then mockMvc.perform(get(DEFAULT_URL + "/{type}", type) @@ -120,10 +117,10 @@ void success_get_goal_test() throws Exception { .andExpect(status().isOk()); } - private List goals() { - List goals = new ArrayList<>(); + private List goals() { + List goals = new ArrayList<>(); for (int i = 0; i < 2; i++) { - goals.add(new GoalResponseVO(APPLY.name(), "현지 언어 체득" + (i + 1))); + goals.add(new GoalResponse(APPLY.name(), "현지 언어 체득" + (i + 1))); } return goals; } diff --git a/smeem-api/src/test/java/com/smeem/api/fixture/goal/GoalFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/goal/GoalFixture.java index 1cabb621..a9fb708d 100644 --- a/smeem-api/src/test/java/com/smeem/api/fixture/goal/GoalFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/goal/GoalFixture.java @@ -1,6 +1,6 @@ package com.smeem.api.fixture.goal; -import com.smeem.api.goal.controller.dto.response.GoalResponseDTO; +import com.smeem.api.goal.dto.response.GoalGetServiceResponse; import com.smeem.domain.goal.model.Goal; import com.smeem.domain.goal.model.GoalType; @@ -20,7 +20,7 @@ public static Goal createGoal() { .build(); } - public static GoalResponseDTO createGoalResponseDTO() { - return GoalResponseDTO.of(createGoal()); + public static GoalGetServiceResponse createGoalResponseDTO() { + return GoalGetServiceResponse.of(createGoal()); } } From cd3c1a2e93eb12d259f656c9bf96ba8b66867892 Mon Sep 17 00:00:00 2001 From: thguss Date: Mon, 12 Feb 2024 22:38:23 +0900 Subject: [PATCH 40/86] =?UTF-8?q?[REFACTOR]=20domain=20=EB=AA=A8=EB=93=88?= =?UTF-8?q?=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/{model => common}/BaseTimeEntity.java | 2 +- .../java/com/smeem/domain/diary/model/Diary.java | 12 ++---------- .../domain/diary/repository/DiaryRepository.java | 6 ------ .../main/java/com/smeem/domain/goal/model/Goal.java | 2 -- .../smeem/domain/goal/repository/GoalRepository.java | 1 - .../java/com/smeem/domain/member/model/Member.java | 2 +- .../com/smeem/domain/member/model/MemberBadge.java | 2 +- .../java/com/smeem/domain/topic/model/Topic.java | 2 -- .../topic/repository/TopicCustomRepository.java | 1 - .../domain/topic/repository/TopicRepository.java | 1 - 10 files changed, 5 insertions(+), 26 deletions(-) rename smeem-domain/src/main/java/com/smeem/domain/{model => common}/BaseTimeEntity.java (94%) diff --git a/smeem-domain/src/main/java/com/smeem/domain/model/BaseTimeEntity.java b/smeem-domain/src/main/java/com/smeem/domain/common/BaseTimeEntity.java similarity index 94% rename from smeem-domain/src/main/java/com/smeem/domain/model/BaseTimeEntity.java rename to smeem-domain/src/main/java/com/smeem/domain/common/BaseTimeEntity.java index e5c0b44a..eb63cc1b 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/model/BaseTimeEntity.java +++ b/smeem-domain/src/main/java/com/smeem/domain/common/BaseTimeEntity.java @@ -1,4 +1,4 @@ -package com.smeem.domain.model; +package com.smeem.domain.common; import jakarta.persistence.EntityListeners; import jakarta.persistence.MappedSuperclass; diff --git a/smeem-domain/src/main/java/com/smeem/domain/diary/model/Diary.java b/smeem-domain/src/main/java/com/smeem/domain/diary/model/Diary.java index 3ac47975..10a8d7b2 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/diary/model/Diary.java +++ b/smeem-domain/src/main/java/com/smeem/domain/diary/model/Diary.java @@ -1,23 +1,15 @@ package com.smeem.domain.diary.model; - import static java.util.Objects.nonNull; -import com.smeem.common.util.Util; import com.smeem.domain.member.model.LangType; import com.smeem.domain.member.model.Member; -import com.smeem.domain.model.BaseTimeEntity; +import com.smeem.domain.common.BaseTimeEntity; import com.smeem.domain.topic.model.Topic; import jakarta.persistence.*; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.val; +import lombok.*; import java.time.LocalDate; -import java.time.LocalDateTime; - - @Entity @NoArgsConstructor diff --git a/smeem-domain/src/main/java/com/smeem/domain/diary/repository/DiaryRepository.java b/smeem-domain/src/main/java/com/smeem/domain/diary/repository/DiaryRepository.java index 6d50ac5e..deff74d1 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/diary/repository/DiaryRepository.java +++ b/smeem-domain/src/main/java/com/smeem/domain/diary/repository/DiaryRepository.java @@ -1,15 +1,9 @@ package com.smeem.domain.diary.repository; - import com.smeem.domain.diary.model.Diary; import com.smeem.domain.member.model.Member; import org.springframework.data.jpa.repository.JpaRepository; -import java.util.List; - public interface DiaryRepository extends JpaRepository { - void deleteAllByMember(Member member); - - List findAllByMemberId(Long memberId); } diff --git a/smeem-domain/src/main/java/com/smeem/domain/goal/model/Goal.java b/smeem-domain/src/main/java/com/smeem/domain/goal/model/Goal.java index 5b184ffc..7807017b 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/goal/model/Goal.java +++ b/smeem-domain/src/main/java/com/smeem/domain/goal/model/Goal.java @@ -1,7 +1,5 @@ package com.smeem.domain.goal.model; -import static jakarta.persistence.GenerationType.*; - import jakarta.persistence.*; import lombok.Builder; import lombok.Getter; diff --git a/smeem-domain/src/main/java/com/smeem/domain/goal/repository/GoalRepository.java b/smeem-domain/src/main/java/com/smeem/domain/goal/repository/GoalRepository.java index 64c921e2..01d59de0 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/goal/repository/GoalRepository.java +++ b/smeem-domain/src/main/java/com/smeem/domain/goal/repository/GoalRepository.java @@ -1,6 +1,5 @@ package com.smeem.domain.goal.repository; - import com.smeem.domain.goal.model.Goal; import com.smeem.domain.goal.model.GoalType; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/smeem-domain/src/main/java/com/smeem/domain/member/model/Member.java b/smeem-domain/src/main/java/com/smeem/domain/member/model/Member.java index 01dbb007..710fc164 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/member/model/Member.java +++ b/smeem-domain/src/main/java/com/smeem/domain/member/model/Member.java @@ -3,7 +3,7 @@ import com.smeem.domain.badge.model.Badge; import com.smeem.domain.diary.model.Diary; import com.smeem.domain.goal.model.GoalType; -import com.smeem.domain.model.BaseTimeEntity; +import com.smeem.domain.common.BaseTimeEntity; import com.smeem.domain.training.model.TrainingTime; import jakarta.persistence.*; import lombok.Builder; diff --git a/smeem-domain/src/main/java/com/smeem/domain/member/model/MemberBadge.java b/smeem-domain/src/main/java/com/smeem/domain/member/model/MemberBadge.java index 608af956..d0c8b048 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/member/model/MemberBadge.java +++ b/smeem-domain/src/main/java/com/smeem/domain/member/model/MemberBadge.java @@ -4,7 +4,7 @@ import com.smeem.domain.badge.model.Badge; -import com.smeem.domain.model.BaseTimeEntity; +import com.smeem.domain.common.BaseTimeEntity; import jakarta.persistence.*; import lombok.Builder; import lombok.Getter; diff --git a/smeem-domain/src/main/java/com/smeem/domain/topic/model/Topic.java b/smeem-domain/src/main/java/com/smeem/domain/topic/model/Topic.java index 62760415..36a30ae0 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/topic/model/Topic.java +++ b/smeem-domain/src/main/java/com/smeem/domain/topic/model/Topic.java @@ -1,7 +1,5 @@ package com.smeem.domain.topic.model; -import static jakarta.persistence.GenerationType.*; - import jakarta.persistence.*; import lombok.Builder; import lombok.Getter; diff --git a/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicCustomRepository.java b/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicCustomRepository.java index a751a53a..1a522b4b 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicCustomRepository.java +++ b/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicCustomRepository.java @@ -1,6 +1,5 @@ package com.smeem.domain.topic.repository; - import com.smeem.domain.topic.model.Topic; public interface TopicCustomRepository { diff --git a/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicRepository.java b/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicRepository.java index b162992f..d8e095f3 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicRepository.java +++ b/smeem-domain/src/main/java/com/smeem/domain/topic/repository/TopicRepository.java @@ -1,6 +1,5 @@ package com.smeem.domain.topic.repository; - import com.smeem.domain.topic.model.Topic; import org.springframework.data.jpa.repository.JpaRepository; From 160006567e1e38722deef9e5a48ede5fd43343ca Mon Sep 17 00:00:00 2001 From: thguss Date: Mon, 12 Feb 2024 22:38:33 +0900 Subject: [PATCH 41/86] =?UTF-8?q?[REFACTOR]=20build=20=EC=8B=A4=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 6 +++++- smeem-batch/build.gradle | 4 ++++ smeem-external/build.gradle | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 9b607044..83108aff 100644 --- a/build.gradle +++ b/build.gradle @@ -45,4 +45,8 @@ allprojects { tasks.named('test') { useJUnitPlatform() } -} \ No newline at end of file +} + +jar { enabled = true } + +bootJar { enabled = false } \ No newline at end of file diff --git a/smeem-batch/build.gradle b/smeem-batch/build.gradle index c0d69595..2a555ed1 100644 --- a/smeem-batch/build.gradle +++ b/smeem-batch/build.gradle @@ -1,3 +1,7 @@ +jar { enabled = true } + +bootJar { enabled = false } + dependencies { implementation project(":smeem-common") implementation project(":smeem-domain") diff --git a/smeem-external/build.gradle b/smeem-external/build.gradle index 94a1383d..be749a0a 100644 --- a/smeem-external/build.gradle +++ b/smeem-external/build.gradle @@ -1,3 +1,7 @@ +jar { enabled = true } + +bootJar { enabled = false } + dependencies { implementation project(':smeem-common') From 1cfec627c297347c335637b1fb13295eb7133fbb Mon Sep 17 00:00:00 2001 From: thguss Date: Mon, 12 Feb 2024 22:47:42 +0900 Subject: [PATCH 42/86] =?UTF-8?q?[REFACTOR]=20=EC=8A=A4=EC=BC=80=EC=A4=84?= =?UTF-8?q?=EB=A7=81=20=EB=B0=8F=20FCM=20API=20=ED=98=B8=EC=B6=9C=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smeem/batch/scheduler/DiaryScheduler.java | 7 ++- .../batch/scheduler/MessageScheduler.java | 2 - .../com/smeem/common/config/ValueConfig.java | 2 +- .../smeem/external/firebase/FcmService.java | 14 +++--- .../smeem/external/firebase/MessageDTO.java | 21 --------- .../external/firebase/MessageRequest.java | 46 +++++++++++++++++++ 6 files changed, 57 insertions(+), 35 deletions(-) delete mode 100644 smeem-external/src/main/java/com/smeem/external/firebase/MessageDTO.java create mode 100644 smeem-external/src/main/java/com/smeem/external/firebase/MessageRequest.java diff --git a/smeem-batch/src/main/java/com/smeem/batch/scheduler/DiaryScheduler.java b/smeem-batch/src/main/java/com/smeem/batch/scheduler/DiaryScheduler.java index a2b6c5bc..5854ec23 100644 --- a/smeem-batch/src/main/java/com/smeem/batch/scheduler/DiaryScheduler.java +++ b/smeem-batch/src/main/java/com/smeem/batch/scheduler/DiaryScheduler.java @@ -3,6 +3,7 @@ import com.smeem.common.config.ValueConfig; import com.smeem.domain.diary.repository.DeletedDiaryRepository; import lombok.RequiredArgsConstructor; +import lombok.val; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -11,8 +12,6 @@ import java.time.LocalDate; import java.time.LocalDateTime; -import static java.lang.Integer.parseInt; - @Component @EnableScheduling @RequiredArgsConstructor @@ -24,12 +23,12 @@ public class DiaryScheduler { @Scheduled(cron = "0 0 0 * * *") @Transactional public void deleteExpiredDiaries() { - LocalDateTime expiryDate = getExpiryDate(); + val expiryDate = getExpiryDate(); deletedDiaryRepository.deleteByUpdatedAtBefore(expiryDate); } private LocalDateTime getExpiryDate() { - int expiredDay = parseInt(valueConfig.getDURATION_EXPIRED()) - 1; + val expiredDay = valueConfig.getDURATION_EXPIRED() - 1; return LocalDate.now().minusDays(expiredDay).atStartOfDay(); } } diff --git a/smeem-batch/src/main/java/com/smeem/batch/scheduler/MessageScheduler.java b/smeem-batch/src/main/java/com/smeem/batch/scheduler/MessageScheduler.java index 97be9bb9..29676d0f 100644 --- a/smeem-batch/src/main/java/com/smeem/batch/scheduler/MessageScheduler.java +++ b/smeem-batch/src/main/java/com/smeem/batch/scheduler/MessageScheduler.java @@ -1,6 +1,5 @@ package com.smeem.batch.scheduler; - import com.smeem.common.config.ValueConfig; import com.smeem.domain.training.model.TrainingTime; import com.smeem.domain.training.repository.TrainingTimeRepository; @@ -27,7 +26,6 @@ public class MessageScheduler { @Transactional(readOnly = true) public void pushMessagesForTrainingTime() throws InterruptedException { Thread.sleep(1000); - val trainingTimes = trainingTimeRepository.getTrainingTimeForPushAlarm(LocalDateTime.now()); trainingTimes.forEach(this::pushMessageForTrainingTime); } diff --git a/smeem-common/src/main/java/com/smeem/common/config/ValueConfig.java b/smeem-common/src/main/java/com/smeem/common/config/ValueConfig.java index cf35da98..682a9a28 100644 --- a/smeem-common/src/main/java/com/smeem/common/config/ValueConfig.java +++ b/smeem-common/src/main/java/com/smeem/common/config/ValueConfig.java @@ -40,7 +40,7 @@ public class ValueConfig { private String GOOGLE_API_URI; @Value("${smeem.duration.expired}") - private String DURATION_EXPIRED; + private int DURATION_EXPIRED; @Value("${smeem.duration.remind}") private int DURATION_REMIND; diff --git a/smeem-external/src/main/java/com/smeem/external/firebase/FcmService.java b/smeem-external/src/main/java/com/smeem/external/firebase/FcmService.java index b70bc583..7482460e 100644 --- a/smeem-external/src/main/java/com/smeem/external/firebase/FcmService.java +++ b/smeem-external/src/main/java/com/smeem/external/firebase/FcmService.java @@ -1,6 +1,5 @@ package com.smeem.external.firebase; - import java.io.IOException; import java.util.List; @@ -9,6 +8,7 @@ import com.smeem.common.config.ValueConfig; import com.smeem.common.exception.FcmException; +import lombok.val; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; @@ -33,17 +33,17 @@ public class FcmService { public void pushMessage(String targetToken, String title, String body) { try { - String message = makeMessage(targetToken, title, body); - RequestBody requestBody = RequestBody.create(message, MediaType.get("application/json; charset=utf-8")); + val message = makeMessage(targetToken, title, body); + val requestBody = RequestBody.create(message, MediaType.get("application/json; charset=utf-8")); - Request request = new Request.Builder() + val request = new Request.Builder() .url(valueConfig.getFIREBASE_API_URI()) .post(requestBody) .addHeader(AUTHORIZATION, "Bearer " + getAccessToken()) .addHeader("Accept", "application/json; UTF-8") .build(); - OkHttpClient client = new OkHttpClient(); + val client = new OkHttpClient(); client.newCall(request).execute(); } catch (Exception exception) { throw new FcmException(INVALID_REQUEST_MESSAGE); @@ -52,7 +52,7 @@ public void pushMessage(String targetToken, String title, String body) { private String makeMessage(String targetToken, String title, String body) { try { - MessageDTO message = MessageDTO.of(targetToken, title, body); + val message = MessageRequest.of(targetToken, title, body); return objectMapper.writeValueAsString(message); } catch (JsonProcessingException exception) { throw new FcmException(INVALID_REQUEST_PATTERN); @@ -60,7 +60,7 @@ private String makeMessage(String targetToken, String title, String body) { } private String getAccessToken() throws IOException { - GoogleCredentials googleCredentials = GoogleCredentials + val googleCredentials = GoogleCredentials .fromStream(new ClassPathResource(valueConfig.getFIREBASE_CONFIG_PATH()).getInputStream()) .createScoped(List.of(valueConfig.getGOOGLE_API_URI())); googleCredentials.refreshIfExpired(); diff --git a/smeem-external/src/main/java/com/smeem/external/firebase/MessageDTO.java b/smeem-external/src/main/java/com/smeem/external/firebase/MessageDTO.java deleted file mode 100644 index a666be27..00000000 --- a/smeem-external/src/main/java/com/smeem/external/firebase/MessageDTO.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.smeem.external.firebase; - -import lombok.Builder; - -@Builder -public record MessageDTO( - boolean validateOnly, - MessageVO message -) { - public static MessageDTO of(String targetToken, String title, String body) { - NotificationVO notification = new NotificationVO(title, body); - MessageVO message = new MessageVO(notification, targetToken); - return new MessageDTO(false, message); - } - - record MessageVO(NotificationVO notification, String token) { - } - - record NotificationVO(String title, String body) { - } -} diff --git a/smeem-external/src/main/java/com/smeem/external/firebase/MessageRequest.java b/smeem-external/src/main/java/com/smeem/external/firebase/MessageRequest.java new file mode 100644 index 00000000..6423da06 --- /dev/null +++ b/smeem-external/src/main/java/com/smeem/external/firebase/MessageRequest.java @@ -0,0 +1,46 @@ +package com.smeem.external.firebase; + +import lombok.Builder; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record MessageRequest( + boolean validateOnly, + MessageRequest message +) { + public static com.smeem.external.firebase.MessageRequest of(String targetToken, String title, String body) { + return com.smeem.external.firebase.MessageRequest.builder() + .validateOnly(false) + .message(com.smeem.external.firebase.MessageRequest.MessageRequest.of(title, body, targetToken)) + .build(); + } + + @Builder(access = PRIVATE) + record MessageRequest( + NotificationRequest notification, + String token + ) { + + private static MessageRequest of(String title, String body, String token) { + return com.smeem.external.firebase.MessageRequest.MessageRequest.builder() + .notification(NotificationRequest.of(title, body)) + .token(token) + .build(); + } + } + + @Builder(access = PRIVATE) + record NotificationRequest( + String title, + String body + ) { + + private static NotificationRequest of(String title, String body) { + return NotificationRequest.builder() + .title(title) + .body(body) + .build(); + } + } +} From acfd9c0092a0dce1e35674e659ccc2d6483cf52a Mon Sep 17 00:00:00 2001 From: unanchoi Date: Tue, 13 Feb 2024 23:03:10 +0900 Subject: [PATCH 43/86] =?UTF-8?q?Member,=20Badge,=20Auth=20domain=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- settings.gradle | 8 + smeem-api/build.gradle | 8 + .../api/auth/controller/AuthController.java | 17 +- ...gnInRequestDTO.java => SignInRequest.java} | 2 +- .../dto/response/SignInResponse.java | 25 +++ .../dto/response/SignInResponseDTO.java | 20 --- .../dto/response/token/TokenResponse.java | 19 +++ .../dto/response/token/TokenResponseDTO.java | 14 -- .../dto/response/token/TokenVO.java | 8 - .../api/auth/jwt/JwtAuthenticationFilter.java | 10 +- .../smeem/api/auth/jwt/JwtTokenProvider.java | 78 --------- .../smeem/api/auth/jwt/JwtValidationType.java | 2 +- .../smeem/api/auth/jwt/SecretKeyFactory.java | 21 +++ .../com/smeem/api/auth/jwt/SmeemToken.java | 24 +++ .../com/smeem/api/auth/jwt/TokenProvider.java | 42 +++++ .../smeem/api/auth/jwt/TokenValidator.java | 42 +++++ .../api/auth/jwt/UserAuthentication.java | 10 ++ .../smeem/api/auth/service/AuthService.java | 94 +++-------- .../smeem/api/auth/service/TokenService.java | 39 +++++ .../dto/request/SignInServiceRequest.java | 22 +++ .../dto/response/SignInServiceResponse.java | 24 +++ .../dto/response/TokenServiceResponse.java | 21 +++ .../api/badge/controller/BadgeController.java | 6 +- .../dto/response/AcquiredBadgeResponse.java | 21 +++ ...esponseDTO.java => BadgeListResponse.java} | 20 +-- .../dto/response/BadgeResponse.java | 24 +++ .../dto/response/BadgeResponseDTO.java | 17 -- .../smeem/api/badge/service/BadgeService.java | 27 ++-- .../AcquiredBadgeServiceResponse.java} | 12 +- .../response/BadgeListServiceResponse.java | 10 ++ .../dto/response/BadgeServiceResponse.java | 24 +++ .../api/common/advicer/ErrorHandler.java | 5 + .../dto/response/CreatedDiaryResponseDTO.java | 6 +- .../api/goal/controller/GoalController.java | 8 +- ...ResponseDTO.java => GoalListResponse.java} | 6 +- ...GoalResponseDTO.java => GoalResponse.java} | 6 +- .../smeem/api/goal/service/GoalService.java | 12 +- .../member/controller/MemberController.java | 30 ++-- ...tDTO.java => MemberPlanUpdateRequest.java} | 4 +- ...tDTO.java => MemberPushUpdateRequest.java} | 2 +- ...questDTO.java => MemberUpdateRequest.java} | 2 +- ...questDTO.java => TrainingTimeRequest.java} | 2 +- .../dto/response/MemberGetResponse.java | 34 ++++ .../dto/response/MemberGetResponseDTO.java | 31 ---- .../dto/response/MemberNameResponse.java | 13 ++ .../dto/response/MemberNameResponseDTO.java | 6 - .../dto/response/MemberUpdateResponse.java | 25 +++ .../dto/response/MemberUpdateResponseDTO.java | 15 -- .../dto/response/TrainingTimeResponse.java | 12 ++ .../dto/response/TrainingTimeResponseDTO.java | 7 - .../member/service/MemberBadgeService.java | 16 +- .../api/member/service/MemberService.java | 148 ++++++++++-------- .../MemberPushUpdateServiceRequest.java | 6 + ...MemberServiceUpdateUserProfileRequest.java | 20 +++ .../MemberUpdatePlanServiceRequest.java | 22 +++ .../request/TrainingTimeServiceRequest.java | 22 +++ .../response/MemberGetServiceResponse.java | 41 +++++ .../response/MemberNameServiceResponse.java | 18 +++ .../response/MemberUpdateServiceResponse.java | 21 +++ .../response/TrainingTimeServiceResponse.java | 17 ++ .../api/controller/BaseControllerTest.java | 9 +- .../api/controller/DiaryControllerTest.java | 11 +- .../api/controller/GoalControllerTest.java | 13 +- .../smeem/api/fixture/auth/AuthFixture.java | 30 ++-- .../smeem/api/fixture/badge/BadgeFixture.java | 20 +-- .../smeem/api/fixture/goal/GoalFixture.java | 6 +- .../api/fixture/member/MemberFixture.java | 25 ++- .../trainingtime/TrainingTimeFixture.java | 12 +- .../smeem/common/exception/AuthException.java | 15 ++ .../com/smeem/domain/badge/model/Badge.java | 8 +- .../smeem/domain/badge/model/BadgeImage.java | 14 ++ .../smeem/domain/member/model/LangType.java | 6 +- .../com/smeem/domain/member/model/Member.java | 12 +- .../domain/member/model/MemberBadge.java | 3 +- .../{ => oauth}/apple/AppleSignInService.java | 3 +- .../{ => oauth}/kakao/KakaoSignInService.java | 2 +- 76 files changed, 962 insertions(+), 495 deletions(-) rename smeem-api/src/main/java/com/smeem/api/auth/controller/dto/request/{SignInRequestDTO.java => SignInRequest.java} (88%) create mode 100644 smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponse.java delete mode 100644 smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponseDTO.java create mode 100644 smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenResponse.java delete mode 100644 smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenResponseDTO.java delete mode 100644 smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenVO.java delete mode 100644 smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtTokenProvider.java create mode 100644 smeem-api/src/main/java/com/smeem/api/auth/jwt/SecretKeyFactory.java create mode 100644 smeem-api/src/main/java/com/smeem/api/auth/jwt/SmeemToken.java create mode 100644 smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenProvider.java create mode 100644 smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenValidator.java create mode 100644 smeem-api/src/main/java/com/smeem/api/auth/service/TokenService.java create mode 100644 smeem-api/src/main/java/com/smeem/api/auth/service/dto/request/SignInServiceRequest.java create mode 100644 smeem-api/src/main/java/com/smeem/api/auth/service/dto/response/SignInServiceResponse.java create mode 100644 smeem-api/src/main/java/com/smeem/api/auth/service/dto/response/TokenServiceResponse.java create mode 100644 smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/AcquiredBadgeResponse.java rename smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/{BadgeListResponseDTO.java => BadgeListResponse.java} (69%) create mode 100644 smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponse.java delete mode 100644 smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponseDTO.java rename smeem-api/src/main/java/com/smeem/api/badge/{controller/dto/response/AcquiredBadgeResponseDTO.java => service/dto/response/AcquiredBadgeServiceResponse.java} (56%) create mode 100644 smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeListServiceResponse.java create mode 100644 smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeServiceResponse.java rename smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/{GoalsResponseDTO.java => GoalListResponse.java} (74%) rename smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/{GoalResponseDTO.java => GoalResponse.java} (70%) rename smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/{MemberPlanUpdateRequestDTO.java => MemberPlanUpdateRequest.java} (64%) rename smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/{MemberPushUpdateRequestDTO.java => MemberPushUpdateRequest.java} (66%) rename smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/{MemberUpdateRequestDTO.java => MemberUpdateRequest.java} (83%) rename smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/{TrainingTimeRequestDTO.java => TrainingTimeRequest.java} (85%) create mode 100644 smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponse.java delete mode 100644 smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponseDTO.java create mode 100644 smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponse.java delete mode 100644 smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponseDTO.java create mode 100644 smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberUpdateResponse.java delete mode 100644 smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberUpdateResponseDTO.java create mode 100644 smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponse.java delete mode 100644 smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponseDTO.java create mode 100644 smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberPushUpdateServiceRequest.java create mode 100644 smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberServiceUpdateUserProfileRequest.java create mode 100644 smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberUpdatePlanServiceRequest.java create mode 100644 smeem-api/src/main/java/com/smeem/api/member/service/dto/request/TrainingTimeServiceRequest.java create mode 100644 smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberGetServiceResponse.java create mode 100644 smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberNameServiceResponse.java create mode 100644 smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberUpdateServiceResponse.java create mode 100644 smeem-api/src/main/java/com/smeem/api/member/service/dto/response/TrainingTimeServiceResponse.java create mode 100644 smeem-common/src/main/java/com/smeem/common/exception/AuthException.java create mode 100644 smeem-domain/src/main/java/com/smeem/domain/badge/model/BadgeImage.java rename smeem-external/src/main/java/com/smeem/external/{ => oauth}/apple/AppleSignInService.java (97%) rename smeem-external/src/main/java/com/smeem/external/{ => oauth}/kakao/KakaoSignInService.java (96%) diff --git a/settings.gradle b/settings.gradle index cf44cc1d..54d0e302 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,11 @@ +pluginManagement { + plugins { + id 'org.jetbrains.kotlin.jvm' version '1.9.21' + } +} +plugins { + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0' +} rootProject.name = 'server' include 'smeem-api' include 'smeem-domain' diff --git a/smeem-api/build.gradle b/smeem-api/build.gradle index 4400c8c3..fbb9a5d7 100644 --- a/smeem-api/build.gradle +++ b/smeem-api/build.gradle @@ -5,6 +5,7 @@ plugins { id 'com.epages.restdocs-api-spec' version "0.18.2" // swagger generator id 'org.hidetake.swagger.generator' version '2.18.2' + id 'org.jetbrains.kotlin.jvm' } dependencies { @@ -26,6 +27,7 @@ dependencies { testImplementation "com.epages:restdocs-api-spec-mockmvc:0.18.2" testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" // implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0' } @@ -62,3 +64,9 @@ bootJar { // enabled = true dependsOn('openapi3') } +repositories { + mavenCentral() +} +kotlin { + jvmToolchain(17) +} diff --git a/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java b/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java index 3c197fba..ec5ed8e3 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java @@ -1,9 +1,11 @@ package com.smeem.api.auth.controller; -import com.smeem.api.auth.controller.dto.request.SignInRequestDTO; -import com.smeem.api.auth.controller.dto.response.SignInResponseDTO; -import com.smeem.api.auth.controller.dto.response.token.TokenResponseDTO; +import com.smeem.api.auth.controller.dto.request.SignInRequest; +import com.smeem.api.auth.controller.dto.response.SignInResponse; +import com.smeem.api.auth.controller.dto.response.token.TokenResponse; import com.smeem.api.auth.service.AuthService; +import com.smeem.api.auth.service.TokenService; +import com.smeem.api.auth.service.dto.request.SignInServiceRequest; import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; import com.smeem.common.util.Util; @@ -24,17 +26,18 @@ public class AuthController { private final AuthService authService; + private final TokenService tokenService; @PostMapping - public ResponseEntity> signIn(@RequestHeader("Authorization") String socialAccessToken, @RequestBody SignInRequestDTO request - ) throws NoSuchAlgorithmException, InvalidKeySpecException { - SignInResponseDTO response = authService.signIn(socialAccessToken, request); + public ResponseEntity> signIn(@RequestHeader("Authorization") String socialAccessToken, + @RequestBody SignInRequest request) throws NoSuchAlgorithmException, InvalidKeySpecException { + SignInResponse response = SignInResponse.of(authService.signIn(socialAccessToken, SignInServiceRequest.of(request))); return ApiResponseUtil.success(SUCCESS_SIGNIN, response); } @PostMapping("/token") public ResponseEntity> reissueToken(Principal principal) { - TokenResponseDTO response = authService.issueToken(Util.getMemberId(principal)); + TokenResponse response = TokenResponse.of(tokenService.issueToken(Util.getMemberId(principal))); return ApiResponseUtil.success(SUCCESS_ISSUE_TOKEN, response); } diff --git a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/request/SignInRequestDTO.java b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/request/SignInRequest.java similarity index 88% rename from smeem-api/src/main/java/com/smeem/api/auth/controller/dto/request/SignInRequestDTO.java rename to smeem-api/src/main/java/com/smeem/api/auth/controller/dto/request/SignInRequest.java index c9970fe2..d05bd87c 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/request/SignInRequestDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/request/SignInRequest.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.smeem.domain.member.model.SocialType; -public record SignInRequestDTO( +public record SignInRequest( @JsonProperty("social") SocialType socialType, String fcmToken diff --git a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponse.java b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponse.java new file mode 100644 index 00000000..ae1ee3a0 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponse.java @@ -0,0 +1,25 @@ +package com.smeem.api.auth.controller.dto.response; + + +import com.smeem.api.auth.jwt.SmeemToken; +import com.smeem.api.auth.service.dto.response.SignInServiceResponse; +import lombok.Builder; + + +@Builder +public record SignInResponse( + String accessToken, + String refreshToken, + boolean isRegistered, + boolean hasPlan +) { + + public static SignInResponse of(SignInServiceResponse response) { + return new SignInResponse( + response.accessToken(), + response.refreshToken(), + response.isRegistered(), + response.hasPlan()); + } + +} diff --git a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponseDTO.java deleted file mode 100644 index 0ff30b98..00000000 --- a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponseDTO.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.smeem.api.auth.controller.dto.response; - - -import com.smeem.api.auth.controller.dto.response.token.TokenVO; -import lombok.Builder; - - -@Builder -public record SignInResponseDTO( - String accessToken, - String refreshToken, - boolean isRegistered, - boolean hasPlan -) { - - public static SignInResponseDTO of(TokenVO tokenVO, boolean isRegistered, boolean hasPlan) { - return new SignInResponseDTO(tokenVO.accessToken(), tokenVO.refreshToken(), isRegistered, hasPlan); - } - -} diff --git a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenResponse.java b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenResponse.java new file mode 100644 index 00000000..fda6586f --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenResponse.java @@ -0,0 +1,19 @@ +package com.smeem.api.auth.controller.dto.response.token; + +import com.smeem.api.auth.service.dto.response.TokenServiceResponse; +import lombok.AccessLevel; +import lombok.Builder; + +@Builder(access = AccessLevel.PRIVATE) +public record TokenResponse( + String accessToken, + String refreshToken +) { + + public static TokenResponse of(TokenServiceResponse response) { + return TokenResponse.builder() + .accessToken(response.accessToken()) + .refreshToken(response.refreshToken()) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenResponseDTO.java deleted file mode 100644 index 76f14668..00000000 --- a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenResponseDTO.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.smeem.api.auth.controller.dto.response.token; - -import lombok.Builder; - -@Builder -public record TokenResponseDTO( - String accessToken, - String refreshToken -) { - - public static TokenResponseDTO of(String accessToken, String refreshToken) { - return new TokenResponseDTO(accessToken, refreshToken); - } -} diff --git a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenVO.java b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenVO.java deleted file mode 100644 index 0278ffde..00000000 --- a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenVO.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.smeem.api.auth.controller.dto.response.token; - - -public record TokenVO(String accessToken, String refreshToken) { - public static TokenVO of(String accessToken, String refreshToken) { - return new TokenVO(accessToken, refreshToken); - } -} diff --git a/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtAuthenticationFilter.java b/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtAuthenticationFilter.java index 64c31e5e..adce0c08 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtAuthenticationFilter.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtAuthenticationFilter.java @@ -1,5 +1,6 @@ package com.smeem.api.auth.jwt; +import com.smeem.common.exception.AuthException; import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; @@ -24,23 +25,22 @@ @RequiredArgsConstructor public class JwtAuthenticationFilter extends OncePerRequestFilter { - private final JwtTokenProvider jwtTokenProvider; + private final TokenValidator tokenValidator; @Override protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull FilterChain filterChain) throws IOException, ServletException { try { final String token = getJwtFromRequest(request); - if (StringUtils.hasText(token) && jwtTokenProvider.validateToken(token) == VALID_JWT) { - Long userId = jwtTokenProvider.getUserFromJwt(token); + if (StringUtils.hasText(token) && tokenValidator.validateToken(token) == VALID_JWT) { + Long userId = tokenValidator.getUserFromJwt(token); UserAuthentication authentication = new UserAuthentication(userId, null, null); authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); SecurityContextHolder.getContext().setAuthentication(authentication); } - } catch (Exception exception) { + } catch (AuthException exception) { log.error("error : ", exception); } - filterChain.doFilter(request, response); } diff --git a/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtTokenProvider.java b/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtTokenProvider.java deleted file mode 100644 index 98be515b..00000000 --- a/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtTokenProvider.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.smeem.api.auth.jwt; - - -import com.smeem.common.config.ValueConfig; -import io.jsonwebtoken.*; -import io.jsonwebtoken.security.Keys; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import lombok.val; -import org.springframework.security.core.Authentication; -import org.springframework.stereotype.Component; - -import javax.crypto.SecretKey; -import java.util.Date; - -import static com.smeem.api.auth.jwt.JwtValidationType.*; -import static java.util.Base64.getEncoder; - -@Slf4j -@Component -@RequiredArgsConstructor -public class JwtTokenProvider { - - private final ValueConfig valueConfig; - - public String generateToken(Authentication authentication, Long tokenExpirationTime) { - val now = new Date(); - - val claims = Jwts.claims() - .setIssuedAt(now) - .setExpiration(new Date(now.getTime() + tokenExpirationTime)); - - claims.put("memberId", authentication.getPrincipal()); - - return Jwts.builder() - .setHeaderParam(Header.TYPE, Header.JWT_TYPE) - .setClaims(claims) - .signWith(getSigningKey()) - .compact(); - } - - public JwtValidationType validateToken(String token) { - try { - getBody(token); - return VALID_JWT; - } catch (MalformedJwtException ex) { - log.error(String.valueOf(INVALID_JWT_TOKEN)); - return INVALID_JWT_TOKEN; - } catch (ExpiredJwtException ex) { - log.error(String.valueOf(EXPIRED_JWT_TOKEN)); - return EXPIRED_JWT_TOKEN; - } catch (UnsupportedJwtException ex) { - log.error(String.valueOf(UNSUPPORTED_JWT_TOKEN)); - return UNSUPPORTED_JWT_TOKEN; - } catch (IllegalArgumentException ex) { - log.error(String.valueOf(EMPTY_JWT)); - return EMPTY_JWT; - } - } - - public Long getUserFromJwt(String token) { - Claims claims = getBody(token); - return Long.parseLong(claims.get("memberId").toString()); - } - - private SecretKey getSigningKey() { - String encodedKey = getEncoder().encodeToString(valueConfig.getJWT_SECRET().getBytes()); - return Keys.hmacShaKeyFor(encodedKey.getBytes()); - } - - private Claims getBody(final String token) { - return Jwts.parserBuilder() - .setSigningKey(getSigningKey()) - .build() - .parseClaimsJws(token) - .getBody(); - } -} diff --git a/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtValidationType.java b/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtValidationType.java index 7960630b..4d462de4 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtValidationType.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtValidationType.java @@ -2,8 +2,8 @@ public enum JwtValidationType { VALID_JWT, - INVALID_JWT_SIGNATURE, INVALID_JWT_TOKEN, + INVALID_JWT_SIGNATURE, EXPIRED_JWT_TOKEN, UNSUPPORTED_JWT_TOKEN, EMPTY_JWT diff --git a/smeem-api/src/main/java/com/smeem/api/auth/jwt/SecretKeyFactory.java b/smeem-api/src/main/java/com/smeem/api/auth/jwt/SecretKeyFactory.java new file mode 100644 index 00000000..55f7cfed --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/auth/jwt/SecretKeyFactory.java @@ -0,0 +1,21 @@ +package com.smeem.api.auth.jwt; + +import com.smeem.common.config.ValueConfig; +import io.jsonwebtoken.security.Keys; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import javax.crypto.SecretKey; + +import static java.util.Base64.getEncoder; + +@Component +@RequiredArgsConstructor +public class SecretKeyFactory { + private final ValueConfig valueConfig; + SecretKey create() { + String encodedKey = getEncoder().encodeToString(valueConfig.getJWT_SECRET().getBytes()); + return Keys.hmacShaKeyFor(encodedKey.getBytes()); + } + +} diff --git a/smeem-api/src/main/java/com/smeem/api/auth/jwt/SmeemToken.java b/smeem-api/src/main/java/com/smeem/api/auth/jwt/SmeemToken.java new file mode 100644 index 00000000..b48f3b35 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/auth/jwt/SmeemToken.java @@ -0,0 +1,24 @@ +package com.smeem.api.auth.jwt; + +import lombok.Builder; +import lombok.Getter; + +@Getter +public class SmeemToken { + + private final String accessToken; + private final String refreshToken; + + @Builder + private SmeemToken(String accessToken, String refreshToken) { + this.accessToken = accessToken; + this.refreshToken = refreshToken; + } + + public static SmeemToken of(String accessToken, String refreshToken) { + return SmeemToken.builder() + .accessToken(accessToken) + .refreshToken(refreshToken) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenProvider.java b/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenProvider.java new file mode 100644 index 00000000..0bc11b43 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenProvider.java @@ -0,0 +1,42 @@ +package com.smeem.api.auth.jwt; + + +import com.smeem.common.config.ValueConfig; +import com.smeem.common.exception.AuthException; +import io.jsonwebtoken.*; +import io.jsonwebtoken.security.Keys; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import lombok.val; +import org.springframework.security.core.Authentication; +import org.springframework.stereotype.Component; + +import javax.crypto.SecretKey; +import java.util.Date; + +import static com.smeem.api.auth.jwt.JwtValidationType.*; +import static java.util.Base64.getEncoder; + +@Slf4j +@Component +@RequiredArgsConstructor +public class TokenProvider { + + private final SecretKeyFactory secretKeyFactory; + + public String generateToken(Authentication authentication, Long tokenExpirationTime) { + val now = new Date(); + + val claims = Jwts.claims() + .setIssuedAt(now) + .setExpiration(new Date(now.getTime() + tokenExpirationTime)); + + claims.put("memberId", authentication.getPrincipal()); + + return Jwts.builder() + .setHeaderParam(Header.TYPE, Header.JWT_TYPE) + .setClaims(claims) + .signWith(secretKeyFactory.create()) + .compact(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenValidator.java b/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenValidator.java new file mode 100644 index 00000000..a4cd9d07 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenValidator.java @@ -0,0 +1,42 @@ +package com.smeem.api.auth.jwt; + +import com.smeem.common.exception.AuthException; +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Jwts; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import static com.smeem.api.auth.jwt.JwtValidationType.INVALID_JWT_TOKEN; +import static com.smeem.api.auth.jwt.JwtValidationType.VALID_JWT; + +@Component +@RequiredArgsConstructor +@Slf4j +public class TokenValidator { + private final SecretKeyFactory secretKeyFactory; + + public JwtValidationType validateToken(String token) { + try { + getBody(token); + return VALID_JWT; + } catch (AuthException ex) { + log.error(String.valueOf(INVALID_JWT_TOKEN)); + return INVALID_JWT_TOKEN; + } + } + + public Long getUserFromJwt(String token) { + Claims claims = getBody(token); + return Long.parseLong(claims.get("memberId").toString()); + } + + private Claims getBody(final String token) { + return Jwts.parserBuilder() + .setSigningKey(secretKeyFactory.create()) + .build() + .parseClaimsJws(token) + .getBody(); + } + +} diff --git a/smeem-api/src/main/java/com/smeem/api/auth/jwt/UserAuthentication.java b/smeem-api/src/main/java/com/smeem/api/auth/jwt/UserAuthentication.java index e1029740..1ab34548 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/jwt/UserAuthentication.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/jwt/UserAuthentication.java @@ -1,6 +1,7 @@ package com.smeem.api.auth.jwt; +import lombok.Builder; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.GrantedAuthority; @@ -8,7 +9,16 @@ public class UserAuthentication extends UsernamePasswordAuthenticationToken { + @Builder public UserAuthentication(Object principal, Object credentials, Collection authorities) { super(principal, credentials, authorities); } + + public static UserAuthentication create(Object principal) { + return UserAuthentication.builder() + .principal(principal) + .credentials(null) + .authorities(null) + .build(); + } } diff --git a/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java b/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java index 92748687..9db1b41e 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java @@ -1,26 +1,21 @@ package com.smeem.api.auth.service; -import com.smeem.api.auth.controller.dto.request.SignInRequestDTO; -import com.smeem.api.auth.controller.dto.response.SignInResponseDTO; -import com.smeem.api.auth.controller.dto.response.token.TokenResponseDTO; -import com.smeem.api.auth.controller.dto.response.token.TokenVO; -import com.smeem.api.auth.jwt.JwtTokenProvider; - - +import com.smeem.api.auth.controller.dto.response.SignInResponse; import com.smeem.api.auth.jwt.UserAuthentication; +import com.smeem.api.auth.service.dto.request.SignInServiceRequest; +import com.smeem.api.auth.service.dto.response.SignInServiceResponse; import com.smeem.api.diary.service.DiaryService; import com.smeem.api.member.service.MemberBadgeService; import com.smeem.api.member.service.TrainingTimeService; import com.smeem.common.exception.MemberException; import com.smeem.common.exception.TokenException; -import com.smeem.domain.member.model.LangType; import com.smeem.domain.member.model.Member; import com.smeem.domain.member.model.SocialType; import com.smeem.domain.member.repository.MemberRepository; -import com.smeem.external.apple.AppleSignInService; -import com.smeem.external.kakao.KakaoSignInService; +import com.smeem.external.oauth.apple.AppleSignInService; +import com.smeem.external.oauth.kakao.KakaoSignInService; import lombok.RequiredArgsConstructor; -import org.springframework.security.core.Authentication; +import lombok.val; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -36,15 +31,9 @@ @Transactional(readOnly = true) public class AuthService { - private static final Long ACCESS_TOKEN_EXPIRATION_TIME = 60 * 60 * 1000 * 2 * 12 * 1000000L; // 2시간 - - private static final Long REFRESH_TOKEN_EXPIRATION_TIME = 60 * 60 * 1000 * 24 * 14L; // 2주 - - - private final JwtTokenProvider jwtTokenProvider; - private final MemberRepository memberRepository; + private final TokenService tokenService; private final AppleSignInService appleSignInService; private final KakaoSignInService kakaoSignInService; private final MemberBadgeService memberBadgeService; @@ -52,55 +41,30 @@ public class AuthService { private final TrainingTimeService trainingTimeService; @Transactional - public SignInResponseDTO signIn(String socialAccessToken, SignInRequestDTO request) throws NoSuchAlgorithmException, InvalidKeySpecException { - - SocialType socialType = request.socialType(); - String socialId = login(socialType, socialAccessToken); - - boolean hasMember = isMemberBySocialAndSocialId(socialType, socialId); - - if (!hasMember) { - Member member = Member.builder() - .social(socialType) - .socialId(socialId) - .targetLang(LangType.en) - .fcmToken(request.fcmToken()) - .build(); - memberRepository.save(member); + public SignInServiceResponse signIn(final String socialAccessToken, final SignInServiceRequest request) throws NoSuchAlgorithmException, InvalidKeySpecException { + val socialType = request.socialType(); + val socialId = socialLogin(socialType, socialAccessToken); + val existMember = isMemberBySocialAndSocialId(socialType, socialId); + if (!existMember) { + val initialMember = Member.createInitialMember(socialType, socialId, request.fcmToken()); + memberRepository.save(initialMember); } - - Member signedMember = getMemberBySocialAndSocialId(socialType, socialId); - boolean isRegistered = nonNull(signedMember.getUsername()); - boolean hasPlan = nonNull(signedMember.getGoal()); - - TokenVO tokenVO = generateToken(new UserAuthentication(signedMember.getId(), null, null)); - signedMember.updateRefreshToken(tokenVO.refreshToken()); - - return SignInResponseDTO.of(tokenVO, isRegistered, hasPlan); + val signedMember = getMemberBySocialAndSocialId(socialType, socialId); + val isRegistered = nonNull(signedMember.getUsername()); + val hasTrainingPlan = nonNull(signedMember.getGoal()); + val smeemToken = tokenService.generateSmeemToken(UserAuthentication.create(signedMember.getId())); + signedMember.updateRefreshToken(smeemToken.getRefreshToken()); + return SignInServiceResponse.of(smeemToken, isRegistered, hasTrainingPlan); } @Transactional - public TokenResponseDTO issueToken(Long memberId) { - - TokenVO tokenVO = generateToken(new UserAuthentication(memberId, null, null)); - - Member member = get(memberId); - member.updateRefreshToken(tokenVO.refreshToken()); - - return TokenResponseDTO.builder() - .accessToken(tokenVO.accessToken()) - .refreshToken(tokenVO.refreshToken()) - .build(); - } - - @Transactional - public void signOut(Long memberId) { + public void signOut(final long memberId) { Member member = get(memberId); member.updateRefreshToken(null); } @Transactional - public void withdraw(Long memberId) { + public void withdraw(final long memberId) { Member member = get(memberId); diaryService.deleteAllByMember(member); trainingTimeService.deleteAllByMember(member); @@ -108,14 +72,7 @@ public void withdraw(Long memberId) { memberRepository.deleteById(memberId); } - private TokenVO generateToken(Authentication authentication) { - return TokenVO.of( - jwtTokenProvider.generateToken(authentication, ACCESS_TOKEN_EXPIRATION_TIME), - jwtTokenProvider.generateToken(authentication, REFRESH_TOKEN_EXPIRATION_TIME)); - } - - - private Member get(Long memberId) { + private Member get(final long memberId) { return memberRepository.findById(memberId) .orElseThrow(() -> new MemberException(INVALID_MEMBER)); } @@ -129,13 +86,10 @@ private boolean isMemberBySocialAndSocialId(SocialType socialType, String social return memberRepository.existsBySocialAndSocialId(socialType, socialId); } - // TODO : Custom Exception 처리 - private String login(SocialType socialType, String socialAccessToken) throws NoSuchAlgorithmException, InvalidKeySpecException { + private String socialLogin(SocialType socialType, String socialAccessToken) throws NoSuchAlgorithmException, InvalidKeySpecException { return switch (socialType.toString()) { case "APPLE" -> appleSignInService.getAppleData(socialAccessToken); case "KAKAO" -> kakaoSignInService.getKakaoData(socialAccessToken); - - // TODO : Change to Custom Exception default -> throw new TokenException(INVALID_TOKEN); }; } diff --git a/smeem-api/src/main/java/com/smeem/api/auth/service/TokenService.java b/smeem-api/src/main/java/com/smeem/api/auth/service/TokenService.java new file mode 100644 index 00000000..b3d36cf6 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/auth/service/TokenService.java @@ -0,0 +1,39 @@ +package com.smeem.api.auth.service; + + +import com.smeem.api.auth.jwt.TokenProvider; +import com.smeem.api.auth.jwt.UserAuthentication; +import com.smeem.api.auth.jwt.SmeemToken; +import com.smeem.api.auth.service.dto.response.TokenServiceResponse; +import com.smeem.api.member.service.MemberService; +import lombok.RequiredArgsConstructor; +import lombok.val; +import org.springframework.security.core.Authentication; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class TokenService { + + private static final Long ACCESS_TOKEN_EXPIRATION_TIME = 60 * 60 * 1000 * 2 * 12 * 1000000L; // 2시간 + private static final Long REFRESH_TOKEN_EXPIRATION_TIME = 60 * 60 * 1000 * 24 * 14L; // 2주 + + private final MemberService memberService; + private final TokenProvider tokenProvider; + + @Transactional + public TokenServiceResponse issueToken(final long memberId) { + val token = generateSmeemToken(UserAuthentication.create(memberId)); + val member = memberService.get(memberId); + member.updateRefreshToken(token.getRefreshToken()); + return TokenServiceResponse.of(token); + } + + public SmeemToken generateSmeemToken(Authentication authentication) { + return SmeemToken.of( + tokenProvider.generateToken(authentication, ACCESS_TOKEN_EXPIRATION_TIME), + tokenProvider.generateToken(authentication, REFRESH_TOKEN_EXPIRATION_TIME)); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/auth/service/dto/request/SignInServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/auth/service/dto/request/SignInServiceRequest.java new file mode 100644 index 00000000..7e39be58 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/auth/service/dto/request/SignInServiceRequest.java @@ -0,0 +1,22 @@ +package com.smeem.api.auth.service.dto.request; + +import com.smeem.api.auth.controller.dto.request.SignInRequest; +import com.smeem.domain.member.model.SocialType; +import lombok.Builder; + +import static lombok.AccessLevel.*; + + +@Builder(access = PRIVATE) +public record SignInServiceRequest( + SocialType socialType, + String fcmToken +) { + public static SignInServiceRequest of(SignInRequest request) { + return SignInServiceRequest + .builder() + .socialType(request.socialType()) + .fcmToken(request.fcmToken()) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/auth/service/dto/response/SignInServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/auth/service/dto/response/SignInServiceResponse.java new file mode 100644 index 00000000..75862794 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/auth/service/dto/response/SignInServiceResponse.java @@ -0,0 +1,24 @@ +package com.smeem.api.auth.service.dto.response; + + +import com.smeem.api.auth.jwt.SmeemToken; +import lombok.Builder; + +import static lombok.AccessLevel.*; + +@Builder(access = PRIVATE) +public record SignInServiceResponse( + String accessToken, + String refreshToken, + boolean isRegistered, + boolean hasPlan +) { + public static SignInServiceResponse of(SmeemToken token, boolean isRegistered, boolean hasPlan) { + return SignInServiceResponse.builder() + .accessToken(token.getAccessToken()) + .refreshToken(token.getRefreshToken()) + .hasPlan(hasPlan) + .isRegistered(isRegistered) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/auth/service/dto/response/TokenServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/auth/service/dto/response/TokenServiceResponse.java new file mode 100644 index 00000000..fc94a920 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/auth/service/dto/response/TokenServiceResponse.java @@ -0,0 +1,21 @@ +package com.smeem.api.auth.service.dto.response; + +import com.smeem.api.auth.jwt.SmeemToken; +import lombok.Builder; + +import static lombok.AccessLevel.*; + + +@Builder(access = PRIVATE) +public record TokenServiceResponse( + String accessToken, + String refreshToken +) { + + public static TokenServiceResponse of(SmeemToken token) { + return new TokenServiceResponse( + token.getAccessToken(), + token.getRefreshToken() + ); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java index 301e992a..84ec42fb 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java @@ -1,6 +1,6 @@ package com.smeem.api.badge.controller; -import com.smeem.api.badge.controller.dto.response.BadgeListResponseDTO; +import com.smeem.api.badge.controller.dto.response.BadgeListResponse; import com.smeem.api.badge.service.BadgeService; import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; @@ -23,8 +23,8 @@ public class BadgeController { private final BadgeService badgeService; @GetMapping - public ResponseEntity> getBadgeList(Principal principal) { - BadgeListResponseDTO response = badgeService.getBadgeList(Util.getMemberId(principal)); + public ResponseEntity> getBadges(Principal principal) { + BadgeListResponse response = badgeService.getBadges(Util.getMemberId(principal)); return ApiResponseUtil.success(SUCCESS_GET_BADGES, response); } diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/AcquiredBadgeResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/AcquiredBadgeResponse.java new file mode 100644 index 00000000..8a95dedf --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/AcquiredBadgeResponse.java @@ -0,0 +1,21 @@ +package com.smeem.api.badge.controller.dto.response; + +import com.smeem.api.badge.service.dto.response.AcquiredBadgeServiceResponse; +import com.smeem.domain.badge.model.BadgeType; +import lombok.AccessLevel; +import lombok.Builder; + +@Builder(access = AccessLevel.PRIVATE) +public record AcquiredBadgeResponse( + String name, + String imageUrl, + BadgeType type +) { + public static AcquiredBadgeResponse of(AcquiredBadgeServiceResponse response) { + return AcquiredBadgeResponse.builder() + .name(response.name()) + .imageUrl(response.imageUrl()) + .type(response.type()) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponse.java similarity index 69% rename from smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponseDTO.java rename to smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponse.java index f735aeca..0b1e40f3 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponse.java @@ -8,28 +8,28 @@ import java.util.List; import java.util.Map; -public record BadgeListResponseDTO( - List badgeTypes +public record BadgeListResponse( + List badgeTypes ) { - public static BadgeListResponseDTO of(Map> badgeMap, List memberBadges) { + public static BadgeListResponse of(Map> badgeMap, List memberBadges) { val badgeTypes = getBadgesType(badgeMap, memberBadges); - return new BadgeListResponseDTO(badgeTypes); + return new BadgeListResponse(badgeTypes); } - private static List getBadgesType(Map> badgeMap, List memberBadges) { + private static List getBadgesType(Map> badgeMap, List memberBadges) { return badgeMap.keySet().stream() - .map(type -> BadgeTypeResponseDTO.of(type, badgeMap.get(type), memberBadges)) + .map(type -> BadgeTypeResponse.of(type, badgeMap.get(type), memberBadges)) .toList(); } @Builder - public record BadgeTypeResponseDTO( + public record BadgeTypeResponse( BadgeType badgeType, String badgeTypeName, List badges ) { - public static BadgeTypeResponseDTO of(BadgeType type, List badges, List memberBadges) { - return BadgeTypeResponseDTO.builder() + public static BadgeTypeResponse of(BadgeType type, List badges, List memberBadges) { + return BadgeTypeResponse.builder() .badgeType(type) .badgeTypeName(type.getDescription()) .badges(getBadges(badges, memberBadges)) @@ -59,7 +59,7 @@ private static BadgeResponseDTO of(Badge badge, List memberBadges) } private static String getImageUrl(Badge badge, List memberBadges) { - return hasBadge(badge, memberBadges) ? badge.getImageUrl() : badge.getGrayImageUrl(); + return hasBadge(badge, memberBadges) ? badge.getBadgeImage().getImageUrl() : badge.getBadgeImage().getGrayImageUrl(); } private static boolean hasBadge(Badge badge, List memberBadges) { diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponse.java new file mode 100644 index 00000000..4093850d --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponse.java @@ -0,0 +1,24 @@ +package com.smeem.api.badge.controller.dto.response; + +import com.smeem.api.badge.service.dto.response.BadgeServiceResponse; +import com.smeem.domain.badge.model.Badge; +import lombok.AccessLevel; +import lombok.Builder; + +@Builder(access = AccessLevel.PRIVATE) +public record BadgeResponse( + Long id, + String name, + String type, + String imageUrl +) { + + public static BadgeResponse of(BadgeServiceResponse response) { + return new BadgeResponse( + response.id(), + response.name(), + response.type(), + response.imageUrl() + ); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponseDTO.java deleted file mode 100644 index 6b7f7c4d..00000000 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponseDTO.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.smeem.api.badge.controller.dto.response; - -import com.smeem.domain.badge.model.Badge; -import lombok.Builder; - -@Builder -public record BadgeResponseDTO( - Long id, - String name, - String type, - String imageUrl -) { - - public static BadgeResponseDTO of(Badge badge) { - return new BadgeResponseDTO(badge.getId(), badge.getName(), badge.getType().toString(), badge.getImageUrl()); - } -} diff --git a/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java b/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java index eb8d499e..b451226b 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java @@ -1,6 +1,6 @@ package com.smeem.api.badge.service; -import com.smeem.api.badge.controller.dto.response.BadgeListResponseDTO; +import com.smeem.api.badge.controller.dto.response.BadgeListResponse; import com.smeem.common.exception.BadgeException; import com.smeem.domain.badge.model.Badge; import com.smeem.domain.badge.model.BadgeType; @@ -28,11 +28,23 @@ public class BadgeService { private final MemberBadgeRepository memberBadgeRepository; private final BadgeRepository badgeRepository; - public BadgeListResponseDTO getBadgeList(Long memberId) { + @Transactional + public void saveMemberBadge(Member member, Badge badge) { + memberBadgeRepository.save(MemberBadge.builder() + .member(member) + .badge(badge) + .build()); + } + public BadgeListResponse getBadges(final long memberId) { val badges = badgeRepository.findAllOrderById(); val badgeMap = classifiedByType(badges); val memberBadges = memberBadgeRepository.findAllByMemberId(memberId); - return BadgeListResponseDTO.of(badgeMap, memberBadges); + return BadgeListResponse.of(badgeMap, memberBadges); + } + + public Badge get(Long id) { + return badgeRepository.findById(id) + .orElseThrow(() -> new BadgeException(INVALID_BADGE)); } private Map> classifiedByType(List badges) { @@ -45,13 +57,4 @@ private void putBadgeMap(Map> badgeMap, Badge badge) { badgeMap.computeIfAbsent(badge.getType(), k -> new ArrayList<>()).add(badge); } - @Transactional - public void saveMemberBadge(Member member, Badge badge) { - memberBadgeRepository.save(new MemberBadge(member, badge)); - } - - public Badge get(Long id) { - return badgeRepository.findById(id) - .orElseThrow(() -> new BadgeException(INVALID_BADGE)); - } } diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/AcquiredBadgeResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/AcquiredBadgeServiceResponse.java similarity index 56% rename from smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/AcquiredBadgeResponseDTO.java rename to smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/AcquiredBadgeServiceResponse.java index fbb04bab..f50a4c93 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/AcquiredBadgeResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/AcquiredBadgeServiceResponse.java @@ -1,20 +1,22 @@ -package com.smeem.api.badge.controller.dto.response; +package com.smeem.api.badge.service.dto.response; import com.smeem.domain.badge.model.Badge; import com.smeem.domain.badge.model.BadgeType; import lombok.AccessLevel; import lombok.Builder; + @Builder(access = AccessLevel.PRIVATE) -public record AcquiredBadgeResponseDTO( +public record AcquiredBadgeServiceResponse( String name, String imageUrl, BadgeType type ) { - public static AcquiredBadgeResponseDTO of(Badge badge) { - return AcquiredBadgeResponseDTO.builder() + + public static AcquiredBadgeServiceResponse of(Badge badge) { + return AcquiredBadgeServiceResponse.builder() .name(badge.getName()) - .imageUrl(badge.getImageUrl()) + .imageUrl(badge.getBadgeImage().getImageUrl()) .type(badge.getType()) .build(); } diff --git a/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeListServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeListServiceResponse.java new file mode 100644 index 00000000..60adcfc1 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeListServiceResponse.java @@ -0,0 +1,10 @@ +package com.smeem.api.badge.service.dto.response; + + +import lombok.Builder; + +import static lombok.AccessLevel.*; + +@Builder(access = PRIVATE) +public class BadgeListServiceResponse { +} diff --git a/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeServiceResponse.java new file mode 100644 index 00000000..93c324ac --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeServiceResponse.java @@ -0,0 +1,24 @@ +package com.smeem.api.badge.service.dto.response; + +import com.smeem.domain.badge.model.Badge; +import lombok.Builder; + +import static lombok.AccessLevel.*; + +@Builder(access = PRIVATE) +public record BadgeServiceResponse( + Long id, + String name, + String type, + String imageUrl +) { + + public static BadgeServiceResponse of(Badge badge) { + return BadgeServiceResponse.builder() + .id(badge.getId()) + .name(badge.getName()) + .type(badge.getType().name()) + .imageUrl(badge.getBadgeImage().getImageUrl()) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java b/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java index f4bbbe1f..a8b59a02 100644 --- a/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java +++ b/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java @@ -54,4 +54,9 @@ public ResponseEntity> appleException(AppleException exception) public ResponseEntity> fcmException(FcmException exception) { return ApiResponseUtil.failure(exception.getFailureCode()); } + + @ExceptionHandler(AuthException.class) + public ResponseEntity> authException(AuthException exception) { + return ApiResponseUtil.failure(exception.getFailureCode()); + } } diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/CreatedDiaryResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/CreatedDiaryResponseDTO.java index 320247e6..3a064e51 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/CreatedDiaryResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/CreatedDiaryResponseDTO.java @@ -1,15 +1,15 @@ package com.smeem.api.diary.controller.dto.response; -import com.smeem.api.badge.controller.dto.response.AcquiredBadgeResponseDTO; +import com.smeem.api.badge.controller.dto.response.AcquiredBadgeResponse; import com.smeem.domain.badge.model.Badge; import java.util.List; public record CreatedDiaryResponseDTO( Long diaryId, - List badges + List badges ) { public static CreatedDiaryResponseDTO of(Long diaryId, List badges) { - return new CreatedDiaryResponseDTO(diaryId, badges.stream().map(AcquiredBadgeResponseDTO::of).toList()); + return new CreatedDiaryResponseDTO(diaryId, badges.stream().map(AcquiredBadgeResponse::of).toList()); } } diff --git a/smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java b/smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java index 4e850afc..7a2848e8 100644 --- a/smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java @@ -3,8 +3,8 @@ import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; -import com.smeem.api.goal.controller.dto.response.GoalResponseDTO; -import com.smeem.api.goal.controller.dto.response.GoalsResponseDTO; +import com.smeem.api.goal.controller.dto.response.GoalResponse; +import com.smeem.api.goal.controller.dto.response.GoalListResponse; import com.smeem.api.goal.service.GoalService; import com.smeem.domain.goal.model.GoalType; import org.springframework.http.ResponseEntity; @@ -27,13 +27,13 @@ public class GoalController { @GetMapping public ResponseEntity> getAll() { - GoalsResponseDTO response = goalService.getAll(); + GoalListResponse response = goalService.getAll(); return ApiResponseUtil.success(SUCCESS_GET_GOALS, response); } @GetMapping("/{type}") public ResponseEntity> getByType(@PathVariable GoalType type) { - GoalResponseDTO response = goalService.getByType(type); + GoalResponse response = goalService.getByType(type); return ApiResponseUtil.success(SUCCESS_GET_GOAL, response); } } diff --git a/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalsResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalListResponse.java similarity index 74% rename from smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalsResponseDTO.java rename to smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalListResponse.java index c975f15f..78ef3542 100644 --- a/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalsResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalListResponse.java @@ -6,11 +6,11 @@ -public record GoalsResponseDTO( +public record GoalListResponse( List goals ) { - public static GoalsResponseDTO of(List goalTypes) { - return new GoalsResponseDTO(goalTypes.stream().map(GoalResponseVO::of).toList()); + public static GoalListResponse of(List goalTypes) { + return new GoalListResponse(goalTypes.stream().map(GoalResponseVO::of).toList()); } public record GoalResponseVO( diff --git a/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalResponse.java similarity index 70% rename from smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalResponseDTO.java rename to smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalResponse.java index d47dc18e..cf8ee291 100644 --- a/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalResponseDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalResponse.java @@ -3,14 +3,14 @@ import com.smeem.domain.goal.model.Goal; -public record GoalResponseDTO( +public record GoalResponse( String name, String way, String detail ) { - public static GoalResponseDTO of(Goal goal) { - return new GoalResponseDTO( + public static GoalResponse of(Goal goal) { + return new GoalResponse( goal.getType().name(), goal.getWay(), goal.getDetail() diff --git a/smeem-api/src/main/java/com/smeem/api/goal/service/GoalService.java b/smeem-api/src/main/java/com/smeem/api/goal/service/GoalService.java index 071b3ba7..3fca430e 100644 --- a/smeem-api/src/main/java/com/smeem/api/goal/service/GoalService.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/service/GoalService.java @@ -3,8 +3,8 @@ import java.util.List; -import com.smeem.api.goal.controller.dto.response.GoalResponseDTO; -import com.smeem.api.goal.controller.dto.response.GoalsResponseDTO; +import com.smeem.api.goal.controller.dto.response.GoalResponse; +import com.smeem.api.goal.controller.dto.response.GoalListResponse; import com.smeem.common.exception.GoalException; import com.smeem.domain.goal.model.Goal; import com.smeem.domain.goal.model.GoalType; @@ -23,14 +23,14 @@ public class GoalService { private final GoalRepository goalRepository; - public GoalsResponseDTO getAll() { + public GoalListResponse getAll() { List goalTypes = List.of(GoalType.values()); - return GoalsResponseDTO.of(goalTypes); + return GoalListResponse.of(goalTypes); } - public GoalResponseDTO getByType(GoalType goalType) { + public GoalResponse getByType(GoalType goalType) { Goal goal = goalRepository.findOneByType(goalType) .orElseThrow(() -> new GoalException(EMPTY_GOAL)); - return new GoalResponseDTO(goal.getType().getDescription(), goal.getWay(), goal.getDetail()); + return new GoalResponse(goal.getType().getDescription(), goal.getWay(), goal.getDetail()); } } diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java b/smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java index 7c4c01d4..a2a394bd 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java @@ -2,17 +2,19 @@ import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; -import com.smeem.api.member.controller.dto.request.MemberPlanUpdateRequestDTO; -import com.smeem.api.member.controller.dto.request.MemberPushUpdateRequestDTO; -import com.smeem.api.member.controller.dto.request.MemberUpdateRequestDTO; -import com.smeem.api.member.controller.dto.response.MemberGetResponseDTO; -import com.smeem.api.member.controller.dto.response.MemberNameResponseDTO; -import com.smeem.api.member.controller.dto.response.MemberUpdateResponseDTO; +import com.smeem.api.member.controller.dto.request.MemberPlanUpdateRequest; +import com.smeem.api.member.controller.dto.request.MemberPushUpdateRequest; +import com.smeem.api.member.controller.dto.request.MemberUpdateRequest; +import com.smeem.api.member.controller.dto.response.MemberGetResponse; +import com.smeem.api.member.controller.dto.response.MemberNameResponse; import com.smeem.api.member.service.MemberService; +import com.smeem.api.member.service.dto.request.MemberUpdatePlanServiceRequest; +import com.smeem.api.member.service.dto.request.MemberServiceUpdateUserProfileRequest; import com.smeem.common.util.Util; import io.swagger.v3.oas.annotations.Parameter; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import lombok.val; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -28,31 +30,33 @@ public class MemberController { private final MemberService memberService; @PatchMapping - public ResponseEntity> updateProfile(Principal principal, @RequestBody MemberUpdateRequestDTO request) { - MemberUpdateResponseDTO response = memberService.updateMember(Util.getMemberId(principal), request); + public ResponseEntity> updateProfile(Principal principal, @RequestBody MemberUpdateRequest request) { + val response = memberService.updateUserProfile( + Util.getMemberId(principal), + MemberServiceUpdateUserProfileRequest.of(request)); return ApiResponseUtil.success(SUCCESS_UPDATE_USERNAME, response); } @GetMapping("/me") public ResponseEntity> getProfile(Principal principal) { - MemberGetResponseDTO response = memberService.getProfile(Util.getMemberId(principal)); + MemberGetResponse response = memberService.getMemberProfile(Util.getMemberId(principal)); return ApiResponseUtil.success(SUCCESS_GET_USER, response); } @PatchMapping("/plan") - public ResponseEntity> updateUserPlan(Principal principal, @Valid @RequestBody MemberPlanUpdateRequestDTO request) { - memberService.updateMemberPlan(Util.getMemberId(principal), request); + public ResponseEntity> updateUserPlan(Principal principal, @Valid @RequestBody MemberPlanUpdateRequest request) { + memberService.updateLearningPlan(Util.getMemberId(principal), MemberUpdatePlanServiceRequest.of(request)); return ApiResponseUtil.success(SUCCESS_UPDATE_USER_PLAN); } @GetMapping("/nickname/check") public ResponseEntity> checkDuplicatedName(@Parameter(description = "유저 닉네임") @RequestParam String name) { - MemberNameResponseDTO response = memberService.checkDuplicatedName(name); + val response = MemberNameResponse.of(memberService.checkDuplicatedName(name)); return ApiResponseUtil.success(SUCCESS_CHECK_DUPLICATED_NAME, response); } @PatchMapping("/push") - public ResponseEntity> updateUserPush(Principal principal, @RequestBody MemberPushUpdateRequestDTO request) { + public ResponseEntity> updateUserPush(Principal principal, @RequestBody MemberPushUpdateRequest request) { memberService.updateHasAlarm(Util.getMemberId(principal), request); return ApiResponseUtil.success(SUCCESS_UPDATE_USER_PUSH); } diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPlanUpdateRequestDTO.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPlanUpdateRequest.java similarity index 64% rename from smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPlanUpdateRequestDTO.java rename to smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPlanUpdateRequest.java index effff809..abbc4ea0 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPlanUpdateRequestDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPlanUpdateRequest.java @@ -3,9 +3,9 @@ import com.smeem.domain.goal.model.GoalType; -public record MemberPlanUpdateRequestDTO( +public record MemberPlanUpdateRequest( GoalType target, - TrainingTimeRequestDTO trainingTime, + TrainingTimeRequest trainingTime, Boolean hasAlarm ) { } diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPushUpdateRequestDTO.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPushUpdateRequest.java similarity index 66% rename from smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPushUpdateRequestDTO.java rename to smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPushUpdateRequest.java index 156d540c..4e7546ca 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPushUpdateRequestDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPushUpdateRequest.java @@ -1,6 +1,6 @@ package com.smeem.api.member.controller.dto.request; -public record MemberPushUpdateRequestDTO( +public record MemberPushUpdateRequest( boolean hasAlarm ) { } diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberUpdateRequestDTO.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberUpdateRequest.java similarity index 83% rename from smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberUpdateRequestDTO.java rename to smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberUpdateRequest.java index ba2abf40..3870c229 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberUpdateRequestDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberUpdateRequest.java @@ -3,7 +3,7 @@ import com.smeem.api.member.controller.dto.ValidUsername; -public record MemberUpdateRequestDTO( +public record MemberUpdateRequest( @ValidUsername String username, Boolean termAccepted diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/TrainingTimeRequestDTO.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/TrainingTimeRequest.java similarity index 85% rename from smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/TrainingTimeRequestDTO.java rename to smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/TrainingTimeRequest.java index 21596a88..a3e1b922 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/TrainingTimeRequestDTO.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/TrainingTimeRequest.java @@ -2,7 +2,7 @@ import jakarta.validation.constraints.NotNull; -public record TrainingTimeRequestDTO( +public record TrainingTimeRequest( @NotNull String day, @NotNull diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponse.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponse.java new file mode 100644 index 00000000..a9789fc0 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponse.java @@ -0,0 +1,34 @@ +package com.smeem.api.member.controller.dto.response; + + +import com.smeem.api.badge.controller.dto.response.BadgeResponse; +import com.smeem.api.member.service.dto.response.MemberGetServiceResponse; +import lombok.AccessLevel; +import lombok.Builder; + + +@Builder(access = AccessLevel.PRIVATE) +public record MemberGetResponse( + String username, + String target, + String way, + String detail, + String targetLang, + boolean hasPushAlarm, + TrainingTimeResponse trainingTime, + BadgeResponse badge +) { + + public static MemberGetResponse of(MemberGetServiceResponse response) { + return MemberGetResponse.builder() + .username(response.username()) + .target(response.target()) + .way(response.way()) + .detail(response.detail()) + .targetLang(response.targetLangType().toString()) + .hasPushAlarm(response.hasPushAlarm()) + .trainingTime(TrainingTimeResponse.of(response.trainingTime())) + .badge(BadgeResponse.of(response.badge())) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponseDTO.java deleted file mode 100644 index 839e8e09..00000000 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponseDTO.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.smeem.api.member.controller.dto.response; - - -import com.smeem.api.badge.controller.dto.response.BadgeResponseDTO; -import com.smeem.api.goal.controller.dto.response.GoalResponseDTO; -import com.smeem.domain.member.model.Member; - -public record MemberGetResponseDTO( - String username, - String target, - String way, - String detail, - String targetLang, - boolean hasPushAlarm, - TrainingTimeResponseDTO trainingTime, - BadgeResponseDTO badge -) { - - public static MemberGetResponseDTO of(GoalResponseDTO goal, Member member, TrainingTimeResponseDTO trainingTime, BadgeResponseDTO badge) { - return new MemberGetResponseDTO( - member.getUsername(), - member.getGoal().getDescription(), - goal.way(), - goal.detail(), - member.getTargetLang().toString(), - member.isHasPushAlarm(), - trainingTime, - badge - ); - } -} diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponse.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponse.java new file mode 100644 index 00000000..4bc959f5 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponse.java @@ -0,0 +1,13 @@ +package com.smeem.api.member.controller.dto.response; + +import com.smeem.api.member.service.dto.response.MemberNameServiceResponse; + +public record MemberNameResponse( + boolean isExist +) { + + public static MemberNameResponse of(MemberNameServiceResponse response) { + return new MemberNameResponse(response.isExist()); + } + +} diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponseDTO.java deleted file mode 100644 index 36dc2b17..00000000 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponseDTO.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.smeem.api.member.controller.dto.response; - -public record MemberNameResponseDTO( - boolean isExist -) { -} diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberUpdateResponse.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberUpdateResponse.java new file mode 100644 index 00000000..611d56db --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberUpdateResponse.java @@ -0,0 +1,25 @@ +package com.smeem.api.member.controller.dto.response; + + +import com.smeem.api.badge.controller.dto.response.AcquiredBadgeResponse; +import com.smeem.api.member.service.dto.response.MemberUpdateServiceResponse; +import lombok.Builder; + +import java.util.List; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record MemberUpdateResponse( + List badges +) { + public static MemberUpdateResponse of( + List response) { + + return MemberUpdateResponse + .builder() + .badges(response) + .build(); + return new MemberUpdateResponse(badges.stream().map(AcquiredBadgeResponse::of).toList()); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberUpdateResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberUpdateResponseDTO.java deleted file mode 100644 index f40262c7..00000000 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberUpdateResponseDTO.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.smeem.api.member.controller.dto.response; - - -import com.smeem.api.badge.controller.dto.response.AcquiredBadgeResponseDTO; -import com.smeem.domain.badge.model.Badge; - -import java.util.List; - -public record MemberUpdateResponseDTO( - List badges -) { - public static MemberUpdateResponseDTO of(List badges) { - return new MemberUpdateResponseDTO(badges.stream().map(AcquiredBadgeResponseDTO::of).toList()); - } -} diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponse.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponse.java new file mode 100644 index 00000000..f95a13f2 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponse.java @@ -0,0 +1,12 @@ +package com.smeem.api.member.controller.dto.response; + +import com.smeem.api.member.service.dto.response.TrainingTimeServiceResponse; + +public record TrainingTimeResponse(String day, int hour, int minute) { + public static TrainingTimeResponse of(TrainingTimeServiceResponse response) { + return new TrainingTimeResponse( + response.day(), + response.hour(), + response.minute()); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponseDTO.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponseDTO.java deleted file mode 100644 index b52a03c5..00000000 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponseDTO.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.smeem.api.member.controller.dto.response; - -public record TrainingTimeResponseDTO(String day, int hour, int minute) { - public static TrainingTimeResponseDTO of(String day, int hour, int minute) { - return new TrainingTimeResponseDTO(day, hour, minute); - } -} diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/MemberBadgeService.java b/smeem-api/src/main/java/com/smeem/api/member/service/MemberBadgeService.java index be04f287..1df8a4bc 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/MemberBadgeService.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/MemberBadgeService.java @@ -8,16 +8,24 @@ import com.smeem.domain.member.repository.MemberBadgeRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import static com.smeem.common.code.failure.BadgeFailureCode.EMPTY_BADGE; @Service @RequiredArgsConstructor +@Transactional(readOnly = true) public class MemberBadgeService { private final MemberBadgeRepository memberBadgeRepository; - protected void save(Member member, Badge badge) { + @Transactional + public void deleteAllByMember(Member member) { + memberBadgeRepository.deleteAllInBatch(member.getBadges()); + } + + @Transactional + public void save(Member member, Badge badge) { MemberBadge memberBadge = MemberBadge.builder() .member(member) .badge(badge) @@ -25,11 +33,7 @@ protected void save(Member member, Badge badge) { memberBadgeRepository.save(memberBadge); } - public void deleteAllByMember(Member member) { - memberBadgeRepository.deleteAll(member.getBadges()); - } - - protected Badge getBadgeByMemberId(Long memberId) { + public Badge getBadgeByMemberId(Long memberId) { return memberBadgeRepository.findFirstByMemberIdOrderByCreatedAtDesc(memberId).orElseThrow( () -> new BadgeException(EMPTY_BADGE)).getBadge(); } diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java b/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java index cf033bd5..238247d2 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java @@ -1,32 +1,32 @@ package com.smeem.api.member.service; -import com.smeem.api.badge.controller.dto.response.BadgeResponseDTO; import com.smeem.api.badge.service.BadgeService; -import com.smeem.api.goal.controller.dto.response.GoalResponseDTO; +import com.smeem.api.badge.service.dto.response.BadgeServiceResponse; import com.smeem.api.goal.service.GoalService; -import com.smeem.api.member.controller.dto.request.MemberPlanUpdateRequestDTO; -import com.smeem.api.member.controller.dto.request.MemberPushUpdateRequestDTO; -import com.smeem.api.member.controller.dto.request.MemberUpdateRequestDTO; -import com.smeem.api.member.controller.dto.response.MemberGetResponseDTO; -import com.smeem.api.member.controller.dto.response.MemberNameResponseDTO; -import com.smeem.api.member.controller.dto.response.MemberUpdateResponseDTO; -import com.smeem.api.member.controller.dto.response.TrainingTimeResponseDTO; +import com.smeem.api.member.service.dto.request.MemberUpdatePlanServiceRequest; +import com.smeem.api.member.service.dto.request.MemberServiceUpdateUserProfileRequest; +import com.smeem.api.member.service.dto.request.TrainingTimeServiceRequest; +import com.smeem.api.member.service.dto.response.MemberGetServiceResponse; +import com.smeem.api.member.service.dto.response.MemberNameServiceResponse; +import com.smeem.api.member.service.dto.response.MemberUpdateServiceResponse; +import com.smeem.api.member.service.dto.response.TrainingTimeServiceResponse; import com.smeem.common.config.ValueConfig; import com.smeem.common.exception.MemberException; import com.smeem.common.exception.TrainingTimeException; import com.smeem.domain.badge.model.Badge; +import com.smeem.domain.goal.model.GoalType; import com.smeem.domain.member.model.Member; import com.smeem.domain.member.repository.MemberRepository; import com.smeem.domain.training.model.DayType; import com.smeem.domain.training.model.TrainingTime; import lombok.RequiredArgsConstructor; +import lombok.val; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import java.util.ArrayList; - import java.util.List; import java.util.stream.Collectors; @@ -51,84 +51,81 @@ public class MemberService { private final ValueConfig valueConfig; @Transactional - public MemberUpdateResponseDTO updateMember(Long memberId, MemberUpdateRequestDTO request) { + public MemberUpdateServiceResponse updateUserProfile(final long memberId, final MemberServiceUpdateUserProfileRequest request) { checkMemberDuplicate(request.username()); - Member member = get(memberId); - - if (nonNull(request.termAccepted())) { - member.updateTermAccepted(request.termAccepted()); - } + val member = get(memberId); + updateTermAccepted(member, request); ArrayList badges = new ArrayList<>(); if (isNull(member.getUsername())) { - Badge welcomeBadge = badgeService.get(valueConfig.getWELCOME_BADGE_ID()); - memberBadgeService.save(member, welcomeBadge); - badges.add(welcomeBadge); + addWelcomeBadge(member, badges); } member.updateUsername(request.username()); - return MemberUpdateResponseDTO.of(badges); + return MemberUpdateServiceResponse.of(badges); } - public MemberGetResponseDTO getProfile(Long memberId) { - Member member = get(memberId); - GoalResponseDTO goal = goalService.getByType(member.getGoal()); - List trainingTimes = trainingTimeService.getAllByMember(member); - // 기본 시간 설정 - if (trainingTimeService.getAllByMember(member).isEmpty()) { - TrainingTimeResponseDTO trainingTimeResponseDTO = TrainingTimeResponseDTO.of("", 22, 0); - BadgeResponseDTO badgeResponseDTO = BadgeResponseDTO.of(memberBadgeService.getBadgeByMemberId(memberId)); - return MemberGetResponseDTO.of(goal, member, trainingTimeResponseDTO,badgeResponseDTO); + private void updateTermAccepted(final Member member, final MemberServiceUpdateUserProfileRequest request) { + if (nonNull(request.termAccepted())) { + member.updateTermAccepted(request.termAccepted()); } - - TrainingTime trainingTime = getOneTrainingTime(trainingTimes); - TrainingTimeResponseDTO trainingTimeResponseDTO = TrainingTimeResponseDTO.of(getDays(trainingTimes), trainingTime.getHour(), trainingTime.getMinute()); - return MemberGetResponseDTO.of(goal, member, trainingTimeResponseDTO, BadgeResponseDTO.of(memberBadgeService.getBadgeByMemberId(memberId))); } - @Transactional - public void updateMemberPlan(Long memberId, MemberPlanUpdateRequestDTO request) { - Member member = get(memberId); + public MemberGetServiceResponse getMemberProfile(final long memberId) { + val member = get(memberId); + val goal = goalService.getByType(member.getGoal()); + val trainingTimes = trainingTimeService.getAllByMember(member); - if (nonNull(request.target())) { - member.updateGoal(request.target()); + // 기본 시간 설정 + if (trainingTimes.isEmpty()) { + val trainingTimeResponse = TrainingTimeServiceResponse.of("", 22, 0); + val badgeResponse = BadgeServiceResponse.of(memberBadgeService.getBadgeByMemberId(memberId)); + return MemberGetServiceResponse.of(goal, member, trainingTimeResponse, badgeResponse); } - if (nonNull(request.hasAlarm())) { - member.updateHasAlarm(request.hasAlarm()); - } + return MemberGetServiceResponse.of( + goal, + member, + generateTrainingTimeResponse(trainingTimes), + BadgeServiceResponse.of(memberBadgeService.getBadgeByMemberId(memberId))); + } - if (nonNull(request.trainingTime()) && StringUtils.hasText(request.trainingTime().day())) { - updateTrainingTime(member, request); - } + @Transactional + public void updateLearningPlan(final long memberId, final MemberUpdatePlanServiceRequest request) { + val member = get(memberId); + updateGoalType(member, request.goalType()); + updatePushAlarmConsent(member, request.hasAlarm()); + updateTrainingTime(member, request.trainingTime()); } @Transactional - public void updateHasAlarm(Long memberId, MemberPushUpdateRequestDTO request) { - Member member = get(memberId); + public void updateHasAlarm(final long memberId, final MemberPushUpdateServiceRequest request) { + val member = get(memberId); member.updateHasAlarm(request.hasAlarm()); } - public MemberNameResponseDTO checkDuplicatedName(String name) { + public MemberNameServiceResponse checkDuplicatedName(final String name) { boolean isExist = memberRepository.existsByUsername(name); - return new MemberNameResponseDTO(isExist); + return MemberNameServiceResponse.of(isExist); } - public Member get(Long id) { + public Member get(final long id) { return memberRepository.findById(id) .orElseThrow(() -> new MemberException(EMPTY_MEMBER)); } - private void updateTrainingTime(Member member, MemberPlanUpdateRequestDTO request) { - trainingTimeService.deleteAll(member); - for (String day : parseDay(request.trainingTime().day())) { - TrainingTime trainingTime = TrainingTime.builder() - .day(DayType.valueOf(day)) - .hour(request.trainingTime().hour()) - .minute(request.trainingTime().minute()) - .member(member) - .build(); - trainingTimeService.save(trainingTime); + private void updateTrainingTime(Member member, TrainingTimeServiceRequest request) { + if (nonNull(request) && StringUtils.hasText(request.day())) { + trainingTimeService.deleteAll(member); + for (String day : parseDay(request.day())) { + val trainingTime = TrainingTime.builder() + .day(DayType.valueOf(day)) + .hour(request.hour()) + .minute(request.minute()) + .member(member) + .build(); + trainingTimeService.save(trainingTime); + } } } @@ -136,22 +133,47 @@ private String[] parseDay(String day) { return day.split(","); } - private TrainingTime getOneTrainingTime(List trainingTimes) { return trainingTimes.stream().findFirst().orElseThrow( () -> new TrainingTimeException(NOT_SET_TRAINING_TIME)); } - private String getDays(List trainingTimeList) { - return trainingTimeList.stream() + private String getDays(List trainingTimes) { + return trainingTimes.stream() .map(trainingTime -> trainingTime.getDay().name()) .distinct() .collect(Collectors.joining(",")); } - private void checkMemberDuplicate(String username) { + private void checkMemberDuplicate(final String username) { if (memberRepository.existsByUsername(username)) { throw new MemberException(DUPLICATE_USERNAME); } } + + private void addWelcomeBadge(final Member member, List badges) { + Badge welcomeBadge = badgeService.get(valueConfig.getWELCOME_BADGE_ID()); + memberBadgeService.save(member, welcomeBadge); + badges.add(welcomeBadge); + } + + private void updateGoalType(Member member, GoalType goalType) { + if (nonNull(goalType)) { + member.updateGoal(goalType); + } + } + + private void updatePushAlarmConsent(Member member, Boolean hasAlarm) { + if (nonNull(hasAlarm)) { + member.updateHasAlarm(hasAlarm); + } + } + + private TrainingTimeServiceResponse generateTrainingTimeResponse(List trainingTimes) { + val trainingTime = getOneTrainingTime(trainingTimes); + return TrainingTimeServiceResponse.of( + getDays(trainingTimes), + trainingTime.getHour(), + trainingTime.getMinute()); + } } \ No newline at end of file diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberPushUpdateServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberPushUpdateServiceRequest.java new file mode 100644 index 00000000..8c5252ee --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberPushUpdateServiceRequest.java @@ -0,0 +1,6 @@ +package com.smeem.api.member.service.dto.request; + +public record MemberPushUpdateServiceRequest( + String fcmToken +) { +} diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberServiceUpdateUserProfileRequest.java b/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberServiceUpdateUserProfileRequest.java new file mode 100644 index 00000000..aaa08d7d --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberServiceUpdateUserProfileRequest.java @@ -0,0 +1,20 @@ +package com.smeem.api.member.service.dto.request; + + +import com.smeem.api.member.controller.dto.request.MemberUpdateRequest; +import lombok.AccessLevel; +import lombok.Builder; + +@Builder(access = AccessLevel.PRIVATE) +public record MemberServiceUpdateUserProfileRequest( + String username, + Boolean termAccepted +) { + + public static MemberServiceUpdateUserProfileRequest of(MemberUpdateRequest request) { + return MemberServiceUpdateUserProfileRequest.builder() + .username(request.username()) + .termAccepted(request.termAccepted()) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberUpdatePlanServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberUpdatePlanServiceRequest.java new file mode 100644 index 00000000..fbdd3190 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberUpdatePlanServiceRequest.java @@ -0,0 +1,22 @@ +package com.smeem.api.member.service.dto.request; + +import com.smeem.api.member.controller.dto.request.MemberPlanUpdateRequest; +import com.smeem.domain.goal.model.GoalType; +import lombok.Builder; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record MemberUpdatePlanServiceRequest( + GoalType goalType, + TrainingTimeServiceRequest trainingTime, + Boolean hasAlarm +) { + public static MemberUpdatePlanServiceRequest of(MemberPlanUpdateRequest request) { + return MemberUpdatePlanServiceRequest.builder() + .goalType(request.target()) + .trainingTime(TrainingTimeServiceRequest.of(request.trainingTime())) + .hasAlarm(request.hasAlarm()) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/TrainingTimeServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/TrainingTimeServiceRequest.java new file mode 100644 index 00000000..f2dedbf6 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/TrainingTimeServiceRequest.java @@ -0,0 +1,22 @@ +package com.smeem.api.member.service.dto.request; + + +import com.smeem.api.member.controller.dto.request.TrainingTimeRequest; +import lombok.Builder; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record TrainingTimeServiceRequest( + String day, + int hour, + int minute +) { + public static TrainingTimeServiceRequest of(TrainingTimeRequest request) { + return TrainingTimeServiceRequest.builder() + .day(request.day()) + .hour(request.hour()) + .minute(request.minute()) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberGetServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberGetServiceResponse.java new file mode 100644 index 00000000..cbf356ba --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberGetServiceResponse.java @@ -0,0 +1,41 @@ +package com.smeem.api.member.service.dto.response; + +import com.smeem.api.badge.service.dto.response.BadgeServiceResponse; +import com.smeem.api.goal.controller.dto.response.GoalResponse; +import com.smeem.domain.member.model.LangType; +import com.smeem.domain.member.model.Member; +import lombok.Builder; + +import static lombok.AccessLevel.*; + + +@Builder(access = PRIVATE) +public record MemberGetServiceResponse( + String username, + String target, + String way, + String detail, + LangType targetLangType, + boolean hasPushAlarm, + TrainingTimeServiceResponse trainingTime, + BadgeServiceResponse badge +) { + + public static MemberGetServiceResponse of( + GoalResponse goal, + Member member, + TrainingTimeServiceResponse trainingTime, + BadgeServiceResponse badge + ) { + return MemberGetServiceResponse.builder() + .username(member.getUsername()) + .target(goal.name()) + .way(goal.way()) + .detail(goal.detail()) + .targetLangType(member.getTargetLang()) + .hasPushAlarm(member.isHasPushAlarm()) + .trainingTime(trainingTime) + .badge(badge) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberNameServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberNameServiceResponse.java new file mode 100644 index 00000000..f42349f9 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberNameServiceResponse.java @@ -0,0 +1,18 @@ +package com.smeem.api.member.service.dto.response; + + +import lombok.Builder; + +import static lombok.AccessLevel.*; + +@Builder(access = PRIVATE) +public record MemberNameServiceResponse( + boolean isExist +) { + public static MemberNameServiceResponse of(boolean isExist) { + return MemberNameServiceResponse + .builder() + .isExist(isExist) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberUpdateServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberUpdateServiceResponse.java new file mode 100644 index 00000000..28e40f87 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberUpdateServiceResponse.java @@ -0,0 +1,21 @@ +package com.smeem.api.member.service.dto.response; + +import com.smeem.api.badge.controller.dto.response.BadgeResponse; +import com.smeem.domain.badge.model.Badge; +import lombok.Builder; + +import java.util.List; + +import static lombok.AccessLevel.*; + +@Builder(access = PRIVATE) +public record MemberUpdateServiceResponse( + List badges +) { + + public static MemberUpdateServiceResponse of(List badges) { + return MemberUpdateServiceResponse.builder() + .badges(badges.stream().map(BadgeResponse::of).toList() + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/TrainingTimeServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/TrainingTimeServiceResponse.java new file mode 100644 index 00000000..49264975 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/TrainingTimeServiceResponse.java @@ -0,0 +1,17 @@ +package com.smeem.api.member.service.dto.response; + + +import lombok.Builder; + +import static lombok.AccessLevel.*; + +@Builder(access = PRIVATE) +public record TrainingTimeServiceResponse(String day, int hour, int minute) { + public static TrainingTimeServiceResponse of(String day, int hour, int minute) { + return TrainingTimeServiceResponse.builder() + .day(day) + .hour(hour) + .minute(minute) + .build(); + } +} \ No newline at end of file diff --git a/smeem-api/src/test/java/com/smeem/api/controller/BaseControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/BaseControllerTest.java index 33003338..d09f5ace 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/BaseControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/BaseControllerTest.java @@ -2,16 +2,11 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.smeem.api.auth.jwt.CustomJwtAuthenticationEntryPoint; -import com.smeem.api.auth.jwt.JwtTokenProvider; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.extension.ExtendWith; +import com.smeem.api.auth.jwt.TokenProvider; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.restdocs.RestDocumentationContextProvider; -import org.springframework.restdocs.RestDocumentationExtension; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; @@ -36,7 +31,7 @@ public abstract class BaseControllerTest { protected MockMvc mockMvc; @MockBean - private JwtTokenProvider jwtTokenProvider; + private TokenProvider jwtTokenProvider; @MockBean private CustomJwtAuthenticationEntryPoint customJwtAuthenticationEntryPoint; diff --git a/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java index 8f72448b..f903ffd6 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java @@ -1,7 +1,7 @@ package com.smeem.api.controller; import com.epages.restdocs.apispec.ResourceSnippetParameters; -import com.smeem.api.badge.controller.dto.response.AcquiredBadgeResponseDTO; +import com.smeem.api.badge.controller.dto.response.AcquiredBadgeResponse; import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; import com.smeem.api.diary.controller.DiaryController; @@ -11,9 +11,6 @@ import com.smeem.api.diary.controller.dto.response.DiariesResponseDTO.DiaryDTO; import com.smeem.api.diary.controller.dto.response.DiaryResponseDTO; import lombok.val; -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.ResponseEntity; import org.springframework.util.LinkedMultiValueMap; @@ -271,13 +268,13 @@ void success_get_diaries() throws Exception { .andExpect(status().isOk()); } - private List acquiredBadges() { + private List acquiredBadges() { return Stream.iterate(1, i -> i + 1).limit(5) .map(i -> acquiredBadge()).toList(); } - private AcquiredBadgeResponseDTO acquiredBadge() { - return new AcquiredBadgeResponseDTO("뱃지 이름", "com.smeem.badge-image-url", EVENT); + private AcquiredBadgeResponse acquiredBadge() { + return new AcquiredBadgeResponse("뱃지 이름", "com.smeem.badge-image-url", EVENT); } private List diaries() { diff --git a/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java index da3519fd..d2c88f6f 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java @@ -3,14 +3,11 @@ import com.epages.restdocs.apispec.ResourceSnippetParameters; import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.goal.controller.GoalController; -import com.smeem.api.goal.controller.dto.response.GoalResponseDTO; -import com.smeem.api.goal.controller.dto.response.GoalsResponseDTO; -import com.smeem.api.goal.controller.dto.response.GoalsResponseDTO.GoalResponseVO; +import com.smeem.api.goal.controller.dto.response.GoalResponse; +import com.smeem.api.goal.controller.dto.response.GoalListResponse; +import com.smeem.api.goal.controller.dto.response.GoalListResponse.GoalResponseVO; import com.smeem.domain.goal.model.GoalType; import lombok.val; -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 java.security.Principal; @@ -47,7 +44,7 @@ class GoalControllerTest extends BaseControllerTest { // @DisplayName("전체 학습 목표 조회 테스트") void success_get_goals_test() throws Exception { // given - val response = new GoalsResponseDTO(goals()); + val response = new GoalListResponse(goals()); val result = ApiResponseUtil.success(SUCCESS_GET_GOALS, response); // when @@ -83,7 +80,7 @@ void success_get_goals_test() throws Exception { void success_get_goal_test() throws Exception { // given GoalType type = APPLY; - val response = new GoalResponseDTO( + val response = new GoalResponse( "현지 언어 체득", "주 5회 이상 오늘 하루를 돌아보는 일기 작성하기", "사전 없이 일기 완성\nsmeem 연속 일기 배지 획득"); diff --git a/smeem-api/src/test/java/com/smeem/api/fixture/auth/AuthFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/auth/AuthFixture.java index 16c4bfcf..e7b71812 100644 --- a/smeem-api/src/test/java/com/smeem/api/fixture/auth/AuthFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/auth/AuthFixture.java @@ -1,9 +1,9 @@ package com.smeem.api.fixture.auth; -import com.smeem.api.auth.controller.dto.request.SignInRequestDTO; -import com.smeem.api.auth.controller.dto.response.SignInResponseDTO; -import com.smeem.api.auth.controller.dto.response.token.TokenResponseDTO; -import com.smeem.api.auth.controller.dto.response.token.TokenVO; +import com.smeem.api.auth.controller.dto.request.SignInRequest; +import com.smeem.api.auth.controller.dto.response.SignInResponse; +import com.smeem.api.auth.controller.dto.response.token.TokenResponse; +import com.smeem.api.auth.jwt.SmeemToken; import com.smeem.domain.member.model.SocialType; public class AuthFixture { @@ -13,30 +13,30 @@ public class AuthFixture { private static final String ACCESS_TOKEN = "testaccesstoken"; private static final String REFRESH_TOKEN = "testrefreshtoken"; - public static SignInRequestDTO createSignInRequestDTO() { - return new SignInRequestDTO( + public static SignInRequest createSignInRequestDTO() { + return new SignInRequest( SOCIAL_TYPE, FCM_TOKEN ); } - public static SignInResponseDTO createSignInResponseDTO() { - return SignInResponseDTO.of( + public static SignInResponse createSignInResponseDTO() { + return SignInResponse.of( createTokenVO(), true, true ); } - public static TokenVO createTokenVO() { - return new TokenVO( - ACCESS_TOKEN, - REFRESH_TOKEN - ); + public static SmeemToken createTokenVO() { + return SmeemToken.builder() + .accessToken(ACCESS_TOKEN) + .refreshToken(REFRESH_TOKEN) + .build(); } - public static TokenResponseDTO createTokenResponseDTO() { - return TokenResponseDTO.of( + public static TokenResponse createTokenResponseDTO() { + return TokenResponse.of( ACCESS_TOKEN, REFRESH_TOKEN ); diff --git a/smeem-api/src/test/java/com/smeem/api/fixture/badge/BadgeFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/badge/BadgeFixture.java index e6ebd711..ae8cb257 100644 --- a/smeem-api/src/test/java/com/smeem/api/fixture/badge/BadgeFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/badge/BadgeFixture.java @@ -1,8 +1,8 @@ package com.smeem.api.fixture.badge; -import com.smeem.api.badge.controller.dto.response.BadgeListResponseDTO; -import com.smeem.api.badge.controller.dto.response.BadgeListResponseDTO.BadgeTypeResponseDTO; -import com.smeem.api.badge.controller.dto.response.BadgeResponseDTO; +import com.smeem.api.badge.controller.dto.response.BadgeListResponse; +import com.smeem.api.badge.controller.dto.response.BadgeListResponse.BadgeTypeResponseDTO; +import com.smeem.api.badge.controller.dto.response.BadgeResponse; import com.smeem.domain.badge.model.BadgeType; import java.util.List; @@ -17,8 +17,8 @@ public class BadgeFixture { private static final BadgeType BADGE_TYPE = COMBO; private static final String BADGE_IMAGE_URL = "https://m.s3.ap-northeast-2.amazonaws.com/badge/streak.png"; - public static BadgeResponseDTO createBadgeResponseDTO() { - return BadgeResponseDTO.builder() + public static BadgeResponse createBadgeResponseDTO() { + return BadgeResponse.builder() .id(BADGE_ID) .name(BADGE_NAME) .type(BADGE_TYPE.toString()) @@ -26,8 +26,8 @@ public static BadgeResponseDTO createBadgeResponseDTO() { .build(); } - public static BadgeListResponseDTO createBadgeListResponseDTO() { - return new BadgeListResponseDTO(createBadgeTypesResponse()); + public static BadgeListResponse createBadgeListResponseDTO() { + return new BadgeListResponse(createBadgeTypesResponse()); } private static List createBadgeTypesResponse() { @@ -40,14 +40,14 @@ private static BadgeTypeResponseDTO createBadgeTypeResponse() { return new BadgeTypeResponseDTO(BADGE_TYPE, BADGE_NAME, createBadgeResponses()); } - private static List createBadgeResponses() { + private static List createBadgeResponses() { return Stream.iterate(1, i -> i + 1).limit(5) .map(BadgeFixture::createBadgeResponse) .toList(); } - private static BadgeListResponseDTO.BadgeResponseDTO createBadgeResponse(int i) { - return BadgeListResponseDTO.BadgeResponseDTO.builder() + private static BadgeListResponse.BadgeResponseDTO createBadgeResponse(int i) { + return BadgeListResponse.BadgeResponseDTO.builder() .name(BADGE_NAME + i) .type(BADGE_TYPE) .imageUrl("https://...") diff --git a/smeem-api/src/test/java/com/smeem/api/fixture/goal/GoalFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/goal/GoalFixture.java index 1cabb621..f7178e3c 100644 --- a/smeem-api/src/test/java/com/smeem/api/fixture/goal/GoalFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/goal/GoalFixture.java @@ -1,6 +1,6 @@ package com.smeem.api.fixture.goal; -import com.smeem.api.goal.controller.dto.response.GoalResponseDTO; +import com.smeem.api.goal.controller.dto.response.GoalResponse; import com.smeem.domain.goal.model.Goal; import com.smeem.domain.goal.model.GoalType; @@ -20,7 +20,7 @@ public static Goal createGoal() { .build(); } - public static GoalResponseDTO createGoalResponseDTO() { - return GoalResponseDTO.of(createGoal()); + public static GoalResponse createGoalResponseDTO() { + return GoalResponse.of(createGoal()); } } diff --git a/smeem-api/src/test/java/com/smeem/api/fixture/member/MemberFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/member/MemberFixture.java index eb7b70c2..49445c7d 100644 --- a/smeem-api/src/test/java/com/smeem/api/fixture/member/MemberFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/member/MemberFixture.java @@ -3,11 +3,10 @@ import com.smeem.api.fixture.goal.GoalFixture; import com.smeem.api.fixture.badge.BadgeFixture; import com.smeem.api.fixture.trainingtime.TrainingTimeFixture; -import com.smeem.api.member.controller.dto.request.MemberPlanUpdateRequestDTO; -import com.smeem.api.member.controller.dto.request.MemberPushUpdateRequestDTO; -import com.smeem.api.member.controller.dto.request.MemberUpdateRequestDTO; -import com.smeem.api.member.controller.dto.response.MemberGetResponseDTO; -import com.smeem.domain.goal.model.GoalType; +import com.smeem.api.member.controller.dto.request.MemberPlanUpdateRequest; +import com.smeem.api.member.controller.dto.request.MemberPushUpdateRequest; +import com.smeem.api.member.controller.dto.request.MemberUpdateRequest; +import com.smeem.api.member.controller.dto.response.MemberGetResponse; import com.smeem.domain.member.model.LangType; import com.smeem.domain.member.model.Member; import com.smeem.domain.member.model.SocialType; @@ -38,8 +37,8 @@ public static Member createMember() { return member; } - public static MemberGetResponseDTO createMemberGetResponseDTO() { - return MemberGetResponseDTO.of( + public static MemberGetResponse createMemberGetResponseDTO() { + return MemberGetResponse.of( GoalFixture.createGoalResponseDTO(), createMember(), TrainingTimeFixture.createTrainingTimeResponseDTO(), @@ -47,19 +46,19 @@ public static MemberGetResponseDTO createMemberGetResponseDTO() { ); } - public static MemberUpdateRequestDTO createMemberUpdateRequestDTO() { - return new MemberUpdateRequestDTO(MEMBER_USERNAME, HAS_ALARM); + public static MemberUpdateRequest createMemberUpdateRequestDTO() { + return new MemberUpdateRequest(MEMBER_USERNAME, HAS_ALARM); } - public static MemberPlanUpdateRequestDTO createMemberPlanUpdateRequestDTO() { - return new MemberPlanUpdateRequestDTO( + public static MemberPlanUpdateRequest createMemberPlanUpdateRequestDTO() { + return new MemberPlanUpdateRequest( DEVELOP, TrainingTimeFixture.createTrainingTimeRequestDTO(), HAS_ALARM ); } - public static MemberPushUpdateRequestDTO createMemberPushUpdateRequestDTO() { - return new MemberPushUpdateRequestDTO(HAS_ALARM); + public static MemberPushUpdateRequest createMemberPushUpdateRequestDTO() { + return new MemberPushUpdateRequest(HAS_ALARM); } } \ No newline at end of file diff --git a/smeem-api/src/test/java/com/smeem/api/fixture/trainingtime/TrainingTimeFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/trainingtime/TrainingTimeFixture.java index 2d2fc365..57fb4081 100644 --- a/smeem-api/src/test/java/com/smeem/api/fixture/trainingtime/TrainingTimeFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/trainingtime/TrainingTimeFixture.java @@ -1,8 +1,8 @@ package com.smeem.api.fixture.trainingtime; import com.smeem.api.fixture.member.MemberFixture; -import com.smeem.api.member.controller.dto.request.TrainingTimeRequestDTO; -import com.smeem.api.member.controller.dto.response.TrainingTimeResponseDTO; +import com.smeem.api.member.controller.dto.request.TrainingTimeRequest; +import com.smeem.api.member.controller.dto.response.TrainingTimeResponse; import com.smeem.domain.training.model.DayType; import com.smeem.domain.training.model.TrainingTime; @@ -14,8 +14,8 @@ public class TrainingTimeFixture { private static final int HOUR = 10; private static final int MINUTE = 30; - public static TrainingTimeRequestDTO createTrainingTimeRequestDTO() { - return new TrainingTimeRequestDTO(DAY_TYPE.name(), HOUR, MINUTE); + public static TrainingTimeRequest createTrainingTimeRequestDTO() { + return new TrainingTimeRequest(DAY_TYPE.name(), HOUR, MINUTE); } public static TrainingTime createTrainingTime() { @@ -27,8 +27,8 @@ public static TrainingTime createTrainingTime() { .build(); } - public static TrainingTimeResponseDTO createTrainingTimeResponseDTO() { - return TrainingTimeResponseDTO.of(DAY_TYPE.name(), HOUR, MINUTE); + public static TrainingTimeResponse createTrainingTimeResponseDTO() { + return TrainingTimeResponse.of(DAY_TYPE.name(), HOUR, MINUTE); } } diff --git a/smeem-common/src/main/java/com/smeem/common/exception/AuthException.java b/smeem-common/src/main/java/com/smeem/common/exception/AuthException.java new file mode 100644 index 00000000..86f3ab16 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/exception/AuthException.java @@ -0,0 +1,15 @@ +package com.smeem.common.exception; + +import com.smeem.common.code.failure.FailureCode; +import lombok.Getter; + +@Getter +public class AuthException extends RuntimeException { + + private final FailureCode failureCode; + + public AuthException(FailureCode failureCode) { + super("[AuthException] : " + failureCode.getMessage()); + this.failureCode = failureCode; + } +} \ No newline at end of file diff --git a/smeem-domain/src/main/java/com/smeem/domain/badge/model/Badge.java b/smeem-domain/src/main/java/com/smeem/domain/badge/model/Badge.java index a92f739f..78b4ae0f 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/badge/model/Badge.java +++ b/smeem-domain/src/main/java/com/smeem/domain/badge/model/Badge.java @@ -2,12 +2,13 @@ import jakarta.persistence.*; +import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @Entity @Getter -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class Badge { @Id @@ -19,7 +20,6 @@ public class Badge { private String name; - private String imageUrl; - - private String grayImageUrl; + @Embedded + private BadgeImage badgeImage; } diff --git a/smeem-domain/src/main/java/com/smeem/domain/badge/model/BadgeImage.java b/smeem-domain/src/main/java/com/smeem/domain/badge/model/BadgeImage.java new file mode 100644 index 00000000..82905a45 --- /dev/null +++ b/smeem-domain/src/main/java/com/smeem/domain/badge/model/BadgeImage.java @@ -0,0 +1,14 @@ +package com.smeem.domain.badge.model; + +import jakarta.persistence.Embeddable; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Embeddable +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class BadgeImage { + private String grayImageUrl; + private String imageUrl; +} diff --git a/smeem-domain/src/main/java/com/smeem/domain/member/model/LangType.java b/smeem-domain/src/main/java/com/smeem/domain/member/model/LangType.java index da7de0dd..7aa13003 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/member/model/LangType.java +++ b/smeem-domain/src/main/java/com/smeem/domain/member/model/LangType.java @@ -1,5 +1,9 @@ package com.smeem.domain.member.model; public enum LangType { - en + en; + + public static LangType defaultLangType() { + return en; + } } diff --git a/smeem-domain/src/main/java/com/smeem/domain/member/model/Member.java b/smeem-domain/src/main/java/com/smeem/domain/member/model/Member.java index 27480caa..12e4f5be 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/member/model/Member.java +++ b/smeem-domain/src/main/java/com/smeem/domain/member/model/Member.java @@ -8,6 +8,7 @@ import com.smeem.domain.model.BaseTimeEntity; import com.smeem.domain.training.model.TrainingTime; import jakarta.persistence.*; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -18,7 +19,7 @@ @Entity -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter public class Member extends BaseTimeEntity { @@ -121,6 +122,15 @@ public void updateDiaryCombo() { this.diaryComboCount = count; } + public static Member createInitialMember(SocialType socialType, String socialId, String fcmToken) { + return Member.builder() + .social(socialType) + .socialId(socialId) + .targetLang(LangType.defaultLangType()) + .fcmToken(fcmToken) + .build(); + } + public boolean hasNotBadge(Badge badge) { return badges.stream().noneMatch(memberBadge -> memberBadge.getBadge().equals(badge)); } diff --git a/smeem-domain/src/main/java/com/smeem/domain/member/model/MemberBadge.java b/smeem-domain/src/main/java/com/smeem/domain/member/model/MemberBadge.java index 608af956..689ccb5c 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/member/model/MemberBadge.java +++ b/smeem-domain/src/main/java/com/smeem/domain/member/model/MemberBadge.java @@ -6,12 +6,13 @@ import com.smeem.domain.model.BaseTimeEntity; import jakarta.persistence.*; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Entity -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter public class MemberBadge extends BaseTimeEntity { diff --git a/smeem-external/src/main/java/com/smeem/external/apple/AppleSignInService.java b/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleSignInService.java similarity index 97% rename from smeem-external/src/main/java/com/smeem/external/apple/AppleSignInService.java rename to smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleSignInService.java index e6091b4a..1a89421f 100644 --- a/smeem-external/src/main/java/com/smeem/external/apple/AppleSignInService.java +++ b/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleSignInService.java @@ -1,4 +1,4 @@ -package com.smeem.external.apple; +package com.smeem.external.oauth.apple; import com.google.gson.*; import com.smeem.common.config.RestTemplateConfig; @@ -32,7 +32,6 @@ public class AppleSignInService { private final ValueConfig valueConfig; - private final RestTemplateConfig restTemplateConfig; public JsonArray getApplePublicKeys() { try { diff --git a/smeem-external/src/main/java/com/smeem/external/kakao/KakaoSignInService.java b/smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoSignInService.java similarity index 96% rename from smeem-external/src/main/java/com/smeem/external/kakao/KakaoSignInService.java rename to smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoSignInService.java index 02d21632..cddab856 100644 --- a/smeem-external/src/main/java/com/smeem/external/kakao/KakaoSignInService.java +++ b/smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoSignInService.java @@ -1,4 +1,4 @@ -package com.smeem.external.kakao; +package com.smeem.external.oauth.kakao; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.JsonArray; From bb333e4aa2522d25f9d704cceee4bd185b4aa9ea Mon Sep 17 00:00:00 2001 From: unanchoi Date: Wed, 14 Feb 2024 01:21:14 +0900 Subject: [PATCH 44/86] =?UTF-8?q?[FIX]=20settings.gradle=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- settings.gradle | 8 -------- 1 file changed, 8 deletions(-) diff --git a/settings.gradle b/settings.gradle index 54d0e302..cf44cc1d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,11 +1,3 @@ -pluginManagement { - plugins { - id 'org.jetbrains.kotlin.jvm' version '1.9.21' - } -} -plugins { - id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0' -} rootProject.name = 'server' include 'smeem-api' include 'smeem-domain' From 4ba3fbeddc6865ee05cde8a045e046a2507dd504 Mon Sep 17 00:00:00 2001 From: thguss Date: Tue, 20 Feb 2024 20:47:54 +0900 Subject: [PATCH 45/86] =?UTF-8?q?[REFACTOR]=20api:=20final=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80,=20=EC=84=A0public=20=ED=9B=84private,=20Response=20D?= =?UTF-8?q?TO=20(Service,=20Controller)=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smeem-api/build.gradle | 4 - .../api/diary/controller/DiaryController.java | 23 +- ...Response.java => DiaryCreateResponse.java} | 10 +- .../dto/response/DiaryGetResponse.java | 34 +++ .../dto/response/DiaryListGetResponse.java | 47 ++++ .../diary/service/DiaryCommandService.java | 54 ++-- .../api/diary/service/DiaryQueryService.java | 14 +- .../response/DiaryCreateServiceResponse.java | 1 + .../dto/response/DiaryGetServiceResponse.java | 21 +- .../response/DiaryListGetServiceResponse.java | 22 +- .../api/goal/controller/GoalController.java | 7 +- .../dto/response/GoalGetResponse.java | 7 +- .../dto/response/GoalListGetResponse.java | 35 +++ .../dto/response/GoalListResponse.java | 23 -- .../smeem/api/goal/service/GoalService.java | 8 +- .../dto/request/GoalGetServiceRequest.java | 2 +- .../dto/response/GoalGetServiceResponse.java | 6 +- .../response/GoalListGetServiceResponse.java | 16 +- .../api/member/service/MemberService.java | 2 +- .../response/MemberGetServiceResponse.java | 2 +- .../api/test/controller/TestController.java | 5 +- .../dto/request/TestPushAlarmRequest.java | 17 -- .../smeem/api/test/service/TestService.java | 5 +- .../request/TestPushAlarmServiceRequest.java | 17 ++ .../api/topic/controller/TopicController.java | 3 +- .../dto/response/RandomTopicGetResponse.java | 20 ++ .../smeem/api/topic/service/TopicService.java | 2 +- .../RandomTopicGetServiceResponse.java | 2 +- .../api/controller/GoalControllerTest.java | 256 +++++++++--------- .../api/controller/TopicControllerTest.java | 2 +- .../smeem/api/fixture/goal/GoalFixture.java | 2 +- .../smeem/api/fixture/topic/TopicFixture.java | 2 +- 32 files changed, 392 insertions(+), 279 deletions(-) rename smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/{CreatedDiaryResponse.java => DiaryCreateResponse.java} (61%) create mode 100644 smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryGetResponse.java create mode 100644 smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryListGetResponse.java create mode 100644 smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalListGetResponse.java delete mode 100644 smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalListResponse.java rename smeem-api/src/main/java/com/smeem/api/goal/{ => service}/dto/request/GoalGetServiceRequest.java (89%) rename smeem-api/src/main/java/com/smeem/api/goal/{ => service}/dto/response/GoalGetServiceResponse.java (78%) rename smeem-api/src/main/java/com/smeem/api/goal/{ => service}/dto/response/GoalListGetServiceResponse.java (55%) delete mode 100644 smeem-api/src/main/java/com/smeem/api/test/dto/request/TestPushAlarmRequest.java create mode 100644 smeem-api/src/main/java/com/smeem/api/test/service/dto/request/TestPushAlarmServiceRequest.java create mode 100644 smeem-api/src/main/java/com/smeem/api/topic/controller/dto/response/RandomTopicGetResponse.java rename smeem-api/src/main/java/com/smeem/api/topic/{ => service}/dto/response/RandomTopicGetServiceResponse.java (90%) diff --git a/smeem-api/build.gradle b/smeem-api/build.gradle index fbb9a5d7..913e2528 100644 --- a/smeem-api/build.gradle +++ b/smeem-api/build.gradle @@ -5,7 +5,6 @@ plugins { id 'com.epages.restdocs-api-spec' version "0.18.2" // swagger generator id 'org.hidetake.swagger.generator' version '2.18.2' - id 'org.jetbrains.kotlin.jvm' } dependencies { @@ -67,6 +66,3 @@ bootJar { repositories { mavenCentral() } -kotlin { - jvmToolchain(17) -} diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java b/smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java index 4fd851c8..b75a5f8f 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java @@ -6,6 +6,9 @@ import com.smeem.api.common.BaseResponse; import com.smeem.api.diary.controller.dto.request.DiaryCreateRequest; import com.smeem.api.diary.controller.dto.request.DiaryModifyRequest; +import com.smeem.api.diary.controller.dto.response.DiaryCreateResponse; +import com.smeem.api.diary.controller.dto.response.DiaryGetResponse; +import com.smeem.api.diary.controller.dto.response.DiaryListGetResponse; import com.smeem.api.diary.service.DiaryQueryService; import com.smeem.api.diary.service.DiaryCommandService; import com.smeem.api.diary.service.dto.request.*; @@ -38,32 +41,28 @@ public class DiaryController { @PostMapping public ResponseEntity> createDiary(Principal principal, @RequestBody DiaryCreateRequest request) { val memberId = Util.getMemberId(principal); - val serviceRequest = DiaryCreateServiceRequest.of(memberId, request); - - val response = diaryCommandService.createDiary(serviceRequest); + val response = DiaryCreateResponse.from( + diaryCommandService.createDiary(DiaryCreateServiceRequest.of(memberId, request))); val uri = Util.getURI("/{diaryId}", response.diaryId()); - return ApiResponseUtil.success(SUCCESS_CREATE_DIARY, uri, response); } @GetMapping("/{diaryId}") public ResponseEntity> getDiaryDetail(@PathVariable long diaryId) { - val serviceRequest = DiaryGetServiceRequest.of(diaryId); - val response = diaryQueryService.getDiaryDetail(serviceRequest); + val response = DiaryGetResponse.from( + diaryQueryService.getDiaryDetail(DiaryGetServiceRequest.of(diaryId))); return ApiResponseUtil.success(SUCCESS_GET_DIARY, response); } @PatchMapping("/{diaryId}") public ResponseEntity> modifyDiary(@PathVariable long diaryId, @RequestBody DiaryModifyRequest request) { - val serviceRequest = DiaryModifyServiceRequest.of(diaryId, request); - diaryCommandService.modifyDiary(serviceRequest); + diaryCommandService.modifyDiary(DiaryModifyServiceRequest.of(diaryId, request)); return ApiResponseUtil.success(SUCCESS_UPDATE_DAIRY); } @DeleteMapping("/{diaryId}") public ResponseEntity> deleteDiary(@PathVariable long diaryId) { - val serviceRequest = DiaryDeleteServiceRequest.of(diaryId); - diaryCommandService.deleteDiary(serviceRequest); + diaryCommandService.deleteDiary(DiaryDeleteServiceRequest.of(diaryId)); return ApiResponseUtil.success(SUCCESS_DELETE_DIARY); } @@ -74,8 +73,8 @@ public ResponseEntity> getDiaries( @RequestParam String end ) { val memberId = Util.getMemberId(principal); - val serviceRequest = DiaryListGetServiceRequest.of(memberId, start, end); - val response = diaryQueryService.getDiaries(serviceRequest); + val response = DiaryListGetResponse.from( + diaryQueryService.getDiaries(DiaryListGetServiceRequest.of(memberId, start, end))); return ApiResponseUtil.success(SUCCESS_GET_DIARIES, response); } } diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/CreatedDiaryResponse.java b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryCreateResponse.java similarity index 61% rename from smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/CreatedDiaryResponse.java rename to smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryCreateResponse.java index df6ff261..a2e0897f 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/CreatedDiaryResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryCreateResponse.java @@ -1,10 +1,7 @@ package com.smeem.api.diary.controller.dto.response; import com.smeem.api.badge.controller.dto.response.AcquiredBadgeResponse; -import com.smeem.api.badge.service.dto.response.AcquiredBadgeServiceResponse; -import com.smeem.api.badge.service.dto.response.BadgeServiceResponse; import com.smeem.api.diary.service.dto.response.DiaryCreateServiceResponse; -import com.smeem.domain.badge.model.Badge; import lombok.Builder; import java.util.List; @@ -12,12 +9,13 @@ import static lombok.AccessLevel.PRIVATE; @Builder(access = PRIVATE) -public record CreatedDiaryResponse( +public record DiaryCreateResponse( long diaryId, List badges ) { - public static CreatedDiaryResponse of(DiaryCreateServiceResponse response) { - return CreatedDiaryResponse.builder() + + public static DiaryCreateResponse from(DiaryCreateServiceResponse response) { + return DiaryCreateResponse.builder() .diaryId(response.diaryId()) .badges(response.badges().stream().map(AcquiredBadgeResponse::of).toList()) .build(); diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryGetResponse.java b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryGetResponse.java new file mode 100644 index 00000000..80b27e37 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryGetResponse.java @@ -0,0 +1,34 @@ +package com.smeem.api.diary.controller.dto.response; + +import com.smeem.api.diary.service.dto.response.DiaryGetServiceResponse; +import com.smeem.common.util.Util; +import lombok.Builder; + +import java.time.LocalDateTime; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record DiaryGetResponse( + long diaryId, + String topic, + String content, + String createdAt, + String username +) { + + public static DiaryGetResponse from(DiaryGetServiceResponse response) { + return DiaryGetResponse.builder() + .diaryId(response.diaryId()) + .topic(response.topicContent()) + .content(response.content()) + .createdAt(getCreatedAtToString(response.createdAt())) + .username(response.username()) + .build(); + } + + private static String getCreatedAtToString(LocalDateTime createdAt) { + return Util.transferToLocalDateTime(createdAt); + } +} + diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryListGetResponse.java b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryListGetResponse.java new file mode 100644 index 00000000..eeaa21b6 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryListGetResponse.java @@ -0,0 +1,47 @@ +package com.smeem.api.diary.controller.dto.response; + +import com.smeem.api.diary.service.dto.response.DiaryListGetServiceResponse; +import com.smeem.api.diary.service.dto.response.DiaryListGetServiceResponse.DiaryServiceResponse; +import com.smeem.common.util.Util; +import lombok.Builder; + +import java.time.LocalDateTime; +import java.util.List; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record DiaryListGetResponse( + List diaries, + boolean has30Past +) { + + public static DiaryListGetResponse from(DiaryListGetServiceResponse response) { + return DiaryListGetResponse.builder() + .diaries(response.diaries().stream().map(DiaryResponse::from).toList()) + .has30Past(response.hasDiaryWrittenAgo()) + .build(); + } + + @Builder(access = PRIVATE) + public record DiaryResponse( + long diaryId, + String content, + String createdAt + ) { + + public static DiaryResponse from(DiaryServiceResponse response) { + return DiaryResponse.builder() + .diaryId(response.diaryId()) + .content(response.content()) + .createdAt(getCreatedAtToString(response.createdAt())) + .build(); + } + + private static String getCreatedAtToString(LocalDateTime createdAt) { + return Util.transferToLocalDateTime(createdAt); + } + } +} + + diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryCommandService.java b/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryCommandService.java index 69506090..954358d4 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryCommandService.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryCommandService.java @@ -51,6 +51,22 @@ public DiaryCreateServiceResponse createDiary(final DiaryCreateServiceRequest re return DiaryCreateServiceResponse.of(savedDiary, acquiredBadges); } + public void modifyDiary(final DiaryModifyServiceRequest request) { + val diary = findDiary(request.diaryId()); + diary.updateContent(request.content()); + } + + public void deleteDiary(final DiaryDeleteServiceRequest request) { + val diary = findDiary(request.diaryId()); + moveToDeletedDairy(diary); + deleteDiary(diary); + } + + public void deleteAllByMember(final Member member) { + diaryRepository.deleteAllByMember(member); + deletedDiaryRepository.deleteByMember(member); + } + private Member getMemberCheckedNoDiaryWrittenToday(long memberId) { val member = findMember(memberId); if (member.hasDiaryWrittenToday()) { @@ -64,26 +80,26 @@ private Member findMember(long id) { .orElseThrow(() -> new MemberException(INVALID_MEMBER)); } - private Diary saveDiary(DiaryCreateServiceRequest request, Member member) { + private Diary saveDiary(final DiaryCreateServiceRequest request, Member member) { val diary = getDiaryByTopic(request, member); return diaryRepository.save(diary); } - private Diary getDiaryByTopic(DiaryCreateServiceRequest request, Member member) { + private Diary getDiaryByTopic(final DiaryCreateServiceRequest request, Member member) { val topicId = request.topicId(); return Objects.isNull(topicId) ? getDiaryWithoutTopic(request, member) : getDiaryWithTopic(request, member); } - private Diary getDiaryWithoutTopic(DiaryCreateServiceRequest request, Member member) { + private Diary getDiaryWithoutTopic(final DiaryCreateServiceRequest request, Member member) { return Diary.builder() .content(request.content()) .member(member) .build(); } - private Diary getDiaryWithTopic(DiaryCreateServiceRequest request, Member member) { + private Diary getDiaryWithTopic(final DiaryCreateServiceRequest request, Member member) { val topic = findTopic(request.topicId()); return Diary.builder() .content(request.content()) @@ -97,27 +113,27 @@ private Topic findTopic(long id) { .orElseThrow(() -> new TopicException(INVALID_TOPIC)); } - private List acquireBadgesByCreatingDiary(Member member, Diary diary) { + private List acquireBadgesByCreatingDiary(final Member member, final Diary diary) { val acquiredBadge = acquireBadge(member, diary); acquiredBadge.forEach(badge -> badgeService.saveMemberBadge(member, badge)); return acquiredBadge; } - private List acquireBadge(Member member, Diary diary) { + private List acquireBadge(final Member member, final Diary diary) { val badges = new ArrayList(); acquireBadgeByCountOfDiary(member, badges); acquireBadgeByComboCountOfDiary(member, diary, badges); return badges; } - private void acquireBadgeByCountOfDiary(Member member, List badges) { + private void acquireBadgeByCountOfDiary(final Member member, List badges) { val countingBadge = badgeService.getBadgeByCountOfDiary(member.getDiaries().size()); if (checkAcquiredBadge(member, countingBadge)) { badges.add(countingBadge); } } - private void acquireBadgeByComboCountOfDiary(Member member, Diary diary, List badges) { + private void acquireBadgeByComboCountOfDiary(final Member member, final Diary diary, List badges) { member.updateDiaryCombo(diary); val comboBadge = badgeService.getBadgeByComboCountOfDiary(member.getDiaryComboCount()); if (checkAcquiredBadge(member, comboBadge)) { @@ -125,37 +141,21 @@ private void acquireBadgeByComboCountOfDiary(Member member, Diary diary, List new DiaryException(INVALID_DIARY)); } - public void deleteDiary(DiaryDeleteServiceRequest request) { - val diary = findDiary(request.diaryId()); - moveToDeletedDairy(diary); - deleteDiary(diary); - } - - private void moveToDeletedDairy(Diary diary) { + private void moveToDeletedDairy(final Diary diary) { deletedDiaryRepository.save(new DeletedDiary(diary)); } - private void deleteDiary(Diary diary) { + private void deleteDiary(final Diary diary) { diary.deleteFromMember(); diaryRepository.deleteById(diary.getId()); } - - public void deleteAllByMember(Member member) { - diaryRepository.deleteAllByMember(member); - deletedDiaryRepository.deleteByMember(member); - } } diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryQueryService.java b/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryQueryService.java index 713d0fff..0be25e59 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryQueryService.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/DiaryQueryService.java @@ -29,22 +29,22 @@ public class DiaryQueryService { private final ValueConfig valueConfig; - public DiaryGetServiceResponse getDiaryDetail(DiaryGetServiceRequest request) { + public DiaryGetServiceResponse getDiaryDetail(final DiaryGetServiceRequest request) { val diary = findDiary(request.diaryId()); return DiaryGetServiceResponse.of(diary); } - private Diary findDiary(long id) { - return diaryRepository.findById(id) - .orElseThrow(() -> new DiaryException(INVALID_DIARY)); - } - - public DiaryListGetServiceResponse getDiaries(DiaryListGetServiceRequest request) { + public DiaryListGetServiceResponse getDiaries(final DiaryListGetServiceRequest request) { val member = findMember(request.memberId()); val diaries = member.getDiariesBetweenDate(request.startDate(), request.endDate()); return DiaryListGetServiceResponse.of(diaries, member, valueConfig); } + private Diary findDiary(long id) { + return diaryRepository.findById(id) + .orElseThrow(() -> new DiaryException(INVALID_DIARY)); + } + private Member findMember(long id) { return memberRepository.findById(id) .orElseThrow(() -> new MemberException(INVALID_MEMBER)); diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryCreateServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryCreateServiceResponse.java index b582e833..70b030ae 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryCreateServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryCreateServiceResponse.java @@ -14,6 +14,7 @@ public record DiaryCreateServiceResponse( long diaryId, List badges ) { + public static DiaryCreateServiceResponse of(Diary diary, List badges) { return DiaryCreateServiceResponse.builder() .diaryId(diary.getId()) diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryGetServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryGetServiceResponse.java index 737bfb5b..5e7c2811 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryGetServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryGetServiceResponse.java @@ -1,30 +1,35 @@ package com.smeem.api.diary.service.dto.response; import static java.util.Objects.*; +import static lombok.AccessLevel.PRIVATE; - -import com.smeem.common.util.Util; import com.smeem.domain.diary.model.Diary; -import lombok.AccessLevel; +import com.smeem.domain.topic.model.Topic; import lombok.Builder; -@Builder(access = AccessLevel.PRIVATE) +import java.time.LocalDateTime; + +@Builder(access = PRIVATE) public record DiaryGetServiceResponse( long diaryId, - String topic, + String topicContent, String content, - String createdAt, + LocalDateTime createdAt, String username ) { + public static DiaryGetServiceResponse of(Diary diary) { return DiaryGetServiceResponse.builder() .diaryId(diary.getId()) - .topic(nonNull(diary.getTopic()) ? diary.getTopic().getContent() : "") + .topicContent(getTopicContent(diary.getTopic())) .content(diary.getContent()) - .createdAt(Util.transferToLocalDateTime(diary.getCreatedAt())) + .createdAt(diary.getCreatedAt()) .username(diary.getMember().getUsername()) .build(); } + private static String getTopicContent(Topic topic) { + return nonNull(topic) ? topic.getContent() : ""; + } } diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryListGetServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryListGetServiceResponse.java index 9248b106..dbe4e126 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryListGetServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/response/DiaryListGetServiceResponse.java @@ -1,38 +1,40 @@ package com.smeem.api.diary.service.dto.response; import com.smeem.common.config.ValueConfig; -import com.smeem.common.util.Util; import com.smeem.domain.diary.model.Diary; import com.smeem.domain.member.model.Member; import lombok.Builder; +import java.time.LocalDateTime; import java.util.List; import static lombok.AccessLevel.PRIVATE; @Builder(access = PRIVATE) public record DiaryListGetServiceResponse( - List diaries, - boolean has30Past + List diaries, + boolean hasDiaryWrittenAgo ) { + public static DiaryListGetServiceResponse of(List diaries, Member member, ValueConfig valueConfig) { return DiaryListGetServiceResponse.builder() - .diaries(diaries.stream().map(DiaryResponse::of).toList()) - .has30Past(member.hasDiaryWrittenAgo(valueConfig.getDURATION_REMIND())) + .diaries(diaries.stream().map(DiaryServiceResponse::of).toList()) + .hasDiaryWrittenAgo(member.hasDiaryWrittenAgo(valueConfig.getDURATION_REMIND())) .build(); } @Builder(access = PRIVATE) - public record DiaryResponse( + public record DiaryServiceResponse( long diaryId, String content, - String createdAt + LocalDateTime createdAt ) { - public static DiaryResponse of(Diary diary) { - return DiaryResponse.builder() + + public static DiaryServiceResponse of(Diary diary) { + return DiaryServiceResponse.builder() .diaryId(diary.getId()) .content(diary.getContent()) - .createdAt(Util.transferToLocalDateTime(diary.getCreatedAt())) + .createdAt(diary.createdAt) .build(); } } diff --git a/smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java b/smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java index ffaff222..f414b14a 100644 --- a/smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java @@ -4,7 +4,8 @@ import com.smeem.api.common.BaseResponse; import com.smeem.api.goal.controller.dto.response.GoalGetResponse; -import com.smeem.api.goal.dto.request.GoalGetServiceRequest; +import com.smeem.api.goal.controller.dto.response.GoalListGetResponse; +import com.smeem.api.goal.service.dto.request.GoalGetServiceRequest; import com.smeem.api.goal.service.GoalService; import com.smeem.domain.goal.model.GoalType; import lombok.val; @@ -28,13 +29,13 @@ public class GoalController { @GetMapping public ResponseEntity> getAllGoals() { - val response = goalService.getAllGoals(); + val response = GoalListGetResponse.from(goalService.getAllGoals()); return ApiResponseUtil.success(SUCCESS_GET_GOALS, response); } @GetMapping("/{type}") public ResponseEntity> getGoalByType(@PathVariable GoalType type) { - val response = GoalGetResponse.of(goalService.getByType(GoalGetServiceRequest.of(type))); + val response = GoalGetResponse.from(goalService.getByType(GoalGetServiceRequest.of(type))); return ApiResponseUtil.success(SUCCESS_GET_GOAL, response); } } diff --git a/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalGetResponse.java b/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalGetResponse.java index a42cc4ef..9d28287e 100644 --- a/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalGetResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalGetResponse.java @@ -1,7 +1,6 @@ package com.smeem.api.goal.controller.dto.response; - -import com.smeem.api.goal.dto.response.GoalGetServiceResponse; +import com.smeem.api.goal.service.dto.response.GoalGetServiceResponse; import lombok.Builder; import static lombok.AccessLevel.PRIVATE; @@ -13,9 +12,9 @@ public record GoalGetResponse( String detail ) { - public static GoalGetResponse of(GoalGetServiceResponse response) { + public static GoalGetResponse from(GoalGetServiceResponse response) { return GoalGetResponse.builder() - .name(response.name()) + .name(response.goalType()) .way(response.way()) .detail(response.detail()) .build(); diff --git a/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalListGetResponse.java b/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalListGetResponse.java new file mode 100644 index 00000000..c6b001ba --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalListGetResponse.java @@ -0,0 +1,35 @@ +package com.smeem.api.goal.controller.dto.response; + +import com.smeem.api.goal.service.dto.response.GoalListGetServiceResponse; +import com.smeem.api.goal.service.dto.response.GoalListGetServiceResponse.GoalServiceResponse; +import lombok.Builder; + +import java.util.List; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record GoalListGetResponse( + List goals +) { + + public static GoalListGetResponse from(GoalListGetServiceResponse response) { + return GoalListGetResponse.builder() + .goals(response.goals().stream().map(GoalResponse::from).toList()) + .build(); + } + + @Builder(access = PRIVATE) + public record GoalResponse( + String goalType, + String name + ) { + + private static GoalResponse from(GoalServiceResponse response) { + return GoalResponse.builder() + .goalType(response.goalType()) + .name(response.goalDescription()) + .build(); + } + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalListResponse.java b/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalListResponse.java deleted file mode 100644 index 919a130a..00000000 --- a/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalListResponse.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.smeem.api.goal.controller.dto.response; - -import com.smeem.domain.goal.model.GoalType; - -import java.util.List; - - -public record GoalListResponse( - List goals -) { - public static GoalListResponse of(List goalTypes) { - return new GoalListResponse(goalTypes.stream().map(GoalResponseVO::of).toList()); - } - - public record GoalResponseVO( - String goalType, - String name - ) { - public static GoalResponseVO of(GoalType goalType) { - return new GoalResponseVO(goalType.name(), goalType.getDescription()); - } - } -} diff --git a/smeem-api/src/main/java/com/smeem/api/goal/service/GoalService.java b/smeem-api/src/main/java/com/smeem/api/goal/service/GoalService.java index 30b40c6f..55787cdd 100644 --- a/smeem-api/src/main/java/com/smeem/api/goal/service/GoalService.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/service/GoalService.java @@ -1,9 +1,9 @@ package com.smeem.api.goal.service; import java.util.List; -import com.smeem.api.goal.dto.request.GoalGetServiceRequest; -import com.smeem.api.goal.dto.response.GoalGetServiceResponse; -import com.smeem.api.goal.dto.response.GoalListGetServiceResponse; +import com.smeem.api.goal.service.dto.request.GoalGetServiceRequest; +import com.smeem.api.goal.service.dto.response.GoalGetServiceResponse; +import com.smeem.api.goal.service.dto.response.GoalListGetServiceResponse; import com.smeem.common.exception.GoalException; import com.smeem.domain.goal.model.Goal; import com.smeem.domain.goal.model.GoalType; @@ -28,7 +28,7 @@ public GoalListGetServiceResponse getAllGoals() { return GoalListGetServiceResponse.of(goalTypes); } - public GoalGetServiceResponse getByType(GoalGetServiceRequest request) { + public GoalGetServiceResponse getByType(final GoalGetServiceRequest request) { val goal = findGoal(request.goalType()); return GoalGetServiceResponse.of(goal); } diff --git a/smeem-api/src/main/java/com/smeem/api/goal/dto/request/GoalGetServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/goal/service/dto/request/GoalGetServiceRequest.java similarity index 89% rename from smeem-api/src/main/java/com/smeem/api/goal/dto/request/GoalGetServiceRequest.java rename to smeem-api/src/main/java/com/smeem/api/goal/service/dto/request/GoalGetServiceRequest.java index 5ff97973..28347aa2 100644 --- a/smeem-api/src/main/java/com/smeem/api/goal/dto/request/GoalGetServiceRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/service/dto/request/GoalGetServiceRequest.java @@ -1,4 +1,4 @@ -package com.smeem.api.goal.dto.request; +package com.smeem.api.goal.service.dto.request; import com.smeem.domain.goal.model.GoalType; import lombok.Builder; diff --git a/smeem-api/src/main/java/com/smeem/api/goal/dto/response/GoalGetServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/goal/service/dto/response/GoalGetServiceResponse.java similarity index 78% rename from smeem-api/src/main/java/com/smeem/api/goal/dto/response/GoalGetServiceResponse.java rename to smeem-api/src/main/java/com/smeem/api/goal/service/dto/response/GoalGetServiceResponse.java index abf0ad49..bf3c8584 100644 --- a/smeem-api/src/main/java/com/smeem/api/goal/dto/response/GoalGetServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/service/dto/response/GoalGetServiceResponse.java @@ -1,4 +1,4 @@ -package com.smeem.api.goal.dto.response; +package com.smeem.api.goal.service.dto.response; import com.smeem.domain.goal.model.Goal; import lombok.Builder; @@ -7,14 +7,14 @@ @Builder(access = PRIVATE) public record GoalGetServiceResponse( - String name, + String goalType, String way, String detail ) { public static GoalGetServiceResponse of(Goal goal) { return GoalGetServiceResponse.builder() - .name(goal.getType().name()) + .goalType(goal.getType().name()) .way(goal.getWay()) .detail(goal.getDetail()) .build(); diff --git a/smeem-api/src/main/java/com/smeem/api/goal/dto/response/GoalListGetServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/goal/service/dto/response/GoalListGetServiceResponse.java similarity index 55% rename from smeem-api/src/main/java/com/smeem/api/goal/dto/response/GoalListGetServiceResponse.java rename to smeem-api/src/main/java/com/smeem/api/goal/service/dto/response/GoalListGetServiceResponse.java index 0bfdd59b..84e77df2 100644 --- a/smeem-api/src/main/java/com/smeem/api/goal/dto/response/GoalListGetServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/service/dto/response/GoalListGetServiceResponse.java @@ -1,4 +1,4 @@ -package com.smeem.api.goal.dto.response; +package com.smeem.api.goal.service.dto.response; import com.smeem.domain.goal.model.GoalType; import lombok.Builder; @@ -9,25 +9,25 @@ @Builder(access = PRIVATE) public record GoalListGetServiceResponse( - List goals + List goals ) { public static GoalListGetServiceResponse of(List goalTypes) { return GoalListGetServiceResponse.builder() - .goals(goalTypes.stream().map(GoalResponse::of).toList()) + .goals(goalTypes.stream().map(GoalServiceResponse::of).toList()) .build(); } @Builder(access = PRIVATE) - public record GoalResponse( + public record GoalServiceResponse( String goalType, - String name + String goalDescription ) { - public static GoalResponse of(GoalType goalType) { - return GoalResponse.builder() + public static GoalServiceResponse of(GoalType goalType) { + return GoalServiceResponse.builder() .goalType(goalType.name()) - .name(goalType.getDescription()) + .goalDescription(goalType.getDescription()) .build(); } } diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java b/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java index faa7d7e2..1d56ff74 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java @@ -3,7 +3,7 @@ import com.smeem.api.badge.service.BadgeService; import com.smeem.api.badge.service.dto.response.BadgeServiceResponse; -import com.smeem.api.goal.dto.request.GoalGetServiceRequest; +import com.smeem.api.goal.service.dto.request.GoalGetServiceRequest; import com.smeem.api.goal.service.GoalService; import com.smeem.api.member.service.dto.request.MemberPushUpdateServiceRequest; import com.smeem.api.member.service.dto.request.MemberServiceUpdateUserProfileRequest; diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberGetServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberGetServiceResponse.java index bd4f1415..d7a7ec5d 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberGetServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberGetServiceResponse.java @@ -1,7 +1,7 @@ package com.smeem.api.member.service.dto.response; import com.smeem.api.badge.service.dto.response.BadgeServiceResponse; -import com.smeem.api.goal.dto.response.GoalGetServiceResponse; +import com.smeem.api.goal.service.dto.response.GoalGetServiceResponse; import com.smeem.domain.member.model.LangType; import com.smeem.domain.member.model.Member; import lombok.Builder; diff --git a/smeem-api/src/main/java/com/smeem/api/test/controller/TestController.java b/smeem-api/src/main/java/com/smeem/api/test/controller/TestController.java index 5f67a6bf..2c81c096 100644 --- a/smeem-api/src/main/java/com/smeem/api/test/controller/TestController.java +++ b/smeem-api/src/main/java/com/smeem/api/test/controller/TestController.java @@ -4,8 +4,8 @@ import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; -import com.smeem.api.test.dto.request.TestPushAlarmRequest; import com.smeem.api.test.service.TestService; +import com.smeem.api.test.service.dto.request.TestPushAlarmServiceRequest; import com.smeem.common.util.Util; import lombok.val; import org.springframework.http.ResponseEntity; @@ -33,8 +33,7 @@ public ResponseEntity> test() { @GetMapping("/alarm") public ResponseEntity> alarmTest(Principal principal) { val memberId = Util.getMemberId(principal); - val serviceRequest = TestPushAlarmRequest.of(memberId); - testService.pushTest(serviceRequest); + testService.pushTest(TestPushAlarmServiceRequest.of(memberId)); return ApiResponseUtil.success(SUCCESS_SEND_PUSH_ALARM); } } diff --git a/smeem-api/src/main/java/com/smeem/api/test/dto/request/TestPushAlarmRequest.java b/smeem-api/src/main/java/com/smeem/api/test/dto/request/TestPushAlarmRequest.java deleted file mode 100644 index 7e9d45e5..00000000 --- a/smeem-api/src/main/java/com/smeem/api/test/dto/request/TestPushAlarmRequest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.smeem.api.test.dto.request; - -import lombok.Builder; - -import static lombok.AccessLevel.PRIVATE; - -@Builder(access = PRIVATE) -public record TestPushAlarmRequest( - long memberId -) { - - public static TestPushAlarmRequest of(long memberId) { - return TestPushAlarmRequest.builder() - .memberId(memberId) - .build(); - } -} diff --git a/smeem-api/src/main/java/com/smeem/api/test/service/TestService.java b/smeem-api/src/main/java/com/smeem/api/test/service/TestService.java index bd229c41..6dd5933b 100644 --- a/smeem-api/src/main/java/com/smeem/api/test/service/TestService.java +++ b/smeem-api/src/main/java/com/smeem/api/test/service/TestService.java @@ -1,7 +1,6 @@ package com.smeem.api.test.service; - -import com.smeem.api.test.dto.request.TestPushAlarmRequest; +import com.smeem.api.test.service.dto.request.TestPushAlarmServiceRequest; import com.smeem.common.config.ValueConfig; import com.smeem.common.exception.MemberException; import com.smeem.domain.member.model.Member; @@ -24,7 +23,7 @@ public class TestService { private final FcmService fcmService; private final ValueConfig valueConfig; - public void pushTest(TestPushAlarmRequest request) { + public void pushTest(final TestPushAlarmServiceRequest request) { val member = findMember(request.memberId()); val title = valueConfig.getMESSAGE_TITLE(); val body = valueConfig.getMESSAGE_BODY(); diff --git a/smeem-api/src/main/java/com/smeem/api/test/service/dto/request/TestPushAlarmServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/test/service/dto/request/TestPushAlarmServiceRequest.java new file mode 100644 index 00000000..b0d3019b --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/test/service/dto/request/TestPushAlarmServiceRequest.java @@ -0,0 +1,17 @@ +package com.smeem.api.test.service.dto.request; + +import lombok.Builder; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record TestPushAlarmServiceRequest( + long memberId +) { + + public static TestPushAlarmServiceRequest of(long memberId) { + return TestPushAlarmServiceRequest.builder() + .memberId(memberId) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/topic/controller/TopicController.java b/smeem-api/src/main/java/com/smeem/api/topic/controller/TopicController.java index d4260a03..187a306d 100644 --- a/smeem-api/src/main/java/com/smeem/api/topic/controller/TopicController.java +++ b/smeem-api/src/main/java/com/smeem/api/topic/controller/TopicController.java @@ -2,6 +2,7 @@ import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; +import com.smeem.api.topic.controller.dto.response.RandomTopicGetResponse; import com.smeem.api.topic.service.TopicService; import lombok.val; import org.springframework.http.ResponseEntity; @@ -22,7 +23,7 @@ public class TopicController { @GetMapping("/random") public ResponseEntity> getTopicByRandom() { - val response = topicService.getTopicByRandom(); + val response = RandomTopicGetResponse.from(topicService.getTopicByRandom()); return ApiResponseUtil.success(SUCCESS_GET_RANDOM_TOPIC, response); } } diff --git a/smeem-api/src/main/java/com/smeem/api/topic/controller/dto/response/RandomTopicGetResponse.java b/smeem-api/src/main/java/com/smeem/api/topic/controller/dto/response/RandomTopicGetResponse.java new file mode 100644 index 00000000..3b310855 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/topic/controller/dto/response/RandomTopicGetResponse.java @@ -0,0 +1,20 @@ +package com.smeem.api.topic.controller.dto.response; + +import com.smeem.api.topic.service.dto.response.RandomTopicGetServiceResponse; +import lombok.Builder; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record RandomTopicGetResponse( + long topicId, + String content +) { + + public static RandomTopicGetResponse from(RandomTopicGetServiceResponse response) { + return RandomTopicGetResponse.builder() + .topicId(response.topicId()) + .content(response.content()) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/topic/service/TopicService.java b/smeem-api/src/main/java/com/smeem/api/topic/service/TopicService.java index 1596c52c..de4fe0f4 100644 --- a/smeem-api/src/main/java/com/smeem/api/topic/service/TopicService.java +++ b/smeem-api/src/main/java/com/smeem/api/topic/service/TopicService.java @@ -1,6 +1,6 @@ package com.smeem.api.topic.service; -import com.smeem.api.topic.dto.response.RandomTopicGetServiceResponse; +import com.smeem.api.topic.service.dto.response.RandomTopicGetServiceResponse; import com.smeem.domain.topic.repository.TopicRepository; import lombok.val; import org.springframework.stereotype.Service; diff --git a/smeem-api/src/main/java/com/smeem/api/topic/dto/response/RandomTopicGetServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/topic/service/dto/response/RandomTopicGetServiceResponse.java similarity index 90% rename from smeem-api/src/main/java/com/smeem/api/topic/dto/response/RandomTopicGetServiceResponse.java rename to smeem-api/src/main/java/com/smeem/api/topic/service/dto/response/RandomTopicGetServiceResponse.java index 64c49651..601c9e79 100644 --- a/smeem-api/src/main/java/com/smeem/api/topic/dto/response/RandomTopicGetServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/topic/service/dto/response/RandomTopicGetServiceResponse.java @@ -1,4 +1,4 @@ -package com.smeem.api.topic.dto.response; +package com.smeem.api.topic.service.dto.response; import com.smeem.domain.topic.model.Topic; import lombok.Builder; diff --git a/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java index d7cf06f8..506232ee 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/GoalControllerTest.java @@ -1,128 +1,128 @@ -package com.smeem.api.controller; - -import com.epages.restdocs.apispec.ResourceSnippetParameters; -import com.smeem.api.common.ApiResponseUtil; -import com.smeem.api.goal.controller.GoalController; -import com.smeem.api.goal.dto.response.GoalListGetServiceResponse.GoalResponse; -import com.smeem.api.goal.dto.response.GoalGetServiceResponse; -import com.smeem.api.goal.dto.response.GoalListGetServiceResponse; -import com.smeem.domain.goal.model.GoalType; -import lombok.val; -import org.springframework.boot.test.mock.mockito.MockBean; - -import java.security.Principal; -import java.util.ArrayList; -import java.util.List; - -import static com.epages.restdocs.apispec.ResourceDocumentation.resource; -import static com.smeem.common.code.success.GoalSuccessCode.SUCCESS_GET_GOAL; -import static com.smeem.common.code.success.GoalSuccessCode.SUCCESS_GET_GOALS; -import static com.smeem.domain.goal.model.GoalType.APPLY; -import static org.mockito.Mockito.when; -import static org.springframework.http.MediaType.APPLICATION_JSON; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; -import static org.springframework.restdocs.payload.JsonFieldType.*; -import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; -import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -//@DisplayName("GoalController 테스트") -//@WebMvcTest(GoalController.class) -class GoalControllerTest extends BaseControllerTest { - @MockBean - GoalController goalController; - @MockBean - Principal principal; - - private final String DEFAULT_URL = "/api/v2/goals"; - private final String TAG = "Goal"; - - // @Test -// @DisplayName("전체 학습 목표 조회 테스트") - void success_get_goals_test() throws Exception { - // given - val response = new GoalListGetServiceResponse(goals()); - val result = ApiResponseUtil.success(SUCCESS_GET_GOALS, response); - - // when - when(goalController.getAllGoals()).thenReturn(result); - - // then - mockMvc.perform(get(DEFAULT_URL) - .contentType(APPLICATION_JSON) - .accept(APPLICATION_JSON)) - .andDo( - document("전체 학습 목표 조회 성공 Example", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint()), - resource(ResourceSnippetParameters.builder() - .tag(TAG) - .description("전체 학습 목표 조회") - .responseFields( - fieldWithPath("success").type(BOOLEAN).description("응답 성공 여부"), - fieldWithPath("message").type(STRING).description("응답 메시지"), - fieldWithPath("data").type(OBJECT).description("응답 데이터"), - fieldWithPath("data.goals[]").type(ARRAY).description("학습 목표 리스트"), - fieldWithPath("data.goals[].goalType").type(STRING).description("학습 목표 ENUM 값"), - fieldWithPath("data.goals[].name").type(STRING).description("학습 목표 이름") - ) - .build() - ) - )) - .andExpect(status().isOk()); - } - - // @Test -// @DisplayName("학습 목표 조회 테스트") - void success_get_goal_test() throws Exception { - // given - GoalType type = APPLY; - val response = new GoalGetServiceResponse( - "현지 언어 체득", - "주 5회 이상 오늘 하루를 돌아보는 일기 작성하기", - "사전 없이 일기 완성\nsmeem 연속 일기 배지 획득"); - val result = ApiResponseUtil.success(SUCCESS_GET_GOAL, response); - - // when - when(goalController.getGoalByType(type)).thenReturn(result); - - // then - mockMvc.perform(get(DEFAULT_URL + "/{type}", type) - .contentType(APPLICATION_JSON) - .accept(APPLICATION_JSON)) - .andDo( - document("학습 목표 조회 성공 Example", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint()), - resource(ResourceSnippetParameters.builder() - .tag(TAG) - .description("전체 학습 목표 조회") - .pathParameters( - parameterWithName("type").description("학습 목표 ENUM 값") - ) - .responseFields( - fieldWithPath("success").type(BOOLEAN).description("응답 성공 여부"), - fieldWithPath("message").type(STRING).description("응답 메시지"), - fieldWithPath("data").type(OBJECT).description("응답 데이터"), - fieldWithPath("data.name").type(STRING).description("학습 목표 이름"), - fieldWithPath("data.way").type(STRING).description("학습 목표 방식"), - fieldWithPath("data.detail").type(STRING).description("학습 목표 내용") - ) - .build() - ) - )) - .andExpect(status().isOk()); - } - - private List goals() { - List goals = new ArrayList<>(); - for (int i = 0; i < 2; i++) { - goals.add(new GoalResponse(APPLY.name(), "현지 언어 체득" + (i + 1))); - } - return goals; - } - -} \ No newline at end of file +//package com.smeem.api.controller; +// +//import com.epages.restdocs.apispec.ResourceSnippetParameters; +//import com.smeem.api.common.ApiResponseUtil; +//import com.smeem.api.goal.controller.GoalController; +//import com.smeem.api.goal.service.dto.response.GoalListGetServiceResponse.GoalResponse; +//import com.smeem.api.goal.service.dto.response.GoalGetServiceResponse; +//import com.smeem.api.goal.service.dto.response.GoalListGetServiceResponse; +//import com.smeem.domain.goal.model.GoalType; +//import lombok.val; +//import org.springframework.boot.test.mock.mockito.MockBean; +// +//import java.security.Principal; +//import java.util.ArrayList; +//import java.util.List; +// +//import static com.epages.restdocs.apispec.ResourceDocumentation.resource; +//import static com.smeem.common.code.success.GoalSuccessCode.SUCCESS_GET_GOAL; +//import static com.smeem.common.code.success.GoalSuccessCode.SUCCESS_GET_GOALS; +//import static com.smeem.domain.goal.model.GoalType.APPLY; +//import static org.mockito.Mockito.when; +//import static org.springframework.http.MediaType.APPLICATION_JSON; +//import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +//import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*; +//import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; +//import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; +//import static org.springframework.restdocs.payload.JsonFieldType.*; +//import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +//import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +// +////@DisplayName("GoalController 테스트") +////@WebMvcTest(GoalController.class) +//class GoalControllerTest extends BaseControllerTest { +// @MockBean +// GoalController goalController; +// @MockBean +// Principal principal; +// +// private final String DEFAULT_URL = "/api/v2/goals"; +// private final String TAG = "Goal"; +// +// // @Test +//// @DisplayName("전체 학습 목표 조회 테스트") +// void success_get_goals_test() throws Exception { +// // given +// val response = new GoalListGetServiceResponse(goals()); +// val result = ApiResponseUtil.success(SUCCESS_GET_GOALS, response); +// +// // when +// when(goalController.getAllGoals()).thenReturn(result); +// +// // then +// mockMvc.perform(get(DEFAULT_URL) +// .contentType(APPLICATION_JSON) +// .accept(APPLICATION_JSON)) +// .andDo( +// document("전체 학습 목표 조회 성공 Example", +// preprocessRequest(prettyPrint()), +// preprocessResponse(prettyPrint()), +// resource(ResourceSnippetParameters.builder() +// .tag(TAG) +// .description("전체 학습 목표 조회") +// .responseFields( +// fieldWithPath("success").type(BOOLEAN).description("응답 성공 여부"), +// fieldWithPath("message").type(STRING).description("응답 메시지"), +// fieldWithPath("data").type(OBJECT).description("응답 데이터"), +// fieldWithPath("data.goals[]").type(ARRAY).description("학습 목표 리스트"), +// fieldWithPath("data.goals[].goalType").type(STRING).description("학습 목표 ENUM 값"), +// fieldWithPath("data.goals[].name").type(STRING).description("학습 목표 이름") +// ) +// .build() +// ) +// )) +// .andExpect(status().isOk()); +// } +// +// // @Test +//// @DisplayName("학습 목표 조회 테스트") +// void success_get_goal_test() throws Exception { +// // given +// GoalType type = APPLY; +// val response = new GoalGetServiceResponse( +// "현지 언어 체득", +// "주 5회 이상 오늘 하루를 돌아보는 일기 작성하기", +// "사전 없이 일기 완성\nsmeem 연속 일기 배지 획득"); +// val result = ApiResponseUtil.success(SUCCESS_GET_GOAL, response); +// +// // when +// when(goalController.getGoalByType(type)).thenReturn(result); +// +// // then +// mockMvc.perform(get(DEFAULT_URL + "/{type}", type) +// .contentType(APPLICATION_JSON) +// .accept(APPLICATION_JSON)) +// .andDo( +// document("학습 목표 조회 성공 Example", +// preprocessRequest(prettyPrint()), +// preprocessResponse(prettyPrint()), +// resource(ResourceSnippetParameters.builder() +// .tag(TAG) +// .description("전체 학습 목표 조회") +// .pathParameters( +// parameterWithName("type").description("학습 목표 ENUM 값") +// ) +// .responseFields( +// fieldWithPath("success").type(BOOLEAN).description("응답 성공 여부"), +// fieldWithPath("message").type(STRING).description("응답 메시지"), +// fieldWithPath("data").type(OBJECT).description("응답 데이터"), +// fieldWithPath("data.name").type(STRING).description("학습 목표 이름"), +// fieldWithPath("data.way").type(STRING).description("학습 목표 방식"), +// fieldWithPath("data.detail").type(STRING).description("학습 목표 내용") +// ) +// .build() +// ) +// )) +// .andExpect(status().isOk()); +// } +// +// private List goals() { +// List goals = new ArrayList<>(); +// for (int i = 0; i < 2; i++) { +// goals.add(new GoalResponse(APPLY.name(), "현지 언어 체득" + (i + 1))); +// } +// return goals; +// } +// +//} \ No newline at end of file diff --git a/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java index f0c2287a..04265072 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java @@ -3,7 +3,7 @@ import com.epages.restdocs.apispec.ResourceSnippetParameters; import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.topic.controller.TopicController; -import com.smeem.api.topic.dto.response.RandomTopicGetServiceResponse; +import com.smeem.api.topic.service.dto.response.RandomTopicGetServiceResponse; import lombok.val; import org.springframework.boot.test.mock.mockito.MockBean; diff --git a/smeem-api/src/test/java/com/smeem/api/fixture/goal/GoalFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/goal/GoalFixture.java index a9a9c4c7..b5a81d65 100644 --- a/smeem-api/src/test/java/com/smeem/api/fixture/goal/GoalFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/goal/GoalFixture.java @@ -1,7 +1,7 @@ package com.smeem.api.fixture.goal; -import com.smeem.api.goal.dto.response.GoalGetServiceResponse; +import com.smeem.api.goal.service.dto.response.GoalGetServiceResponse; import com.smeem.domain.goal.model.Goal; import com.smeem.domain.goal.model.GoalType; diff --git a/smeem-api/src/test/java/com/smeem/api/fixture/topic/TopicFixture.java b/smeem-api/src/test/java/com/smeem/api/fixture/topic/TopicFixture.java index 5eba7f17..d860a31f 100644 --- a/smeem-api/src/test/java/com/smeem/api/fixture/topic/TopicFixture.java +++ b/smeem-api/src/test/java/com/smeem/api/fixture/topic/TopicFixture.java @@ -1,7 +1,7 @@ package com.smeem.api.fixture.topic; -import com.smeem.api.topic.dto.response.RandomTopicGetServiceResponse; +import com.smeem.api.topic.service.dto.response.RandomTopicGetServiceResponse; import com.smeem.domain.topic.model.Category; import com.smeem.domain.topic.model.Topic; From 17d6460875562ab8d96e0b697f59694abc44f396 Mon Sep 17 00:00:00 2001 From: thguss Date: Tue, 20 Feb 2024 20:50:16 +0900 Subject: [PATCH 46/86] =?UTF-8?q?[REFACTOR]=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/service/dto/response/MemberGetServiceResponse.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberGetServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberGetServiceResponse.java index d7a7ec5d..4d8f76d4 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberGetServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberGetServiceResponse.java @@ -29,7 +29,7 @@ public static MemberGetServiceResponse of( ) { return MemberGetServiceResponse.builder() .username(member.getUsername()) - .target(goal.name()) + .target(goal.goalType()) .way(goal.way()) .detail(goal.detail()) .targetLangType(member.getTargetLang()) From c477caf4f57b7adfc645a1680ddede989b8010a9 Mon Sep 17 00:00:00 2001 From: thguss Date: Tue, 20 Feb 2024 21:03:27 +0900 Subject: [PATCH 47/86] =?UTF-8?q?[REFACTOR]=20domain:=20PROTECTED=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80,=20=EA=B8=B0=ED=83=80=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../code/failure/TrainingTimeFailureCode.java | 2 ++ .../com/smeem/common/config/ValueConfig.java | 2 ++ .../domain/diary/model/DeletedDiary.java | 4 ++- .../com/smeem/domain/diary/model/Diary.java | 24 +++++++------- .../repository/DeletedDiaryRepository.java | 1 - .../com/smeem/domain/goal/model/Goal.java | 4 ++- .../com/smeem/domain/goal/model/GoalType.java | 4 ++- .../smeem/domain/topic/model/Category.java | 4 ++- .../com/smeem/domain/topic/model/Topic.java | 4 ++- .../smeem/domain/training/model/DayType.java | 4 ++- .../domain/training/model/TrainingTime.java | 31 +++++++++++++------ 11 files changed, 56 insertions(+), 28 deletions(-) diff --git a/smeem-common/src/main/java/com/smeem/common/code/failure/TrainingTimeFailureCode.java b/smeem-common/src/main/java/com/smeem/common/code/failure/TrainingTimeFailureCode.java index 245077f5..9cc62648 100644 --- a/smeem-common/src/main/java/com/smeem/common/code/failure/TrainingTimeFailureCode.java +++ b/smeem-common/src/main/java/com/smeem/common/code/failure/TrainingTimeFailureCode.java @@ -15,6 +15,8 @@ public enum TrainingTimeFailureCode implements FailureCode { * 400 BAD REQUEST */ INVALID_DAY_OF_WEEK(BAD_REQUEST, "유효하지 않은 요일 값입니다."), + INVALID_HOUR(BAD_REQUEST, "시(hour)는 1 이상 24 이하이어야 합니다."), + INVALID_MINUTE(BAD_REQUEST, "분(minute)은 30분 단위이어야 합니다. (0 또는 30)"), /** * 404 NOT FOUND diff --git a/smeem-common/src/main/java/com/smeem/common/config/ValueConfig.java b/smeem-common/src/main/java/com/smeem/common/config/ValueConfig.java index 682a9a28..ee073164 100644 --- a/smeem-common/src/main/java/com/smeem/common/config/ValueConfig.java +++ b/smeem-common/src/main/java/com/smeem/common/config/ValueConfig.java @@ -45,6 +45,8 @@ public class ValueConfig { @Value("${smeem.duration.remind}") private int DURATION_REMIND; + public static final boolean DEFAULT_IS_PUBLIC_VALUE = true; + @PostConstruct protected void init() { JWT_SECRET = Base64.getEncoder().encodeToString(JWT_SECRET.getBytes(StandardCharsets.UTF_8)); diff --git a/smeem-domain/src/main/java/com/smeem/domain/diary/model/DeletedDiary.java b/smeem-domain/src/main/java/com/smeem/domain/diary/model/DeletedDiary.java index 9a68b45e..958a6db4 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/diary/model/DeletedDiary.java +++ b/smeem-domain/src/main/java/com/smeem/domain/diary/model/DeletedDiary.java @@ -9,9 +9,11 @@ import java.time.LocalDateTime; +import static lombok.AccessLevel.PROTECTED; + @Entity @Getter -@NoArgsConstructor +@NoArgsConstructor(access = PROTECTED) public class DeletedDiary { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/smeem-domain/src/main/java/com/smeem/domain/diary/model/Diary.java b/smeem-domain/src/main/java/com/smeem/domain/diary/model/Diary.java index 10a8d7b2..9f5451be 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/diary/model/Diary.java +++ b/smeem-domain/src/main/java/com/smeem/domain/diary/model/Diary.java @@ -1,6 +1,8 @@ package com.smeem.domain.diary.model; +import static com.smeem.common.config.ValueConfig.DEFAULT_IS_PUBLIC_VALUE; import static java.util.Objects.nonNull; +import static lombok.AccessLevel.PROTECTED; import com.smeem.domain.member.model.LangType; import com.smeem.domain.member.model.Member; @@ -12,7 +14,7 @@ import java.time.LocalDate; @Entity -@NoArgsConstructor +@NoArgsConstructor(access = PROTECTED) @Getter public class Diary extends BaseTimeEntity { @@ -42,7 +44,7 @@ public class Diary extends BaseTimeEntity { public Diary(String content, Topic topic, Member member) { this.content = content; this.targetLang = member.getTargetLang(); - this.isPublic = true; + this.isPublic = DEFAULT_IS_PUBLIC_VALUE; this.topic = topic; setMember(member); } @@ -51,18 +53,10 @@ public Diary(String content, Topic topic, Member member) { public Diary(String content, Member member) { this.content = content; this.targetLang = member.getTargetLang(); - this.isPublic = true; + this.isPublic = DEFAULT_IS_PUBLIC_VALUE; setMember(member); } - private void setMember(Member member) { - if (nonNull(this.member)) { - this.member.getDiaries().remove(this); - } - this.member = member; - member.getDiaries().add(this); - } - public void updateContent(String content) { this.content = content; } @@ -97,4 +91,12 @@ public boolean isBetween(LocalDate startDate, LocalDate endDate) { public boolean isCombo() { return this.member.getDiaries().stream().anyMatch(Diary::isWrittenYesterday); } + + private void setMember(Member member) { + if (nonNull(this.member)) { + this.member.getDiaries().remove(this); + } + this.member = member; + member.getDiaries().add(this); + } } diff --git a/smeem-domain/src/main/java/com/smeem/domain/diary/repository/DeletedDiaryRepository.java b/smeem-domain/src/main/java/com/smeem/domain/diary/repository/DeletedDiaryRepository.java index 02eb2caf..b228d6a8 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/diary/repository/DeletedDiaryRepository.java +++ b/smeem-domain/src/main/java/com/smeem/domain/diary/repository/DeletedDiaryRepository.java @@ -1,6 +1,5 @@ package com.smeem.domain.diary.repository; - import com.smeem.domain.diary.model.DeletedDiary; import com.smeem.domain.member.model.Member; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/smeem-domain/src/main/java/com/smeem/domain/goal/model/Goal.java b/smeem-domain/src/main/java/com/smeem/domain/goal/model/Goal.java index 7807017b..a80c9b23 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/goal/model/Goal.java +++ b/smeem-domain/src/main/java/com/smeem/domain/goal/model/Goal.java @@ -5,9 +5,11 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import static lombok.AccessLevel.PROTECTED; + @Entity @Getter -@NoArgsConstructor +@NoArgsConstructor(access = PROTECTED) public class Goal { @Id diff --git a/smeem-domain/src/main/java/com/smeem/domain/goal/model/GoalType.java b/smeem-domain/src/main/java/com/smeem/domain/goal/model/GoalType.java index b231ec80..ff080cd9 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/goal/model/GoalType.java +++ b/smeem-domain/src/main/java/com/smeem/domain/goal/model/GoalType.java @@ -3,7 +3,9 @@ import lombok.AllArgsConstructor; import lombok.Getter; -@AllArgsConstructor +import static lombok.AccessLevel.PROTECTED; + +@AllArgsConstructor(access = PROTECTED) @Getter public enum GoalType { DEVELOP("자기계발"), diff --git a/smeem-domain/src/main/java/com/smeem/domain/topic/model/Category.java b/smeem-domain/src/main/java/com/smeem/domain/topic/model/Category.java index f97a946c..a84f1253 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/topic/model/Category.java +++ b/smeem-domain/src/main/java/com/smeem/domain/topic/model/Category.java @@ -3,8 +3,10 @@ import lombok.AllArgsConstructor; import lombok.Getter; +import static lombok.AccessLevel.PROTECTED; + @Getter -@AllArgsConstructor +@AllArgsConstructor(access = PROTECTED) public enum Category { TRIP("여행"), TASTE("취향"), diff --git a/smeem-domain/src/main/java/com/smeem/domain/topic/model/Topic.java b/smeem-domain/src/main/java/com/smeem/domain/topic/model/Topic.java index 36a30ae0..d2529c3d 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/topic/model/Topic.java +++ b/smeem-domain/src/main/java/com/smeem/domain/topic/model/Topic.java @@ -5,8 +5,10 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import static lombok.AccessLevel.PROTECTED; + @Entity -@NoArgsConstructor +@NoArgsConstructor(access = PROTECTED) @Getter public class Topic { diff --git a/smeem-domain/src/main/java/com/smeem/domain/training/model/DayType.java b/smeem-domain/src/main/java/com/smeem/domain/training/model/DayType.java index fb744fe8..08f35a42 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/training/model/DayType.java +++ b/smeem-domain/src/main/java/com/smeem/domain/training/model/DayType.java @@ -3,7 +3,9 @@ import lombok.AllArgsConstructor; import lombok.Getter; -@AllArgsConstructor +import static lombok.AccessLevel.PROTECTED; + +@AllArgsConstructor(access = PROTECTED) @Getter public enum DayType { MON("월"), diff --git a/smeem-domain/src/main/java/com/smeem/domain/training/model/TrainingTime.java b/smeem-domain/src/main/java/com/smeem/domain/training/model/TrainingTime.java index 4fa1205f..f548a1f3 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/training/model/TrainingTime.java +++ b/smeem-domain/src/main/java/com/smeem/domain/training/model/TrainingTime.java @@ -1,8 +1,11 @@ package com.smeem.domain.training.model; +import static com.smeem.common.code.failure.TrainingTimeFailureCode.INVALID_HOUR; +import static com.smeem.common.code.failure.TrainingTimeFailureCode.INVALID_MINUTE; import static java.util.Objects.*; +import static lombok.AccessLevel.PROTECTED; - +import com.smeem.common.exception.TrainingTimeException; import com.smeem.domain.member.model.Member; import jakarta.persistence.*; import lombok.Builder; @@ -10,7 +13,7 @@ import lombok.NoArgsConstructor; @Entity -@NoArgsConstructor +@NoArgsConstructor(access = PROTECTED) @Getter public class TrainingTime { @@ -21,14 +24,8 @@ public class TrainingTime { @Enumerated(value = EnumType.STRING) private DayType day; - // TODO : validation -> 생성자에 validation method 직접 구현 - // @Min(value = 1, message = "시(hour)는 1 이상이어야 합니다.") - // @Max(value = 24, message = "시(hour)는 24 이하여야 합니다.") private int hour; - // TODO : validation -> 생성자에 validation method 직접 구현 - // @Min(value = 0, message = "분(minute)은 0 이상이어야 합니다.") - // @Max(value = 59, message = "분(minute)은 59 이하이어야 합니다.") private int minute; @ManyToOne(fetch = FetchType.LAZY) @@ -38,8 +35,8 @@ public class TrainingTime { @Builder public TrainingTime(DayType day, int hour, int minute, Member member) { this.day = day; - this.hour = hour; - this.minute = minute; + setHour(hour); + setMinute(minute); setMember(member); } @@ -50,4 +47,18 @@ private void setMember(Member member) { this.member = member; member.getTrainingTimes().add(this); } + + private void setHour(int hour) { + if (hour < 1 || hour > 24) { + throw new TrainingTimeException(INVALID_HOUR); + } + this.hour = hour; + } + + private void setMinute(int minute) { + if (minute != 0 && minute != 30) { + throw new TrainingTimeException(INVALID_MINUTE); + } + this.minute = minute; + } } \ No newline at end of file From c4d33d4ba3cf3ed71f53eb3c8eac193e3f358d3d Mon Sep 17 00:00:00 2001 From: thguss Date: Tue, 20 Feb 2024 21:22:39 +0900 Subject: [PATCH 48/86] =?UTF-8?q?[REFACTOR]=20external:=20DTO=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smeem/api/test/service/TestService.java | 3 +- .../batch/scheduler/MessageScheduler.java | 3 +- .../smeem/external/firebase/FcmService.java | 18 ++++--- .../external/firebase/MessageRequest.java | 46 ------------------ .../dto/request/MessagePushRequest.java | 47 +++++++++++++++++++ .../request/MessagePushServiceRequest.java | 21 +++++++++ 6 files changed, 80 insertions(+), 58 deletions(-) delete mode 100644 smeem-external/src/main/java/com/smeem/external/firebase/MessageRequest.java create mode 100644 smeem-external/src/main/java/com/smeem/external/firebase/dto/request/MessagePushRequest.java create mode 100644 smeem-external/src/main/java/com/smeem/external/firebase/dto/request/MessagePushServiceRequest.java diff --git a/smeem-api/src/main/java/com/smeem/api/test/service/TestService.java b/smeem-api/src/main/java/com/smeem/api/test/service/TestService.java index 6dd5933b..1a795486 100644 --- a/smeem-api/src/main/java/com/smeem/api/test/service/TestService.java +++ b/smeem-api/src/main/java/com/smeem/api/test/service/TestService.java @@ -6,6 +6,7 @@ import com.smeem.domain.member.model.Member; import com.smeem.domain.member.repository.MemberRepository; import com.smeem.external.firebase.FcmService; +import com.smeem.external.firebase.dto.request.MessagePushServiceRequest; import lombok.RequiredArgsConstructor; import lombok.val; import org.springframework.stereotype.Service; @@ -27,7 +28,7 @@ public void pushTest(final TestPushAlarmServiceRequest request) { val member = findMember(request.memberId()); val title = valueConfig.getMESSAGE_TITLE(); val body = valueConfig.getMESSAGE_BODY(); - fcmService.pushMessage(member.getFcmToken(), title, body); + fcmService.pushMessage(MessagePushServiceRequest.of(member.getFcmToken(), title, body)); } private Member findMember(long id) { diff --git a/smeem-batch/src/main/java/com/smeem/batch/scheduler/MessageScheduler.java b/smeem-batch/src/main/java/com/smeem/batch/scheduler/MessageScheduler.java index 29676d0f..2e2055ad 100644 --- a/smeem-batch/src/main/java/com/smeem/batch/scheduler/MessageScheduler.java +++ b/smeem-batch/src/main/java/com/smeem/batch/scheduler/MessageScheduler.java @@ -4,6 +4,7 @@ import com.smeem.domain.training.model.TrainingTime; import com.smeem.domain.training.repository.TrainingTimeRepository; import com.smeem.external.firebase.FcmService; +import com.smeem.external.firebase.dto.request.MessagePushServiceRequest; import lombok.RequiredArgsConstructor; import lombok.val; import org.springframework.scheduling.annotation.EnableScheduling; @@ -34,6 +35,6 @@ private void pushMessageForTrainingTime(TrainingTime trainingTime) { val fcmToken = trainingTime.getMember().getFcmToken(); val messageTitle = valueConfig.getMESSAGE_TITLE(); val messageBody = valueConfig.getMESSAGE_BODY(); - fcmService.pushMessage(fcmToken, messageTitle, messageBody); + fcmService.pushMessage(MessagePushServiceRequest.of(fcmToken, messageTitle, messageBody)); } } diff --git a/smeem-external/src/main/java/com/smeem/external/firebase/FcmService.java b/smeem-external/src/main/java/com/smeem/external/firebase/FcmService.java index 7482460e..d34e55e6 100644 --- a/smeem-external/src/main/java/com/smeem/external/firebase/FcmService.java +++ b/smeem-external/src/main/java/com/smeem/external/firebase/FcmService.java @@ -8,6 +8,8 @@ import com.smeem.common.config.ValueConfig; import com.smeem.common.exception.FcmException; +import com.smeem.external.firebase.dto.request.MessagePushRequest; +import com.smeem.external.firebase.dto.request.MessagePushServiceRequest; import lombok.val; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; @@ -31,28 +33,24 @@ public class FcmService { private final ObjectMapper objectMapper; private final ValueConfig valueConfig; - public void pushMessage(String targetToken, String title, String body) { + public void pushMessage(final MessagePushServiceRequest request) { try { - val message = makeMessage(targetToken, title, body); - val requestBody = RequestBody.create(message, MediaType.get("application/json; charset=utf-8")); - - val request = new Request.Builder() + val fcmRequest = new Request.Builder() .url(valueConfig.getFIREBASE_API_URI()) - .post(requestBody) + .post(RequestBody.create(makeMessage(request), MediaType.get("application/json; charset=utf-8"))) .addHeader(AUTHORIZATION, "Bearer " + getAccessToken()) .addHeader("Accept", "application/json; UTF-8") .build(); - val client = new OkHttpClient(); - client.newCall(request).execute(); + client.newCall(fcmRequest).execute(); } catch (Exception exception) { throw new FcmException(INVALID_REQUEST_MESSAGE); } } - private String makeMessage(String targetToken, String title, String body) { + private String makeMessage(MessagePushServiceRequest request) { try { - val message = MessageRequest.of(targetToken, title, body); + val message = MessagePushRequest.of(request); return objectMapper.writeValueAsString(message); } catch (JsonProcessingException exception) { throw new FcmException(INVALID_REQUEST_PATTERN); diff --git a/smeem-external/src/main/java/com/smeem/external/firebase/MessageRequest.java b/smeem-external/src/main/java/com/smeem/external/firebase/MessageRequest.java deleted file mode 100644 index bce4e6bc..00000000 --- a/smeem-external/src/main/java/com/smeem/external/firebase/MessageRequest.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.smeem.external.firebase; - -import lombok.Builder; - -import static lombok.AccessLevel.PRIVATE; - -@Builder(access = PRIVATE) -public record MessageRequest( - boolean validateOnly, - Message message -) { - public static MessageRequest of(String targetToken, String title, String body) { - return MessageRequest.builder() - .validateOnly(false) - .message(Message.of(title, body, targetToken)) - .build(); - } - - @Builder(access = PRIVATE) - record Message( - NotificationRequest notification, - String token - ) { - - private static Message of(String title, String body, String token) { - return Message.builder() - .notification(NotificationRequest.of(title, body)) - .token(token) - .build(); - } - } - - @Builder(access = PRIVATE) - record NotificationRequest( - String title, - String body - ) { - - private static NotificationRequest of(String title, String body) { - return NotificationRequest.builder() - .title(title) - .body(body) - .build(); - } - } -} diff --git a/smeem-external/src/main/java/com/smeem/external/firebase/dto/request/MessagePushRequest.java b/smeem-external/src/main/java/com/smeem/external/firebase/dto/request/MessagePushRequest.java new file mode 100644 index 00000000..aed9cea2 --- /dev/null +++ b/smeem-external/src/main/java/com/smeem/external/firebase/dto/request/MessagePushRequest.java @@ -0,0 +1,47 @@ +package com.smeem.external.firebase.dto.request; + +import lombok.Builder; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record MessagePushRequest( + boolean validateOnly, + MessageRequest message +) { + + public static MessagePushRequest of(MessagePushServiceRequest request) { + return MessagePushRequest.builder() + .validateOnly(false) + .message(MessageRequest.of(request)) + .build(); + } + + @Builder(access = PRIVATE) + record MessageRequest( + NotificationRequest notification, + String token + ) { + + private static MessageRequest of(MessagePushServiceRequest request) { + return MessageRequest.builder() + .notification(NotificationRequest.of(request)) + .token(request.targetToken()) + .build(); + } + } + + @Builder(access = PRIVATE) + record NotificationRequest( + String title, + String body + ) { + + private static NotificationRequest of(MessagePushServiceRequest request) { + return NotificationRequest.builder() + .title(request.title()) + .body(request.body()) + .build(); + } + } +} diff --git a/smeem-external/src/main/java/com/smeem/external/firebase/dto/request/MessagePushServiceRequest.java b/smeem-external/src/main/java/com/smeem/external/firebase/dto/request/MessagePushServiceRequest.java new file mode 100644 index 00000000..90551621 --- /dev/null +++ b/smeem-external/src/main/java/com/smeem/external/firebase/dto/request/MessagePushServiceRequest.java @@ -0,0 +1,21 @@ +package com.smeem.external.firebase.dto.request; + +import lombok.Builder; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record MessagePushServiceRequest( + String targetToken, + String title, + String body +) { + + public static MessagePushServiceRequest of(String token, String title, String body) { + return MessagePushServiceRequest.builder() + .targetToken(token) + .title(title) + .body(body) + .build(); + } +} From 90fb18dfb3321ee6cfb10e09d724fc2fee749e18 Mon Sep 17 00:00:00 2001 From: unanchoi Date: Tue, 20 Feb 2024 22:56:42 +0900 Subject: [PATCH 49/86] =?UTF-8?q?[REFACTOR]=202=EC=B0=A8=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/auth/controller/AuthController.java | 5 +++-- .../dto/response/SignInResponse.java | 17 +++++++++-------- .../com/smeem/api/auth/jwt/TokenProvider.java | 10 ++-------- .../dto/response/TokenServiceResponse.java | 8 ++++---- .../api/badge/controller/BadgeController.java | 4 ++-- .../dto/response/BadgeResponse.java | 1 - .../dto/response/MemberNameResponse.java | 9 ++++++++- .../dto/response/TrainingTimeResponse.java | 19 ++++++++++++++----- 8 files changed, 42 insertions(+), 31 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java b/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java index ec5ed8e3..9af1b785 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java @@ -10,6 +10,7 @@ import com.smeem.api.common.BaseResponse; import com.smeem.common.util.Util; import lombok.RequiredArgsConstructor; +import lombok.val; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -31,13 +32,13 @@ public class AuthController { @PostMapping public ResponseEntity> signIn(@RequestHeader("Authorization") String socialAccessToken, @RequestBody SignInRequest request) throws NoSuchAlgorithmException, InvalidKeySpecException { - SignInResponse response = SignInResponse.of(authService.signIn(socialAccessToken, SignInServiceRequest.of(request))); + val response = SignInResponse.of(authService.signIn(socialAccessToken, SignInServiceRequest.of(request))); return ApiResponseUtil.success(SUCCESS_SIGNIN, response); } @PostMapping("/token") public ResponseEntity> reissueToken(Principal principal) { - TokenResponse response = TokenResponse.of(tokenService.issueToken(Util.getMemberId(principal))); + val response = TokenResponse.of(tokenService.issueToken(Util.getMemberId(principal))); return ApiResponseUtil.success(SUCCESS_ISSUE_TOKEN, response); } diff --git a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponse.java b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponse.java index ae1ee3a0..a0428e38 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponse.java @@ -1,12 +1,13 @@ package com.smeem.api.auth.controller.dto.response; -import com.smeem.api.auth.jwt.SmeemToken; import com.smeem.api.auth.service.dto.response.SignInServiceResponse; import lombok.Builder; +import static lombok.AccessLevel.PRIVATE; -@Builder + +@Builder(access = PRIVATE) public record SignInResponse( String accessToken, String refreshToken, @@ -15,11 +16,11 @@ public record SignInResponse( ) { public static SignInResponse of(SignInServiceResponse response) { - return new SignInResponse( - response.accessToken(), - response.refreshToken(), - response.isRegistered(), - response.hasPlan()); + return SignInResponse.builder() + .accessToken(response.accessToken()) + .refreshToken(response.refreshToken()) + .isRegistered(response.isRegistered()) + .hasPlan(response.hasPlan()) + .build(); } - } diff --git a/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenProvider.java b/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenProvider.java index 0bc11b43..5ce393a8 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenProvider.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenProvider.java @@ -1,22 +1,16 @@ package com.smeem.api.auth.jwt; -import com.smeem.common.config.ValueConfig; -import com.smeem.common.exception.AuthException; -import io.jsonwebtoken.*; -import io.jsonwebtoken.security.Keys; +import io.jsonwebtoken.Header; +import io.jsonwebtoken.Jwts; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import lombok.val; import org.springframework.security.core.Authentication; import org.springframework.stereotype.Component; -import javax.crypto.SecretKey; import java.util.Date; -import static com.smeem.api.auth.jwt.JwtValidationType.*; -import static java.util.Base64.getEncoder; - @Slf4j @Component @RequiredArgsConstructor diff --git a/smeem-api/src/main/java/com/smeem/api/auth/service/dto/response/TokenServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/auth/service/dto/response/TokenServiceResponse.java index fc94a920..faf8d095 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/service/dto/response/TokenServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/service/dto/response/TokenServiceResponse.java @@ -13,9 +13,9 @@ public record TokenServiceResponse( ) { public static TokenServiceResponse of(SmeemToken token) { - return new TokenServiceResponse( - token.getAccessToken(), - token.getRefreshToken() - ); + return TokenServiceResponse.builder() + .accessToken(token.getAccessToken()) + .refreshToken(token.getRefreshToken()) + .build(); } } diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java index 84ec42fb..44d1c872 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java @@ -1,11 +1,11 @@ package com.smeem.api.badge.controller; -import com.smeem.api.badge.controller.dto.response.BadgeListResponse; import com.smeem.api.badge.service.BadgeService; import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; import com.smeem.common.util.Util; import lombok.RequiredArgsConstructor; +import lombok.val; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -24,7 +24,7 @@ public class BadgeController { @GetMapping public ResponseEntity> getBadges(Principal principal) { - BadgeListResponse response = badgeService.getBadges(Util.getMemberId(principal)); + val response = badgeService.getBadges(Util.getMemberId(principal)); return ApiResponseUtil.success(SUCCESS_GET_BADGES, response); } diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponse.java index 4093850d..1dd81452 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponse.java @@ -1,7 +1,6 @@ package com.smeem.api.badge.controller.dto.response; import com.smeem.api.badge.service.dto.response.BadgeServiceResponse; -import com.smeem.domain.badge.model.Badge; import lombok.AccessLevel; import lombok.Builder; diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponse.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponse.java index 4bc959f5..c6439983 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponse.java @@ -1,13 +1,20 @@ package com.smeem.api.member.controller.dto.response; import com.smeem.api.member.service.dto.response.MemberNameServiceResponse; +import lombok.AccessLevel; +import lombok.Builder; +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) public record MemberNameResponse( boolean isExist ) { public static MemberNameResponse of(MemberNameServiceResponse response) { - return new MemberNameResponse(response.isExist()); + return MemberNameResponse.builder() + .isExist(response.isExist()) + .build(); } } diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponse.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponse.java index f95a13f2..93c4b2ff 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponse.java @@ -1,12 +1,21 @@ package com.smeem.api.member.controller.dto.response; import com.smeem.api.member.service.dto.response.TrainingTimeServiceResponse; +import lombok.Builder; -public record TrainingTimeResponse(String day, int hour, int minute) { +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record TrainingTimeResponse( + String day, + int hour, + int minute +) { public static TrainingTimeResponse of(TrainingTimeServiceResponse response) { - return new TrainingTimeResponse( - response.day(), - response.hour(), - response.minute()); + return TrainingTimeResponse.builder() + .day(response.day()) + .hour(response.hour()) + .minute(response.minute()) + .build(); } } From 56cc7395e15039daf3bece19d35bfa23e88a4440 Mon Sep 17 00:00:00 2001 From: unanchoi Date: Fri, 23 Feb 2024 01:30:50 +0900 Subject: [PATCH 50/86] =?UTF-8?q?[REFACTOR]=20DTO=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/auth/controller/AuthController.java | 6 +- .../dto/response/SignInResponse.java | 2 +- .../dto/response/token/TokenResponse.java | 2 +- .../smeem/api/auth/service/AuthService.java | 4 +- .../dto/response/AcquiredBadgeResponse.java | 2 +- .../dto/response/BadgeBaseResponse.java | 22 +++++++ .../dto/response/BadgeListResponse.java | 59 ++----------------- .../dto/response/BadgeResponse.java | 2 +- .../dto/response/BadgeTypeResponse.java | 30 ++++++++++ .../smeem/api/badge/service/BadgeService.java | 13 ++-- .../response/BadgeBaseServiceResponse.java | 36 +++++++++++ .../response/BadgeListServiceResponse.java | 25 +++++++- .../response/BadgeTypeServiceResponse.java | 38 ++++++++++++ .../dto/response/DiaryCreateResponse.java | 2 +- .../member/controller/MemberController.java | 2 +- .../controller/dto/UsernameValidator.java | 4 +- .../dto/response/MemberGetResponse.java | 6 +- .../dto/response/MemberNameResponse.java | 2 +- .../dto/response/MemberUpdateResponse.java | 4 +- .../dto/response/TrainingTimeResponse.java | 2 +- .../member/service/MemberBadgeService.java | 3 +- .../api/member/service/MemberService.java | 2 +- 22 files changed, 187 insertions(+), 81 deletions(-) create mode 100644 smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeBaseResponse.java create mode 100644 smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeTypeResponse.java create mode 100644 smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeBaseServiceResponse.java create mode 100644 smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeTypeServiceResponse.java diff --git a/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java b/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java index 9af1b785..4fc4ee7a 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java @@ -30,15 +30,15 @@ public class AuthController { private final TokenService tokenService; @PostMapping - public ResponseEntity> signIn(@RequestHeader("Authorization") String socialAccessToken, + public ResponseEntity> signIn(@RequestHeader("Authorization") final String socialAccessToken, @RequestBody SignInRequest request) throws NoSuchAlgorithmException, InvalidKeySpecException { - val response = SignInResponse.of(authService.signIn(socialAccessToken, SignInServiceRequest.of(request))); + val response = SignInResponse.from(authService.signIn(socialAccessToken, SignInServiceRequest.of(request))); return ApiResponseUtil.success(SUCCESS_SIGNIN, response); } @PostMapping("/token") public ResponseEntity> reissueToken(Principal principal) { - val response = TokenResponse.of(tokenService.issueToken(Util.getMemberId(principal))); + val response = TokenResponse.from(tokenService.issueToken(Util.getMemberId(principal))); return ApiResponseUtil.success(SUCCESS_ISSUE_TOKEN, response); } diff --git a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponse.java b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponse.java index a0428e38..a6436ca6 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponse.java @@ -15,7 +15,7 @@ public record SignInResponse( boolean hasPlan ) { - public static SignInResponse of(SignInServiceResponse response) { + public static SignInResponse from(SignInServiceResponse response) { return SignInResponse.builder() .accessToken(response.accessToken()) .refreshToken(response.refreshToken()) diff --git a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenResponse.java b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenResponse.java index fda6586f..d3fe80ae 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenResponse.java @@ -10,7 +10,7 @@ public record TokenResponse( String refreshToken ) { - public static TokenResponse of(TokenServiceResponse response) { + public static TokenResponse from(TokenServiceResponse response) { return TokenResponse.builder() .accessToken(response.accessToken()) .refreshToken(response.refreshToken()) diff --git a/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java b/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java index 430f3e04..0dc5d0a3 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java @@ -58,13 +58,13 @@ public SignInServiceResponse signIn(final String socialAccessToken, final SignIn @Transactional public void signOut(final long memberId) { - Member member = get(memberId); + val member = get(memberId); member.updateRefreshToken(null); } @Transactional public void withdraw(final long memberId) { - Member member = get(memberId); + val member = get(memberId); diaryService.deleteAllByMember(member); trainingTimeService.deleteAllByMember(member); memberBadgeService.deleteAllByMember(member); diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/AcquiredBadgeResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/AcquiredBadgeResponse.java index 8a95dedf..3550c176 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/AcquiredBadgeResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/AcquiredBadgeResponse.java @@ -11,7 +11,7 @@ public record AcquiredBadgeResponse( String imageUrl, BadgeType type ) { - public static AcquiredBadgeResponse of(AcquiredBadgeServiceResponse response) { + public static AcquiredBadgeResponse from(AcquiredBadgeServiceResponse response) { return AcquiredBadgeResponse.builder() .name(response.name()) .imageUrl(response.imageUrl()) diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeBaseResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeBaseResponse.java new file mode 100644 index 00000000..f263e082 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeBaseResponse.java @@ -0,0 +1,22 @@ +package com.smeem.api.badge.controller.dto.response; + +import com.smeem.api.badge.service.dto.response.BadgeBaseServiceResponse; +import com.smeem.domain.badge.model.BadgeType; +import lombok.AccessLevel; +import lombok.Builder; + +@Builder(access = AccessLevel.PRIVATE) +public record BadgeBaseResponse( + String name, + BadgeType type, + String imageUrl +) { + + public static BadgeBaseResponse from(BadgeBaseServiceResponse response) { + return BadgeBaseResponse.builder() + .name(response.name()) + .imageUrl(response.imageUrl()) + .type(response.type()) + .build(); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponse.java index 0b1e40f3..d47a830b 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponse.java @@ -8,62 +8,15 @@ import java.util.List; import java.util.Map; +@Builder(access = AccessLevel.PRIVATE) public record BadgeListResponse( List badgeTypes ) { - public static BadgeListResponse of(Map> badgeMap, List memberBadges) { - val badgeTypes = getBadgesType(badgeMap, memberBadges); - return new BadgeListResponse(badgeTypes); - } - - private static List getBadgesType(Map> badgeMap, List memberBadges) { - return badgeMap.keySet().stream() - .map(type -> BadgeTypeResponse.of(type, badgeMap.get(type), memberBadges)) - .toList(); - } - - @Builder - public record BadgeTypeResponse( - BadgeType badgeType, - String badgeTypeName, - List badges + public static BadgeListResponse from( + List response ) { - public static BadgeTypeResponse of(BadgeType type, List badges, List memberBadges) { - return BadgeTypeResponse.builder() - .badgeType(type) - .badgeTypeName(type.getDescription()) - .badges(getBadges(badges, memberBadges)) - .build(); - } - - private static List getBadges(List badges, List memberBadges) { - return badges.stream() - .map(badge -> BadgeResponseDTO.of(badge, memberBadges)) - .toList(); - } - } - - @Builder - public record BadgeResponseDTO( - String name, - BadgeType type, - String imageUrl - ) { - - private static BadgeResponseDTO of(Badge badge, List memberBadges) { - return BadgeResponseDTO.builder() - .name(badge.getName()) - .type(badge.getType()) - .imageUrl(getImageUrl(badge, memberBadges)) - .build(); - } - - private static String getImageUrl(Badge badge, List memberBadges) { - return hasBadge(badge, memberBadges) ? badge.getBadgeImage().getImageUrl() : badge.getBadgeImage().getGrayImageUrl(); - } - - private static boolean hasBadge(Badge badge, List memberBadges) { - return memberBadges.stream().anyMatch(memberBadge -> memberBadge.getBadge().equals(badge)); - } + return BadgeListResponse.builder() + .badgeTypes(response) + .build(); } } \ No newline at end of file diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponse.java index 1dd81452..597fc313 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponse.java @@ -12,7 +12,7 @@ public record BadgeResponse( String imageUrl ) { - public static BadgeResponse of(BadgeServiceResponse response) { + public static BadgeResponse from(BadgeServiceResponse response) { return new BadgeResponse( response.id(), response.name(), diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeTypeResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeTypeResponse.java new file mode 100644 index 00000000..499647ff --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeTypeResponse.java @@ -0,0 +1,30 @@ +package com.smeem.api.badge.controller.dto.response; + +import com.smeem.api.badge.service.dto.response.BadgeBaseServiceResponse; +import com.smeem.api.badge.service.dto.response.BadgeTypeServiceResponse; +import com.smeem.domain.badge.model.Badge; +import com.smeem.domain.badge.model.BadgeType; +import com.smeem.domain.member.model.MemberBadge; +import lombok.Builder; + +import java.util.List; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record BadgeTypeResponse( + BadgeType badgeType, + String badgeTypeName, + List badges +) { + public static BadgeTypeResponse from(BadgeTypeServiceResponse response) { + return BadgeTypeResponse.builder() + .badgeType(response.badgeType()) + .badgeTypeName(response.badgeTypeName()) + .badges(response.badges() + .stream() + .map(BadgeBaseResponse::from) + .toList()) + .build(); + } +} \ No newline at end of file diff --git a/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java b/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java index e21d9a6b..99a82b5a 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java @@ -1,6 +1,7 @@ package com.smeem.api.badge.service; import com.smeem.api.badge.controller.dto.response.BadgeListResponse; +import com.smeem.api.badge.service.dto.response.BadgeListServiceResponse; import com.smeem.common.exception.BadgeException; import com.smeem.domain.badge.model.Badge; import com.smeem.domain.badge.model.BadgeType; @@ -29,25 +30,25 @@ public class BadgeService { private final BadgeRepository badgeRepository; @Transactional - public void saveMemberBadge(Member member, Badge badge) { + public void saveMemberBadge(final Member member, final Badge badge) { memberBadgeRepository.save(MemberBadge.builder() .member(member) .badge(badge) .build()); } - public BadgeListResponse getBadges(final long memberId) { + public BadgeListServiceResponse getBadges(final long memberId) { val badges = badgeRepository.findAllOrderById(); val badgeMap = classifiedByType(badges); val memberBadges = memberBadgeRepository.findAllByMemberId(memberId); - return BadgeListResponse.of(badgeMap, memberBadges); + return BadgeListServiceResponse.of(badgeMap, memberBadges); } - public Badge get(Long id) { + public Badge get(final long id) { return badgeRepository.findById(id) .orElseThrow(() -> new BadgeException(INVALID_BADGE)); } - public Badge getBadgeByCountOfDiary(int diaryCount) { + public Badge getBadgeByCountOfDiary(final int diaryCount) { return switch (diaryCount) { case 50 -> get(5L); case 30 -> get(4L); @@ -57,7 +58,7 @@ public Badge getBadgeByCountOfDiary(int diaryCount) { }; } - public Badge getBadgeByComboCountOfDiary(int diaryComboCount) { + public Badge getBadgeByComboCountOfDiary(final int diaryComboCount) { return switch (diaryComboCount) { case 30 -> get(9L); case 15 -> get(8L); diff --git a/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeBaseServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeBaseServiceResponse.java new file mode 100644 index 00000000..2995fca5 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeBaseServiceResponse.java @@ -0,0 +1,36 @@ +package com.smeem.api.badge.service.dto.response; + +import com.smeem.api.badge.controller.dto.response.BadgeListResponse; +import com.smeem.domain.badge.model.Badge; +import com.smeem.domain.badge.model.BadgeType; +import com.smeem.domain.member.model.MemberBadge; +import lombok.AccessLevel; +import lombok.Builder; + +import java.util.List; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record BadgeBaseServiceResponse( + String name, + BadgeType type, + String imageUrl +) { + + public static BadgeBaseServiceResponse of(Badge badge, List memberBadges) { + return BadgeBaseServiceResponse.builder() + .name(badge.getName()) + .type(badge.getType()) + .imageUrl(getImageUrl(badge, memberBadges)) + .build(); + } + + private static String getImageUrl(Badge badge, List memberBadges) { + return hasBadge(badge, memberBadges) ? badge.getBadgeImage().getImageUrl() : badge.getBadgeImage().getGrayImageUrl(); + } + + private static boolean hasBadge(Badge badge, List memberBadges) { + return memberBadges.stream().anyMatch(memberBadge -> memberBadge.getBadge().equals(badge)); + } +} diff --git a/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeListServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeListServiceResponse.java index 60adcfc1..c851b4b4 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeListServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeListServiceResponse.java @@ -1,10 +1,33 @@ package com.smeem.api.badge.service.dto.response; +import com.smeem.api.badge.controller.dto.response.BadgeListResponse; +import com.smeem.api.badge.controller.dto.response.BadgeTypeResponse; +import com.smeem.domain.badge.model.Badge; +import com.smeem.domain.badge.model.BadgeType; +import com.smeem.domain.member.model.MemberBadge; import lombok.Builder; +import lombok.val; + +import java.util.List; +import java.util.Map; import static lombok.AccessLevel.*; @Builder(access = PRIVATE) -public class BadgeListServiceResponse { +public record BadgeListServiceResponse( + List badgeTypes +) { + public static BadgeListServiceResponse of(Map> badgeMap, List memberBadges) { + val badgeTypes = getBadgesType(badgeMap, memberBadges); + return BadgeListServiceResponse.builder() + .badgeTypes(badgeTypes) + .build(); + } + + private static List getBadgesType(Map> badgeMap, List memberBadges) { + return badgeMap.keySet().stream() + .map(type -> BadgeTypeServiceResponse.of(type, badgeMap.get(type), memberBadges)) + .toList(); + } } diff --git a/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeTypeServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeTypeServiceResponse.java new file mode 100644 index 00000000..eb7bc0df --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeTypeServiceResponse.java @@ -0,0 +1,38 @@ +package com.smeem.api.badge.service.dto.response; + +import com.smeem.api.badge.controller.dto.response.BadgeBaseResponse; +import com.smeem.domain.badge.model.Badge; +import com.smeem.domain.badge.model.BadgeType; +import com.smeem.domain.member.model.MemberBadge; +import lombok.AccessLevel; +import lombok.Builder; + +import java.util.List; + +@Builder(access = AccessLevel.PRIVATE) +public record BadgeTypeServiceResponse( + BadgeType badgeType, + String badgeTypeName, + List badges +) { + public static BadgeTypeServiceResponse of( + BadgeType type, + List badges, + List memberBadges) { + return BadgeTypeServiceResponse.builder() + .badgeType(type) + .badgeTypeName(type.getDescription()) + .badges(getBadges(badges, memberBadges)) + .build(); + } + + private static List getBadges( + List badges, + List memberBadges + ) { + return badges.stream() + .map(badge -> BadgeBaseServiceResponse.of(badge, memberBadges)) + .toList(); + } + +} diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryCreateResponse.java b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryCreateResponse.java index a2e0897f..c06ee419 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryCreateResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryCreateResponse.java @@ -17,7 +17,7 @@ public record DiaryCreateResponse( public static DiaryCreateResponse from(DiaryCreateServiceResponse response) { return DiaryCreateResponse.builder() .diaryId(response.diaryId()) - .badges(response.badges().stream().map(AcquiredBadgeResponse::of).toList()) + .badges(response.badges().stream().map(AcquiredBadgeResponse::from).toList()) .build(); } } diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java b/smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java index d51e0294..bbeb41fe 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java @@ -51,7 +51,7 @@ public ResponseEntity> updateUserPlan(Principal principal, @Vali @GetMapping("/nickname/check") public ResponseEntity> checkDuplicatedName(@Parameter(description = "유저 닉네임") @RequestParam String name) { - val response = MemberNameResponse.of(memberService.checkDuplicatedName(name)); + val response = MemberNameResponse.from(memberService.checkDuplicatedName(name)); return ApiResponseUtil.success(SUCCESS_CHECK_DUPLICATED_NAME, response); } diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/UsernameValidator.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/UsernameValidator.java index 622b59a2..02246005 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/UsernameValidator.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/UsernameValidator.java @@ -3,6 +3,8 @@ import jakarta.validation.ConstraintValidator; import jakarta.validation.ConstraintValidatorContext; +import java.util.Objects; + public class UsernameValidator implements ConstraintValidator { @Override @@ -19,6 +21,6 @@ public boolean isValid(String username, ConstraintValidatorContext context) { } // 첫 글자가 공백인 경우 - return !(username.charAt(0) == ' '); + return !(Objects.equals(username.charAt(0),' ')); } } \ No newline at end of file diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponse.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponse.java index 397c8d7a..b8e8ee89 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponse.java @@ -18,7 +18,7 @@ public record MemberGetResponse( BadgeResponse badge ) { - public static MemberGetResponse of(MemberGetServiceResponse response) { + public static MemberGetResponse from(MemberGetServiceResponse response) { return MemberGetResponse.builder() .username(response.username()) .target(response.target()) @@ -26,8 +26,8 @@ public static MemberGetResponse of(MemberGetServiceResponse response) { .detail(response.detail()) .targetLang(response.targetLangType().toString()) .hasPushAlarm(response.hasPushAlarm()) - .trainingTime(TrainingTimeResponse.of(response.trainingTime())) - .badge(BadgeResponse.of(response.badge())) + .trainingTime(TrainingTimeResponse.from(response.trainingTime())) + .badge(BadgeResponse.from(response.badge())) .build(); } } diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponse.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponse.java index c6439983..607c7942 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponse.java @@ -11,7 +11,7 @@ public record MemberNameResponse( boolean isExist ) { - public static MemberNameResponse of(MemberNameServiceResponse response) { + public static MemberNameResponse from(MemberNameServiceResponse response) { return MemberNameResponse.builder() .isExist(response.isExist()) .build(); diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberUpdateResponse.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberUpdateResponse.java index 743ee3ad..4cf15c4c 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberUpdateResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberUpdateResponse.java @@ -13,12 +13,12 @@ public record MemberUpdateResponse( List badges ) { - public static MemberUpdateResponse of( + public static MemberUpdateResponse from( MemberUpdateServiceResponse response ) { return MemberUpdateResponse .builder() - .badges(response.badges().stream().map(AcquiredBadgeResponse::of).toList()) + .badges(response.badges().stream().map(AcquiredBadgeResponse::from).toList()) .build(); } } diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponse.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponse.java index 93c4b2ff..259bc8b9 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponse.java @@ -11,7 +11,7 @@ public record TrainingTimeResponse( int hour, int minute ) { - public static TrainingTimeResponse of(TrainingTimeServiceResponse response) { + public static TrainingTimeResponse from(TrainingTimeServiceResponse response) { return TrainingTimeResponse.builder() .day(response.day()) .hour(response.hour()) diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/MemberBadgeService.java b/smeem-api/src/main/java/com/smeem/api/member/service/MemberBadgeService.java index 1df8a4bc..8189f754 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/MemberBadgeService.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/MemberBadgeService.java @@ -7,6 +7,7 @@ import com.smeem.domain.member.model.MemberBadge; import com.smeem.domain.member.repository.MemberBadgeRepository; import lombok.RequiredArgsConstructor; +import lombok.val; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -26,7 +27,7 @@ public void deleteAllByMember(Member member) { @Transactional public void save(Member member, Badge badge) { - MemberBadge memberBadge = MemberBadge.builder() + val memberBadge = MemberBadge.builder() .member(member) .badge(badge) .build(); diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java b/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java index 1d56ff74..c6e4e9ad 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java @@ -106,7 +106,7 @@ public void updateHasAlarm(final long memberId, final MemberPushUpdateServiceReq } public MemberNameServiceResponse checkDuplicatedName(final String name) { - boolean isExist = memberRepository.existsByUsername(name); + val isExist = memberRepository.existsByUsername(name); return MemberNameServiceResponse.of(isExist); } From c7a9e26f90f6670688db6f4517ab8b9ec76e8c4b Mon Sep 17 00:00:00 2001 From: unanchoi Date: Fri, 23 Feb 2024 01:37:46 +0900 Subject: [PATCH 51/86] =?UTF-8?q?[REFACTOR]=20=ED=8C=8C=EB=9D=BC=EB=AF=B8?= =?UTF-8?q?=ED=84=B0=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20import=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/smeem/api/auth/service/AuthService.java | 2 +- .../main/java/com/smeem/api/badge/service/BadgeService.java | 1 - .../badge/service/dto/response/BadgeBaseServiceResponse.java | 2 -- .../badge/service/dto/response/BadgeListServiceResponse.java | 4 +--- .../badge/service/dto/response/BadgeTypeServiceResponse.java | 1 - .../java/com/smeem/api/member/service/MemberBadgeService.java | 4 ++-- .../service/dto/response/MemberUpdateServiceResponse.java | 2 -- 7 files changed, 4 insertions(+), 12 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java b/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java index 0dc5d0a3..3a123701 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java @@ -76,7 +76,7 @@ private Member get(final long memberId) { .orElseThrow(() -> new MemberException(INVALID_MEMBER)); } - private Member getMemberBySocialAndSocialId(SocialType socialType, String socialId) { + private Member getMemberBySocialAndSocialId(final SocialType socialType, final String socialId) { return memberRepository.findBySocialAndSocialId(socialType, socialId) .orElseThrow(() -> new MemberException(INVALID_MEMBER)); } diff --git a/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java b/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java index 99a82b5a..f3aa5a26 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java @@ -1,6 +1,5 @@ package com.smeem.api.badge.service; -import com.smeem.api.badge.controller.dto.response.BadgeListResponse; import com.smeem.api.badge.service.dto.response.BadgeListServiceResponse; import com.smeem.common.exception.BadgeException; import com.smeem.domain.badge.model.Badge; diff --git a/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeBaseServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeBaseServiceResponse.java index 2995fca5..6be03f5b 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeBaseServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeBaseServiceResponse.java @@ -1,10 +1,8 @@ package com.smeem.api.badge.service.dto.response; -import com.smeem.api.badge.controller.dto.response.BadgeListResponse; import com.smeem.domain.badge.model.Badge; import com.smeem.domain.badge.model.BadgeType; import com.smeem.domain.member.model.MemberBadge; -import lombok.AccessLevel; import lombok.Builder; import java.util.List; diff --git a/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeListServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeListServiceResponse.java index c851b4b4..d17f4657 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeListServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeListServiceResponse.java @@ -1,8 +1,6 @@ package com.smeem.api.badge.service.dto.response; -import com.smeem.api.badge.controller.dto.response.BadgeListResponse; -import com.smeem.api.badge.controller.dto.response.BadgeTypeResponse; import com.smeem.domain.badge.model.Badge; import com.smeem.domain.badge.model.BadgeType; import com.smeem.domain.member.model.MemberBadge; @@ -12,7 +10,7 @@ import java.util.List; import java.util.Map; -import static lombok.AccessLevel.*; +import static lombok.AccessLevel.PRIVATE; @Builder(access = PRIVATE) public record BadgeListServiceResponse( diff --git a/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeTypeServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeTypeServiceResponse.java index eb7bc0df..c65e5148 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeTypeServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeTypeServiceResponse.java @@ -1,6 +1,5 @@ package com.smeem.api.badge.service.dto.response; -import com.smeem.api.badge.controller.dto.response.BadgeBaseResponse; import com.smeem.domain.badge.model.Badge; import com.smeem.domain.badge.model.BadgeType; import com.smeem.domain.member.model.MemberBadge; diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/MemberBadgeService.java b/smeem-api/src/main/java/com/smeem/api/member/service/MemberBadgeService.java index 8189f754..31e302a4 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/MemberBadgeService.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/MemberBadgeService.java @@ -21,7 +21,7 @@ public class MemberBadgeService { private final MemberBadgeRepository memberBadgeRepository; @Transactional - public void deleteAllByMember(Member member) { + public void deleteAllByMember(final Member member) { memberBadgeRepository.deleteAllInBatch(member.getBadges()); } @@ -34,7 +34,7 @@ public void save(Member member, Badge badge) { memberBadgeRepository.save(memberBadge); } - public Badge getBadgeByMemberId(Long memberId) { + public Badge getBadgeByMemberId(final long memberId) { return memberBadgeRepository.findFirstByMemberIdOrderByCreatedAtDesc(memberId).orElseThrow( () -> new BadgeException(EMPTY_BADGE)).getBadge(); } diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberUpdateServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberUpdateServiceResponse.java index beb553ed..1ed158ca 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberUpdateServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberUpdateServiceResponse.java @@ -1,8 +1,6 @@ package com.smeem.api.member.service.dto.response; -import com.smeem.api.badge.controller.dto.response.AcquiredBadgeResponse; import com.smeem.api.badge.service.dto.response.AcquiredBadgeServiceResponse; -import com.smeem.api.badge.service.dto.response.BadgeServiceResponse; import com.smeem.domain.badge.model.Badge; import lombok.Builder; From 5825e5579a9eb0f2e13b630edb930d619f0c339d Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 23 Feb 2024 02:01:46 +0900 Subject: [PATCH 52/86] =?UTF-8?q?[REFACTOR]=20=EB=B2=84=EC=A0=84=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 83108aff..51591398 100644 --- a/build.gradle +++ b/build.gradle @@ -6,8 +6,8 @@ buildscript { plugins { id 'java' - id 'org.springframework.boot' version '3.0.1' - id 'io.spring.dependency-management' version '1.1.0' + id 'org.springframework.boot' version '3.2.0' + id 'io.spring.dependency-management' version '1.1.4' } allprojects { From 0bd439775c57547c5e377bf62d2fc53de47bef0b Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 23 Feb 2024 02:02:37 +0900 Subject: [PATCH 53/86] =?UTF-8?q?[REFACTOR]=20=EC=99=B8=EB=B6=80=20API=20?= =?UTF-8?q?=ED=98=B8=EC=B6=9C=20:=20RestClient=20=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/code/failure/FcmFailureCode.java | 6 +++ .../smeem/common/exception/FcmException.java | 6 +++ .../smeem/external/firebase/FcmService.java | 54 ++++++++++--------- 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/smeem-common/src/main/java/com/smeem/common/code/failure/FcmFailureCode.java b/smeem-common/src/main/java/com/smeem/common/code/failure/FcmFailureCode.java index d4c0b900..49fd2430 100644 --- a/smeem-common/src/main/java/com/smeem/common/code/failure/FcmFailureCode.java +++ b/smeem-common/src/main/java/com/smeem/common/code/failure/FcmFailureCode.java @@ -5,6 +5,7 @@ import org.springframework.http.HttpStatus; import static org.springframework.http.HttpStatus.BAD_REQUEST; +import static org.springframework.http.HttpStatus.METHOD_NOT_ALLOWED; @RequiredArgsConstructor @Getter @@ -15,6 +16,11 @@ public enum FcmFailureCode implements FailureCode { */ INVALID_REQUEST_PATTERN(BAD_REQUEST, "잘못된 요청 형식입니다."), INVALID_REQUEST_MESSAGE(BAD_REQUEST, "잘못된 fcm 요청입니다."), + + /** + * 405 METHOD NOT ALLOW + */ + INVALID_REQUEST_URI(METHOD_NOT_ALLOWED, "외부 API 요청에 실패했습니다"), ; private final HttpStatus status; diff --git a/smeem-common/src/main/java/com/smeem/common/exception/FcmException.java b/smeem-common/src/main/java/com/smeem/common/exception/FcmException.java index 6460e776..b71b016d 100644 --- a/smeem-common/src/main/java/com/smeem/common/exception/FcmException.java +++ b/smeem-common/src/main/java/com/smeem/common/exception/FcmException.java @@ -3,6 +3,7 @@ import com.smeem.common.code.failure.FailureCode; import com.smeem.common.code.failure.FcmFailureCode; import lombok.Getter; +import org.springframework.http.HttpStatusCode; @Getter public class FcmException extends RuntimeException { @@ -13,4 +14,9 @@ public FcmException(FcmFailureCode failureCode) { super("[FcmException] : " + failureCode.getMessage()); this.failureCode = failureCode; } + + public FcmException(FcmFailureCode failureCode, HttpStatusCode statusCode) { + super("[FcmException] : " + statusCode + ", " + failureCode.getMessage()); + this.failureCode = failureCode; + } } diff --git a/smeem-external/src/main/java/com/smeem/external/firebase/FcmService.java b/smeem-external/src/main/java/com/smeem/external/firebase/FcmService.java index d34e55e6..f20143cc 100644 --- a/smeem-external/src/main/java/com/smeem/external/firebase/FcmService.java +++ b/smeem-external/src/main/java/com/smeem/external/firebase/FcmService.java @@ -12,19 +12,18 @@ import com.smeem.external.firebase.dto.request.MessagePushServiceRequest; import lombok.val; import org.springframework.core.io.ClassPathResource; +import org.springframework.http.HttpStatusCode; import org.springframework.stereotype.Service; import com.google.auth.oauth2.GoogleCredentials; import lombok.RequiredArgsConstructor; -import okhttp3.MediaType; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.RequestBody; +import org.springframework.web.client.RestClient; -import static com.smeem.common.code.failure.FcmFailureCode.INVALID_REQUEST_MESSAGE; -import static com.smeem.common.code.failure.FcmFailureCode.INVALID_REQUEST_PATTERN; +import static com.smeem.common.code.failure.FcmFailureCode.*; +import static org.springframework.http.HttpHeaders.ACCEPT; import static org.springframework.http.HttpHeaders.AUTHORIZATION; +import static org.springframework.http.MediaType.APPLICATION_JSON; @Service @RequiredArgsConstructor @@ -34,18 +33,21 @@ public class FcmService { private final ValueConfig valueConfig; public void pushMessage(final MessagePushServiceRequest request) { - try { - val fcmRequest = new Request.Builder() - .url(valueConfig.getFIREBASE_API_URI()) - .post(RequestBody.create(makeMessage(request), MediaType.get("application/json; charset=utf-8"))) - .addHeader(AUTHORIZATION, "Bearer " + getAccessToken()) - .addHeader("Accept", "application/json; UTF-8") - .build(); - val client = new OkHttpClient(); - client.newCall(fcmRequest).execute(); - } catch (Exception exception) { - throw new FcmException(INVALID_REQUEST_MESSAGE); - } + val restClient = RestClient.create(); + restClient.post() + .uri(valueConfig.getFIREBASE_API_URI()) + .contentType(APPLICATION_JSON) + .body(makeMessage(request)) + .header(AUTHORIZATION, "Bearer " + getAccessToken()) + .header(ACCEPT, "application/json; UTF-8") + .retrieve() + .onStatus(HttpStatusCode::is4xxClientError, (fcmRequest, fcmResponse) -> { + throw new FcmException(INVALID_REQUEST_MESSAGE, fcmResponse.getStatusCode()); + }) + .onStatus(HttpStatusCode::is5xxServerError, (fcmRequest, fcmResponse) -> { + throw new FcmException(INVALID_REQUEST_URI, fcmResponse.getStatusCode()); + }) + .toBodilessEntity(); } private String makeMessage(MessagePushServiceRequest request) { @@ -57,11 +59,15 @@ private String makeMessage(MessagePushServiceRequest request) { } } - private String getAccessToken() throws IOException { - val googleCredentials = GoogleCredentials - .fromStream(new ClassPathResource(valueConfig.getFIREBASE_CONFIG_PATH()).getInputStream()) - .createScoped(List.of(valueConfig.getGOOGLE_API_URI())); - googleCredentials.refreshIfExpired(); - return googleCredentials.getAccessToken().getTokenValue(); + private String getAccessToken() { + try { + val googleCredentials = GoogleCredentials + .fromStream(new ClassPathResource(valueConfig.getFIREBASE_CONFIG_PATH()).getInputStream()) + .createScoped(List.of(valueConfig.getGOOGLE_API_URI())); + googleCredentials.refreshIfExpired(); + return googleCredentials.getAccessToken().getTokenValue(); + } catch (IOException exception) { + throw new FcmException(INVALID_REQUEST_PATTERN); + } } } From ce2b3a699493fa27082bd0fd5828a59c69d206eb Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 23 Feb 2024 02:02:56 +0900 Subject: [PATCH 54/86] =?UTF-8?q?[REFACTOR]=20=EB=9E=8C=EB=8B=A4=EC=8B=9D?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EB=A9=94=EC=86=8C=EB=93=9C?= =?UTF-8?q?=20=EC=9E=AC=ED=99=9C=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/smeem/api/config/SecurityConfig.java | 85 ++++++++----------- 1 file changed, 35 insertions(+), 50 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/config/SecurityConfig.java b/smeem-api/src/main/java/com/smeem/api/config/SecurityConfig.java index 72041c1a..a9d5c85d 100644 --- a/smeem-api/src/main/java/com/smeem/api/config/SecurityConfig.java +++ b/smeem-api/src/main/java/com/smeem/api/config/SecurityConfig.java @@ -8,9 +8,11 @@ import org.springframework.context.annotation.Profile; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; @Configuration @@ -21,62 +23,45 @@ public class SecurityConfig { private final JwtAuthenticationFilter jwtAuthenticationFilter; private final CustomJwtAuthenticationEntryPoint customJwtAuthenticationEntryPoint; - private static final String[] AUTH_WHITELIST = { - "/api/v2/auth", - "/api/v2/test", - "/api/beta/token", - "/error", - "/favicon.ico", - "/api/v2/members/nickname/check", - "/api/v2/goals", - "/api/v2/goals/{type}" - }; - - private static final String[] AUTH_WHITELIST_SWAGGER = { - "/v3/api-docs/**", - "/swagger-ui/**", - "/swagger-ui.html", - "/docs/**" - }; - @Bean @Profile({"dev", "local"}) - public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { - return http - .csrf().disable() - .formLogin().disable() - .sessionManagement() - .sessionCreationPolicy(SessionCreationPolicy.STATELESS) - .and() - .exceptionHandling() - .authenticationEntryPoint(customJwtAuthenticationEntryPoint) - .and() - .authorizeHttpRequests() - .requestMatchers(AUTH_WHITELIST).permitAll() - .requestMatchers(AUTH_WHITELIST_SWAGGER).permitAll() - .anyRequest().authenticated() - .and() - .addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class) - .build(); + public SecurityFilterChain filterChainDev(HttpSecurity http) throws Exception { + permitSwaggerUri(http); + setHttp(http); + return http.build(); } @Bean @Profile("prod") public SecurityFilterChain filterChainProd(HttpSecurity http) throws Exception { - return http - .csrf().disable() - .formLogin().disable() - .sessionManagement() - .sessionCreationPolicy(SessionCreationPolicy.STATELESS) - .and() - .exceptionHandling() - .authenticationEntryPoint(customJwtAuthenticationEntryPoint) - .and() - .authorizeHttpRequests() - .requestMatchers(AUTH_WHITELIST).permitAll() - .anyRequest().authenticated() - .and() - .addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class) - .build(); + setHttp(http); + return http.build(); + } + + private void setHttp(HttpSecurity http) throws Exception { + http.csrf(AbstractHttpConfigurer::disable) + .formLogin(AbstractHttpConfigurer::disable) + .sessionManagement(sessionManagement -> + sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) + .exceptionHandling(exceptionHandling -> + exceptionHandling.authenticationEntryPoint(customJwtAuthenticationEntryPoint)) + .authorizeHttpRequests(authorizeHttpRequests -> + authorizeHttpRequests + .requestMatchers(new AntPathRequestMatcher("/api/v2/auth", "POST")).permitAll() + .requestMatchers(new AntPathRequestMatcher("/api/v2/test")).permitAll() + .requestMatchers(new AntPathRequestMatcher("/api/v2/goals/{type}")).permitAll() + .requestMatchers(new AntPathRequestMatcher("/api/v2/goals")).permitAll() + .requestMatchers(new AntPathRequestMatcher("/api/v2/members/nickname/check")).permitAll() + .requestMatchers(new AntPathRequestMatcher("/favicon.ico")).permitAll() + .requestMatchers(new AntPathRequestMatcher("/error")).permitAll() + .anyRequest().authenticated()) + .addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class); + } + + private void permitSwaggerUri(HttpSecurity http) throws Exception { + http.authorizeHttpRequests(authorizeHttpRequests -> authorizeHttpRequests + .requestMatchers(new AntPathRequestMatcher("/v3/api-docs/**")).permitAll() + .requestMatchers(new AntPathRequestMatcher("/swagger-ui/**")).permitAll() + .requestMatchers(new AntPathRequestMatcher("/docs/**")).permitAll()); } } From 745fdcba6f714d479c348d5a489d589086b31fb4 Mon Sep 17 00:00:00 2001 From: unanchoi Date: Sat, 24 Feb 2024 01:20:21 +0900 Subject: [PATCH 55/86] =?UTF-8?q?[REFACTOR]=203=EC=B0=A8=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 +- .../api/auth/jwt/JwtAuthenticationFilter.java | 18 +-- .../smeem/api/auth/jwt/JwtValidationType.java | 6 +- .../smeem/api/auth/jwt/TokenValidator.java | 10 +- .../smeem/api/auth/service/AuthService.java | 15 +-- .../com/smeem/api/common/ApiResponseUtil.java | 2 +- .../com/smeem/api/config/SecurityConfig.java | 87 ++++++-------- .../common/code/failure/AuthFailureCode.java | 3 +- .../smeem/external/oauth/apple/AppleKey.java | 11 ++ .../oauth/apple/AppleKeyListResponse.java | 8 ++ .../external/oauth/apple/AppleService.java | 102 ++++++++++++++++ .../oauth/apple/AppleSignInService.java | 113 ------------------ .../external/oauth/apple/DecodedAppleKey.java | 19 +++ .../external/oauth/kakao/KakaoResponse.java | 7 ++ .../external/oauth/kakao/KakaoService.java | 38 ++++++ .../oauth/kakao/KakaoSignInService.java | 30 ----- 16 files changed, 246 insertions(+), 227 deletions(-) create mode 100644 smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleKey.java create mode 100644 smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleKeyListResponse.java create mode 100644 smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleService.java delete mode 100644 smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleSignInService.java create mode 100644 smeem-external/src/main/java/com/smeem/external/oauth/apple/DecodedAppleKey.java create mode 100644 smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoResponse.java create mode 100644 smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoService.java delete mode 100644 smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoSignInService.java diff --git a/build.gradle b/build.gradle index 83108aff..51591398 100644 --- a/build.gradle +++ b/build.gradle @@ -6,8 +6,8 @@ buildscript { plugins { id 'java' - id 'org.springframework.boot' version '3.0.1' - id 'io.spring.dependency-management' version '1.1.0' + id 'org.springframework.boot' version '3.2.0' + id 'io.spring.dependency-management' version '1.1.4' } allprojects { diff --git a/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtAuthenticationFilter.java b/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtAuthenticationFilter.java index adce0c08..009a1138 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtAuthenticationFilter.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtAuthenticationFilter.java @@ -20,7 +20,6 @@ import static com.smeem.api.auth.jwt.JwtValidationType.VALID_JWT; -@Slf4j @Component @RequiredArgsConstructor public class JwtAuthenticationFilter extends OncePerRequestFilter { @@ -29,17 +28,12 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter { @Override protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull FilterChain filterChain) throws IOException, ServletException { - try { - final String token = getJwtFromRequest(request); - - if (StringUtils.hasText(token) && tokenValidator.validateToken(token) == VALID_JWT) { - Long userId = tokenValidator.getUserFromJwt(token); - UserAuthentication authentication = new UserAuthentication(userId, null, null); - authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); - SecurityContextHolder.getContext().setAuthentication(authentication); - } - } catch (AuthException exception) { - log.error("error : ", exception); + final String token = getJwtFromRequest(request); + if (StringUtils.hasText(token) && tokenValidator.validateToken(token) == VALID_JWT) { + Long userId = tokenValidator.getUserFromJwt(token); + UserAuthentication authentication = new UserAuthentication(userId, null, null); + authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); + SecurityContextHolder.getContext().setAuthentication(authentication); } filterChain.doFilter(request, response); } diff --git a/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtValidationType.java b/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtValidationType.java index 4d462de4..fa26c60a 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtValidationType.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtValidationType.java @@ -2,9 +2,9 @@ public enum JwtValidationType { VALID_JWT, - INVALID_JWT_TOKEN, + INVALID_JWT, INVALID_JWT_SIGNATURE, - EXPIRED_JWT_TOKEN, - UNSUPPORTED_JWT_TOKEN, + EXPIRED_JWT, + UNSUPPORTED_JWT, EMPTY_JWT } diff --git a/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenValidator.java b/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenValidator.java index a4cd9d07..c8ff72b9 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenValidator.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenValidator.java @@ -1,18 +1,15 @@ package com.smeem.api.auth.jwt; -import com.smeem.common.exception.AuthException; import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -import static com.smeem.api.auth.jwt.JwtValidationType.INVALID_JWT_TOKEN; +import static com.smeem.api.auth.jwt.JwtValidationType.INVALID_JWT; import static com.smeem.api.auth.jwt.JwtValidationType.VALID_JWT; @Component @RequiredArgsConstructor -@Slf4j public class TokenValidator { private final SecretKeyFactory secretKeyFactory; @@ -20,9 +17,8 @@ public JwtValidationType validateToken(String token) { try { getBody(token); return VALID_JWT; - } catch (AuthException ex) { - log.error(String.valueOf(INVALID_JWT_TOKEN)); - return INVALID_JWT_TOKEN; + } catch (RuntimeException ex) { + return INVALID_JWT; } } diff --git a/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java b/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java index 3a123701..4ed9f214 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java @@ -11,8 +11,8 @@ import com.smeem.domain.member.model.Member; import com.smeem.domain.member.model.SocialType; import com.smeem.domain.member.repository.MemberRepository; -import com.smeem.external.oauth.apple.AppleSignInService; -import com.smeem.external.oauth.kakao.KakaoSignInService; +import com.smeem.external.oauth.apple.AppleService; +import com.smeem.external.oauth.kakao.KakaoService; import lombok.RequiredArgsConstructor; import lombok.val; import org.springframework.stereotype.Service; @@ -33,8 +33,8 @@ public class AuthService { private final MemberRepository memberRepository; private final TokenService tokenService; - private final AppleSignInService appleSignInService; - private final KakaoSignInService kakaoSignInService; + private final AppleService appleService; + private final KakaoService kakaoService; private final MemberBadgeService memberBadgeService; private final DiaryCommandService diaryService; private final TrainingTimeService trainingTimeService; @@ -44,6 +44,7 @@ public SignInServiceResponse signIn(final String socialAccessToken, final SignIn val socialType = request.socialType(); val socialId = socialLogin(socialType, socialAccessToken); val existMember = isMemberBySocialAndSocialId(socialType, socialId); + if (!existMember) { val initialMember = Member.createInitialMember(socialType, socialId, request.fcmToken()); memberRepository.save(initialMember); @@ -85,10 +86,10 @@ private boolean isMemberBySocialAndSocialId(SocialType socialType, String social return memberRepository.existsBySocialAndSocialId(socialType, socialId); } - private String socialLogin(SocialType socialType, String socialAccessToken) throws NoSuchAlgorithmException, InvalidKeySpecException { + private String socialLogin(SocialType socialType, String socialAccessToken) { return switch (socialType.toString()) { - case "APPLE" -> appleSignInService.getAppleData(socialAccessToken); - case "KAKAO" -> kakaoSignInService.getKakaoData(socialAccessToken); + case "APPLE" -> appleService.getAppleData(socialAccessToken); + case "KAKAO" -> kakaoService.getKakaoData(socialAccessToken); default -> throw new TokenException(INVALID_TOKEN); }; } diff --git a/smeem-api/src/main/java/com/smeem/api/common/ApiResponseUtil.java b/smeem-api/src/main/java/com/smeem/api/common/ApiResponseUtil.java index 9aa8512d..86b34e23 100644 --- a/smeem-api/src/main/java/com/smeem/api/common/ApiResponseUtil.java +++ b/smeem-api/src/main/java/com/smeem/api/common/ApiResponseUtil.java @@ -30,6 +30,6 @@ static ResponseEntity> success(SuccessCode code, URI uri, T static ResponseEntity> failure(FailureCode code) { return ResponseEntity .status(code.getStatus()) - .body(BaseResponse.of(true, code.getMessage())); + .body(BaseResponse.of(false, code.getMessage())); } } diff --git a/smeem-api/src/main/java/com/smeem/api/config/SecurityConfig.java b/smeem-api/src/main/java/com/smeem/api/config/SecurityConfig.java index 72041c1a..d65012c0 100644 --- a/smeem-api/src/main/java/com/smeem/api/config/SecurityConfig.java +++ b/smeem-api/src/main/java/com/smeem/api/config/SecurityConfig.java @@ -11,6 +11,8 @@ import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; @Configuration @@ -21,62 +23,45 @@ public class SecurityConfig { private final JwtAuthenticationFilter jwtAuthenticationFilter; private final CustomJwtAuthenticationEntryPoint customJwtAuthenticationEntryPoint; - private static final String[] AUTH_WHITELIST = { - "/api/v2/auth", - "/api/v2/test", - "/api/beta/token", - "/error", - "/favicon.ico", - "/api/v2/members/nickname/check", - "/api/v2/goals", - "/api/v2/goals/{type}" - }; - - private static final String[] AUTH_WHITELIST_SWAGGER = { - "/v3/api-docs/**", - "/swagger-ui/**", - "/swagger-ui.html", - "/docs/**" - }; - @Bean @Profile({"dev", "local"}) - public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { - return http - .csrf().disable() - .formLogin().disable() - .sessionManagement() - .sessionCreationPolicy(SessionCreationPolicy.STATELESS) - .and() - .exceptionHandling() - .authenticationEntryPoint(customJwtAuthenticationEntryPoint) - .and() - .authorizeHttpRequests() - .requestMatchers(AUTH_WHITELIST).permitAll() - .requestMatchers(AUTH_WHITELIST_SWAGGER).permitAll() - .anyRequest().authenticated() - .and() - .addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class) - .build(); + public SecurityFilterChain filterChainDev(HttpSecurity http) throws Exception { + permitSwaggerUri(http); + setHttp(http); + return http.build(); } @Bean @Profile("prod") public SecurityFilterChain filterChainProd(HttpSecurity http) throws Exception { - return http - .csrf().disable() - .formLogin().disable() - .sessionManagement() - .sessionCreationPolicy(SessionCreationPolicy.STATELESS) - .and() - .exceptionHandling() - .authenticationEntryPoint(customJwtAuthenticationEntryPoint) - .and() - .authorizeHttpRequests() - .requestMatchers(AUTH_WHITELIST).permitAll() - .anyRequest().authenticated() - .and() - .addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class) - .build(); + setHttp(http); + return http.build(); + } + + private void setHttp(HttpSecurity http) throws Exception { + http.csrf(AbstractHttpConfigurer::disable) + .formLogin(AbstractHttpConfigurer::disable) + .sessionManagement(sessionManagement -> + sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) + .exceptionHandling(exceptionHandling -> + exceptionHandling.authenticationEntryPoint(customJwtAuthenticationEntryPoint)) + .authorizeHttpRequests(authorizeHttpRequests -> + authorizeHttpRequests + .requestMatchers(new AntPathRequestMatcher("/api/v2/auth", "POST")).permitAll() + .requestMatchers(new AntPathRequestMatcher("/api/v2/test")).permitAll() + .requestMatchers(new AntPathRequestMatcher("/api/v2/goals/{type}")).permitAll() + .requestMatchers(new AntPathRequestMatcher("/api/v2/goals")).permitAll() + .requestMatchers(new AntPathRequestMatcher("/api/v2/members/nickname/check")).permitAll() + .requestMatchers(new AntPathRequestMatcher("/favicon.ico")).permitAll() + .requestMatchers(new AntPathRequestMatcher("/error")).permitAll() + .anyRequest().authenticated()) + .addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class); + } + + private void permitSwaggerUri(HttpSecurity http) throws Exception { + http.authorizeHttpRequests(authorizeHttpRequests -> authorizeHttpRequests + .requestMatchers(new AntPathRequestMatcher("/v3/api-docs/**")).permitAll() + .requestMatchers(new AntPathRequestMatcher("/swagger-ui/**")).permitAll() + .requestMatchers(new AntPathRequestMatcher("/docs/**")).permitAll()); } -} +} \ No newline at end of file diff --git a/smeem-common/src/main/java/com/smeem/common/code/failure/AuthFailureCode.java b/smeem-common/src/main/java/com/smeem/common/code/failure/AuthFailureCode.java index e1d3a6fc..9c75f5ed 100644 --- a/smeem-common/src/main/java/com/smeem/common/code/failure/AuthFailureCode.java +++ b/smeem-common/src/main/java/com/smeem/common/code/failure/AuthFailureCode.java @@ -15,7 +15,8 @@ public enum AuthFailureCode implements FailureCode { */ EMPTY_ACCESS_TOKEN(UNAUTHORIZED, "액세스 토큰이 없습니다."), INVALID_TOKEN(UNAUTHORIZED, "유효하지 않은 토큰입니다"), - INVALID_APPLE_TOKEN(UNAUTHORIZED, "유효하지 않은 애플 토큰입니다.") + FAIL_APPLE_REQUEST(UNAUTHORIZED, "애플 로그인에 실패했습니다."), + FAIL_KAKAO_REQUEST(UNAUTHORIZED, "카카오 로그인에 실패했습니다."), ; private final HttpStatus status; diff --git a/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleKey.java b/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleKey.java new file mode 100644 index 00000000..b034a118 --- /dev/null +++ b/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleKey.java @@ -0,0 +1,11 @@ +package com.smeem.external.oauth.apple; + +public record AppleKey( + String kty, + String kid, + String use, + String alg, + String n, + String e +) { +} diff --git a/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleKeyListResponse.java b/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleKeyListResponse.java new file mode 100644 index 00000000..4e01516c --- /dev/null +++ b/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleKeyListResponse.java @@ -0,0 +1,8 @@ +package com.smeem.external.oauth.apple; + +import java.util.List; + +public record AppleKeyListResponse( + List keys +) { +} diff --git a/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleService.java b/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleService.java new file mode 100644 index 00000000..2945dbf9 --- /dev/null +++ b/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleService.java @@ -0,0 +1,102 @@ +package com.smeem.external.oauth.apple; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.smeem.common.config.ValueConfig; +import com.smeem.common.exception.AuthException; +import io.jsonwebtoken.Jwts; +import lombok.RequiredArgsConstructor; +import lombok.val; +import org.springframework.http.HttpStatusCode; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestClient; + +import java.math.BigInteger; +import java.security.KeyFactory; +import java.security.NoSuchAlgorithmException; +import java.security.PublicKey; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.RSAPublicKeySpec; +import java.util.Base64; +import java.util.Map; +import java.util.Objects; + +import static com.smeem.common.code.failure.AuthFailureCode.FAIL_APPLE_REQUEST; + +@RequiredArgsConstructor +@Component +public class AppleService { + + private final ObjectMapper objectMapper = new ObjectMapper(); + private final ValueConfig valueConfig; + + public String getAppleData(final String appleAccessToken) { + val publicAppleKeys = getApplePublicKeys(); + val decodedAppleKey = decodeAppleAccessToken(appleAccessToken); + val matchedAppleKey = matchDecodedKeyWithApplePublicKeys(decodedAppleKey, publicAppleKeys); + try { + val userInfo = Jwts.parserBuilder() + .setSigningKey(generatePublicKey(matchedAppleKey)) + .build() + .parseClaimsJws(appleAccessToken.substring(7)) + .getBody(); + return userInfo.get("sub", String.class); + } catch (RuntimeException e) { + throw new AuthException(FAIL_APPLE_REQUEST); + } + } + + private AppleKeyListResponse getApplePublicKeys() { + try { + val restClient = RestClient.create(); + return restClient.get() + .uri(valueConfig.getAPPLE_URL()) + .retrieve() + .onStatus(HttpStatusCode::is4xxClientError, + (appleRequest, appleResponse) -> { + throw new AuthException(FAIL_APPLE_REQUEST); + }) + .body(AppleKeyListResponse.class); + } catch (Exception e) { + throw new AuthException(FAIL_APPLE_REQUEST); + } + } + + private AppleKey matchDecodedKeyWithApplePublicKeys(DecodedAppleKey decodedAppleKey, AppleKeyListResponse appleKeyList) { + return appleKeyList.keys().stream() + .filter(appleKey -> + Objects.equals(decodedAppleKey.alg(), appleKey.alg()) && + Objects.equals(decodedAppleKey.kid(), appleKey.kid()) + ) + .findFirst() + .orElseThrow(() -> new AuthException(FAIL_APPLE_REQUEST)); + } + + private DecodedAppleKey decodeAppleAccessToken(String accessToken) { + try { + val encoded = accessToken.split("\\."); + val decoded = new String(Base64.getDecoder().decode(encoded[0].substring(7))); + val decodedMap = objectMapper.readValue(decoded, Map.class); + return DecodedAppleKey.of( + decodedMap.get("kid").toString(), + decodedMap.get("alg").toString()); + } catch (JsonProcessingException e) { + throw new AuthException(FAIL_APPLE_REQUEST); + } + } + + private PublicKey generatePublicKey(AppleKey key) { + try { + val eBytes = Base64.getUrlDecoder().decode(key.e()); + val nBytes = Base64.getUrlDecoder().decode(key.n()); + val publicKeySpec = new RSAPublicKeySpec( + new BigInteger(1, nBytes), + new BigInteger(1, eBytes)); + val keyFactory = KeyFactory.getInstance(key.kty()); + return keyFactory.generatePublic(publicKeySpec); + } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { + throw new AuthException(FAIL_APPLE_REQUEST); + } + } + +} \ No newline at end of file diff --git a/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleSignInService.java b/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleSignInService.java deleted file mode 100644 index 1a89421f..00000000 --- a/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleSignInService.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.smeem.external.oauth.apple; - -import com.google.gson.*; -import com.smeem.common.config.RestTemplateConfig; -import com.smeem.common.config.ValueConfig; - -import com.smeem.common.exception.AppleException; -import io.jsonwebtoken.Claims; -import io.jsonwebtoken.Jwts; -import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpMethod; -import org.springframework.stereotype.Component; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.math.BigInteger; -import java.net.HttpURLConnection; -import java.net.URL; -import java.security.KeyFactory; -import java.security.NoSuchAlgorithmException; -import java.security.PublicKey; -import java.security.spec.InvalidKeySpecException; -import java.security.spec.RSAPublicKeySpec; -import java.util.Base64; -import java.util.Objects; - -import static com.smeem.common.code.failure.AuthFailureCode.INVALID_APPLE_TOKEN; - -@RequiredArgsConstructor -@Component -public class AppleSignInService { - - private final ValueConfig valueConfig; - - public JsonArray getApplePublicKeys() { - try { - URL url = new URL(valueConfig.getAPPLE_URL()); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod(HttpMethod.GET.name()); - BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); - StringBuilder result = new StringBuilder(); - - String line; - while ((line = br.readLine()) != null) { - result.append(line); - } - br.close(); - - JsonObject keys = (JsonObject) JsonParser.parseString(result.toString()); - return (JsonArray) keys.get("keys"); - } catch (IOException exception) { - throw new AppleException(INVALID_APPLE_TOKEN); - } - } - - public PublicKey makePublicKey(String accessToken, JsonArray publicKeyList) throws NoSuchAlgorithmException, InvalidKeySpecException { - JsonObject selectedObject = null; - - String[] decodeArray = accessToken.split("\\."); - String header = new String(Base64.getDecoder().decode(decodeArray[0].substring(7))); - - JsonElement kid = ((JsonObject) JsonParser.parseString(header)).get("kid"); - JsonElement alg = ((JsonObject) JsonParser.parseString(header)).get("alg"); - - for (JsonElement publicKey : publicKeyList) { - JsonObject publicKeyObject = publicKey.getAsJsonObject(); - JsonElement publicKid = publicKeyObject.get("kid"); - JsonElement publicAlg = publicKeyObject.get("alg"); - - if (Objects.equals(kid, publicKid) && Objects.equals(alg, publicAlg)) { - selectedObject = publicKeyObject; - break; - } - } - - if (selectedObject == null) { - throw new InvalidKeySpecException("공개키를 찾을 수 없습니다."); - } - - return getPublicKey(selectedObject); - } - - public String getAppleData(String socialAccessToken) throws NoSuchAlgorithmException, InvalidKeySpecException { - JsonArray publicKeyList = getApplePublicKeys(); - PublicKey publicKey = makePublicKey(socialAccessToken, publicKeyList); - - Claims userInfo = Jwts.parserBuilder() - .setSigningKey(publicKey) - .build() - .parseClaimsJws(socialAccessToken.substring(7)) - .getBody(); - - JsonObject userInfoObject = (JsonObject) JsonParser.parseString(new Gson().toJson(userInfo)); - return userInfoObject.get("sub").getAsString(); - } - - private PublicKey getPublicKey(JsonObject object) throws NoSuchAlgorithmException, InvalidKeySpecException { - String nStr = object.get("n").toString(); - String eStr = object.get("e").toString(); - - byte[] nBytes = Base64.getUrlDecoder().decode(nStr.substring(1, nStr.length() - 1)); - byte[] eBytes = Base64.getUrlDecoder().decode(eStr.substring(1, eStr.length() - 1)); - - BigInteger nValue = new BigInteger(1, nBytes); - BigInteger eValue = new BigInteger(1, eBytes); - - RSAPublicKeySpec publicKeySpec = new RSAPublicKeySpec(nValue, eValue); - KeyFactory keyFactory = KeyFactory.getInstance("RSA"); - return keyFactory.generatePublic(publicKeySpec); - } - -} \ No newline at end of file diff --git a/smeem-external/src/main/java/com/smeem/external/oauth/apple/DecodedAppleKey.java b/smeem-external/src/main/java/com/smeem/external/oauth/apple/DecodedAppleKey.java new file mode 100644 index 00000000..9585b769 --- /dev/null +++ b/smeem-external/src/main/java/com/smeem/external/oauth/apple/DecodedAppleKey.java @@ -0,0 +1,19 @@ +package com.smeem.external.oauth.apple; + +import lombok.Builder; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record DecodedAppleKey( + String kid, + String alg +) { + + public static DecodedAppleKey of(String kid, String alg) { + return DecodedAppleKey.builder() + .kid(kid) + .alg(alg) + .build(); + } +} diff --git a/smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoResponse.java b/smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoResponse.java new file mode 100644 index 00000000..4480cfa6 --- /dev/null +++ b/smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoResponse.java @@ -0,0 +1,7 @@ +package com.smeem.external.oauth.kakao; + + +public record KakaoResponse( + String id +) { +} diff --git a/smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoService.java b/smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoService.java new file mode 100644 index 00000000..5fbc482c --- /dev/null +++ b/smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoService.java @@ -0,0 +1,38 @@ +package com.smeem.external.oauth.kakao; + +import com.smeem.common.config.ValueConfig; +import com.smeem.common.exception.AuthException; +import lombok.RequiredArgsConstructor; +import lombok.val; +import org.springframework.http.HttpStatusCode; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestClient; + +import static com.smeem.common.code.failure.AuthFailureCode.FAIL_KAKAO_REQUEST; +import static org.springframework.http.HttpHeaders.AUTHORIZATION; + +@RequiredArgsConstructor +@Service +public class KakaoService { + + private final ValueConfig valueConfig; + + public String getKakaoData(final String accessToken) { + try { + RestClient restClient = RestClient.create(); + val response = restClient.get() + .uri(valueConfig.getKAKAO_URL()) + .header(AUTHORIZATION, "Bearer " + accessToken) + .retrieve() + .onStatus(HttpStatusCode::is4xxClientError, + (kakaoRequest, kakaoResponse) -> { + throw new AuthException(FAIL_KAKAO_REQUEST); + }) + .body(KakaoResponse.class); + assert response != null; + return response.id(); + } catch (Exception e) { + throw new AuthException(FAIL_KAKAO_REQUEST); + } + } +} diff --git a/smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoSignInService.java b/smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoSignInService.java deleted file mode 100644 index cddab856..00000000 --- a/smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoSignInService.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.smeem.external.oauth.kakao; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.gson.JsonArray; -import com.smeem.common.config.ValueConfig; -import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Service; -import org.springframework.web.client.RestTemplate; - -import java.util.Map; - -@RequiredArgsConstructor -@Service -public class KakaoSignInService { - - private final ValueConfig valueConfig; - - public String getKakaoData(String accessToken) { - RestTemplate restTemplate = new RestTemplate(); - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", accessToken); - HttpEntity httpEntity = new HttpEntity<>(headers); - ResponseEntity responseData = restTemplate.postForEntity(valueConfig.getKAKAO_URL(), httpEntity, Object.class); - ObjectMapper objectMapper = new ObjectMapper(); - return objectMapper.convertValue(responseData.getBody(), Map.class).get("id").toString(); - } -} From 37830047db26da848c76e3daac2fdc7074d89be1 Mon Sep 17 00:00:00 2001 From: unanchoi Date: Sat, 24 Feb 2024 01:31:16 +0900 Subject: [PATCH 56/86] =?UTF-8?q?[REFACTOR]=20=EB=B6=88=EB=B3=80=EC=84=B1?= =?UTF-8?q?=20=EB=B3=B4=EC=9E=A5=EC=9D=84=20=EC=9C=84=ED=95=9C=20final=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/smeem/api/auth/service/AuthService.java | 3 +-- .../java/com/smeem/api/member/service/MemberService.java | 4 ++-- .../java/com/smeem/external/oauth/apple/AppleService.java | 6 +++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java b/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java index 4ed9f214..35efff8b 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/service/AuthService.java @@ -44,7 +44,6 @@ public SignInServiceResponse signIn(final String socialAccessToken, final SignIn val socialType = request.socialType(); val socialId = socialLogin(socialType, socialAccessToken); val existMember = isMemberBySocialAndSocialId(socialType, socialId); - if (!existMember) { val initialMember = Member.createInitialMember(socialType, socialId, request.fcmToken()); memberRepository.save(initialMember); @@ -86,7 +85,7 @@ private boolean isMemberBySocialAndSocialId(SocialType socialType, String social return memberRepository.existsBySocialAndSocialId(socialType, socialId); } - private String socialLogin(SocialType socialType, String socialAccessToken) { + private String socialLogin(SocialType socialType, final String socialAccessToken) { return switch (socialType.toString()) { case "APPLE" -> appleService.getAppleData(socialAccessToken); case "KAKAO" -> kakaoService.getKakaoData(socialAccessToken); diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java b/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java index c6e4e9ad..d3cc2fb8 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java @@ -130,7 +130,7 @@ private void updateTrainingTime(Member member, TrainingTimeServiceRequest reques } } - private String[] parseDay(String day) { + private String[] parseDay(final String day) { return day.split(","); } @@ -164,7 +164,7 @@ private void updateGoalType(Member member, GoalType goalType) { } } - private void updatePushAlarmConsent(Member member, Boolean hasAlarm) { + private void updatePushAlarmConsent(Member member, final Boolean hasAlarm) { if (nonNull(hasAlarm)) { member.updateHasAlarm(hasAlarm); } diff --git a/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleService.java b/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleService.java index 2945dbf9..54c16c66 100644 --- a/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleService.java +++ b/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleService.java @@ -62,7 +62,7 @@ private AppleKeyListResponse getApplePublicKeys() { } } - private AppleKey matchDecodedKeyWithApplePublicKeys(DecodedAppleKey decodedAppleKey, AppleKeyListResponse appleKeyList) { + private AppleKey matchDecodedKeyWithApplePublicKeys(final DecodedAppleKey decodedAppleKey, AppleKeyListResponse appleKeyList) { return appleKeyList.keys().stream() .filter(appleKey -> Objects.equals(decodedAppleKey.alg(), appleKey.alg()) && @@ -72,7 +72,7 @@ private AppleKey matchDecodedKeyWithApplePublicKeys(DecodedAppleKey decodedApple .orElseThrow(() -> new AuthException(FAIL_APPLE_REQUEST)); } - private DecodedAppleKey decodeAppleAccessToken(String accessToken) { + private DecodedAppleKey decodeAppleAccessToken(final String accessToken) { try { val encoded = accessToken.split("\\."); val decoded = new String(Base64.getDecoder().decode(encoded[0].substring(7))); @@ -85,7 +85,7 @@ private DecodedAppleKey decodeAppleAccessToken(String accessToken) { } } - private PublicKey generatePublicKey(AppleKey key) { + private PublicKey generatePublicKey(final AppleKey key) { try { val eBytes = Base64.getUrlDecoder().decode(key.e()); val nBytes = Base64.getUrlDecoder().decode(key.n()); From edb34925739acafde61e259f49f0fee02b8b52b7 Mon Sep 17 00:00:00 2001 From: unanchoi Date: Tue, 27 Feb 2024 23:56:58 +0900 Subject: [PATCH 57/86] =?UTF-8?q?[FIX]=20=EB=A6=AC=EB=B7=B0=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/auth/jwt/JwtAuthenticationFilter.java | 11 +++++++--- .../com/smeem/api/auth/jwt/TokenProvider.java | 1 - .../smeem/api/auth/jwt/TokenValidator.java | 2 +- .../dto/response/BadgeBaseResponse.java | 4 +++- .../response/BadgeTypeServiceResponse.java | 3 +-- .../controller/dto/UsernameValidator.java | 3 --- .../api/member/service/MemberService.java | 20 ++++--------------- .../oauth/kakao/KakaoServiceTest.java | 7 +++++++ .../com/smeem/domain/member/model/Member.java | 20 ++++++++++++------- .../external/oauth/apple/AppleService.java | 10 ++++++---- .../external/oauth/kakao/KakaoService.java | 2 +- 11 files changed, 44 insertions(+), 39 deletions(-) create mode 100644 smeem-api/src/test/java/com/smeem/external/oauth/kakao/KakaoServiceTest.java diff --git a/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtAuthenticationFilter.java b/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtAuthenticationFilter.java index 009a1138..d62e3338 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtAuthenticationFilter.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/jwt/JwtAuthenticationFilter.java @@ -9,6 +9,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import lombok.val; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; import org.springframework.stereotype.Component; @@ -29,8 +30,8 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter { @Override protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull FilterChain filterChain) throws IOException, ServletException { final String token = getJwtFromRequest(request); - if (StringUtils.hasText(token) && tokenValidator.validateToken(token) == VALID_JWT) { - Long userId = tokenValidator.getUserFromJwt(token); + if (isValidToken(token)) { + val userId = tokenValidator.getUserFromJwt(token); UserAuthentication authentication = new UserAuthentication(userId, null, null); authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); SecurityContextHolder.getContext().setAuthentication(authentication); @@ -38,8 +39,12 @@ protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull Ht filterChain.doFilter(request, response); } + private boolean isValidToken(String token) { + return StringUtils.hasText(token) && tokenValidator.validateToken(token) == VALID_JWT; + } + private String getJwtFromRequest(HttpServletRequest request) { String bearerToken = request.getHeader("Authorization"); return (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) ? bearerToken.substring("Bearer ".length()) : null; } -} +} \ No newline at end of file diff --git a/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenProvider.java b/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenProvider.java index 5ce393a8..1d6a0a41 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenProvider.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenProvider.java @@ -11,7 +11,6 @@ import java.util.Date; -@Slf4j @Component @RequiredArgsConstructor public class TokenProvider { diff --git a/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenValidator.java b/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenValidator.java index c8ff72b9..7914fd16 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenValidator.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/jwt/TokenValidator.java @@ -22,7 +22,7 @@ public JwtValidationType validateToken(String token) { } } - public Long getUserFromJwt(String token) { + public long getUserFromJwt(String token) { Claims claims = getBody(token); return Long.parseLong(claims.get("memberId").toString()); } diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeBaseResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeBaseResponse.java index f263e082..e2eca689 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeBaseResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeBaseResponse.java @@ -5,7 +5,9 @@ import lombok.AccessLevel; import lombok.Builder; -@Builder(access = AccessLevel.PRIVATE) +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) public record BadgeBaseResponse( String name, BadgeType type, diff --git a/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeTypeServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeTypeServiceResponse.java index c65e5148..ee1c74e9 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeTypeServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeTypeServiceResponse.java @@ -30,8 +30,7 @@ private static List getBadges( List memberBadges ) { return badges.stream() - .map(badge -> BadgeBaseServiceResponse.of(badge, memberBadges)) - .toList(); + .map(badge -> BadgeBaseServiceResponse.of(badge, memberBadges)).toList(); } } diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/UsernameValidator.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/UsernameValidator.java index 02246005..8b0418e5 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/UsernameValidator.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/UsernameValidator.java @@ -10,17 +10,14 @@ public class UsernameValidator implements ConstraintValidator 10) { return false; } - // 첫 글자가 공백인 경우 return !(Objects.equals(username.charAt(0),' ')); } } \ No newline at end of file diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java b/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java index d3cc2fb8..7a1caac1 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java @@ -3,8 +3,8 @@ import com.smeem.api.badge.service.BadgeService; import com.smeem.api.badge.service.dto.response.BadgeServiceResponse; -import com.smeem.api.goal.service.dto.request.GoalGetServiceRequest; import com.smeem.api.goal.service.GoalService; +import com.smeem.api.goal.service.dto.request.GoalGetServiceRequest; import com.smeem.api.member.service.dto.request.MemberPushUpdateServiceRequest; import com.smeem.api.member.service.dto.request.MemberServiceUpdateUserProfileRequest; import com.smeem.api.member.service.dto.request.MemberUpdatePlanServiceRequest; @@ -17,7 +17,6 @@ import com.smeem.common.exception.MemberException; import com.smeem.common.exception.TrainingTimeException; import com.smeem.domain.badge.model.Badge; -import com.smeem.domain.goal.model.GoalType; import com.smeem.domain.member.model.Member; import com.smeem.domain.member.repository.MemberRepository; import com.smeem.domain.training.model.DayType; @@ -94,8 +93,9 @@ public MemberGetServiceResponse getMemberProfile(final long memberId) { @Transactional public void updateLearningPlan(final long memberId, final MemberUpdatePlanServiceRequest request) { val member = get(memberId); - updateGoalType(member, request.goalType()); - updatePushAlarmConsent(member, request.hasAlarm()); + member.updateGoal(request.goalType()); + member.updateGoal(request.goalType()); + member.updateHasAlarm(request.hasAlarm()); updateTrainingTime(member, request.trainingTime()); } @@ -158,18 +158,6 @@ private void addWelcomeBadge(final Member member, List badges) { badges.add(welcomeBadge); } - private void updateGoalType(Member member, GoalType goalType) { - if (nonNull(goalType)) { - member.updateGoal(goalType); - } - } - - private void updatePushAlarmConsent(Member member, final Boolean hasAlarm) { - if (nonNull(hasAlarm)) { - member.updateHasAlarm(hasAlarm); - } - } - private TrainingTimeServiceResponse generateTrainingTimeResponse(List trainingTimes) { val trainingTime = getOneTrainingTime(trainingTimes); return TrainingTimeServiceResponse.of( diff --git a/smeem-api/src/test/java/com/smeem/external/oauth/kakao/KakaoServiceTest.java b/smeem-api/src/test/java/com/smeem/external/oauth/kakao/KakaoServiceTest.java new file mode 100644 index 00000000..e28b7b2c --- /dev/null +++ b/smeem-api/src/test/java/com/smeem/external/oauth/kakao/KakaoServiceTest.java @@ -0,0 +1,7 @@ +package com.smeem.external.oauth.kakao; + +import static org.junit.jupiter.api.Assertions.*; + +class KakaoServiceTest { + +} \ No newline at end of file diff --git a/smeem-domain/src/main/java/com/smeem/domain/member/model/Member.java b/smeem-domain/src/main/java/com/smeem/domain/member/model/Member.java index a87d259c..fcc4c177 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/member/model/Member.java +++ b/smeem-domain/src/main/java/com/smeem/domain/member/model/Member.java @@ -16,6 +16,7 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import java.util.Objects; @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -63,6 +64,10 @@ public class Member extends BaseTimeEntity { @OneToMany(mappedBy = "member") private final List badges = new ArrayList<>(); + public void updateRefreshToken(String refreshToken) { + this.refreshToken = refreshToken; + } + @Builder public Member(SocialType social, String socialId, LangType targetLang, String fcmToken) { this.social = social; @@ -73,11 +78,8 @@ public Member(SocialType social, String socialId, LangType targetLang, String fc this.diaryComboCount = 0; } - public void updateRefreshToken(String refreshToken) { - this.refreshToken = refreshToken; - } - public void updateUsername(String username) { + this.username = username; } @@ -85,12 +87,16 @@ public void updateTermAccepted(boolean termAccepted) { this.termAccepted = termAccepted; } - public void updateHasAlarm(boolean hasAlarm) { - this.hasPushAlarm = hasAlarm; + public void updateHasAlarm(Boolean hasAlarm) { + if (Objects.nonNull(hasAlarm)) { + this.hasPushAlarm = hasAlarm; + } } public void updateGoal(GoalType goal) { - this.goal = goal; + if (Objects.nonNull(goal)) { + this.goal = goal; + } } public boolean hasDiaryWrittenToday() { diff --git a/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleService.java b/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleService.java index 54c16c66..910d4aef 100644 --- a/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleService.java +++ b/smeem-external/src/main/java/com/smeem/external/oauth/apple/AppleService.java @@ -64,14 +64,16 @@ private AppleKeyListResponse getApplePublicKeys() { private AppleKey matchDecodedKeyWithApplePublicKeys(final DecodedAppleKey decodedAppleKey, AppleKeyListResponse appleKeyList) { return appleKeyList.keys().stream() - .filter(appleKey -> - Objects.equals(decodedAppleKey.alg(), appleKey.alg()) && - Objects.equals(decodedAppleKey.kid(), appleKey.kid()) - ) + .filter(appleKey -> checkEqualAppleKey(decodedAppleKey, appleKey)) .findFirst() .orElseThrow(() -> new AuthException(FAIL_APPLE_REQUEST)); } + private boolean checkEqualAppleKey(final DecodedAppleKey decodedAppleKey, final AppleKey appleKey) { + return Objects.equals(decodedAppleKey.alg(), appleKey.alg()) && + Objects.equals(decodedAppleKey.kid(), appleKey.kid()); + } + private DecodedAppleKey decodeAppleAccessToken(final String accessToken) { try { val encoded = accessToken.split("\\."); diff --git a/smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoService.java b/smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoService.java index 5fbc482c..c63d9fe8 100644 --- a/smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoService.java +++ b/smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoService.java @@ -19,7 +19,7 @@ public class KakaoService { public String getKakaoData(final String accessToken) { try { - RestClient restClient = RestClient.create(); + val restClient = RestClient.create(); val response = restClient.get() .uri(valueConfig.getKAKAO_URL()) .header(AUTHORIZATION, "Bearer " + accessToken) From 78b3adafce3a011a01dea31caa0e52666c9f0e7a Mon Sep 17 00:00:00 2001 From: unanchoi Date: Tue, 27 Feb 2024 23:59:58 +0900 Subject: [PATCH 58/86] =?UTF-8?q?[CHORE]=20BadgeListResponse=20=EC=BB=A8?= =?UTF-8?q?=EB=B2=A4=EC=85=98=EC=97=90=20=EB=A7=9E=EC=B6=B0=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../badge/controller/dto/response/BadgeListResponse.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponse.java index d47a830b..654b4c87 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponse.java @@ -1,14 +1,12 @@ package com.smeem.api.badge.controller.dto.response; -import com.smeem.domain.badge.model.Badge; -import com.smeem.domain.badge.model.BadgeType; -import com.smeem.domain.member.model.MemberBadge; import lombok.*; import java.util.List; -import java.util.Map; -@Builder(access = AccessLevel.PRIVATE) +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) public record BadgeListResponse( List badgeTypes ) { From a595bf94b930163e04e4c7df02c698b894e9bb4e Mon Sep 17 00:00:00 2001 From: unanchoi Date: Wed, 28 Feb 2024 00:01:06 +0900 Subject: [PATCH 59/86] =?UTF-8?q?[CHORE]=20static=20import=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9=20=EB=B0=8F=20=EC=BD=94=EB=93=9C=20=EC=A0=95=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/badge/controller/dto/response/BadgeTypeResponse.java | 3 +-- .../badge/service/dto/response/BadgeListServiceResponse.java | 3 +-- .../badge/service/dto/response/BadgeTypeServiceResponse.java | 4 +++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeTypeResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeTypeResponse.java index 499647ff..37f82495 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeTypeResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeTypeResponse.java @@ -23,8 +23,7 @@ public static BadgeTypeResponse from(BadgeTypeServiceResponse response) { .badgeTypeName(response.badgeTypeName()) .badges(response.badges() .stream() - .map(BadgeBaseResponse::from) - .toList()) + .map(BadgeBaseResponse::from).toList()) .build(); } } \ No newline at end of file diff --git a/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeListServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeListServiceResponse.java index d17f4657..9fde9ecb 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeListServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeListServiceResponse.java @@ -25,7 +25,6 @@ public static BadgeListServiceResponse of(Map> badgeMap, private static List getBadgesType(Map> badgeMap, List memberBadges) { return badgeMap.keySet().stream() - .map(type -> BadgeTypeServiceResponse.of(type, badgeMap.get(type), memberBadges)) - .toList(); + .map(type -> BadgeTypeServiceResponse.of(type, badgeMap.get(type), memberBadges)).toList(); } } diff --git a/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeTypeServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeTypeServiceResponse.java index ee1c74e9..74291400 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeTypeServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/service/dto/response/BadgeTypeServiceResponse.java @@ -8,7 +8,9 @@ import java.util.List; -@Builder(access = AccessLevel.PRIVATE) +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) public record BadgeTypeServiceResponse( BadgeType badgeType, String badgeTypeName, From bf37a67379359eb29556cf62d61deb8f6105f6b1 Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 28 Feb 2024 00:15:26 +0900 Subject: [PATCH 60/86] =?UTF-8?q?[FIX]=20jar=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EA=B2=BD=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/run_new_was.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/run_new_was.sh b/scripts/run_new_was.sh index 3ae9af08..d53fee3e 100644 --- a/scripts/run_new_was.sh +++ b/scripts/run_new_was.sh @@ -22,13 +22,13 @@ fi if [ "$DEPLOYMENT_GROUP_NAME" == "prod-group" ] then - nohup java -jar -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=prod /home/ubuntu/smeme/build/libs/server-0.0.1-SNAPSHOT.jar > /dev/null 2> /dev/null < /dev/null & + nohup java -jar -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=prod /home/ubuntu/smeme/smeem-api/build/libs/smeem-api-0.0.1-SNAPSHOT.jar > /dev/null 2> /dev/null < /dev/null & echo "> Now new WAS runs at ${TARGET_PORT}." fi if [ "$DEPLOYMENT_GROUP_NAME" == "smeme-group" ] then - nohup java -jar -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=dev /home/ubuntu/smeme/build/libs/server-0.0.1-SNAPSHOT.jar > /dev/null 2> /dev/null < /dev/null & + nohup java -jar -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=dev /home/ubuntu/smeme/smeem-api/build/libs/smeem-api-0.0.1-SNAPSHOT.jar > /dev/null 2> /dev/null < /dev/null & echo "> Now new WAS runs at ${TARGET_PORT}." fi From d5ad78cdca53c8ca85f364f7e81b0f27164f6eff Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 28 Feb 2024 00:27:01 +0900 Subject: [PATCH 61/86] =?UTF-8?q?[FIX]=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20URI?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/health_check.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/health_check.sh b/scripts/health_check.sh index 65e7a73c..378271e9 100644 --- a/scripts/health_check.sh +++ b/scripts/health_check.sh @@ -20,7 +20,7 @@ echo "> Start health check of WAS at 'http://127.0.0.1:${TARGET_PORT}/api/v2/tes for RETRY_COUNT in 1 2 3 4 5 6 7 8 9 10 do echo "> #${RETRY_COUNT} trying..." - RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:${TARGET_PORT}/api/v2/com.smeem.test) + RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:${TARGET_PORT}/api/v2/test) if [ ${RESPONSE_CODE} -eq 200 ]; then echo "> New WAS successfully running" From 4e35c29a0d2fedbe353850a034bb82e9c98a5d53 Mon Sep 17 00:00:00 2001 From: unanchoi Date: Sat, 2 Mar 2024 16:56:42 +0900 Subject: [PATCH 62/86] =?UTF-8?q?[FIX]=20Bearer=20=EC=A4=91=EB=B3=B5?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=93=A4=EC=96=B4=EA=B0=80=EB=8A=94=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/smeem/external/oauth/kakao/KakaoService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoService.java b/smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoService.java index c63d9fe8..b0d59781 100644 --- a/smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoService.java +++ b/smeem-external/src/main/java/com/smeem/external/oauth/kakao/KakaoService.java @@ -22,7 +22,7 @@ public String getKakaoData(final String accessToken) { val restClient = RestClient.create(); val response = restClient.get() .uri(valueConfig.getKAKAO_URL()) - .header(AUTHORIZATION, "Bearer " + accessToken) + .header(AUTHORIZATION, accessToken) .retrieve() .onStatus(HttpStatusCode::is4xxClientError, (kakaoRequest, kakaoResponse) -> { From a26094a42fc25a0b47ccba2c1335efe2c09f9fb8 Mon Sep 17 00:00:00 2001 From: unanchoi Date: Sun, 3 Mar 2024 23:55:27 +0900 Subject: [PATCH 63/86] =?UTF-8?q?[FIX]=20MemberController=20Response=20DTO?= =?UTF-8?q?=20=EA=B5=90=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/smeem/api/member/controller/MemberController.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java b/smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java index bbeb41fe..21c7a276 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java @@ -5,7 +5,9 @@ import com.smeem.api.member.controller.dto.request.MemberPlanUpdateRequest; import com.smeem.api.member.controller.dto.request.MemberPushUpdateRequest; import com.smeem.api.member.controller.dto.request.MemberUpdateRequest; +import com.smeem.api.member.controller.dto.response.MemberGetResponse; import com.smeem.api.member.controller.dto.response.MemberNameResponse; +import com.smeem.api.member.controller.dto.response.MemberUpdateResponse; import com.smeem.api.member.service.MemberService; import com.smeem.api.member.service.dto.request.MemberPushUpdateServiceRequest; import com.smeem.api.member.service.dto.request.MemberUpdatePlanServiceRequest; @@ -31,15 +33,15 @@ public class MemberController { @PatchMapping public ResponseEntity> updateProfile(Principal principal, @RequestBody MemberUpdateRequest request) { - val response = memberService.updateUserProfile( + val response = MemberUpdateResponse.from(memberService.updateUserProfile( Util.getMemberId(principal), - MemberServiceUpdateUserProfileRequest.of(request)); + MemberServiceUpdateUserProfileRequest.of(request))); return ApiResponseUtil.success(SUCCESS_UPDATE_USERNAME, response); } @GetMapping("/me") public ResponseEntity> getProfile(Principal principal) { - val response = memberService.getMemberProfile(Util.getMemberId(principal)); + val response = MemberGetResponse.from(memberService.getMemberProfile(Util.getMemberId(principal))); return ApiResponseUtil.success(SUCCESS_GET_USER, response); } From 08279ee22dfaa58eb9c185587f5005f693479a28 Mon Sep 17 00:00:00 2001 From: unanchoi Date: Mon, 4 Mar 2024 00:00:16 +0900 Subject: [PATCH 64/86] =?UTF-8?q?[FIX]=20Badge=20=EB=AA=A9=EB=A1=9D=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=20DTO=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/smeem/api/badge/controller/BadgeController.java | 3 ++- .../badge/controller/dto/response/BadgeListResponse.java | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java index 44d1c872..8b45deaf 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java @@ -1,5 +1,6 @@ package com.smeem.api.badge.controller; +import com.smeem.api.badge.controller.dto.response.BadgeListResponse; import com.smeem.api.badge.service.BadgeService; import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; @@ -24,7 +25,7 @@ public class BadgeController { @GetMapping public ResponseEntity> getBadges(Principal principal) { - val response = badgeService.getBadges(Util.getMemberId(principal)); + val response = BadgeListResponse.from(badgeService.getBadges(Util.getMemberId(principal))); return ApiResponseUtil.success(SUCCESS_GET_BADGES, response); } diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponse.java index 654b4c87..c4cdf4d4 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponse.java @@ -1,5 +1,6 @@ package com.smeem.api.badge.controller.dto.response; +import com.smeem.api.badge.service.dto.response.BadgeListServiceResponse; import lombok.*; import java.util.List; @@ -11,10 +12,11 @@ public record BadgeListResponse( List badgeTypes ) { public static BadgeListResponse from( - List response + BadgeListServiceResponse response ) { return BadgeListResponse.builder() - .badgeTypes(response) + .badgeTypes(response.badgeTypes().stream() + .map(BadgeTypeResponse::from).toList()) .build(); } } \ No newline at end of file From db7057e4b9f46437a65ba72a6cefc937ff6e90be Mon Sep 17 00:00:00 2001 From: thguss Date: Tue, 5 Mar 2024 13:15:11 +0900 Subject: [PATCH 65/86] =?UTF-8?q?[CHORE]=20=EC=8A=A4=EC=9B=A8=EA=B1=B0=20?= =?UTF-8?q?=EC=9D=B4=EC=82=AC(=EC=9D=B8=ED=84=B0=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4)=20=EC=B4=88=EA=B8=B0=20=EC=84=B8=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smeem-api/build.gradle | 43 +----- .../com/smeem/api/config/SwaggerConfig.java | 9 +- .../java/com/smeem/api/test/api/TestApi.java | 30 ++++ .../TestApiController.java} | 4 +- .../src/main/resources/application-dev.yml | 7 - .../resources/static/docs/open-api-3.0.1.json | 16 -- .../api/controller/BaseControllerTest.java | 94 ++++++------ .../api/controller/TestControllerTest.java | 124 ++++++++-------- .../api/controller/TopicControllerTest.java | 140 +++++++++--------- 9 files changed, 217 insertions(+), 250 deletions(-) create mode 100644 smeem-api/src/main/java/com/smeem/api/test/api/TestApi.java rename smeem-api/src/main/java/com/smeem/api/test/{controller/TestController.java => api/TestApiController.java} (93%) delete mode 100644 smeem-api/src/main/resources/static/docs/open-api-3.0.1.json diff --git a/smeem-api/build.gradle b/smeem-api/build.gradle index 913e2528..3ad57e82 100644 --- a/smeem-api/build.gradle +++ b/smeem-api/build.gradle @@ -1,12 +1,3 @@ -import org.hidetake.gradle.swagger.generator.GenerateSwaggerUI - -plugins { - // restdocs-api-spec - id 'com.epages.restdocs-api-spec' version "0.18.2" - // swagger generator - id 'org.hidetake.swagger.generator' version '2.18.2' -} - dependencies { implementation project(':smeem-common') implementation project(':smeem-domain') @@ -22,47 +13,15 @@ dependencies { implementation group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.5' implementation group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.5' - // Swagger & RestDocs - testImplementation "com.epages:restdocs-api-spec-mockmvc:0.18.2" - testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' + // Swagger implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2' - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" -// implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0' - -} -swaggerSources { - sample { - setInputFile(file("build/api-spec/openapi3.yaml")) - } -} - -openapi3 { - server = "http://localhost:8080" - title = "SMEEM API Documentation" - description = "Spring REST Docs with SwaggerUI." - version = "0.0.1" - outputFileNamePrefix = 'open-api-3.0.1' - format = 'json' - outputDirectory = 'build/resources/main/static/docs' } ext { set('snippetsDir', file("build/generated-snippets")) } -tasks.withType(GenerateSwaggerUI).configureEach { - dependsOn 'openapi3' - copy { - from "build/resources/main/static/docs" - into "src/main/resources/static/docs/" - } -} - -bootJar { -// enabled = true - dependsOn('openapi3') -} repositories { mavenCentral() } diff --git a/smeem-api/src/main/java/com/smeem/api/config/SwaggerConfig.java b/smeem-api/src/main/java/com/smeem/api/config/SwaggerConfig.java index 94e9a683..733a95eb 100644 --- a/smeem-api/src/main/java/com/smeem/api/config/SwaggerConfig.java +++ b/smeem-api/src/main/java/com/smeem/api/config/SwaggerConfig.java @@ -7,6 +7,7 @@ import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; +import lombok.val; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -16,16 +17,16 @@ in = SecuritySchemeIn.HEADER, type = SecuritySchemeType.HTTP, bearerFormat = "JWT", - scheme = "bearer", + scheme = "Bearer", description = "Authorization: Bearer ~" ) public class SwaggerConfig { @Bean public OpenAPI openAPI() { - Info info = new Info() - .title("Smeme Server API V2 Spec") - .description("Smeme API V2 Document") + val info = new Info() + .title("Smeem Server API Spec") + .description("Smeme API Document") .version("1.0.0"); return new OpenAPI() diff --git a/smeem-api/src/main/java/com/smeem/api/test/api/TestApi.java b/smeem-api/src/main/java/com/smeem/api/test/api/TestApi.java new file mode 100644 index 00000000..2586784f --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/test/api/TestApi.java @@ -0,0 +1,30 @@ +package com.smeem.api.test.api; + +import com.smeem.api.common.BaseResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import org.springframework.http.ResponseEntity; + +import java.security.Principal; + +public interface TestApi { + + @Operation( + summary = "서버 연결 테스트", + responses = { + @ApiResponse(responseCode = "200", description = "성공"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") + } + ) + ResponseEntity> test(); + + @Operation( + summary = "푸시알림 테스트", + responses = { + @ApiResponse(responseCode = "200", description = "성공"), + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") + } + ) + ResponseEntity> alarmTest(Principal principal); +} diff --git a/smeem-api/src/main/java/com/smeem/api/test/controller/TestController.java b/smeem-api/src/main/java/com/smeem/api/test/api/TestApiController.java similarity index 93% rename from smeem-api/src/main/java/com/smeem/api/test/controller/TestController.java rename to smeem-api/src/main/java/com/smeem/api/test/api/TestApiController.java index 2c81c096..a08c9276 100644 --- a/smeem-api/src/main/java/com/smeem/api/test/controller/TestController.java +++ b/smeem-api/src/main/java/com/smeem/api/test/api/TestApiController.java @@ -1,4 +1,4 @@ -package com.smeem.api.test.controller; +package com.smeem.api.test.api; import java.security.Principal; @@ -21,7 +21,7 @@ @RestController @RequiredArgsConstructor @RequestMapping("/api/v2/test") -public class TestController { +public class TestApiController implements TestApi { private final TestService testService; diff --git a/smeem-api/src/main/resources/application-dev.yml b/smeem-api/src/main/resources/application-dev.yml index 7cc4ddb1..27ac09f0 100644 --- a/smeem-api/src/main/resources/application-dev.yml +++ b/smeem-api/src/main/resources/application-dev.yml @@ -38,13 +38,6 @@ jwt: badge: welcome-badge-id: ${WELCOME_BADGE_ID} -springdoc: - default-consumes-media-type: application/json;charset=UTF-8 - default-produces-media-type: application/json;charset=UTF-8 - swagger-ui: - url: /docs/open-api-3.0.1.json - path: /swagger - smeem: duration: expired: ${SMEEM.DURATION.EXPIRED} diff --git a/smeem-api/src/main/resources/static/docs/open-api-3.0.1.json b/smeem-api/src/main/resources/static/docs/open-api-3.0.1.json deleted file mode 100644 index e71bebc4..00000000 --- a/smeem-api/src/main/resources/static/docs/open-api-3.0.1.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "openapi" : "3.0.1", - "info" : { - "title" : "SMEEM API Documentation", - "description" : "Spring REST Docs with SwaggerUI.", - "version" : "0.0.1" - }, - "servers" : [ { - "url" : "http://localhost:8080" - } ], - "tags" : [ ], - "paths" : { }, - "components" : { - "schemas" : { } - } -} \ No newline at end of file diff --git a/smeem-api/src/test/java/com/smeem/api/controller/BaseControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/BaseControllerTest.java index d09f5ace..bb762b06 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/BaseControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/BaseControllerTest.java @@ -1,47 +1,47 @@ -package com.smeem.api.controller; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.smeem.api.auth.jwt.CustomJwtAuthenticationEntryPoint; -import com.smeem.api.auth.jwt.TokenProvider; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.restdocs.RestDocumentationContextProvider; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; -import org.springframework.web.filter.CharacterEncodingFilter; - -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; - -//@AutoConfigureMockMvc -//@AutoConfigureRestDocs -//@ExtendWith({RestDocumentationExtension.class}) -@WebMvcTest(properties = "spring.config.location=classpath:/application.yml") -public abstract class BaseControllerTest { - - @Autowired - protected WebApplicationContext context; - - @Autowired - protected ObjectMapper objectMapper; - - @Autowired - protected MockMvc mockMvc; - - @MockBean - private TokenProvider jwtTokenProvider; - - @MockBean - private CustomJwtAuthenticationEntryPoint customJwtAuthenticationEntryPoint; - -// @BeforeEach - void setUp(final RestDocumentationContextProvider restDocumentation) { - mockMvc = MockMvcBuilders.webAppContextSetup(context) - .apply(documentationConfiguration(restDocumentation)) - .addFilters(new CharacterEncodingFilter("UTF-8", true)) - .alwaysDo(print()) - .build(); - } -} +//package com.smeem.api.controller; +// +//import com.fasterxml.jackson.databind.ObjectMapper; +//import com.smeem.api.auth.jwt.CustomJwtAuthenticationEntryPoint; +//import com.smeem.api.auth.jwt.TokenProvider; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +//import org.springframework.boot.test.mock.mockito.MockBean; +//import org.springframework.restdocs.RestDocumentationContextProvider; +//import org.springframework.test.web.servlet.MockMvc; +//import org.springframework.test.web.servlet.setup.MockMvcBuilders; +//import org.springframework.web.context.WebApplicationContext; +//import org.springframework.web.filter.CharacterEncodingFilter; +// +//import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; +//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +// +////@AutoConfigureMockMvc +////@AutoConfigureRestDocs +////@ExtendWith({RestDocumentationExtension.class}) +//@WebMvcTest(properties = "spring.config.location=classpath:/application.yml") +//public abstract class BaseControllerTest { +// +// @Autowired +// protected WebApplicationContext context; +// +// @Autowired +// protected ObjectMapper objectMapper; +// +// @Autowired +// protected MockMvc mockMvc; +// +// @MockBean +// private TokenProvider jwtTokenProvider; +// +// @MockBean +// private CustomJwtAuthenticationEntryPoint customJwtAuthenticationEntryPoint; +// +//// @BeforeEach +// void setUp(final RestDocumentationContextProvider restDocumentation) { +// mockMvc = MockMvcBuilders.webAppContextSetup(context) +// .apply(documentationConfiguration(restDocumentation)) +// .addFilters(new CharacterEncodingFilter("UTF-8", true)) +// .alwaysDo(print()) +// .build(); +// } +//} diff --git a/smeem-api/src/test/java/com/smeem/api/controller/TestControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/TestControllerTest.java index 22c43242..1660589c 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/TestControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/TestControllerTest.java @@ -1,62 +1,62 @@ -package com.smeem.api.controller; - -import com.epages.restdocs.apispec.ResourceSnippetParameters; -import com.smeem.api.common.ApiResponseUtil; -import com.smeem.api.test.controller.TestController; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; -import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; -import org.springframework.restdocs.payload.JsonFieldType; -import org.springframework.test.web.servlet.ResultActions; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; - -import static com.epages.restdocs.apispec.ResourceDocumentation.resource; -import static com.smeem.common.code.success.TestSuccessCode.SUCCESS_SERVER_CONNECT; -import static org.mockito.Mockito.when; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; -import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; - -//@DisplayName("TestController 테스트") -//@WebMvcTest(value = TestController.class) -class TestControllerTest extends BaseControllerTest { - - private static final String DEFAULT_URL = "/api/v2/com.smeem.test"; - - @MockBean - TestController testController; - -// @Test -// @DisplayName("서버 연결 테스트") - void success_test() throws Exception { - - //given - when(testController.test()) - .thenReturn(ApiResponseUtil.success(SUCCESS_SERVER_CONNECT)); - - //then - ResultActions resultActions = mockMvc.perform( - RestDocumentationRequestBuilders.get(DEFAULT_URL) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON) - ).andDo( - MockMvcRestDocumentation.document( - "com.smeem.test-docs", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint()), - resource( - ResourceSnippetParameters.builder() - .description("서버 연결 테스트") - .requestFields() - .responseFields( - fieldWithPath("success").type(JsonFieldType.BOOLEAN).description("응답 성공 여부"), - fieldWithPath("message").type(JsonFieldType.STRING).description("응답 메시지"), - fieldWithPath("data").type(JsonFieldType.NULL).description("응답 데이터") - ).build() - ) - ) - ); - resultActions.andExpect(MockMvcResultMatchers.status().isOk()); - } -} - +//package com.smeem.api.controller; +// +//import com.epages.restdocs.apispec.ResourceSnippetParameters; +//import com.smeem.api.common.ApiResponseUtil; +//import com.smeem.api.test.api.TestApiController; +//import org.springframework.boot.test.mock.mockito.MockBean; +//import org.springframework.http.MediaType; +//import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; +//import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; +//import org.springframework.restdocs.payload.JsonFieldType; +//import org.springframework.test.web.servlet.ResultActions; +//import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +// +//import static com.epages.restdocs.apispec.ResourceDocumentation.resource; +//import static com.smeem.common.code.success.TestSuccessCode.SUCCESS_SERVER_CONNECT; +//import static org.mockito.Mockito.when; +//import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; +//import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +// +////@DisplayName("TestController 테스트") +////@WebMvcTest(value = TestController.class) +//class TestControllerTest extends BaseControllerTest { +// +// private static final String DEFAULT_URL = "/api/v2/com.smeem.test"; +// +// @MockBean +// TestApiController testController; +// +//// @Test +//// @DisplayName("서버 연결 테스트") +// void success_test() throws Exception { +// +// //given +// when(testController.test()) +// .thenReturn(ApiResponseUtil.success(SUCCESS_SERVER_CONNECT)); +// +// //then +// ResultActions resultActions = mockMvc.perform( +// RestDocumentationRequestBuilders.get(DEFAULT_URL) +// .contentType(MediaType.APPLICATION_JSON) +// .accept(MediaType.APPLICATION_JSON) +// ).andDo( +// MockMvcRestDocumentation.document( +// "com.smeem.test-docs", +// preprocessRequest(prettyPrint()), +// preprocessResponse(prettyPrint()), +// resource( +// ResourceSnippetParameters.builder() +// .description("서버 연결 테스트") +// .requestFields() +// .responseFields( +// fieldWithPath("success").type(JsonFieldType.BOOLEAN).description("응답 성공 여부"), +// fieldWithPath("message").type(JsonFieldType.STRING).description("응답 메시지"), +// fieldWithPath("data").type(JsonFieldType.NULL).description("응답 데이터") +// ).build() +// ) +// ) +// ); +// resultActions.andExpect(MockMvcResultMatchers.status().isOk()); +// } +//} +// diff --git a/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java index 04265072..bb79e5ec 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/TopicControllerTest.java @@ -1,70 +1,70 @@ -package com.smeem.api.controller; - -import com.epages.restdocs.apispec.ResourceSnippetParameters; -import com.smeem.api.common.ApiResponseUtil; -import com.smeem.api.topic.controller.TopicController; -import com.smeem.api.topic.service.dto.response.RandomTopicGetServiceResponse; -import lombok.val; -import org.springframework.boot.test.mock.mockito.MockBean; - -import java.security.Principal; - -import static com.epages.restdocs.apispec.ResourceDocumentation.resource; -import static com.smeem.common.code.success.TopicSuccessCode.SUCCESS_GET_RANDOM_TOPIC; -import static org.mockito.Mockito.when; -import static org.springframework.http.MediaType.APPLICATION_JSON; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; -import static org.springframework.restdocs.payload.JsonFieldType.*; -import static org.springframework.restdocs.payload.JsonFieldType.STRING; -import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -//@DisplayName("TopicController 테스트") -//@WebMvcTest(TopicController.class) -class TopicControllerTest extends BaseControllerTest { - @MockBean - TopicController topicController; - @MockBean - Principal principal; - - private final String DEFAULT_URL = "/api/v2/topics"; - private final String TAG = "Topic"; - -// @Test -// @DisplayName("랜덤 주제 조회 테스트") - void success_get_random_topic_test() throws Exception { - // given - RandomTopicGetServiceResponse response = new RandomTopicGetServiceResponse(1L, "가보고 싶은 해외 여행 지가 있다면 소개해 주세요!"); - val result = ApiResponseUtil.success(SUCCESS_GET_RANDOM_TOPIC, response); - - // when - when(topicController.getTopicByRandom()).thenReturn(result); - - // then - mockMvc.perform(get(DEFAULT_URL + "/random") - .contentType(APPLICATION_JSON) - .accept(APPLICATION_JSON) - .principal(principal)) - .andDo( - document("랜덤 주제 조회 성공 Example", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint()), - resource(ResourceSnippetParameters.builder() - .tag(TAG) - .description("랜덤 주제 조회") - .responseFields( - fieldWithPath("success").type(BOOLEAN).description("응답 성공 여부"), - fieldWithPath("message").type(STRING).description("응답 메시지"), - fieldWithPath("data").type(OBJECT).description("응답 데이터"), - fieldWithPath("data.topicId").type(NUMBER).description("랜덤 주제 id"), - fieldWithPath("data.content").type(STRING).description("랜덤 주제 내용") - ) - .build() - ) - )) - .andExpect(status().isOk()); - } -} \ No newline at end of file +//package com.smeem.api.controller; +// +//import com.epages.restdocs.apispec.ResourceSnippetParameters; +//import com.smeem.api.common.ApiResponseUtil; +//import com.smeem.api.topic.controller.TopicController; +//import com.smeem.api.topic.service.dto.response.RandomTopicGetServiceResponse; +//import lombok.val; +//import org.springframework.boot.test.mock.mockito.MockBean; +// +//import java.security.Principal; +// +//import static com.epages.restdocs.apispec.ResourceDocumentation.resource; +//import static com.smeem.common.code.success.TopicSuccessCode.SUCCESS_GET_RANDOM_TOPIC; +//import static org.mockito.Mockito.when; +//import static org.springframework.http.MediaType.APPLICATION_JSON; +//import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +//import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; +//import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; +//import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; +//import static org.springframework.restdocs.payload.JsonFieldType.*; +//import static org.springframework.restdocs.payload.JsonFieldType.STRING; +//import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +// +////@DisplayName("TopicController 테스트") +////@WebMvcTest(TopicController.class) +//class TopicControllerTest extends BaseControllerTest { +// @MockBean +// TopicController topicController; +// @MockBean +// Principal principal; +// +// private final String DEFAULT_URL = "/api/v2/topics"; +// private final String TAG = "Topic"; +// +//// @Test +//// @DisplayName("랜덤 주제 조회 테스트") +// void success_get_random_topic_test() throws Exception { +// // given +// RandomTopicGetServiceResponse response = new RandomTopicGetServiceResponse(1L, "가보고 싶은 해외 여행 지가 있다면 소개해 주세요!"); +// val result = ApiResponseUtil.success(SUCCESS_GET_RANDOM_TOPIC, response); +// +// // when +// when(topicController.getTopicByRandom()).thenReturn(result); +// +// // then +// mockMvc.perform(get(DEFAULT_URL + "/random") +// .contentType(APPLICATION_JSON) +// .accept(APPLICATION_JSON) +// .principal(principal)) +// .andDo( +// document("랜덤 주제 조회 성공 Example", +// preprocessRequest(prettyPrint()), +// preprocessResponse(prettyPrint()), +// resource(ResourceSnippetParameters.builder() +// .tag(TAG) +// .description("랜덤 주제 조회") +// .responseFields( +// fieldWithPath("success").type(BOOLEAN).description("응답 성공 여부"), +// fieldWithPath("message").type(STRING).description("응답 메시지"), +// fieldWithPath("data").type(OBJECT).description("응답 데이터"), +// fieldWithPath("data.topicId").type(NUMBER).description("랜덤 주제 id"), +// fieldWithPath("data.content").type(STRING).description("랜덤 주제 내용") +// ) +// .build() +// ) +// )) +// .andExpect(status().isOk()); +// } +//} \ No newline at end of file From d630dab61af87eee9bf3a2b6db2131a6893f265e Mon Sep 17 00:00:00 2001 From: unanchoi Date: Tue, 5 Mar 2024 23:54:57 +0900 Subject: [PATCH 66/86] =?UTF-8?q?[FEAT]=20Discord=20=EC=95=8C=EB=9E=8C=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../failure/InternalServerFailureCode.java | 23 +++++++++ .../external/discord/DiscordAlarmCase.java | 13 +++++ .../external/discord/DiscordAlarmSender.java | 48 +++++++++++++++++++ .../external/discord/DiscordRequest.java | 17 +++++++ 4 files changed, 101 insertions(+) create mode 100644 smeem-common/src/main/java/com/smeem/common/code/failure/InternalServerFailureCode.java create mode 100644 smeem-external/src/main/java/com/smeem/external/discord/DiscordAlarmCase.java create mode 100644 smeem-external/src/main/java/com/smeem/external/discord/DiscordAlarmSender.java create mode 100644 smeem-external/src/main/java/com/smeem/external/discord/DiscordRequest.java diff --git a/smeem-common/src/main/java/com/smeem/common/code/failure/InternalServerFailureCode.java b/smeem-common/src/main/java/com/smeem/common/code/failure/InternalServerFailureCode.java new file mode 100644 index 00000000..d1ac0ec9 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/code/failure/InternalServerFailureCode.java @@ -0,0 +1,23 @@ +package com.smeem.common.code.failure; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; + +@Getter +@RequiredArgsConstructor +public enum InternalServerFailureCode implements FailureCode { + + /* + * 500 INTERNAL_SERVER_ERROR + */ + + SERVER_ERROR(INTERNAL_SERVER_ERROR, "서버 내부 오류"), + ; + + private final HttpStatus status; + private final String message; + +} diff --git a/smeem-external/src/main/java/com/smeem/external/discord/DiscordAlarmCase.java b/smeem-external/src/main/java/com/smeem/external/discord/DiscordAlarmCase.java new file mode 100644 index 00000000..201b38f8 --- /dev/null +++ b/smeem-external/src/main/java/com/smeem/external/discord/DiscordAlarmCase.java @@ -0,0 +1,13 @@ +package com.smeem.external.discord; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum DiscordAlarmCase { + ERROR("서버 에러 알라미"), + INFO("서버 알리미"); + + private final String message; +} diff --git a/smeem-external/src/main/java/com/smeem/external/discord/DiscordAlarmSender.java b/smeem-external/src/main/java/com/smeem/external/discord/DiscordAlarmSender.java new file mode 100644 index 00000000..8aac8945 --- /dev/null +++ b/smeem-external/src/main/java/com/smeem/external/discord/DiscordAlarmSender.java @@ -0,0 +1,48 @@ +package com.smeem.external.discord; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.smeem.common.config.ValueConfig; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import lombok.val; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestClient; + +import static org.springframework.http.HttpHeaders.ACCEPT; + +@Component +@RequiredArgsConstructor +@Slf4j +public class DiscordAlarmSender { + + private final ObjectMapper objectMapper; + private final ValueConfig valueConfig; + + public void send(final String content, final DiscordAlarmCase alarmCase) { + try { + val restClient = RestClient.create(); + restClient.post() + .uri(webHookUri(alarmCase)) + .header(ACCEPT, "application/json; UTF-8") + .body(makeRequestBody(content)) + .retrieve(); + } catch (RuntimeException | JsonProcessingException e) { + log.error("디스코드 알람 전송에 실패했습니다.", e); + // TODO: add Sentry Capture Exception + } + + } + + private String makeRequestBody(String content) throws JsonProcessingException { + val request = DiscordRequest.of(content); + return objectMapper.writeValueAsString(request); + } + + private String webHookUri(DiscordAlarmCase alarmCase) { + return switch (alarmCase) { + case ERROR -> valueConfig.getDISCORD_WEBHOOK_ERROR_URL(); + case INFO -> valueConfig.getDISCORD_WEBHOOK_INFO_URL(); + }; + } +} diff --git a/smeem-external/src/main/java/com/smeem/external/discord/DiscordRequest.java b/smeem-external/src/main/java/com/smeem/external/discord/DiscordRequest.java new file mode 100644 index 00000000..e9ece87d --- /dev/null +++ b/smeem-external/src/main/java/com/smeem/external/discord/DiscordRequest.java @@ -0,0 +1,17 @@ +package com.smeem.external.discord; + +import lombok.Builder; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record DiscordRequest( + String content +) { + + public static DiscordRequest of(String content) { + return DiscordRequest.builder() + .content(content) + .build(); + } +} From 200afe3e30a04124766216a3b0114cb74f09c109 Mon Sep 17 00:00:00 2001 From: unanchoi Date: Tue, 5 Mar 2024 23:56:33 +0900 Subject: [PATCH 67/86] =?UTF-8?q?[SETTING]=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=EC=97=90=20Discord=20Webhook=20Uri=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smeem-api/src/main/resources/application-dev.yml | 7 ++++++- smeem-api/src/main/resources/application-local.yml | 7 ++++++- smeem-api/src/main/resources/application-prod.yml | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/smeem-api/src/main/resources/application-dev.yml b/smeem-api/src/main/resources/application-dev.yml index 7cc4ddb1..8561db94 100644 --- a/smeem-api/src/main/resources/application-dev.yml +++ b/smeem-api/src/main/resources/application-dev.yml @@ -48,4 +48,9 @@ springdoc: smeem: duration: expired: ${SMEEM.DURATION.EXPIRED} - remind: ${SMEEM.DURATION.REMIND} \ No newline at end of file + remind: ${SMEEM.DURATION.REMIND} + +discord: + webhook: + error-url: ${DISCORD.WEBHOOK_ERROR_URL} + info-url: ${DISCORD.WEBHOOK_INFO_URL} \ No newline at end of file diff --git a/smeem-api/src/main/resources/application-local.yml b/smeem-api/src/main/resources/application-local.yml index 871b38a6..8d5e9c9a 100644 --- a/smeem-api/src/main/resources/application-local.yml +++ b/smeem-api/src/main/resources/application-local.yml @@ -48,4 +48,9 @@ springdoc: smeem: duration: expired: ${SMEEM.DURATION.EXPIRED} - remind: ${SMEEM.DURATION.REMIND} \ No newline at end of file + remind: ${SMEEM.DURATION.REMIND} + +discord: + webhook: + error-url: ${DISCORD.WEBHOOK_ERROR_URL} + info-url: ${DISCORD.WEBHOOK_INFO_URL} \ No newline at end of file diff --git a/smeem-api/src/main/resources/application-prod.yml b/smeem-api/src/main/resources/application-prod.yml index 87eea351..f67e35d7 100644 --- a/smeem-api/src/main/resources/application-prod.yml +++ b/smeem-api/src/main/resources/application-prod.yml @@ -42,4 +42,9 @@ badge: smeem: duration: expired: ${SMEEM.DURATION.EXPIRED} - remind: ${SMEEM.DURATION.REMIND} \ No newline at end of file + remind: ${SMEEM.DURATION.REMIND} + +discord: + webhook: + error-url: ${DISCORD.WEBHOOK_ERROR_URL} + info-url: ${DISCORD.WEBHOOK_INFO_URL} \ No newline at end of file From 150d353090d2137e1fc1c7061ed57a50a74cf071 Mon Sep 17 00:00:00 2001 From: unanchoi Date: Tue, 5 Mar 2024 23:59:53 +0900 Subject: [PATCH 68/86] =?UTF-8?q?[FEAT]=20=EB=94=94=EC=8A=A4=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85=20=EC=95=8C?= =?UTF-8?q?=EB=9E=8C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/common/advicer/ErrorHandler.java | 19 +++++++++++++++ .../api/member/service/MemberService.java | 23 +++++++++++++------ .../com/smeem/common/config/ValueConfig.java | 8 +++++++ 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java b/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java index a8b59a02..fe749c02 100644 --- a/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java +++ b/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java @@ -2,14 +2,23 @@ import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; +import com.smeem.common.code.failure.FailureCode; +import com.smeem.common.code.failure.InternalServerFailureCode; import com.smeem.common.exception.*; +import com.smeem.external.discord.DiscordAlarmSender; +import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import static com.smeem.external.discord.DiscordAlarmCase.ERROR; + @RestControllerAdvice +@RequiredArgsConstructor public class ErrorHandler { + private final DiscordAlarmSender discordAlarmSender; + @ExceptionHandler(TrainingTimeException.class) public ResponseEntity> trainingTimeException(TrainingTimeException exception) { return ApiResponseUtil.failure(exception.getFailureCode()); @@ -59,4 +68,14 @@ public ResponseEntity> fcmException(FcmException exception) { public ResponseEntity> authException(AuthException exception) { return ApiResponseUtil.failure(exception.getFailureCode()); } + + @ExceptionHandler(RuntimeException.class) + public ResponseEntity> baseException(RuntimeException exception) { + sendDiscordAlarm(exception); + return ApiResponseUtil.failure(InternalServerFailureCode.SERVER_ERROR); + } + + private void sendDiscordAlarm(RuntimeException exception) { + discordAlarmSender.send(exception.getMessage(), ERROR); + } } diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java b/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java index 7a1caac1..24b13cfd 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java @@ -21,6 +21,7 @@ import com.smeem.domain.member.repository.MemberRepository; import com.smeem.domain.training.model.DayType; import com.smeem.domain.training.model.TrainingTime; +import com.smeem.external.discord.DiscordAlarmSender; import lombok.RequiredArgsConstructor; import lombok.val; import org.springframework.stereotype.Service; @@ -34,6 +35,8 @@ import static com.smeem.common.code.failure.MemberFailureCode.DUPLICATE_USERNAME; import static com.smeem.common.code.failure.MemberFailureCode.EMPTY_MEMBER; import static com.smeem.common.code.failure.TrainingTimeFailureCode.NOT_SET_TRAINING_TIME; +import static com.smeem.common.config.ValueConfig.SIGN_IN_MESSAGE; +import static com.smeem.external.discord.DiscordAlarmCase.INFO; import static java.util.Objects.isNull; import static java.util.Objects.nonNull; @@ -48,6 +51,7 @@ public class MemberService { private final GoalService goalService; private final BadgeService badgeService; private final MemberBadgeService memberBadgeService; + private final DiscordAlarmSender discordAlarmSender; private final ValueConfig valueConfig; @@ -58,19 +62,14 @@ public MemberUpdateServiceResponse updateUserProfile(final long memberId, final updateTermAccepted(member, request); ArrayList badges = new ArrayList<>(); - if (isNull(member.getUsername())) { + if (isNewMember(member)) { addWelcomeBadge(member, badges); + discordAlarmSender.send(SIGN_IN_MESSAGE + member.getId(), INFO); } member.updateUsername(request.username()); return MemberUpdateServiceResponse.of(badges); } - private void updateTermAccepted(final Member member, final MemberServiceUpdateUserProfileRequest request) { - if (nonNull(request.termAccepted())) { - member.updateTermAccepted(request.termAccepted()); - } - } - public MemberGetServiceResponse getMemberProfile(final long memberId) { val member = get(memberId); val goal = goalService.getByType(GoalGetServiceRequest.of(member.getGoal())); @@ -165,4 +164,14 @@ private TrainingTimeServiceResponse generateTrainingTimeResponse(List Date: Wed, 6 Mar 2024 00:29:42 +0900 Subject: [PATCH 69/86] =?UTF-8?q?[CHORE]=20=EB=94=94=EC=8A=A4=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=95=8C=EB=9E=8C=EC=8B=9C=EC=97=90=20=EC=8B=A4?= =?UTF-8?q?=ED=96=89=20=ED=99=98=EA=B2=BD=20=ED=99=95=EC=9D=B8=20=EA=B0=80?= =?UTF-8?q?=EB=8A=A5=ED=95=98=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smeem/external/discord/DiscordAlarmSender.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/smeem-external/src/main/java/com/smeem/external/discord/DiscordAlarmSender.java b/smeem-external/src/main/java/com/smeem/external/discord/DiscordAlarmSender.java index 8aac8945..f13d4735 100644 --- a/smeem-external/src/main/java/com/smeem/external/discord/DiscordAlarmSender.java +++ b/smeem-external/src/main/java/com/smeem/external/discord/DiscordAlarmSender.java @@ -6,6 +6,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import lombok.val; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; import org.springframework.web.client.RestClient; @@ -18,6 +19,7 @@ public class DiscordAlarmSender { private final ObjectMapper objectMapper; private final ValueConfig valueConfig; + private final Environment environment; public void send(final String content, final DiscordAlarmCase alarmCase) { try { @@ -35,10 +37,17 @@ public void send(final String content, final DiscordAlarmCase alarmCase) { } private String makeRequestBody(String content) throws JsonProcessingException { - val request = DiscordRequest.of(content); + val request = DiscordRequest.of("[" + getCurrentProfile() + "] : " + content); return objectMapper.writeValueAsString(request); } + private String getCurrentProfile() { + if (environment.getActiveProfiles().length == 0) { + return "default"; + } + return environment.getActiveProfiles()[0]; + } + private String webHookUri(DiscordAlarmCase alarmCase) { return switch (alarmCase) { case ERROR -> valueConfig.getDISCORD_WEBHOOK_ERROR_URL(); From ad0102c7e12783fb3f72f9a556b7d80e345f9ff8 Mon Sep 17 00:00:00 2001 From: unanchoi Date: Wed, 6 Mar 2024 00:30:52 +0900 Subject: [PATCH 70/86] =?UTF-8?q?[STYLE]:=20FailureCode=20static=20import?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/smeem/api/common/advicer/ErrorHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java b/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java index fe749c02..76a4615d 100644 --- a/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java +++ b/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java @@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import static com.smeem.common.code.failure.InternalServerFailureCode.SERVER_ERROR; import static com.smeem.external.discord.DiscordAlarmCase.ERROR; @RestControllerAdvice @@ -72,7 +73,7 @@ public ResponseEntity> authException(AuthException exception) { @ExceptionHandler(RuntimeException.class) public ResponseEntity> baseException(RuntimeException exception) { sendDiscordAlarm(exception); - return ApiResponseUtil.failure(InternalServerFailureCode.SERVER_ERROR); + return ApiResponseUtil.failure(SERVER_ERROR); } private void sendDiscordAlarm(RuntimeException exception) { From 525536874210def11f35f2347507532403dcb727 Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 6 Mar 2024 13:14:46 +0900 Subject: [PATCH 71/86] =?UTF-8?q?[FIX]=20=EC=9C=A0=EC=97=B0=EC=84=B1?= =?UTF-8?q?=EC=9D=84=20=EC=9C=84=ED=95=B4=20GoalType=20=ED=83=80=EC=9E=85?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goal/service/dto/response/GoalGetServiceResponse.java | 5 +++-- .../service/dto/response/MemberGetServiceResponse.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/goal/service/dto/response/GoalGetServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/goal/service/dto/response/GoalGetServiceResponse.java index bf3c8584..db0f1875 100644 --- a/smeem-api/src/main/java/com/smeem/api/goal/service/dto/response/GoalGetServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/service/dto/response/GoalGetServiceResponse.java @@ -1,20 +1,21 @@ package com.smeem.api.goal.service.dto.response; import com.smeem.domain.goal.model.Goal; +import com.smeem.domain.goal.model.GoalType; import lombok.Builder; import static lombok.AccessLevel.PRIVATE; @Builder(access = PRIVATE) public record GoalGetServiceResponse( - String goalType, + GoalType goalType, String way, String detail ) { public static GoalGetServiceResponse of(Goal goal) { return GoalGetServiceResponse.builder() - .goalType(goal.getType().name()) + .goalType(goal.getType()) .way(goal.getWay()) .detail(goal.getDetail()) .build(); diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberGetServiceResponse.java b/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberGetServiceResponse.java index 4d8f76d4..59681ecf 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberGetServiceResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/dto/response/MemberGetServiceResponse.java @@ -2,6 +2,7 @@ import com.smeem.api.badge.service.dto.response.BadgeServiceResponse; import com.smeem.api.goal.service.dto.response.GoalGetServiceResponse; +import com.smeem.domain.goal.model.GoalType; import com.smeem.domain.member.model.LangType; import com.smeem.domain.member.model.Member; import lombok.Builder; @@ -12,7 +13,7 @@ @Builder(access = PRIVATE) public record MemberGetServiceResponse( String username, - String target, + GoalType goalType, String way, String detail, LangType targetLangType, @@ -29,7 +30,7 @@ public static MemberGetServiceResponse of( ) { return MemberGetServiceResponse.builder() .username(member.getUsername()) - .target(goal.goalType()) + .goalType(goal.goalType()) .way(goal.way()) .detail(goal.detail()) .targetLangType(member.getTargetLang()) From b7dc49ccb4fe98dea62f3b1174027873d9a067b6 Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 6 Mar 2024 13:15:21 +0900 Subject: [PATCH 72/86] =?UTF-8?q?[ADD]=20=EB=AA=A9=ED=91=9C=20=EC=A0=9C?= =?UTF-8?q?=EB=AA=A9=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/goal/controller/dto/response/GoalGetResponse.java | 4 +++- .../api/member/controller/dto/response/MemberGetResponse.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalGetResponse.java b/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalGetResponse.java index 9d28287e..0c423bca 100644 --- a/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalGetResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalGetResponse.java @@ -8,13 +8,15 @@ @Builder(access = PRIVATE) public record GoalGetResponse( String name, + String title, String way, String detail ) { public static GoalGetResponse from(GoalGetServiceResponse response) { return GoalGetResponse.builder() - .name(response.goalType()) + .name(response.goalType().name()) + .title(response.goalType().getDescription()) .way(response.way()) .detail(response.detail()) .build(); diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponse.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponse.java index b8e8ee89..79746858 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponse.java @@ -10,6 +10,7 @@ public record MemberGetResponse( String username, String target, + String title, String way, String detail, String targetLang, @@ -21,7 +22,8 @@ public record MemberGetResponse( public static MemberGetResponse from(MemberGetServiceResponse response) { return MemberGetResponse.builder() .username(response.username()) - .target(response.target()) + .target(response.goalType().name()) + .title(response.goalType().getDescription()) .way(response.way()) .detail(response.detail()) .targetLang(response.targetLangType().toString()) From df0bc745d9ba0a0bbb0da37b9cca9371cad9e4e7 Mon Sep 17 00:00:00 2001 From: unanchoi Date: Mon, 11 Mar 2024 20:10:06 +0900 Subject: [PATCH 73/86] =?UTF-8?q?[FIX]=20=EC=A4=91=EB=B3=B5=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=EB=90=9C=20=EB=A1=9C=EC=A7=81=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/smeem/api/member/service/MemberService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java b/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java index 24b13cfd..74f78145 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/MemberService.java @@ -93,7 +93,6 @@ public MemberGetServiceResponse getMemberProfile(final long memberId) { public void updateLearningPlan(final long memberId, final MemberUpdatePlanServiceRequest request) { val member = get(memberId); member.updateGoal(request.goalType()); - member.updateGoal(request.goalType()); member.updateHasAlarm(request.hasAlarm()); updateTrainingTime(member, request.trainingTime()); } From cd8800ef19414c4ca81adbc47ce5de20305cbea5 Mon Sep 17 00:00:00 2001 From: unanchoi Date: Mon, 11 Mar 2024 20:35:01 +0900 Subject: [PATCH 74/86] =?UTF-8?q?[CHORE]=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20import=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/smeem/api/common/advicer/ErrorHandler.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java b/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java index 76a4615d..ca0f1637 100644 --- a/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java +++ b/smeem-api/src/main/java/com/smeem/api/common/advicer/ErrorHandler.java @@ -2,8 +2,6 @@ import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; -import com.smeem.common.code.failure.FailureCode; -import com.smeem.common.code.failure.InternalServerFailureCode; import com.smeem.common.exception.*; import com.smeem.external.discord.DiscordAlarmSender; import lombok.RequiredArgsConstructor; From c36c99715092b286425392543831628ad80dca31 Mon Sep 17 00:00:00 2001 From: unanchoi Date: Mon, 11 Mar 2024 22:54:43 +0900 Subject: [PATCH 75/86] [SETTING] Spring Boot version 3.2.0 -> 3.2.1 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 51591398..0fe158d1 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { plugins { id 'java' - id 'org.springframework.boot' version '3.2.0' + id 'org.springframework.boot' version '3.2.1' id 'io.spring.dependency-management' version '1.1.4' } From fd6c775070c4b624e26bf43fc676d997a4a39a88 Mon Sep 17 00:00:00 2001 From: unanchoi Date: Mon, 11 Mar 2024 22:55:19 +0900 Subject: [PATCH 76/86] =?UTF-8?q?[FIX]=20TrainingTimeRequest=EB=A5=BC=20nu?= =?UTF-8?q?ll=EB=A1=9C=20=EB=B3=B4=EB=82=B4=EB=8A=94=20=EA=B2=83=EC=97=90?= =?UTF-8?q?=20=EB=8C=80=EC=9D=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/dto/request/TrainingTimeRequest.java | 8 ++------ .../service/dto/request/TrainingTimeServiceRequest.java | 7 +++++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/TrainingTimeRequest.java b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/TrainingTimeRequest.java index a3e1b922..d76e06f8 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/TrainingTimeRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/TrainingTimeRequest.java @@ -1,13 +1,9 @@ package com.smeem.api.member.controller.dto.request; -import jakarta.validation.constraints.NotNull; public record TrainingTimeRequest( - @NotNull String day, - @NotNull - int hour, - @NotNull - int minute + Integer hour, + Integer minute ) { } diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/TrainingTimeServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/TrainingTimeServiceRequest.java index f2dedbf6..cff380a7 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/TrainingTimeServiceRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/TrainingTimeServiceRequest.java @@ -9,10 +9,13 @@ @Builder(access = PRIVATE) public record TrainingTimeServiceRequest( String day, - int hour, - int minute + Integer hour, + Integer minute ) { public static TrainingTimeServiceRequest of(TrainingTimeRequest request) { + if (request == null) { + return null; + } return TrainingTimeServiceRequest.builder() .day(request.day()) .hour(request.hour()) From 26a03a3eb3a311d6d88e77736fe670d13841da7d Mon Sep 17 00:00:00 2001 From: unanchoi Date: Tue, 12 Mar 2024 01:04:19 +0900 Subject: [PATCH 77/86] =?UTF-8?q?[CHORE]=20null=20=EC=A1=B0=EA=B1=B4?= =?UTF-8?q?=EB=AC=B8=20Objects.isNull()=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 리뷰 반영 --- .../service/dto/request/TrainingTimeServiceRequest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/TrainingTimeServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/TrainingTimeServiceRequest.java index cff380a7..4d5b9b83 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/TrainingTimeServiceRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/TrainingTimeServiceRequest.java @@ -4,6 +4,8 @@ import com.smeem.api.member.controller.dto.request.TrainingTimeRequest; import lombok.Builder; +import java.util.Objects; + import static lombok.AccessLevel.PRIVATE; @Builder(access = PRIVATE) @@ -13,7 +15,7 @@ public record TrainingTimeServiceRequest( Integer minute ) { public static TrainingTimeServiceRequest of(TrainingTimeRequest request) { - if (request == null) { + if (Objects.isNull(request)) { return null; } return TrainingTimeServiceRequest.builder() From 12af42ee1228c80ad6700261351fc5616bc18d88 Mon Sep 17 00:00:00 2001 From: thguss Date: Tue, 12 Mar 2024 22:15:57 +0900 Subject: [PATCH 78/86] =?UTF-8?q?[CHORE]=20=EC=8A=A4=EC=9B=A8=EA=B1=B0=20?= =?UTF-8?q?=EC=9D=B4=EC=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/smeem/api/diary/api/DiaryApi.java | 65 +++++++++++++++++++ .../DiaryApiController.java} | 14 ++-- .../dto/request/DiaryCreateRequest.java | 2 +- .../dto/request/DiaryModifyRequest.java | 2 +- .../dto/response/DiaryCreateResponse.java | 2 +- .../dto/response/DiaryGetResponse.java | 2 +- .../dto/response/DiaryListGetResponse.java | 2 +- .../request/DiaryCreateServiceRequest.java | 2 +- .../request/DiaryModifyServiceRequest.java | 2 +- .../java/com/smeem/api/goal/api/GoalApi.java | 29 +++++++++ .../GoalApiController.java} | 8 +-- .../dto/response/GoalGetResponse.java | 2 +- .../dto/response/GoalListGetResponse.java | 2 +- .../com/smeem/api/topic/api/TopicApi.java | 18 +++++ .../TopicApiController.java} | 6 +- .../dto/response/RandomTopicGetResponse.java | 2 +- .../api/controller/DiaryControllerTest.java | 4 +- 17 files changed, 138 insertions(+), 26 deletions(-) create mode 100644 smeem-api/src/main/java/com/smeem/api/diary/api/DiaryApi.java rename smeem-api/src/main/java/com/smeem/api/diary/{controller/DiaryController.java => api/DiaryApiController.java} (87%) rename smeem-api/src/main/java/com/smeem/api/diary/{controller => api}/dto/request/DiaryCreateRequest.java (70%) rename smeem-api/src/main/java/com/smeem/api/diary/{controller => api}/dto/request/DiaryModifyRequest.java (70%) rename smeem-api/src/main/java/com/smeem/api/diary/{controller => api}/dto/response/DiaryCreateResponse.java (92%) rename smeem-api/src/main/java/com/smeem/api/diary/{controller => api}/dto/response/DiaryGetResponse.java (94%) rename smeem-api/src/main/java/com/smeem/api/diary/{controller => api}/dto/response/DiaryListGetResponse.java (96%) create mode 100644 smeem-api/src/main/java/com/smeem/api/goal/api/GoalApi.java rename smeem-api/src/main/java/com/smeem/api/goal/{controller/GoalController.java => api/GoalApiController.java} (87%) rename smeem-api/src/main/java/com/smeem/api/goal/{controller => api}/dto/response/GoalGetResponse.java (92%) rename smeem-api/src/main/java/com/smeem/api/goal/{controller => api}/dto/response/GoalListGetResponse.java (95%) create mode 100644 smeem-api/src/main/java/com/smeem/api/topic/api/TopicApi.java rename smeem-api/src/main/java/com/smeem/api/topic/{controller/TopicController.java => api/TopicApiController.java} (85%) rename smeem-api/src/main/java/com/smeem/api/topic/{controller => api}/dto/response/RandomTopicGetResponse.java (90%) diff --git a/smeem-api/src/main/java/com/smeem/api/diary/api/DiaryApi.java b/smeem-api/src/main/java/com/smeem/api/diary/api/DiaryApi.java new file mode 100644 index 00000000..682d4dd2 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/diary/api/DiaryApi.java @@ -0,0 +1,65 @@ +package com.smeem.api.diary.api; + +import com.smeem.api.common.BaseResponse; +import com.smeem.api.diary.api.dto.request.DiaryCreateRequest; +import com.smeem.api.diary.api.dto.request.DiaryModifyRequest; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; + +import java.security.Principal; + +public interface DiaryApi { + + @Operation( + summary = "일기 생성", + responses = { + @ApiResponse(responseCode = "201", description = "성공"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") + } + ) + ResponseEntity> createDiary(Principal principal, @RequestBody DiaryCreateRequest request); + + @Operation( + summary = "일기 상세 조회", + responses = { + @ApiResponse(responseCode = "200", description = "성공"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") + } + ) + ResponseEntity> getDiaryDetail(@PathVariable long diaryId); + + @Operation( + summary = "일기 수정", + responses = { + @ApiResponse(responseCode = "200", description = "성공"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") + } + ) + ResponseEntity> modifyDiary(@PathVariable long diaryId, @RequestBody DiaryModifyRequest request); + + @Operation( + summary = "일기 삭제", + responses = { + @ApiResponse(responseCode = "200", description = "성공"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") + } + ) + ResponseEntity> deleteDiary(@PathVariable long diaryId); + + @Operation( + summary = "기간 내 일기 목록 조회", + responses = { + @ApiResponse(responseCode = "200", description = "성공"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") + } + ) + ResponseEntity> getDiaries( + Principal principal, + @RequestParam String start, + @RequestParam String end + ); +} diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java b/smeem-api/src/main/java/com/smeem/api/diary/api/DiaryApiController.java similarity index 87% rename from smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java rename to smeem-api/src/main/java/com/smeem/api/diary/api/DiaryApiController.java index b75a5f8f..7192fe4c 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/controller/DiaryController.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/api/DiaryApiController.java @@ -1,14 +1,14 @@ -package com.smeem.api.diary.controller; +package com.smeem.api.diary.api; import java.security.Principal; import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; -import com.smeem.api.diary.controller.dto.request.DiaryCreateRequest; -import com.smeem.api.diary.controller.dto.request.DiaryModifyRequest; -import com.smeem.api.diary.controller.dto.response.DiaryCreateResponse; -import com.smeem.api.diary.controller.dto.response.DiaryGetResponse; -import com.smeem.api.diary.controller.dto.response.DiaryListGetResponse; +import com.smeem.api.diary.api.dto.request.DiaryCreateRequest; +import com.smeem.api.diary.api.dto.request.DiaryModifyRequest; +import com.smeem.api.diary.api.dto.response.DiaryCreateResponse; +import com.smeem.api.diary.api.dto.response.DiaryGetResponse; +import com.smeem.api.diary.api.dto.response.DiaryListGetResponse; import com.smeem.api.diary.service.DiaryQueryService; import com.smeem.api.diary.service.DiaryCommandService; import com.smeem.api.diary.service.dto.request.*; @@ -33,7 +33,7 @@ @RestController @RequiredArgsConstructor @RequestMapping("/api/v2/diaries") -public class DiaryController { +public class DiaryApiController implements DiaryApi { private final DiaryCommandService diaryCommandService; private final DiaryQueryService diaryQueryService; diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryCreateRequest.java b/smeem-api/src/main/java/com/smeem/api/diary/api/dto/request/DiaryCreateRequest.java similarity index 70% rename from smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryCreateRequest.java rename to smeem-api/src/main/java/com/smeem/api/diary/api/dto/request/DiaryCreateRequest.java index 3b4cf852..ac6c2d0e 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryCreateRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/api/dto/request/DiaryCreateRequest.java @@ -1,4 +1,4 @@ -package com.smeem.api.diary.controller.dto.request; +package com.smeem.api.diary.api.dto.request; import lombok.NonNull; diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryModifyRequest.java b/smeem-api/src/main/java/com/smeem/api/diary/api/dto/request/DiaryModifyRequest.java similarity index 70% rename from smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryModifyRequest.java rename to smeem-api/src/main/java/com/smeem/api/diary/api/dto/request/DiaryModifyRequest.java index 8377c67f..c858567e 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/request/DiaryModifyRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/api/dto/request/DiaryModifyRequest.java @@ -1,4 +1,4 @@ -package com.smeem.api.diary.controller.dto.request; +package com.smeem.api.diary.api.dto.request; import lombok.NonNull; diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryCreateResponse.java b/smeem-api/src/main/java/com/smeem/api/diary/api/dto/response/DiaryCreateResponse.java similarity index 92% rename from smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryCreateResponse.java rename to smeem-api/src/main/java/com/smeem/api/diary/api/dto/response/DiaryCreateResponse.java index c06ee419..dbbe5096 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryCreateResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/api/dto/response/DiaryCreateResponse.java @@ -1,4 +1,4 @@ -package com.smeem.api.diary.controller.dto.response; +package com.smeem.api.diary.api.dto.response; import com.smeem.api.badge.controller.dto.response.AcquiredBadgeResponse; import com.smeem.api.diary.service.dto.response.DiaryCreateServiceResponse; diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryGetResponse.java b/smeem-api/src/main/java/com/smeem/api/diary/api/dto/response/DiaryGetResponse.java similarity index 94% rename from smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryGetResponse.java rename to smeem-api/src/main/java/com/smeem/api/diary/api/dto/response/DiaryGetResponse.java index 80b27e37..e6984b71 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryGetResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/api/dto/response/DiaryGetResponse.java @@ -1,4 +1,4 @@ -package com.smeem.api.diary.controller.dto.response; +package com.smeem.api.diary.api.dto.response; import com.smeem.api.diary.service.dto.response.DiaryGetServiceResponse; import com.smeem.common.util.Util; diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryListGetResponse.java b/smeem-api/src/main/java/com/smeem/api/diary/api/dto/response/DiaryListGetResponse.java similarity index 96% rename from smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryListGetResponse.java rename to smeem-api/src/main/java/com/smeem/api/diary/api/dto/response/DiaryListGetResponse.java index eeaa21b6..6a9f90b9 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryListGetResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/api/dto/response/DiaryListGetResponse.java @@ -1,4 +1,4 @@ -package com.smeem.api.diary.controller.dto.response; +package com.smeem.api.diary.api.dto.response; import com.smeem.api.diary.service.dto.response.DiaryListGetServiceResponse; import com.smeem.api.diary.service.dto.response.DiaryListGetServiceResponse.DiaryServiceResponse; diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryCreateServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryCreateServiceRequest.java index 9d359cb1..774ab3ae 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryCreateServiceRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryCreateServiceRequest.java @@ -1,6 +1,6 @@ package com.smeem.api.diary.service.dto.request; -import com.smeem.api.diary.controller.dto.request.DiaryCreateRequest; +import com.smeem.api.diary.api.dto.request.DiaryCreateRequest; import lombok.Builder; import static lombok.AccessLevel.PRIVATE; diff --git a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryModifyServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryModifyServiceRequest.java index 58836b7b..51d4f329 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryModifyServiceRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/service/dto/request/DiaryModifyServiceRequest.java @@ -1,6 +1,6 @@ package com.smeem.api.diary.service.dto.request; -import com.smeem.api.diary.controller.dto.request.DiaryModifyRequest; +import com.smeem.api.diary.api.dto.request.DiaryModifyRequest; import lombok.Builder; import static lombok.AccessLevel.PRIVATE; diff --git a/smeem-api/src/main/java/com/smeem/api/goal/api/GoalApi.java b/smeem-api/src/main/java/com/smeem/api/goal/api/GoalApi.java new file mode 100644 index 00000000..2469f4ba --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/goal/api/GoalApi.java @@ -0,0 +1,29 @@ +package com.smeem.api.goal.api; + +import com.smeem.api.common.BaseResponse; +import com.smeem.domain.goal.model.GoalType; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; + +public interface GoalApi { + + @Operation( + summary = "목표 전체 목록 조회", + responses = { + @ApiResponse(responseCode = "200", description = "성공"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") + } + ) + ResponseEntity> getAllGoals(); + + @Operation( + summary = "목표 상세 조회", + responses = { + @ApiResponse(responseCode = "200", description = "성공"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") + } + ) + ResponseEntity> getGoalByType(@PathVariable GoalType type); +} diff --git a/smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java b/smeem-api/src/main/java/com/smeem/api/goal/api/GoalApiController.java similarity index 87% rename from smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java rename to smeem-api/src/main/java/com/smeem/api/goal/api/GoalApiController.java index f414b14a..539f7e27 100644 --- a/smeem-api/src/main/java/com/smeem/api/goal/controller/GoalController.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/api/GoalApiController.java @@ -1,10 +1,10 @@ -package com.smeem.api.goal.controller; +package com.smeem.api.goal.api; import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; -import com.smeem.api.goal.controller.dto.response.GoalGetResponse; -import com.smeem.api.goal.controller.dto.response.GoalListGetResponse; +import com.smeem.api.goal.api.dto.response.GoalGetResponse; +import com.smeem.api.goal.api.dto.response.GoalListGetResponse; import com.smeem.api.goal.service.dto.request.GoalGetServiceRequest; import com.smeem.api.goal.service.GoalService; import com.smeem.domain.goal.model.GoalType; @@ -23,7 +23,7 @@ @RestController @RequiredArgsConstructor @RequestMapping("/api/v2/goals") -public class GoalController { +public class GoalApiController implements GoalApi { private final GoalService goalService; diff --git a/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalGetResponse.java b/smeem-api/src/main/java/com/smeem/api/goal/api/dto/response/GoalGetResponse.java similarity index 92% rename from smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalGetResponse.java rename to smeem-api/src/main/java/com/smeem/api/goal/api/dto/response/GoalGetResponse.java index 0c423bca..b45d3320 100644 --- a/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalGetResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/api/dto/response/GoalGetResponse.java @@ -1,4 +1,4 @@ -package com.smeem.api.goal.controller.dto.response; +package com.smeem.api.goal.api.dto.response; import com.smeem.api.goal.service.dto.response.GoalGetServiceResponse; import lombok.Builder; diff --git a/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalListGetResponse.java b/smeem-api/src/main/java/com/smeem/api/goal/api/dto/response/GoalListGetResponse.java similarity index 95% rename from smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalListGetResponse.java rename to smeem-api/src/main/java/com/smeem/api/goal/api/dto/response/GoalListGetResponse.java index c6b001ba..119b5546 100644 --- a/smeem-api/src/main/java/com/smeem/api/goal/controller/dto/response/GoalListGetResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/api/dto/response/GoalListGetResponse.java @@ -1,4 +1,4 @@ -package com.smeem.api.goal.controller.dto.response; +package com.smeem.api.goal.api.dto.response; import com.smeem.api.goal.service.dto.response.GoalListGetServiceResponse; import com.smeem.api.goal.service.dto.response.GoalListGetServiceResponse.GoalServiceResponse; diff --git a/smeem-api/src/main/java/com/smeem/api/topic/api/TopicApi.java b/smeem-api/src/main/java/com/smeem/api/topic/api/TopicApi.java new file mode 100644 index 00000000..567efd58 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/topic/api/TopicApi.java @@ -0,0 +1,18 @@ +package com.smeem.api.topic.api; + +import com.smeem.api.common.BaseResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import org.springframework.http.ResponseEntity; + +public interface TopicApi { + + @Operation( + summary = "랜덤 주제 조회", + responses = { + @ApiResponse(responseCode = "200", description = "성공"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") + } + ) + ResponseEntity> getTopicByRandom(); +} diff --git a/smeem-api/src/main/java/com/smeem/api/topic/controller/TopicController.java b/smeem-api/src/main/java/com/smeem/api/topic/api/TopicApiController.java similarity index 85% rename from smeem-api/src/main/java/com/smeem/api/topic/controller/TopicController.java rename to smeem-api/src/main/java/com/smeem/api/topic/api/TopicApiController.java index 187a306d..9a779a44 100644 --- a/smeem-api/src/main/java/com/smeem/api/topic/controller/TopicController.java +++ b/smeem-api/src/main/java/com/smeem/api/topic/api/TopicApiController.java @@ -1,8 +1,8 @@ -package com.smeem.api.topic.controller; +package com.smeem.api.topic.api; import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; -import com.smeem.api.topic.controller.dto.response.RandomTopicGetResponse; +import com.smeem.api.topic.api.dto.response.RandomTopicGetResponse; import com.smeem.api.topic.service.TopicService; import lombok.val; import org.springframework.http.ResponseEntity; @@ -17,7 +17,7 @@ @RestController @RequiredArgsConstructor @RequestMapping("/api/v2/topics") -public class TopicController { +public class TopicApiController implements TopicApi { private final TopicService topicService; diff --git a/smeem-api/src/main/java/com/smeem/api/topic/controller/dto/response/RandomTopicGetResponse.java b/smeem-api/src/main/java/com/smeem/api/topic/api/dto/response/RandomTopicGetResponse.java similarity index 90% rename from smeem-api/src/main/java/com/smeem/api/topic/controller/dto/response/RandomTopicGetResponse.java rename to smeem-api/src/main/java/com/smeem/api/topic/api/dto/response/RandomTopicGetResponse.java index 3b310855..c4afebb8 100644 --- a/smeem-api/src/main/java/com/smeem/api/topic/controller/dto/response/RandomTopicGetResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/topic/api/dto/response/RandomTopicGetResponse.java @@ -1,4 +1,4 @@ -package com.smeem.api.topic.controller.dto.response; +package com.smeem.api.topic.api.dto.response; import com.smeem.api.topic.service.dto.response.RandomTopicGetServiceResponse; import lombok.Builder; diff --git a/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java b/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java index 6597b78a..0be52f44 100644 --- a/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java +++ b/smeem-api/src/test/java/com/smeem/api/controller/DiaryControllerTest.java @@ -5,8 +5,8 @@ //import com.smeem.api.common.ApiResponseUtil; //import com.smeem.api.common.BaseResponse; //import com.smeem.api.diary.controller.DiaryController; -//import com.smeem.api.diary.controller.dto.request.DiaryCreateRequest; -//import com.smeem.api.diary.controller.dto.request.DiaryModifyRequest; +//import com.smeem.api.diary.api.dto.request.DiaryCreateRequest; +//import com.smeem.api.diary.api.dto.request.DiaryModifyRequest; //import com.smeem.api.diary.service.dto.response.DiaryCreateServiceResponse; //import com.smeem.api.diary.service.dto.response.DiaryListGetServiceResponse; //import com.smeem.api.diary.service.dto.response.DiaryGetServiceResponse; From d0e024941d4360031e01356859d02ffcf31e950b Mon Sep 17 00:00:00 2001 From: unanchoi Date: Tue, 12 Mar 2024 23:02:51 +0900 Subject: [PATCH 79/86] =?UTF-8?q?[REFACTOR]=20Swagger=20Interface=EB=A1=9C?= =?UTF-8?q?=20=EB=B6=84=EB=A6=AC=20=EC=9E=91=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smeem/api/auth/controller/AuthApi.java | 61 ++++++++++++++++ .../smeem/api/badge/controller/BadgeApi.java | 27 ++++++++ .../api/badge/controller/BadgeController.java | 3 +- .../com/smeem/api/member/api/MemberApi.java | 69 +++++++++++++++++++ .../{controller => api}/MemberController.java | 21 +++--- .../dto/UsernameValidator.java | 2 +- .../dto/ValidUsername.java | 2 +- .../dto/request/MemberPlanUpdateRequest.java | 2 +- .../dto/request/MemberPushUpdateRequest.java | 2 +- .../dto/request/MemberUpdateRequest.java | 4 +- .../dto/request/TrainingTimeRequest.java | 2 +- .../dto/response/MemberGetResponse.java | 2 +- .../dto/response/MemberNameResponse.java | 3 +- .../dto/response/MemberUpdateResponse.java | 2 +- .../dto/response/TrainingTimeResponse.java | 2 +- .../MemberPushUpdateServiceRequest.java | 2 +- ...MemberServiceUpdateUserProfileRequest.java | 2 +- .../MemberUpdatePlanServiceRequest.java | 2 +- .../request/TrainingTimeServiceRequest.java | 2 +- 19 files changed, 187 insertions(+), 25 deletions(-) create mode 100644 smeem-api/src/main/java/com/smeem/api/auth/controller/AuthApi.java create mode 100644 smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeApi.java create mode 100644 smeem-api/src/main/java/com/smeem/api/member/api/MemberApi.java rename smeem-api/src/main/java/com/smeem/api/member/{controller => api}/MemberController.java (82%) rename smeem-api/src/main/java/com/smeem/api/member/{controller => api}/dto/UsernameValidator.java (92%) rename smeem-api/src/main/java/com/smeem/api/member/{controller => api}/dto/ValidUsername.java (87%) rename smeem-api/src/main/java/com/smeem/api/member/{controller => api}/dto/request/MemberPlanUpdateRequest.java (77%) rename smeem-api/src/main/java/com/smeem/api/member/{controller => api}/dto/request/MemberPushUpdateRequest.java (57%) rename smeem-api/src/main/java/com/smeem/api/member/{controller => api}/dto/request/MemberUpdateRequest.java (52%) rename smeem-api/src/main/java/com/smeem/api/member/{controller => api}/dto/request/TrainingTimeRequest.java (67%) rename smeem-api/src/main/java/com/smeem/api/member/{controller => api}/dto/response/MemberGetResponse.java (95%) rename smeem-api/src/main/java/com/smeem/api/member/{controller => api}/dto/response/MemberNameResponse.java (84%) rename smeem-api/src/main/java/com/smeem/api/member/{controller => api}/dto/response/MemberUpdateResponse.java (92%) rename smeem-api/src/main/java/com/smeem/api/member/{controller => api}/dto/response/TrainingTimeResponse.java (91%) diff --git a/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthApi.java b/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthApi.java new file mode 100644 index 00000000..96f69461 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthApi.java @@ -0,0 +1,61 @@ +package com.smeem.api.auth.controller; + +import com.smeem.api.auth.controller.dto.request.SignInRequest; +import com.smeem.api.common.BaseResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; + +import java.security.Principal; + +import static io.swagger.v3.oas.annotations.enums.ParameterIn.HEADER; + +@Tag(name = "[Auth] 인증 관련 API (V2)") +public interface AuthApi { + + @Operation(summary = "소셜 로그인 API") + @Parameter(name = "Authorization", description = "Social Platform Access Token", in = HEADER) + @ApiResponses(value = { + @ApiResponse(responseCode = "201", description = "소셜로그인 성공"), + @ApiResponse(responseCode = "400", description = "유효하지 않은 요청", content = @Content), + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), + @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) + }) + ResponseEntity> signIn(@RequestHeader("Authorization") final String socialAccessToken, @RequestBody SignInRequest request); + + @Operation(summary = "토큰 재발급 API") + @Parameter(name = "Authorization", description = "Smeem Refresh Token", in = HEADER) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "토큰 재발급 성공"), + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), + @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) + }) + ResponseEntity> reissueToken(Principal principal); + + + @Operation(summary = "사용자 로그아웃 API") + @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "로그아웃 성공"), + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), + @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) + }) + ResponseEntity> signOut(Principal principal); + + + @Operation(summary = "회원 탈퇴 API") + @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "회원 탈퇴 성공"), + @ApiResponse(responseCode = "400", description = "", content = @Content), + @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) + }) + ResponseEntity> withDrawl(Principal principal); + +} diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeApi.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeApi.java new file mode 100644 index 00000000..79436fe0 --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeApi.java @@ -0,0 +1,27 @@ +package com.smeem.api.badge.controller; + +import com.smeem.api.common.BaseResponse; +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.tags.Tag; +import org.springframework.http.ResponseEntity; + +import java.security.Principal; + + +@Tag(name = "[Badge] 뱃지 관련 API (V2)") +public interface BadgeApi { + + @Operation(summary = "뱃지 목록 조회 API") + @Parameter(name = "Authorization", description = "Bearer {access_token}", in = ParameterIn.HEADER, required = true) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "뱃지 목록 조회 성공"), + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), + @ApiResponse(responseCode = "500", description = "서버 오류") + }) + ResponseEntity> getBadges(Principal principal); + +} diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java index 8b45deaf..0ba60077 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java @@ -19,10 +19,11 @@ @RestController @RequiredArgsConstructor @RequestMapping("/api/v2/members/badges") -public class BadgeController { +public class BadgeController implements BadgeApi { private final BadgeService badgeService; + @Override @GetMapping public ResponseEntity> getBadges(Principal principal) { val response = BadgeListResponse.from(badgeService.getBadges(Util.getMemberId(principal))); diff --git a/smeem-api/src/main/java/com/smeem/api/member/api/MemberApi.java b/smeem-api/src/main/java/com/smeem/api/member/api/MemberApi.java new file mode 100644 index 00000000..a3f2c98f --- /dev/null +++ b/smeem-api/src/main/java/com/smeem/api/member/api/MemberApi.java @@ -0,0 +1,69 @@ +package com.smeem.api.member.api; + +import com.smeem.api.common.BaseResponse; +import com.smeem.api.member.api.dto.request.MemberPlanUpdateRequest; +import com.smeem.api.member.api.dto.request.MemberPushUpdateRequest; +import com.smeem.api.member.api.dto.request.MemberUpdateRequest; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; + +import java.security.Principal; + +import static io.swagger.v3.oas.annotations.enums.ParameterIn.HEADER; + +@Tag(name = "[Member] 사용자 관련 API (V2)") +public interface MemberApi { + @Operation(summary = "사용자 프로필 업데이트 API") + @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "사용자 프로필 업데이트 성공"), + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), + @ApiResponse(responseCode = "400", description = "유효하지 않은 요청"), + @ApiResponse(responseCode = "500", description = "서버 오류") + }) + ResponseEntity> updateProfile(Principal principal, @RequestBody MemberUpdateRequest request); + + + @Operation(summary = "사용자 프로필 조회 API") + @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "사용자 프로필 조회 성공"), + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), + @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) + }) + ResponseEntity> getProfile(Principal principal); + + @Operation(summary = "사용자 학습 계획 수정 API") + @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "회원 학습 계획 업데이트 성공"), + @ApiResponse(responseCode = "400", description = "유효하지 않은 요청"), + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), + @ApiResponse(responseCode = "500", description = "서버 오류") + }) + ResponseEntity> updateUserPlan(Principal principal, @Valid @RequestBody MemberPlanUpdateRequest request); + + @Operation(summary = "사용자 닉네임 중복체크 수정 API") + @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "닉네임 중복 체크 성공"), + @ApiResponse(responseCode = "500", description = "서버 오류") + }) + ResponseEntity> checkDuplicatedName(@Parameter(description = "유저 닉네임") @RequestParam String name); + + @Operation(summary = "사용자 학습 계획 수정 API") + @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "사용자 학습 계획 수정 성공"), + @ApiResponse(responseCode = "500", description = "서버 오류") + }) + ResponseEntity> updateUserPush(Principal principal, @RequestBody MemberPushUpdateRequest request); +} diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java b/smeem-api/src/main/java/com/smeem/api/member/api/MemberController.java similarity index 82% rename from smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java rename to smeem-api/src/main/java/com/smeem/api/member/api/MemberController.java index 21c7a276..b40e5818 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/MemberController.java +++ b/smeem-api/src/main/java/com/smeem/api/member/api/MemberController.java @@ -1,13 +1,13 @@ -package com.smeem.api.member.controller; +package com.smeem.api.member.api; import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; -import com.smeem.api.member.controller.dto.request.MemberPlanUpdateRequest; -import com.smeem.api.member.controller.dto.request.MemberPushUpdateRequest; -import com.smeem.api.member.controller.dto.request.MemberUpdateRequest; -import com.smeem.api.member.controller.dto.response.MemberGetResponse; -import com.smeem.api.member.controller.dto.response.MemberNameResponse; -import com.smeem.api.member.controller.dto.response.MemberUpdateResponse; +import com.smeem.api.member.api.dto.request.MemberPlanUpdateRequest; +import com.smeem.api.member.api.dto.request.MemberPushUpdateRequest; +import com.smeem.api.member.api.dto.request.MemberUpdateRequest; +import com.smeem.api.member.api.dto.response.MemberGetResponse; +import com.smeem.api.member.api.dto.response.MemberNameResponse; +import com.smeem.api.member.api.dto.response.MemberUpdateResponse; import com.smeem.api.member.service.MemberService; import com.smeem.api.member.service.dto.request.MemberPushUpdateServiceRequest; import com.smeem.api.member.service.dto.request.MemberUpdatePlanServiceRequest; @@ -27,10 +27,11 @@ @RestController @RequiredArgsConstructor @RequestMapping("/api/v2/members") -public class MemberController { +public class MemberController implements MemberApi { private final MemberService memberService; + @Override @PatchMapping public ResponseEntity> updateProfile(Principal principal, @RequestBody MemberUpdateRequest request) { val response = MemberUpdateResponse.from(memberService.updateUserProfile( @@ -39,24 +40,28 @@ public ResponseEntity> updateProfile(Principal principal, @Reque return ApiResponseUtil.success(SUCCESS_UPDATE_USERNAME, response); } + @Override @GetMapping("/me") public ResponseEntity> getProfile(Principal principal) { val response = MemberGetResponse.from(memberService.getMemberProfile(Util.getMemberId(principal))); return ApiResponseUtil.success(SUCCESS_GET_USER, response); } + @Override @PatchMapping("/plan") public ResponseEntity> updateUserPlan(Principal principal, @Valid @RequestBody MemberPlanUpdateRequest request) { memberService.updateLearningPlan(Util.getMemberId(principal), MemberUpdatePlanServiceRequest.of(request)); return ApiResponseUtil.success(SUCCESS_UPDATE_USER_PLAN); } + @Override @GetMapping("/nickname/check") public ResponseEntity> checkDuplicatedName(@Parameter(description = "유저 닉네임") @RequestParam String name) { val response = MemberNameResponse.from(memberService.checkDuplicatedName(name)); return ApiResponseUtil.success(SUCCESS_CHECK_DUPLICATED_NAME, response); } + @Override @PatchMapping("/push") public ResponseEntity> updateUserPush(Principal principal, @RequestBody MemberPushUpdateRequest request) { memberService.updateHasAlarm(Util.getMemberId(principal), MemberPushUpdateServiceRequest.of(request)); diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/UsernameValidator.java b/smeem-api/src/main/java/com/smeem/api/member/api/dto/UsernameValidator.java similarity index 92% rename from smeem-api/src/main/java/com/smeem/api/member/controller/dto/UsernameValidator.java rename to smeem-api/src/main/java/com/smeem/api/member/api/dto/UsernameValidator.java index 8b0418e5..4ecd3858 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/UsernameValidator.java +++ b/smeem-api/src/main/java/com/smeem/api/member/api/dto/UsernameValidator.java @@ -1,4 +1,4 @@ -package com.smeem.api.member.controller.dto; +package com.smeem.api.member.api.dto; import jakarta.validation.ConstraintValidator; import jakarta.validation.ConstraintValidatorContext; diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/ValidUsername.java b/smeem-api/src/main/java/com/smeem/api/member/api/dto/ValidUsername.java similarity index 87% rename from smeem-api/src/main/java/com/smeem/api/member/controller/dto/ValidUsername.java rename to smeem-api/src/main/java/com/smeem/api/member/api/dto/ValidUsername.java index 6ca432b1..000fcac6 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/ValidUsername.java +++ b/smeem-api/src/main/java/com/smeem/api/member/api/dto/ValidUsername.java @@ -1,4 +1,4 @@ -package com.smeem.api.member.controller.dto; +package com.smeem.api.member.api.dto; import jakarta.validation.Constraint; diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPlanUpdateRequest.java b/smeem-api/src/main/java/com/smeem/api/member/api/dto/request/MemberPlanUpdateRequest.java similarity index 77% rename from smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPlanUpdateRequest.java rename to smeem-api/src/main/java/com/smeem/api/member/api/dto/request/MemberPlanUpdateRequest.java index abbc4ea0..a6579e5f 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPlanUpdateRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/member/api/dto/request/MemberPlanUpdateRequest.java @@ -1,4 +1,4 @@ -package com.smeem.api.member.controller.dto.request; +package com.smeem.api.member.api.dto.request; import com.smeem.domain.goal.model.GoalType; diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPushUpdateRequest.java b/smeem-api/src/main/java/com/smeem/api/member/api/dto/request/MemberPushUpdateRequest.java similarity index 57% rename from smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPushUpdateRequest.java rename to smeem-api/src/main/java/com/smeem/api/member/api/dto/request/MemberPushUpdateRequest.java index 4e7546ca..bbcf303a 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberPushUpdateRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/member/api/dto/request/MemberPushUpdateRequest.java @@ -1,4 +1,4 @@ -package com.smeem.api.member.controller.dto.request; +package com.smeem.api.member.api.dto.request; public record MemberPushUpdateRequest( boolean hasAlarm diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberUpdateRequest.java b/smeem-api/src/main/java/com/smeem/api/member/api/dto/request/MemberUpdateRequest.java similarity index 52% rename from smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberUpdateRequest.java rename to smeem-api/src/main/java/com/smeem/api/member/api/dto/request/MemberUpdateRequest.java index 3870c229..b0469fe2 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/MemberUpdateRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/member/api/dto/request/MemberUpdateRequest.java @@ -1,7 +1,7 @@ -package com.smeem.api.member.controller.dto.request; +package com.smeem.api.member.api.dto.request; -import com.smeem.api.member.controller.dto.ValidUsername; +import com.smeem.api.member.api.dto.ValidUsername; public record MemberUpdateRequest( @ValidUsername diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/TrainingTimeRequest.java b/smeem-api/src/main/java/com/smeem/api/member/api/dto/request/TrainingTimeRequest.java similarity index 67% rename from smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/TrainingTimeRequest.java rename to smeem-api/src/main/java/com/smeem/api/member/api/dto/request/TrainingTimeRequest.java index d76e06f8..a126b5c1 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/request/TrainingTimeRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/member/api/dto/request/TrainingTimeRequest.java @@ -1,4 +1,4 @@ -package com.smeem.api.member.controller.dto.request; +package com.smeem.api.member.api.dto.request; public record TrainingTimeRequest( diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponse.java b/smeem-api/src/main/java/com/smeem/api/member/api/dto/response/MemberGetResponse.java similarity index 95% rename from smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponse.java rename to smeem-api/src/main/java/com/smeem/api/member/api/dto/response/MemberGetResponse.java index 79746858..b0eec36c 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberGetResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/member/api/dto/response/MemberGetResponse.java @@ -1,4 +1,4 @@ -package com.smeem.api.member.controller.dto.response; +package com.smeem.api.member.api.dto.response; import com.smeem.api.badge.controller.dto.response.BadgeResponse; diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponse.java b/smeem-api/src/main/java/com/smeem/api/member/api/dto/response/MemberNameResponse.java similarity index 84% rename from smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponse.java rename to smeem-api/src/main/java/com/smeem/api/member/api/dto/response/MemberNameResponse.java index 607c7942..6449c477 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberNameResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/member/api/dto/response/MemberNameResponse.java @@ -1,7 +1,6 @@ -package com.smeem.api.member.controller.dto.response; +package com.smeem.api.member.api.dto.response; import com.smeem.api.member.service.dto.response.MemberNameServiceResponse; -import lombok.AccessLevel; import lombok.Builder; import static lombok.AccessLevel.PRIVATE; diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberUpdateResponse.java b/smeem-api/src/main/java/com/smeem/api/member/api/dto/response/MemberUpdateResponse.java similarity index 92% rename from smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberUpdateResponse.java rename to smeem-api/src/main/java/com/smeem/api/member/api/dto/response/MemberUpdateResponse.java index 4cf15c4c..7107aafa 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/MemberUpdateResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/member/api/dto/response/MemberUpdateResponse.java @@ -1,4 +1,4 @@ -package com.smeem.api.member.controller.dto.response; +package com.smeem.api.member.api.dto.response; import com.smeem.api.badge.controller.dto.response.AcquiredBadgeResponse; diff --git a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponse.java b/smeem-api/src/main/java/com/smeem/api/member/api/dto/response/TrainingTimeResponse.java similarity index 91% rename from smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponse.java rename to smeem-api/src/main/java/com/smeem/api/member/api/dto/response/TrainingTimeResponse.java index 259bc8b9..42feb827 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/controller/dto/response/TrainingTimeResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/member/api/dto/response/TrainingTimeResponse.java @@ -1,4 +1,4 @@ -package com.smeem.api.member.controller.dto.response; +package com.smeem.api.member.api.dto.response; import com.smeem.api.member.service.dto.response.TrainingTimeServiceResponse; import lombok.Builder; diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberPushUpdateServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberPushUpdateServiceRequest.java index b49f985d..17e52c92 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberPushUpdateServiceRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberPushUpdateServiceRequest.java @@ -1,6 +1,6 @@ package com.smeem.api.member.service.dto.request; -import com.smeem.api.member.controller.dto.request.MemberPushUpdateRequest; +import com.smeem.api.member.api.dto.request.MemberPushUpdateRequest; import lombok.Builder; import static lombok.AccessLevel.*; diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberServiceUpdateUserProfileRequest.java b/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberServiceUpdateUserProfileRequest.java index aaa08d7d..69ba241d 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberServiceUpdateUserProfileRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberServiceUpdateUserProfileRequest.java @@ -1,7 +1,7 @@ package com.smeem.api.member.service.dto.request; -import com.smeem.api.member.controller.dto.request.MemberUpdateRequest; +import com.smeem.api.member.api.dto.request.MemberUpdateRequest; import lombok.AccessLevel; import lombok.Builder; diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberUpdatePlanServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberUpdatePlanServiceRequest.java index fbdd3190..7ae0ee5a 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberUpdatePlanServiceRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/MemberUpdatePlanServiceRequest.java @@ -1,6 +1,6 @@ package com.smeem.api.member.service.dto.request; -import com.smeem.api.member.controller.dto.request.MemberPlanUpdateRequest; +import com.smeem.api.member.api.dto.request.MemberPlanUpdateRequest; import com.smeem.domain.goal.model.GoalType; import lombok.Builder; diff --git a/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/TrainingTimeServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/TrainingTimeServiceRequest.java index 4d5b9b83..89fdbf96 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/TrainingTimeServiceRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/member/service/dto/request/TrainingTimeServiceRequest.java @@ -1,7 +1,7 @@ package com.smeem.api.member.service.dto.request; -import com.smeem.api.member.controller.dto.request.TrainingTimeRequest; +import com.smeem.api.member.api.dto.request.TrainingTimeRequest; import lombok.Builder; import java.util.Objects; From 35f935a58572022c06b81d7054bb592c063b91f7 Mon Sep 17 00:00:00 2001 From: thguss Date: Tue, 12 Mar 2024 23:51:58 +0900 Subject: [PATCH 80/86] =?UTF-8?q?[ADD]=20=EC=8A=A4=EC=9B=A8=EA=B1=B0=20?= =?UTF-8?q?=EC=BB=A8=EB=B2=A4=EC=85=98=20=ED=86=B5=EC=9D=BC=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/smeem/api/diary/api/DiaryApi.java | 81 +++++++++++-------- .../java/com/smeem/api/goal/api/GoalApi.java | 29 +++---- .../java/com/smeem/api/test/api/TestApi.java | 35 ++++---- .../com/smeem/api/topic/api/TopicApi.java | 21 +++-- 4 files changed, 95 insertions(+), 71 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/diary/api/DiaryApi.java b/smeem-api/src/main/java/com/smeem/api/diary/api/DiaryApi.java index 682d4dd2..d372d45b 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/api/DiaryApi.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/api/DiaryApi.java @@ -4,7 +4,10 @@ import com.smeem.api.diary.api.dto.request.DiaryCreateRequest; import com.smeem.api.diary.api.dto.request.DiaryModifyRequest; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -12,51 +15,59 @@ import java.security.Principal; +import static io.swagger.v3.oas.annotations.enums.ParameterIn.HEADER; + +@Tag(name = "[Diary] 일기 관련 API (V2)") public interface DiaryApi { - @Operation( - summary = "일기 생성", - responses = { - @ApiResponse(responseCode = "201", description = "성공"), - @ApiResponse(responseCode = "500", description = "서버 내부 오류") - } - ) + @Operation(summary = "일기 생성 API") + @Parameter(name = "Authorization", description = "Bearer {access_token}", in = HEADER, required = true) + @ApiResponses(value = { + @ApiResponse(responseCode = "201", description = "성공"), + @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") + }) ResponseEntity> createDiary(Principal principal, @RequestBody DiaryCreateRequest request); - @Operation( - summary = "일기 상세 조회", - responses = { - @ApiResponse(responseCode = "200", description = "성공"), - @ApiResponse(responseCode = "500", description = "서버 내부 오류") - } - ) + @Operation(summary = "일기 상세 조회 API") + @Parameter(name = "Authorization", description = "Bearer {access_token}", in = HEADER, required = true) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "성공"), + @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") + }) ResponseEntity> getDiaryDetail(@PathVariable long diaryId); - @Operation( - summary = "일기 수정", - responses = { - @ApiResponse(responseCode = "200", description = "성공"), - @ApiResponse(responseCode = "500", description = "서버 내부 오류") - } - ) + @Operation(summary = "일기 수정 API") + @Parameter(name = "Authorization", description = "Bearer {access_token}", in = HEADER, required = true) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "성공"), + @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") + }) ResponseEntity> modifyDiary(@PathVariable long diaryId, @RequestBody DiaryModifyRequest request); - @Operation( - summary = "일기 삭제", - responses = { - @ApiResponse(responseCode = "200", description = "성공"), - @ApiResponse(responseCode = "500", description = "서버 내부 오류") - } - ) + @Operation(summary = "일기 삭제 API") + @Parameter(name = "Authorization", description = "Bearer {access_token}", in = HEADER, required = true) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "성공"), + @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") + }) ResponseEntity> deleteDiary(@PathVariable long diaryId); - @Operation( - summary = "기간 내 일기 목록 조회", - responses = { - @ApiResponse(responseCode = "200", description = "성공"), - @ApiResponse(responseCode = "500", description = "서버 내부 오류") - } - ) + @Operation(summary = "기간 내 일기 목록 조회 API") + @Parameter(name = "Authorization", description = "Bearer {access_token}", in = HEADER, required = true) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "성공"), + @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") + }) ResponseEntity> getDiaries( Principal principal, @RequestParam String start, diff --git a/smeem-api/src/main/java/com/smeem/api/goal/api/GoalApi.java b/smeem-api/src/main/java/com/smeem/api/goal/api/GoalApi.java index 2469f4ba..830965c0 100644 --- a/smeem-api/src/main/java/com/smeem/api/goal/api/GoalApi.java +++ b/smeem-api/src/main/java/com/smeem/api/goal/api/GoalApi.java @@ -4,26 +4,27 @@ import com.smeem.domain.goal.model.GoalType; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; +@Tag(name = "[Goal] 목표 관련 API (V2)") public interface GoalApi { - @Operation( - summary = "목표 전체 목록 조회", - responses = { - @ApiResponse(responseCode = "200", description = "성공"), - @ApiResponse(responseCode = "500", description = "서버 내부 오류") - } - ) + @Operation(summary = "목표 전체 목록 조회 API") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "성공"), + @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") + }) ResponseEntity> getAllGoals(); - @Operation( - summary = "목표 상세 조회", - responses = { - @ApiResponse(responseCode = "200", description = "성공"), - @ApiResponse(responseCode = "500", description = "서버 내부 오류") - } - ) + @Operation(summary = "목표 상세 조회 API") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "성공"), + @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") + }) ResponseEntity> getGoalByType(@PathVariable GoalType type); } diff --git a/smeem-api/src/main/java/com/smeem/api/test/api/TestApi.java b/smeem-api/src/main/java/com/smeem/api/test/api/TestApi.java index 2586784f..c473b81a 100644 --- a/smeem-api/src/main/java/com/smeem/api/test/api/TestApi.java +++ b/smeem-api/src/main/java/com/smeem/api/test/api/TestApi.java @@ -2,29 +2,34 @@ import com.smeem.api.common.BaseResponse; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.http.ResponseEntity; import java.security.Principal; +import static io.swagger.v3.oas.annotations.enums.ParameterIn.HEADER; + +@Tag(name = "[Test] 테스트 관련 API (V2)") public interface TestApi { - @Operation( - summary = "서버 연결 테스트", - responses = { - @ApiResponse(responseCode = "200", description = "성공"), - @ApiResponse(responseCode = "500", description = "서버 내부 오류") - } - ) + @Operation(summary = "서버 연결 테스트 API") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "성공"), + @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") + }) ResponseEntity> test(); - @Operation( - summary = "푸시알림 테스트", - responses = { - @ApiResponse(responseCode = "200", description = "성공"), - @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), - @ApiResponse(responseCode = "500", description = "서버 내부 오류") - } - ) + @Operation(summary = "푸시알림 테스트 API") + @Parameter(name = "Authorization", description = "Bearer {access_token}", in = HEADER, required = true) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "성공"), + @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") + }) ResponseEntity> alarmTest(Principal principal); } diff --git a/smeem-api/src/main/java/com/smeem/api/topic/api/TopicApi.java b/smeem-api/src/main/java/com/smeem/api/topic/api/TopicApi.java index 567efd58..274c8c6b 100644 --- a/smeem-api/src/main/java/com/smeem/api/topic/api/TopicApi.java +++ b/smeem-api/src/main/java/com/smeem/api/topic/api/TopicApi.java @@ -2,17 +2,24 @@ import com.smeem.api.common.BaseResponse; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.http.ResponseEntity; +import static io.swagger.v3.oas.annotations.enums.ParameterIn.HEADER; + +@Tag(name = "[Topic] 주제 관련 API (V2)") public interface TopicApi { - @Operation( - summary = "랜덤 주제 조회", - responses = { - @ApiResponse(responseCode = "200", description = "성공"), - @ApiResponse(responseCode = "500", description = "서버 내부 오류") - } - ) + @Operation(summary = "랜덤 주제 조회 API") + @Parameter(name = "Authorization", description = "Bearer {access_token}", in = HEADER, required = true) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "성공"), + @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") + }) ResponseEntity> getTopicByRandom(); } From e5dd9ede09607552a00def9bdb39308cbedde470 Mon Sep 17 00:00:00 2001 From: unanchoi Date: Tue, 12 Mar 2024 23:55:41 +0900 Subject: [PATCH 81/86] =?UTF-8?q?[REFACTOR]=20Swagger=20=EC=BB=A8=EB=B2=A4?= =?UTF-8?q?=EC=85=98=EC=97=90=20=EB=A7=9E=EC=B6=B0=EC=84=9C=20Member,=20Au?= =?UTF-8?q?th,=20Badge=20API=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smeem/api/auth/controller/AuthApi.java | 27 ++++++++------- .../smeem/api/badge/controller/BadgeApi.java | 10 +++--- .../com/smeem/api/member/api/MemberApi.java | 34 ++++++++++--------- .../api/member/api/MemberController.java | 2 +- 4 files changed, 39 insertions(+), 34 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthApi.java b/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthApi.java index 96f69461..ba9a4ae4 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthApi.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthApi.java @@ -4,6 +4,7 @@ import com.smeem.api.common.BaseResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.headers.Header; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; @@ -20,41 +21,41 @@ public interface AuthApi { @Operation(summary = "소셜 로그인 API") - @Parameter(name = "Authorization", description = "Social Platform Access Token", in = HEADER) + @Parameter(name = "Authorization", description = "Social Platform Access Token", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "201", description = "소셜로그인 성공"), - @ApiResponse(responseCode = "400", description = "유효하지 않은 요청", content = @Content), - @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), - @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) + @ApiResponse(responseCode = "400", description = "유효하지 않은 요청"), + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") }) ResponseEntity> signIn(@RequestHeader("Authorization") final String socialAccessToken, @RequestBody SignInRequest request); @Operation(summary = "토큰 재발급 API") - @Parameter(name = "Authorization", description = "Smeem Refresh Token", in = HEADER) + @Parameter(name = "Authorization", description = "Smeem Refresh Token", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "토큰 재발급 성공"), - @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), - @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") }) ResponseEntity> reissueToken(Principal principal); @Operation(summary = "사용자 로그아웃 API") - @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER) + @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "로그아웃 성공"), - @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), - @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") }) ResponseEntity> signOut(Principal principal); @Operation(summary = "회원 탈퇴 API") - @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER) + @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "회원 탈퇴 성공"), - @ApiResponse(responseCode = "400", description = "", content = @Content), - @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") }) ResponseEntity> withDrawl(Principal principal); diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeApi.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeApi.java index 79436fe0..f60d962b 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeApi.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeApi.java @@ -11,16 +11,18 @@ import java.security.Principal; +import static io.swagger.v3.oas.annotations.enums.ParameterIn.HEADER; + @Tag(name = "[Badge] 뱃지 관련 API (V2)") public interface BadgeApi { @Operation(summary = "뱃지 목록 조회 API") - @Parameter(name = "Authorization", description = "Bearer {access_token}", in = ParameterIn.HEADER, required = true) + @Parameter(name = "Authorization", description = "Bearer {access_token}", in = HEADER, required = true) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "뱃지 목록 조회 성공"), - @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), - @ApiResponse(responseCode = "500", description = "서버 오류") + @ApiResponse(responseCode = "200", description = "뱃지 리스트 조회 성공"), + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") }) ResponseEntity> getBadges(Principal principal); diff --git a/smeem-api/src/main/java/com/smeem/api/member/api/MemberApi.java b/smeem-api/src/main/java/com/smeem/api/member/api/MemberApi.java index a3f2c98f..94b5e256 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/api/MemberApi.java +++ b/smeem-api/src/main/java/com/smeem/api/member/api/MemberApi.java @@ -22,10 +22,10 @@ @Tag(name = "[Member] 사용자 관련 API (V2)") public interface MemberApi { @Operation(summary = "사용자 프로필 업데이트 API") - @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER) + @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER, required = true) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "사용자 프로필 업데이트 성공"), - @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), + @ApiResponse(responseCode = "200", description = "회원 정보 조회 성공"), + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), @ApiResponse(responseCode = "400", description = "유효하지 않은 요청"), @ApiResponse(responseCode = "500", description = "서버 오류") }) @@ -33,37 +33,39 @@ public interface MemberApi { @Operation(summary = "사용자 프로필 조회 API") - @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER) + @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER, required = true) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "사용자 프로필 조회 성공"), - @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), - @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) + @ApiResponse(responseCode = "200", description = "회원 정보 조회 성공"), + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") }) ResponseEntity> getProfile(Principal principal); @Operation(summary = "사용자 학습 계획 수정 API") - @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER) + @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "회원 학습 계획 업데이트 성공"), @ApiResponse(responseCode = "400", description = "유효하지 않은 요청"), - @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰"), - @ApiResponse(responseCode = "500", description = "서버 오류") + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") }) ResponseEntity> updateUserPlan(Principal principal, @Valid @RequestBody MemberPlanUpdateRequest request); @Operation(summary = "사용자 닉네임 중복체크 수정 API") - @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER) + @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER, required = true) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "닉네임 중복 체크 성공"), - @ApiResponse(responseCode = "500", description = "서버 오류") + @ApiResponse(responseCode = "200", description = "닉네임 중복 검사 성공"), + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") }) ResponseEntity> checkDuplicatedName(@Parameter(description = "유저 닉네임") @RequestParam String name); @Operation(summary = "사용자 학습 계획 수정 API") - @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER) + @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER, required = true) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "사용자 학습 계획 수정 성공"), - @ApiResponse(responseCode = "500", description = "서버 오류") + @ApiResponse(responseCode = "200", description = "회원 푸시알람 동의여부 업데이트 성공"), + @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), + @ApiResponse(responseCode = "500", description = "서버 내부 오류") }) ResponseEntity> updateUserPush(Principal principal, @RequestBody MemberPushUpdateRequest request); } diff --git a/smeem-api/src/main/java/com/smeem/api/member/api/MemberController.java b/smeem-api/src/main/java/com/smeem/api/member/api/MemberController.java index b40e5818..f8bc4bf2 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/api/MemberController.java +++ b/smeem-api/src/main/java/com/smeem/api/member/api/MemberController.java @@ -56,7 +56,7 @@ public ResponseEntity> updateUserPlan(Principal principal, @Vali @Override @GetMapping("/nickname/check") - public ResponseEntity> checkDuplicatedName(@Parameter(description = "유저 닉네임") @RequestParam String name) { + public ResponseEntity> checkDuplicatedName(@Parameter(description = "유저 닉네임", required = true) @RequestParam String name) { val response = MemberNameResponse.from(memberService.checkDuplicatedName(name)); return ApiResponseUtil.success(SUCCESS_CHECK_DUPLICATED_NAME, response); } From 3fc2a0f819a472d857f8b1df66207963f1b24fbd Mon Sep 17 00:00:00 2001 From: unanchoi Date: Tue, 12 Mar 2024 23:58:45 +0900 Subject: [PATCH 82/86] =?UTF-8?q?[FIX]=20Swagger=20400=20response=204xx?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/smeem/api/auth/controller/AuthApi.java | 2 +- .../main/java/com/smeem/api/badge/controller/BadgeApi.java | 2 +- .../src/main/java/com/smeem/api/member/api/MemberApi.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthApi.java b/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthApi.java index ba9a4ae4..6f8065c6 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthApi.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthApi.java @@ -24,7 +24,7 @@ public interface AuthApi { @Parameter(name = "Authorization", description = "Social Platform Access Token", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "201", description = "소셜로그인 성공"), - @ApiResponse(responseCode = "400", description = "유효하지 않은 요청"), + @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), @ApiResponse(responseCode = "500", description = "서버 내부 오류") }) diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeApi.java b/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeApi.java index f60d962b..a4d322c7 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeApi.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeApi.java @@ -21,7 +21,7 @@ public interface BadgeApi { @Parameter(name = "Authorization", description = "Bearer {access_token}", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "뱃지 리스트 조회 성공"), - @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), + @ApiResponse(responseCode = "4011", description = "유효하지 않은 토큰입니다"), @ApiResponse(responseCode = "500", description = "서버 내부 오류") }) ResponseEntity> getBadges(Principal principal); diff --git a/smeem-api/src/main/java/com/smeem/api/member/api/MemberApi.java b/smeem-api/src/main/java/com/smeem/api/member/api/MemberApi.java index 94b5e256..82dbef6d 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/api/MemberApi.java +++ b/smeem-api/src/main/java/com/smeem/api/member/api/MemberApi.java @@ -26,7 +26,7 @@ public interface MemberApi { @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "회원 정보 조회 성공"), @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), - @ApiResponse(responseCode = "400", description = "유효하지 않은 요청"), + @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), @ApiResponse(responseCode = "500", description = "서버 오류") }) ResponseEntity> updateProfile(Principal principal, @RequestBody MemberUpdateRequest request); @@ -45,7 +45,7 @@ public interface MemberApi { @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "회원 학습 계획 업데이트 성공"), - @ApiResponse(responseCode = "400", description = "유효하지 않은 요청"), + @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), @ApiResponse(responseCode = "500", description = "서버 내부 오류") }) From 4427a56d23b76a2a7b9ce70049f3428772d47c24 Mon Sep 17 00:00:00 2001 From: unanchoi Date: Wed, 13 Mar 2024 00:00:41 +0900 Subject: [PATCH 83/86] =?UTF-8?q?[CHORE]=20controller=20package=20->=20api?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/smeem/api/auth/{controller => api}/AuthApi.java | 6 ++---- .../api/auth/{controller => api}/AuthController.java | 8 ++++---- .../{controller => api}/dto/request/SignInRequest.java | 2 +- .../{controller => api}/dto/response/SignInResponse.java | 2 +- .../dto/response/token/TokenResponse.java | 2 +- .../auth/service/dto/request/SignInServiceRequest.java | 2 +- .../com/smeem/api/badge/{controller => api}/BadgeApi.java | 3 +-- .../api/badge/{controller => api}/BadgeController.java | 4 ++-- .../dto/response/AcquiredBadgeResponse.java | 2 +- .../dto/response/BadgeBaseResponse.java | 3 +-- .../dto/response/BadgeListResponse.java | 2 +- .../{controller => api}/dto/response/BadgeResponse.java | 2 +- .../dto/response/BadgeTypeResponse.java | 5 +---- .../controller/dto/response/DiaryCreateResponse.java | 2 +- .../api/member/api/dto/response/MemberGetResponse.java | 2 +- .../api/member/api/dto/response/MemberUpdateResponse.java | 2 +- 16 files changed, 21 insertions(+), 28 deletions(-) rename smeem-api/src/main/java/com/smeem/api/auth/{controller => api}/AuthApi.java (93%) rename smeem-api/src/main/java/com/smeem/api/auth/{controller => api}/AuthController.java (89%) rename smeem-api/src/main/java/com/smeem/api/auth/{controller => api}/dto/request/SignInRequest.java (81%) rename smeem-api/src/main/java/com/smeem/api/auth/{controller => api}/dto/response/SignInResponse.java (93%) rename smeem-api/src/main/java/com/smeem/api/auth/{controller => api}/dto/response/token/TokenResponse.java (89%) rename smeem-api/src/main/java/com/smeem/api/badge/{controller => api}/BadgeApi.java (91%) rename smeem-api/src/main/java/com/smeem/api/badge/{controller => api}/BadgeController.java (90%) rename smeem-api/src/main/java/com/smeem/api/badge/{controller => api}/dto/response/AcquiredBadgeResponse.java (92%) rename smeem-api/src/main/java/com/smeem/api/badge/{controller => api}/dto/response/BadgeBaseResponse.java (88%) rename smeem-api/src/main/java/com/smeem/api/badge/{controller => api}/dto/response/BadgeListResponse.java (91%) rename smeem-api/src/main/java/com/smeem/api/badge/{controller => api}/dto/response/BadgeResponse.java (90%) rename smeem-api/src/main/java/com/smeem/api/badge/{controller => api}/dto/response/BadgeTypeResponse.java (77%) diff --git a/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthApi.java b/smeem-api/src/main/java/com/smeem/api/auth/api/AuthApi.java similarity index 93% rename from smeem-api/src/main/java/com/smeem/api/auth/controller/AuthApi.java rename to smeem-api/src/main/java/com/smeem/api/auth/api/AuthApi.java index 6f8065c6..b20e092a 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthApi.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/api/AuthApi.java @@ -1,11 +1,9 @@ -package com.smeem.api.auth.controller; +package com.smeem.api.auth.api; -import com.smeem.api.auth.controller.dto.request.SignInRequest; +import com.smeem.api.auth.api.dto.request.SignInRequest; import com.smeem.api.common.BaseResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.headers.Header; -import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; diff --git a/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java b/smeem-api/src/main/java/com/smeem/api/auth/api/AuthController.java similarity index 89% rename from smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java rename to smeem-api/src/main/java/com/smeem/api/auth/api/AuthController.java index 4fc4ee7a..d0e544de 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/controller/AuthController.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/api/AuthController.java @@ -1,8 +1,8 @@ -package com.smeem.api.auth.controller; +package com.smeem.api.auth.api; -import com.smeem.api.auth.controller.dto.request.SignInRequest; -import com.smeem.api.auth.controller.dto.response.SignInResponse; -import com.smeem.api.auth.controller.dto.response.token.TokenResponse; +import com.smeem.api.auth.api.dto.request.SignInRequest; +import com.smeem.api.auth.api.dto.response.SignInResponse; +import com.smeem.api.auth.api.dto.response.token.TokenResponse; import com.smeem.api.auth.service.AuthService; import com.smeem.api.auth.service.TokenService; import com.smeem.api.auth.service.dto.request.SignInServiceRequest; diff --git a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/request/SignInRequest.java b/smeem-api/src/main/java/com/smeem/api/auth/api/dto/request/SignInRequest.java similarity index 81% rename from smeem-api/src/main/java/com/smeem/api/auth/controller/dto/request/SignInRequest.java rename to smeem-api/src/main/java/com/smeem/api/auth/api/dto/request/SignInRequest.java index d05bd87c..a6fa217f 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/request/SignInRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/api/dto/request/SignInRequest.java @@ -1,4 +1,4 @@ -package com.smeem.api.auth.controller.dto.request; +package com.smeem.api.auth.api.dto.request; import com.fasterxml.jackson.annotation.JsonProperty; import com.smeem.domain.member.model.SocialType; diff --git a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponse.java b/smeem-api/src/main/java/com/smeem/api/auth/api/dto/response/SignInResponse.java similarity index 93% rename from smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponse.java rename to smeem-api/src/main/java/com/smeem/api/auth/api/dto/response/SignInResponse.java index a6436ca6..e86d7708 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/SignInResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/api/dto/response/SignInResponse.java @@ -1,4 +1,4 @@ -package com.smeem.api.auth.controller.dto.response; +package com.smeem.api.auth.api.dto.response; import com.smeem.api.auth.service.dto.response.SignInServiceResponse; diff --git a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenResponse.java b/smeem-api/src/main/java/com/smeem/api/auth/api/dto/response/token/TokenResponse.java similarity index 89% rename from smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenResponse.java rename to smeem-api/src/main/java/com/smeem/api/auth/api/dto/response/token/TokenResponse.java index d3fe80ae..e607be39 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/controller/dto/response/token/TokenResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/api/dto/response/token/TokenResponse.java @@ -1,4 +1,4 @@ -package com.smeem.api.auth.controller.dto.response.token; +package com.smeem.api.auth.api.dto.response.token; import com.smeem.api.auth.service.dto.response.TokenServiceResponse; import lombok.AccessLevel; diff --git a/smeem-api/src/main/java/com/smeem/api/auth/service/dto/request/SignInServiceRequest.java b/smeem-api/src/main/java/com/smeem/api/auth/service/dto/request/SignInServiceRequest.java index 7e39be58..33d89e4d 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/service/dto/request/SignInServiceRequest.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/service/dto/request/SignInServiceRequest.java @@ -1,6 +1,6 @@ package com.smeem.api.auth.service.dto.request; -import com.smeem.api.auth.controller.dto.request.SignInRequest; +import com.smeem.api.auth.api.dto.request.SignInRequest; import com.smeem.domain.member.model.SocialType; import lombok.Builder; diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeApi.java b/smeem-api/src/main/java/com/smeem/api/badge/api/BadgeApi.java similarity index 91% rename from smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeApi.java rename to smeem-api/src/main/java/com/smeem/api/badge/api/BadgeApi.java index a4d322c7..ec4e8721 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeApi.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/api/BadgeApi.java @@ -1,9 +1,8 @@ -package com.smeem.api.badge.controller; +package com.smeem.api.badge.api; import com.smeem.api.common.BaseResponse; 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.tags.Tag; diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java b/smeem-api/src/main/java/com/smeem/api/badge/api/BadgeController.java similarity index 90% rename from smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java rename to smeem-api/src/main/java/com/smeem/api/badge/api/BadgeController.java index 0ba60077..d2aa7595 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/BadgeController.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/api/BadgeController.java @@ -1,6 +1,6 @@ -package com.smeem.api.badge.controller; +package com.smeem.api.badge.api; -import com.smeem.api.badge.controller.dto.response.BadgeListResponse; +import com.smeem.api.badge.api.dto.response.BadgeListResponse; import com.smeem.api.badge.service.BadgeService; import com.smeem.api.common.ApiResponseUtil; import com.smeem.api.common.BaseResponse; diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/AcquiredBadgeResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/api/dto/response/AcquiredBadgeResponse.java similarity index 92% rename from smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/AcquiredBadgeResponse.java rename to smeem-api/src/main/java/com/smeem/api/badge/api/dto/response/AcquiredBadgeResponse.java index 3550c176..adb84840 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/AcquiredBadgeResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/api/dto/response/AcquiredBadgeResponse.java @@ -1,4 +1,4 @@ -package com.smeem.api.badge.controller.dto.response; +package com.smeem.api.badge.api.dto.response; import com.smeem.api.badge.service.dto.response.AcquiredBadgeServiceResponse; import com.smeem.domain.badge.model.BadgeType; diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeBaseResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/api/dto/response/BadgeBaseResponse.java similarity index 88% rename from smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeBaseResponse.java rename to smeem-api/src/main/java/com/smeem/api/badge/api/dto/response/BadgeBaseResponse.java index e2eca689..ec69911c 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeBaseResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/api/dto/response/BadgeBaseResponse.java @@ -1,8 +1,7 @@ -package com.smeem.api.badge.controller.dto.response; +package com.smeem.api.badge.api.dto.response; import com.smeem.api.badge.service.dto.response.BadgeBaseServiceResponse; import com.smeem.domain.badge.model.BadgeType; -import lombok.AccessLevel; import lombok.Builder; import static lombok.AccessLevel.PRIVATE; diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/api/dto/response/BadgeListResponse.java similarity index 91% rename from smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponse.java rename to smeem-api/src/main/java/com/smeem/api/badge/api/dto/response/BadgeListResponse.java index c4cdf4d4..5853ad7f 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeListResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/api/dto/response/BadgeListResponse.java @@ -1,4 +1,4 @@ -package com.smeem.api.badge.controller.dto.response; +package com.smeem.api.badge.api.dto.response; import com.smeem.api.badge.service.dto.response.BadgeListServiceResponse; import lombok.*; diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/api/dto/response/BadgeResponse.java similarity index 90% rename from smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponse.java rename to smeem-api/src/main/java/com/smeem/api/badge/api/dto/response/BadgeResponse.java index 597fc313..14620d48 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/api/dto/response/BadgeResponse.java @@ -1,4 +1,4 @@ -package com.smeem.api.badge.controller.dto.response; +package com.smeem.api.badge.api.dto.response; import com.smeem.api.badge.service.dto.response.BadgeServiceResponse; import lombok.AccessLevel; diff --git a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeTypeResponse.java b/smeem-api/src/main/java/com/smeem/api/badge/api/dto/response/BadgeTypeResponse.java similarity index 77% rename from smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeTypeResponse.java rename to smeem-api/src/main/java/com/smeem/api/badge/api/dto/response/BadgeTypeResponse.java index 37f82495..3ffa1235 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/controller/dto/response/BadgeTypeResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/api/dto/response/BadgeTypeResponse.java @@ -1,10 +1,7 @@ -package com.smeem.api.badge.controller.dto.response; +package com.smeem.api.badge.api.dto.response; -import com.smeem.api.badge.service.dto.response.BadgeBaseServiceResponse; import com.smeem.api.badge.service.dto.response.BadgeTypeServiceResponse; -import com.smeem.domain.badge.model.Badge; import com.smeem.domain.badge.model.BadgeType; -import com.smeem.domain.member.model.MemberBadge; import lombok.Builder; import java.util.List; diff --git a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryCreateResponse.java b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryCreateResponse.java index c06ee419..0883ad04 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryCreateResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/controller/dto/response/DiaryCreateResponse.java @@ -1,6 +1,6 @@ package com.smeem.api.diary.controller.dto.response; -import com.smeem.api.badge.controller.dto.response.AcquiredBadgeResponse; +import com.smeem.api.badge.api.dto.response.AcquiredBadgeResponse; import com.smeem.api.diary.service.dto.response.DiaryCreateServiceResponse; import lombok.Builder; diff --git a/smeem-api/src/main/java/com/smeem/api/member/api/dto/response/MemberGetResponse.java b/smeem-api/src/main/java/com/smeem/api/member/api/dto/response/MemberGetResponse.java index b0eec36c..6f646edd 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/api/dto/response/MemberGetResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/member/api/dto/response/MemberGetResponse.java @@ -1,7 +1,7 @@ package com.smeem.api.member.api.dto.response; -import com.smeem.api.badge.controller.dto.response.BadgeResponse; +import com.smeem.api.badge.api.dto.response.BadgeResponse; import com.smeem.api.member.service.dto.response.MemberGetServiceResponse; import lombok.AccessLevel; import lombok.Builder; diff --git a/smeem-api/src/main/java/com/smeem/api/member/api/dto/response/MemberUpdateResponse.java b/smeem-api/src/main/java/com/smeem/api/member/api/dto/response/MemberUpdateResponse.java index 7107aafa..db181df3 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/api/dto/response/MemberUpdateResponse.java +++ b/smeem-api/src/main/java/com/smeem/api/member/api/dto/response/MemberUpdateResponse.java @@ -1,7 +1,7 @@ package com.smeem.api.member.api.dto.response; -import com.smeem.api.badge.controller.dto.response.AcquiredBadgeResponse; +import com.smeem.api.badge.api.dto.response.AcquiredBadgeResponse; import com.smeem.api.member.service.dto.response.MemberUpdateServiceResponse; import lombok.Builder; From 09c77b68b0c2fae3c23b79fd0c90cfec76ed714f Mon Sep 17 00:00:00 2001 From: thguss Date: Wed, 13 Mar 2024 00:09:02 +0900 Subject: [PATCH 84/86] =?UTF-8?q?[FIX]=20=ED=86=A0=ED=81=B0=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=EB=AA=85=20=ED=86=B5=EC=9D=BC=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/smeem/api/diary/api/DiaryApi.java | 10 +++++----- .../src/main/java/com/smeem/api/test/api/TestApi.java | 2 +- .../main/java/com/smeem/api/topic/api/TopicApi.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/diary/api/DiaryApi.java b/smeem-api/src/main/java/com/smeem/api/diary/api/DiaryApi.java index d372d45b..c222892d 100644 --- a/smeem-api/src/main/java/com/smeem/api/diary/api/DiaryApi.java +++ b/smeem-api/src/main/java/com/smeem/api/diary/api/DiaryApi.java @@ -21,7 +21,7 @@ public interface DiaryApi { @Operation(summary = "일기 생성 API") - @Parameter(name = "Authorization", description = "Bearer {access_token}", in = HEADER, required = true) + @Parameter(name = "Authorization", description = "Bearer ${Smeem Access Token}", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "201", description = "성공"), @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), @@ -31,7 +31,7 @@ public interface DiaryApi { ResponseEntity> createDiary(Principal principal, @RequestBody DiaryCreateRequest request); @Operation(summary = "일기 상세 조회 API") - @Parameter(name = "Authorization", description = "Bearer {access_token}", in = HEADER, required = true) + @Parameter(name = "Authorization", description = "Bearer ${Smeem Access Token}", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "성공"), @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), @@ -41,7 +41,7 @@ public interface DiaryApi { ResponseEntity> getDiaryDetail(@PathVariable long diaryId); @Operation(summary = "일기 수정 API") - @Parameter(name = "Authorization", description = "Bearer {access_token}", in = HEADER, required = true) + @Parameter(name = "Authorization", description = "Bearer ${Smeem Access Token}", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "성공"), @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), @@ -51,7 +51,7 @@ public interface DiaryApi { ResponseEntity> modifyDiary(@PathVariable long diaryId, @RequestBody DiaryModifyRequest request); @Operation(summary = "일기 삭제 API") - @Parameter(name = "Authorization", description = "Bearer {access_token}", in = HEADER, required = true) + @Parameter(name = "Authorization", description = "Bearer ${Smeem Access Token}", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "성공"), @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), @@ -61,7 +61,7 @@ public interface DiaryApi { ResponseEntity> deleteDiary(@PathVariable long diaryId); @Operation(summary = "기간 내 일기 목록 조회 API") - @Parameter(name = "Authorization", description = "Bearer {access_token}", in = HEADER, required = true) + @Parameter(name = "Authorization", description = "Bearer ${Smeem Access Token}", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "성공"), @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), diff --git a/smeem-api/src/main/java/com/smeem/api/test/api/TestApi.java b/smeem-api/src/main/java/com/smeem/api/test/api/TestApi.java index c473b81a..a0af99d1 100644 --- a/smeem-api/src/main/java/com/smeem/api/test/api/TestApi.java +++ b/smeem-api/src/main/java/com/smeem/api/test/api/TestApi.java @@ -24,7 +24,7 @@ public interface TestApi { ResponseEntity> test(); @Operation(summary = "푸시알림 테스트 API") - @Parameter(name = "Authorization", description = "Bearer {access_token}", in = HEADER, required = true) + @Parameter(name = "Authorization", description = "Bearer ${Smeem Access Token}", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "성공"), @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), diff --git a/smeem-api/src/main/java/com/smeem/api/topic/api/TopicApi.java b/smeem-api/src/main/java/com/smeem/api/topic/api/TopicApi.java index 274c8c6b..84351294 100644 --- a/smeem-api/src/main/java/com/smeem/api/topic/api/TopicApi.java +++ b/smeem-api/src/main/java/com/smeem/api/topic/api/TopicApi.java @@ -14,7 +14,7 @@ public interface TopicApi { @Operation(summary = "랜덤 주제 조회 API") - @Parameter(name = "Authorization", description = "Bearer {access_token}", in = HEADER, required = true) + @Parameter(name = "Authorization", description = "Bearer ${Smeem Access Token}", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "성공"), @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), From 9441d14e1735274dabeabefa881dd496751eb1b7 Mon Sep 17 00:00:00 2001 From: unanchoi Date: Wed, 13 Mar 2024 00:11:18 +0900 Subject: [PATCH 85/86] =?UTF-8?q?[FIX]=20=ED=86=A0=ED=81=B0=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=EB=AA=85=20=ED=86=B5=EC=9D=BC=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/smeem/api/auth/api/AuthApi.java | 8 ++++---- .../main/java/com/smeem/api/badge/api/BadgeApi.java | 2 +- .../main/java/com/smeem/api/member/api/MemberApi.java | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/auth/api/AuthApi.java b/smeem-api/src/main/java/com/smeem/api/auth/api/AuthApi.java index b20e092a..36e3131d 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/api/AuthApi.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/api/AuthApi.java @@ -19,7 +19,7 @@ public interface AuthApi { @Operation(summary = "소셜 로그인 API") - @Parameter(name = "Authorization", description = "Social Platform Access Token", in = HEADER, required = true) + @Parameter(name = "Authorization", description = "Bearer ${Social Platform Access Token}", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "201", description = "소셜로그인 성공"), @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), @@ -29,7 +29,7 @@ public interface AuthApi { ResponseEntity> signIn(@RequestHeader("Authorization") final String socialAccessToken, @RequestBody SignInRequest request); @Operation(summary = "토큰 재발급 API") - @Parameter(name = "Authorization", description = "Smeem Refresh Token", in = HEADER, required = true) + @Parameter(name = "Authorization", description = "Bearer ${Smeme Refresh Token}", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "토큰 재발급 성공"), @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), @@ -39,7 +39,7 @@ public interface AuthApi { @Operation(summary = "사용자 로그아웃 API") - @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER, required = true) + @Parameter(name = "Authorization", description = "Bearer ${Smeme Access Token}", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "로그아웃 성공"), @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), @@ -49,7 +49,7 @@ public interface AuthApi { @Operation(summary = "회원 탈퇴 API") - @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER, required = true) + @Parameter(name = "Authorization", description = "Bearer ${Smeme Access Token}", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "회원 탈퇴 성공"), @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), diff --git a/smeem-api/src/main/java/com/smeem/api/badge/api/BadgeApi.java b/smeem-api/src/main/java/com/smeem/api/badge/api/BadgeApi.java index ec4e8721..f30aed04 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/api/BadgeApi.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/api/BadgeApi.java @@ -17,7 +17,7 @@ public interface BadgeApi { @Operation(summary = "뱃지 목록 조회 API") - @Parameter(name = "Authorization", description = "Bearer {access_token}", in = HEADER, required = true) + @Parameter(name = "Authorization", description = "Bearer ${Smeme Access Token}", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "뱃지 리스트 조회 성공"), @ApiResponse(responseCode = "4011", description = "유효하지 않은 토큰입니다"), diff --git a/smeem-api/src/main/java/com/smeem/api/member/api/MemberApi.java b/smeem-api/src/main/java/com/smeem/api/member/api/MemberApi.java index 82dbef6d..6761ca11 100644 --- a/smeem-api/src/main/java/com/smeem/api/member/api/MemberApi.java +++ b/smeem-api/src/main/java/com/smeem/api/member/api/MemberApi.java @@ -22,7 +22,7 @@ @Tag(name = "[Member] 사용자 관련 API (V2)") public interface MemberApi { @Operation(summary = "사용자 프로필 업데이트 API") - @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER, required = true) + @Parameter(name = "Authorization", description = "Bearer ${Smeme Access Token}", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "회원 정보 조회 성공"), @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), @@ -33,7 +33,7 @@ public interface MemberApi { @Operation(summary = "사용자 프로필 조회 API") - @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER, required = true) + @Parameter(name = "Authorization", description = "Bearer ${Smeme Access Token}", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "회원 정보 조회 성공"), @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), @@ -42,7 +42,7 @@ public interface MemberApi { ResponseEntity> getProfile(Principal principal); @Operation(summary = "사용자 학습 계획 수정 API") - @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER, required = true) + @Parameter(name = "Authorization", description = "Bearer ${Smeme Access Token}", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "회원 학습 계획 업데이트 성공"), @ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"), @@ -52,7 +52,7 @@ public interface MemberApi { ResponseEntity> updateUserPlan(Principal principal, @Valid @RequestBody MemberPlanUpdateRequest request); @Operation(summary = "사용자 닉네임 중복체크 수정 API") - @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER, required = true) + @Parameter(name = "Authorization", description = "Bearer ${Smeme Access Token}", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "닉네임 중복 검사 성공"), @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), @@ -61,7 +61,7 @@ public interface MemberApi { ResponseEntity> checkDuplicatedName(@Parameter(description = "유저 닉네임") @RequestParam String name); @Operation(summary = "사용자 학습 계획 수정 API") - @Parameter(name = "Authorization", description = "Smeme Access Token", in = HEADER, required = true) + @Parameter(name = "Authorization", description = "Bearer ${Smeme Access Token}", in = HEADER, required = true) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "회원 푸시알람 동의여부 업데이트 성공"), @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), From 77a8d7948f23ec547b37bdb53416da74b5c9728c Mon Sep 17 00:00:00 2001 From: unanchoi Date: Wed, 13 Mar 2024 00:29:05 +0900 Subject: [PATCH 86/86] =?UTF-8?q?[CHORE]=20Auth=20API=20implements=20?= =?UTF-8?q?=ED=82=A4=EC=9B=8C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smeem-api/src/main/java/com/smeem/api/auth/api/AuthApi.java | 4 +++- .../main/java/com/smeem/api/auth/api/AuthController.java | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/auth/api/AuthApi.java b/smeem-api/src/main/java/com/smeem/api/auth/api/AuthApi.java index 36e3131d..92777064 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/api/AuthApi.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/api/AuthApi.java @@ -11,7 +11,9 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; +import java.security.NoSuchAlgorithmException; import java.security.Principal; +import java.security.spec.InvalidKeySpecException; import static io.swagger.v3.oas.annotations.enums.ParameterIn.HEADER; @@ -26,7 +28,7 @@ public interface AuthApi { @ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"), @ApiResponse(responseCode = "500", description = "서버 내부 오류") }) - ResponseEntity> signIn(@RequestHeader("Authorization") final String socialAccessToken, @RequestBody SignInRequest request); + ResponseEntity> signIn(@RequestHeader("Authorization") final String socialAccessToken, @RequestBody SignInRequest request) throws NoSuchAlgorithmException, InvalidKeySpecException; @Operation(summary = "토큰 재발급 API") @Parameter(name = "Authorization", description = "Bearer ${Smeme Refresh Token}", in = HEADER, required = true) diff --git a/smeem-api/src/main/java/com/smeem/api/auth/api/AuthController.java b/smeem-api/src/main/java/com/smeem/api/auth/api/AuthController.java index d0e544de..3ac1bc4a 100644 --- a/smeem-api/src/main/java/com/smeem/api/auth/api/AuthController.java +++ b/smeem-api/src/main/java/com/smeem/api/auth/api/AuthController.java @@ -24,11 +24,12 @@ @RestController @RequiredArgsConstructor @RequestMapping("api/v2/auth") -public class AuthController { +public class AuthController implements AuthApi { private final AuthService authService; private final TokenService tokenService; + @Override @PostMapping public ResponseEntity> signIn(@RequestHeader("Authorization") final String socialAccessToken, @RequestBody SignInRequest request) throws NoSuchAlgorithmException, InvalidKeySpecException { @@ -36,18 +37,21 @@ public ResponseEntity> signIn(@RequestHeader("Authorization") fi return ApiResponseUtil.success(SUCCESS_SIGNIN, response); } + @Override @PostMapping("/token") public ResponseEntity> reissueToken(Principal principal) { val response = TokenResponse.from(tokenService.issueToken(Util.getMemberId(principal))); return ApiResponseUtil.success(SUCCESS_ISSUE_TOKEN, response); } + @Override @PostMapping("/sign-out") public ResponseEntity> signOut(Principal principal) { authService.signOut(Util.getMemberId(principal)); return ApiResponseUtil.success(SUCCESS_SIGNOUT); } + @Override @DeleteMapping public ResponseEntity> withDrawl(Principal principal) { authService.withdraw(Util.getMemberId(principal));