diff --git a/src/docs/asciidoc/block.adoc b/src/docs/asciidoc/block.adoc index 173294fb..5ce40b65 100644 --- a/src/docs/asciidoc/block.adoc +++ b/src/docs/asciidoc/block.adoc @@ -83,4 +83,14 @@ include::{snippets}/block/delete/path-parameters.adoc[] ==== 응답 -include::{snippets}/block/delete/http-response.adoc[] \ No newline at end of file +include::{snippets}/block/delete/http-response.adoc[] + +=== 블록 상태 변경 + +==== 요청 + +include::{snippets}/block/change/http-request.adoc[] + +==== 응답 + +include::{snippets}/block/change/http-response.adoc[] diff --git a/src/docs/asciidoc/index.adoc b/src/docs/asciidoc/index.adoc index c78b7060..f9dd6da4 100644 --- a/src/docs/asciidoc/index.adoc +++ b/src/docs/asciidoc/index.adoc @@ -8,5 +8,5 @@ include::block.adoc[] include::challenge.adoc[] -include::peronsalDashboard.adoc[] +include::personalDashboard.adoc[] include::notification.adoc[] \ No newline at end of file diff --git a/src/docs/asciidoc/peronsalDashboard.adoc b/src/docs/asciidoc/personalDashboard.adoc similarity index 100% rename from src/docs/asciidoc/peronsalDashboard.adoc rename to src/docs/asciidoc/personalDashboard.adoc diff --git a/src/main/java/shop/kkeujeok/kkeujeokbackend/block/api/BlockController.java b/src/main/java/shop/kkeujeok/kkeujeokbackend/block/api/BlockController.java index aba93bf5..b40aec19 100644 --- a/src/main/java/shop/kkeujeok/kkeujeokbackend/block/api/BlockController.java +++ b/src/main/java/shop/kkeujeok/kkeujeokbackend/block/api/BlockController.java @@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import shop.kkeujeok.kkeujeokbackend.block.api.dto.request.BlockSaveReqDto; +import shop.kkeujeok.kkeujeokbackend.block.api.dto.request.BlockSequenceUpdateReqDto; import shop.kkeujeok.kkeujeokbackend.block.api.dto.request.BlockUpdateReqDto; import shop.kkeujeok.kkeujeokbackend.block.api.dto.response.BlockInfoResDto; import shop.kkeujeok.kkeujeokbackend.block.api.dto.response.BlockListResDto; @@ -71,4 +72,11 @@ public RspTemplate findById(@CurrentUserEmail String email, return new RspTemplate<>(HttpStatus.OK, "블록 상세보기", blockService.findById(email, blockId)); } + @PatchMapping("/change") + public RspTemplate changeBlocksSequence(@CurrentUserEmail String email, + @RequestBody BlockSequenceUpdateReqDto blockSequenceUpdateReqDto) { + blockService.changeBlocksSequence(email, blockSequenceUpdateReqDto); + return new RspTemplate<>(HttpStatus.OK, "블록 순서 변경"); + } + } diff --git a/src/main/java/shop/kkeujeok/kkeujeokbackend/block/api/dto/request/BlockSaveReqDto.java b/src/main/java/shop/kkeujeok/kkeujeokbackend/block/api/dto/request/BlockSaveReqDto.java index 53bf3cee..480480a6 100644 --- a/src/main/java/shop/kkeujeok/kkeujeokbackend/block/api/dto/request/BlockSaveReqDto.java +++ b/src/main/java/shop/kkeujeok/kkeujeokbackend/block/api/dto/request/BlockSaveReqDto.java @@ -14,7 +14,7 @@ public record BlockSaveReqDto( String startDate, String deadLine ) { - public Block toEntity(Member member, Dashboard dashboard) { + public Block toEntity(Member member, Dashboard dashboard, int lastSequence) { return Block.builder() .title(title) .contents(contents) @@ -22,6 +22,7 @@ public Block toEntity(Member member, Dashboard dashboard) { .type(Type.BASIC) .startDate(startDate) .deadLine(deadLine) + .sequence(lastSequence + 1) .member(member) .dashboard(dashboard) .build(); diff --git a/src/main/java/shop/kkeujeok/kkeujeokbackend/block/api/dto/request/BlockSequenceUpdateReqDto.java b/src/main/java/shop/kkeujeok/kkeujeokbackend/block/api/dto/request/BlockSequenceUpdateReqDto.java new file mode 100644 index 00000000..fe291c90 --- /dev/null +++ b/src/main/java/shop/kkeujeok/kkeujeokbackend/block/api/dto/request/BlockSequenceUpdateReqDto.java @@ -0,0 +1,10 @@ +package shop.kkeujeok.kkeujeokbackend.block.api.dto.request; + +import java.util.List; + +public record BlockSequenceUpdateReqDto( + List notStartedList, + List inProgressList, + List completedList +) { +} diff --git a/src/main/java/shop/kkeujeok/kkeujeokbackend/block/api/dto/response/BlockInfoResDto.java b/src/main/java/shop/kkeujeok/kkeujeokbackend/block/api/dto/response/BlockInfoResDto.java index 903d92a0..627d691a 100644 --- a/src/main/java/shop/kkeujeok/kkeujeokbackend/block/api/dto/response/BlockInfoResDto.java +++ b/src/main/java/shop/kkeujeok/kkeujeokbackend/block/api/dto/response/BlockInfoResDto.java @@ -16,6 +16,7 @@ public record BlockInfoResDto( String contents, Progress progress, Type type, + String dType, String startDate, String deadLine, String nickname, @@ -28,6 +29,7 @@ public static BlockInfoResDto from(Block block) { .contents(block.getContents()) .progress(block.getProgress()) .type(block.getType()) + .dType(block.getDashboard().getDType()) .startDate(block.getStartDate()) .deadLine(block.getDeadLine()) .nickname(block.getMember().getNickname()) diff --git a/src/main/java/shop/kkeujeok/kkeujeokbackend/block/application/BlockService.java b/src/main/java/shop/kkeujeok/kkeujeokbackend/block/application/BlockService.java index 8211fddb..58bb9a75 100644 --- a/src/main/java/shop/kkeujeok/kkeujeokbackend/block/application/BlockService.java +++ b/src/main/java/shop/kkeujeok/kkeujeokbackend/block/application/BlockService.java @@ -7,6 +7,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import shop.kkeujeok.kkeujeokbackend.block.api.dto.request.BlockSaveReqDto; +import shop.kkeujeok.kkeujeokbackend.block.api.dto.request.BlockSequenceUpdateReqDto; import shop.kkeujeok.kkeujeokbackend.block.api.dto.request.BlockUpdateReqDto; import shop.kkeujeok.kkeujeokbackend.block.api.dto.response.BlockInfoResDto; import shop.kkeujeok.kkeujeokbackend.block.api.dto.response.BlockListResDto; @@ -38,7 +39,13 @@ public BlockInfoResDto save(String email, BlockSaveReqDto blockSaveReqDto) { Member member = memberRepository.findByEmail(email).orElseThrow(MemberNotFoundException::new); Dashboard dashboard = dashboardRepository.findById(blockSaveReqDto.dashboardId()) .orElseThrow(DashboardNotFoundException::new); - Block block = blockRepository.save(blockSaveReqDto.toEntity(member, dashboard)); + + int lastSequence = blockRepository.findLastSequenceByProgress( + member, + dashboard.getId(), + blockSaveReqDto.progress()); + + Block block = blockRepository.save(blockSaveReqDto.toEntity(member, dashboard, lastSequence)); return BlockInfoResDto.from(block); } @@ -99,6 +106,30 @@ public void delete(String email, Long blockId) { block.statusUpdate(); } + // 블록 순번 변경 + @Transactional + public void changeBlocksSequence(String email, BlockSequenceUpdateReqDto blockSequenceUpdateReqDto) { + Member member = memberRepository.findByEmail(email).orElseThrow(MemberNotFoundException::new); + + updateBlockSequence(blockSequenceUpdateReqDto.notStartedList()); + updateBlockSequence(blockSequenceUpdateReqDto.inProgressList()); + updateBlockSequence(blockSequenceUpdateReqDto.completedList()); + } + + private void updateBlockSequence(List blockIds) { + int sequence = blockIds.size(); + + for (Long blockId : blockIds) { + Block block = blockRepository.findById(blockId).orElseThrow(BlockNotFoundException::new); + + if (block.getSequence() != sequence) { + block.sequenceUpdate(sequence); + } + + sequence--; + } + } + private Progress parseProgress(String progressString) { try { return Progress.valueOf(progressString); diff --git a/src/main/java/shop/kkeujeok/kkeujeokbackend/block/domain/Block.java b/src/main/java/shop/kkeujeok/kkeujeokbackend/block/domain/Block.java index f8a68687..36c49c4e 100644 --- a/src/main/java/shop/kkeujeok/kkeujeokbackend/block/domain/Block.java +++ b/src/main/java/shop/kkeujeok/kkeujeokbackend/block/domain/Block.java @@ -40,6 +40,8 @@ public class Block extends BaseEntity { private String deadLine; + private int sequence; + @ManyToOne @JoinColumn(name = "member_id") private Member member; @@ -54,8 +56,7 @@ public class Block extends BaseEntity { @Builder private Block(String title, String contents, Progress progress, Type type, Member member, String startDate, - String deadLine, - Dashboard dashboard, Challenge challenge) { + String deadLine, int sequence, Dashboard dashboard, Challenge challenge) { this.status = Status.ACTIVE; this.title = title; this.contents = contents; @@ -63,6 +64,7 @@ private Block(String title, String contents, Progress progress, Type type, Membe this.type = type; this.startDate = startDate; this.deadLine = deadLine; + this.sequence = sequence; this.member = member; this.dashboard = dashboard; this.challenge = challenge; @@ -99,4 +101,9 @@ public void updateChallengeStatus(Status status) { } this.status = status; } + + public void sequenceUpdate(int sequence) { + this.sequence = sequence; + } + } diff --git a/src/main/java/shop/kkeujeok/kkeujeokbackend/block/domain/repository/BlockCustomRepository.java b/src/main/java/shop/kkeujeok/kkeujeokbackend/block/domain/repository/BlockCustomRepository.java index 06fbf916..6f07e29b 100644 --- a/src/main/java/shop/kkeujeok/kkeujeokbackend/block/domain/repository/BlockCustomRepository.java +++ b/src/main/java/shop/kkeujeok/kkeujeokbackend/block/domain/repository/BlockCustomRepository.java @@ -4,7 +4,10 @@ import org.springframework.data.domain.Pageable; import shop.kkeujeok.kkeujeokbackend.block.domain.Block; import shop.kkeujeok.kkeujeokbackend.block.domain.Progress; +import shop.kkeujeok.kkeujeokbackend.member.domain.Member; public interface BlockCustomRepository { Page findByBlockWithProgress(Long dashboardId, Progress progress, Pageable pageable); + + int findLastSequenceByProgress(Member member, Long dashboardId, Progress progress); } diff --git a/src/main/java/shop/kkeujeok/kkeujeokbackend/block/domain/repository/BlockCustomRepositoryImpl.java b/src/main/java/shop/kkeujeok/kkeujeokbackend/block/domain/repository/BlockCustomRepositoryImpl.java index 6366e49d..c26ba434 100644 --- a/src/main/java/shop/kkeujeok/kkeujeokbackend/block/domain/repository/BlockCustomRepositoryImpl.java +++ b/src/main/java/shop/kkeujeok/kkeujeokbackend/block/domain/repository/BlockCustomRepositoryImpl.java @@ -4,6 +4,7 @@ import com.querydsl.jpa.impl.JPAQueryFactory; import java.util.List; +import java.util.Optional; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; @@ -12,6 +13,7 @@ import shop.kkeujeok.kkeujeokbackend.block.domain.Block; import shop.kkeujeok.kkeujeokbackend.block.domain.Progress; import shop.kkeujeok.kkeujeokbackend.global.entity.Status; +import shop.kkeujeok.kkeujeokbackend.member.domain.Member; @Repository @Transactional(readOnly = true) @@ -35,7 +37,7 @@ public Page findByBlockWithProgress(Long dashboardId, Progress progress, .where(block.dashboard.id.eq(dashboardId) .and(block.progress.eq(progress)) .and(block.status.eq(Status.ACTIVE))) - .orderBy(block.id.desc()) + .orderBy(block.sequence.desc()) .offset(pageable.getOffset()) .limit(pageable.getPageSize()) .fetch(); @@ -43,4 +45,21 @@ public Page findByBlockWithProgress(Long dashboardId, Progress progress, return new PageImpl<>(blocks, pageable, total); } + @Override + public int findLastSequenceByProgress(Member member, Long dashboardId, Progress progress) { + return Optional.of( + Math.toIntExact( + queryFactory + .select(block.sequence) + .from(block) + .where(block.dashboard.id.eq(dashboardId) + .and(block.progress.eq(progress)) + .and(block.status.eq(Status.ACTIVE))) + .stream() + .count() + ) + ) + .orElse(0); + } + } diff --git a/src/main/java/shop/kkeujeok/kkeujeokbackend/dashboard/domain/Dashboard.java b/src/main/java/shop/kkeujeok/kkeujeokbackend/dashboard/domain/Dashboard.java index ab16c511..3a9d7806 100644 --- a/src/main/java/shop/kkeujeok/kkeujeokbackend/dashboard/domain/Dashboard.java +++ b/src/main/java/shop/kkeujeok/kkeujeokbackend/dashboard/domain/Dashboard.java @@ -23,7 +23,7 @@ @Entity @Getter -@DiscriminatorColumn +@DiscriminatorColumn(name = "dtype") @Inheritance(strategy = InheritanceType.JOINED) @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Dashboard extends BaseEntity { @@ -36,6 +36,9 @@ public class Dashboard extends BaseEntity { @Column(columnDefinition = "TEXT") private String description; + @Column(name = "dtype", insertable = false, updatable = false) + private String dType; + @ManyToOne @JoinColumn(name = "member_id") private Member member; @@ -43,10 +46,11 @@ public class Dashboard extends BaseEntity { @OneToMany(mappedBy = "dashboard", cascade = CascadeType.ALL, orphanRemoval = true) private List blocks = new ArrayList<>(); - public Dashboard(String title, String description, Member member) { + public Dashboard(String title, String description, String dType, Member member) { this.status = Status.ACTIVE; this.title = title; this.description = description; + this.dType = dType; this.member = member; } diff --git a/src/main/java/shop/kkeujeok/kkeujeokbackend/dashboard/personal/domain/PersonalDashboard.java b/src/main/java/shop/kkeujeok/kkeujeokbackend/dashboard/personal/domain/PersonalDashboard.java index 0222978e..a86fcf9b 100644 --- a/src/main/java/shop/kkeujeok/kkeujeokbackend/dashboard/personal/domain/PersonalDashboard.java +++ b/src/main/java/shop/kkeujeok/kkeujeokbackend/dashboard/personal/domain/PersonalDashboard.java @@ -19,8 +19,9 @@ public class PersonalDashboard extends Dashboard { private String category; @Builder - private PersonalDashboard(String title, String description, Member member, boolean isPublic, String category) { - super(title, description, member); + private PersonalDashboard(String title, String description, String dType, Member member, boolean isPublic, + String category) { + super(title, description, dType, member); this.category = category; this.isPublic = isPublic; } diff --git a/src/main/java/shop/kkeujeok/kkeujeokbackend/dashboard/team/domain/TeamDashboard.java b/src/main/java/shop/kkeujeok/kkeujeokbackend/dashboard/team/domain/TeamDashboard.java index 039c449e..d5d76249 100644 --- a/src/main/java/shop/kkeujeok/kkeujeokbackend/dashboard/team/domain/TeamDashboard.java +++ b/src/main/java/shop/kkeujeok/kkeujeokbackend/dashboard/team/domain/TeamDashboard.java @@ -27,8 +27,8 @@ public class TeamDashboard extends Dashboard { private List documents = new ArrayList<>(); @Builder - private TeamDashboard(String title, String description, Member member) { - super(title, description, member); + private TeamDashboard(String title, String description, String dType, Member member) { + super(title, description, dType, member); } public void update(String updateTitle, String updateDescription) { diff --git a/src/test/java/shop/kkeujeok/kkeujeokbackend/block/api/BlockControllerTest.java b/src/test/java/shop/kkeujeok/kkeujeokbackend/block/api/BlockControllerTest.java index 7b386e61..f15b02af 100644 --- a/src/test/java/shop/kkeujeok/kkeujeokbackend/block/api/BlockControllerTest.java +++ b/src/test/java/shop/kkeujeok/kkeujeokbackend/block/api/BlockControllerTest.java @@ -37,9 +37,11 @@ import org.springframework.data.domain.PageRequest; import org.springframework.http.MediaType; import org.springframework.restdocs.RestDocumentationContextProvider; +import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import shop.kkeujeok.kkeujeokbackend.auth.api.dto.request.TokenReqDto; import shop.kkeujeok.kkeujeokbackend.block.api.dto.request.BlockSaveReqDto; +import shop.kkeujeok.kkeujeokbackend.block.api.dto.request.BlockSequenceUpdateReqDto; import shop.kkeujeok.kkeujeokbackend.block.api.dto.request.BlockUpdateReqDto; import shop.kkeujeok.kkeujeokbackend.block.api.dto.response.BlockInfoResDto; import shop.kkeujeok.kkeujeokbackend.block.api.dto.response.BlockListResDto; @@ -61,6 +63,7 @@ class BlockControllerTest extends ControllerTest { private Block block; private BlockSaveReqDto blockSaveReqDto; private BlockUpdateReqDto blockUpdateReqDto; + private BlockSequenceUpdateReqDto blockSequenceUpdateReqDto; @InjectMocks BlockController blockController; @@ -80,6 +83,7 @@ void setUp(RestDocumentationContextProvider restDocumentation) { .member(member) .title("title") .description("description") + .dType("PersonalDashboard") .isPublic(false) .category("category") .build(); @@ -88,7 +92,15 @@ void setUp(RestDocumentationContextProvider restDocumentation) { "2024.08.03 13:23"); blockUpdateReqDto = new BlockUpdateReqDto("UpdateTitle", "UpdateContents", "2024.07.03 13:23", "2024.07.28 16:40"); - block = blockSaveReqDto.toEntity(member, dashboard); + block = blockSaveReqDto.toEntity(member, dashboard, 0); + + ReflectionTestUtils.setField(block, "id", 1L); + + blockSequenceUpdateReqDto = new BlockSequenceUpdateReqDto( + List.of(2L, 3L), + List.of(3L, 1L), + List.of(1L, 2L) + ); blockController = new BlockController(blockService); @@ -136,7 +148,9 @@ void setUp(RestDocumentationContextProvider restDocumentation) { fieldWithPath("data.title").description("블록 제목"), fieldWithPath("data.contents").description("블록 내용"), fieldWithPath("data.progress").description("블록 진행 상태"), - fieldWithPath("data.type").description("블록 타입"), + fieldWithPath("data.type").description( + "블록 타입(일반(General) 블록인지 챌린지(Challenge) 블록인지 구별)"), + fieldWithPath("data.dType").description("개인 대시보드, 팀 대시보드를 구별"), fieldWithPath("data.startDate").description("블록 시작 시간"), fieldWithPath("data.deadLine").description("블록 마감 시간"), fieldWithPath("data.nickname").description("회원 닉네임"), @@ -181,7 +195,9 @@ void setUp(RestDocumentationContextProvider restDocumentation) { fieldWithPath("data.title").description("블록 제목"), fieldWithPath("data.contents").description("블록 내용"), fieldWithPath("data.progress").description("블록 진행 상태"), - fieldWithPath("data.type").description("블록 타입"), + fieldWithPath("data.type").description( + "블록 타입(일반(General) 블록인지 챌린지(Challenge) 블록인지 구별)"), + fieldWithPath("data.dType").description("개인 대시보드, 팀 대시보드를 구별"), fieldWithPath("data.startDate").description("블록 시작 시간"), fieldWithPath("data.deadLine").description("블록 마감 시간"), fieldWithPath("data.nickname").description("회원 닉네임"), @@ -224,7 +240,9 @@ void setUp(RestDocumentationContextProvider restDocumentation) { fieldWithPath("data.contents").description("블록 내용"), fieldWithPath("data.startDate").description("블록 시작 시간"), fieldWithPath("data.deadLine").description("블록 마감 시간"), - fieldWithPath("data.type").description("블록 타입"), + fieldWithPath("data.type").description( + "블록 타입(일반(General) 블록인지 챌린지(Challenge) 블록인지 구별)"), + fieldWithPath("data.dType").description("개인 대시보드, 팀 대시보드를 구별"), fieldWithPath("data.progress").description("블록 진행 상태"), fieldWithPath("data.nickname").description("회원 닉네임"), fieldWithPath("data.dDay").description("마감 기한") @@ -317,7 +335,9 @@ void setUp(RestDocumentationContextProvider restDocumentation) { fieldWithPath("data.blockListResDto[].title").description("블록 제목"), fieldWithPath("data.blockListResDto[].contents").description("블록 내용"), fieldWithPath("data.blockListResDto[].progress").description("블록 진행 상태"), - fieldWithPath("data.blockListResDto[].type").description("블록 타입"), + fieldWithPath("data.blockListResDto[].type").description( + "블록 타입(일반(General) 블록인지 챌린지(Challenge) 블록인지 구별)"), + fieldWithPath("data.blockListResDto[].dType").description("개인 대시보드, 팀 대시보드를 구별"), fieldWithPath("data.blockListResDto[].startDate").description("블록 시작 시간"), fieldWithPath("data.blockListResDto[].deadLine").description("블록 마감 시간"), fieldWithPath("data.blockListResDto[].nickname").description("회원 닉네임"), @@ -356,7 +376,9 @@ void setUp(RestDocumentationContextProvider restDocumentation) { fieldWithPath("data.title").description("블록 제목"), fieldWithPath("data.contents").description("블록 내용"), fieldWithPath("data.progress").description("블록 진행 상태"), - fieldWithPath("data.type").description("블록 타입"), + fieldWithPath("data.type").description( + "블록 타입(일반(General) 블록인지 챌린지(Challenge) 블록인지 구별)"), + fieldWithPath("data.dType").description("개인 대시보드, 팀 대시보드를 구별"), fieldWithPath("data.startDate").description("블록 시작 시간"), fieldWithPath("data.deadLine").description("블록 마감 시간"), fieldWithPath("data.nickname").description("회원 닉네임"), @@ -366,4 +388,28 @@ void setUp(RestDocumentationContextProvider restDocumentation) { .andExpect(status().isOk()); } + @DisplayName("PATCH 블록의 순번을 변경합니다.") + @Test + void 블록_순번_변경() throws Exception { + // given + doNothing().when(blockService).changeBlocksSequence(anyString(), any()); + + // when & then + mockMvc.perform(patch("/api/blocks/change") + .header("Authorization", "Bearer token") // 필요에 따라 토큰 추가 + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(blockSequenceUpdateReqDto))) + .andDo(print()) + .andDo(document("block/change", + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint()), + requestFields( + fieldWithPath("notStartedList").description("시작 전 블록 아이디 리스트"), + fieldWithPath("inProgressList").description("진행 중 블록 아이디 리스트"), + fieldWithPath("completedList").description("완료 블록 아이디 리스트") + ) + )) + .andExpect(status().isOk()); + } + } \ No newline at end of file diff --git a/src/test/java/shop/kkeujeok/kkeujeokbackend/block/application/BlockServiceTest.java b/src/test/java/shop/kkeujeok/kkeujeokbackend/block/application/BlockServiceTest.java index 59b02082..91151283 100644 --- a/src/test/java/shop/kkeujeok/kkeujeokbackend/block/application/BlockServiceTest.java +++ b/src/test/java/shop/kkeujeok/kkeujeokbackend/block/application/BlockServiceTest.java @@ -7,8 +7,11 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.util.List; import java.util.Optional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -18,6 +21,7 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import shop.kkeujeok.kkeujeokbackend.block.api.dto.request.BlockSaveReqDto; +import shop.kkeujeok.kkeujeokbackend.block.api.dto.request.BlockSequenceUpdateReqDto; import shop.kkeujeok.kkeujeokbackend.block.api.dto.request.BlockUpdateReqDto; import shop.kkeujeok.kkeujeokbackend.block.api.dto.response.BlockInfoResDto; import shop.kkeujeok.kkeujeokbackend.block.domain.Block; @@ -53,6 +57,7 @@ class BlockServiceTest { private Dashboard dashboard; private BlockSaveReqDto blockSaveReqDto; private BlockUpdateReqDto blockUpdateReqDto; + private BlockSequenceUpdateReqDto blockSequenceUpdateReqDto; @BeforeEach void setUp() { @@ -79,6 +84,13 @@ void setUp() { "2024.07.25 13:23"); blockUpdateReqDto = new BlockUpdateReqDto("UpdateTitle", "UpdateContents", "2024.07.03 13:23", "2024.07.28 16:40"); + + blockSequenceUpdateReqDto = new BlockSequenceUpdateReqDto( + List.of(1L, 2L), + List.of(3L, 4L), + List.of(5L, 6L) + ); + block = Block.builder() .title(blockSaveReqDto.title()) .contents(blockSaveReqDto.contents()) @@ -241,4 +253,17 @@ void setUp() { }); } + @DisplayName("블록의 순번을 변경합니다.") + @Test + void 블록_순번_변경() { + // given + when(blockRepository.findById(anyLong())).thenReturn(Optional.of(block)); + + // when + blockService.changeBlocksSequence("email", blockSequenceUpdateReqDto); + + // then + verify(blockRepository, times(6)).findById(anyLong()); // 6번 블록 조회가 이루어졌는지 검증 + } + } \ No newline at end of file diff --git a/src/test/java/shop/kkeujeok/kkeujeokbackend/block/domain/BlockTest.java b/src/test/java/shop/kkeujeok/kkeujeokbackend/block/domain/BlockTest.java index ddd61791..a7977f27 100644 --- a/src/test/java/shop/kkeujeok/kkeujeokbackend/block/domain/BlockTest.java +++ b/src/test/java/shop/kkeujeok/kkeujeokbackend/block/domain/BlockTest.java @@ -29,6 +29,7 @@ void setUp() { .progress(Progress.NOT_STARTED) .startDate(startDate) .deadLine(deadLine) + .sequence(1) .build(); } @@ -135,4 +136,16 @@ void setUp() { assertThat(block.getStatus()).isEqualTo(Status.ACTIVE); } + @DisplayName("블록의 순번이 변경됩니다.") + @Test + void 블록_순번_변경() { + // given + + // when + block.sequenceUpdate(5); + + // then + assertThat(block.getSequence()).isEqualTo(5); + } + } \ No newline at end of file diff --git a/src/test/java/shop/kkeujeok/kkeujeokbackend/block/domain/repository/BlockRepositoryTest.java b/src/test/java/shop/kkeujeok/kkeujeokbackend/block/domain/repository/BlockRepositoryTest.java index df63dc06..f088bce0 100644 --- a/src/test/java/shop/kkeujeok/kkeujeokbackend/block/domain/repository/BlockRepositoryTest.java +++ b/src/test/java/shop/kkeujeok/kkeujeokbackend/block/domain/repository/BlockRepositoryTest.java @@ -70,6 +70,7 @@ void setUp() { .progress(Progress.NOT_STARTED) .deadLine("2024.07.27 11:03") .dashboard(dashboard) + .sequence(1) .build(); block2 = Block.builder() @@ -78,6 +79,7 @@ void setUp() { .progress(Progress.NOT_STARTED) .deadLine("2024.07.27 11:04") .dashboard(dashboard) + .sequence(2) .build(); block3 = Block.builder() @@ -86,6 +88,7 @@ void setUp() { .progress(Progress.IN_PROGRESS) .deadLine("2024.07.27 11:05") .dashboard(dashboard) + .sequence(3) .build(); memberRepository.save(member); @@ -124,4 +127,16 @@ void setUp() { assertThat(blocks.getContent().size()).isEqualTo(1); } + @DisplayName("블록의 마지막 순번을 가져옵니다.") + @Test + void 블록_마지막_순번() { + // given + + // when + int lastSequence = blockRepository.findLastSequenceByProgress(member, dashboard.getId(), Progress.NOT_STARTED); + + // then + assertThat(lastSequence).isEqualTo(2); + } + } \ No newline at end of file diff --git a/src/test/java/shop/kkeujeok/kkeujeokbackend/challenge/api/ChallengeControllerTest.java b/src/test/java/shop/kkeujeok/kkeujeokbackend/challenge/api/ChallengeControllerTest.java index 027e9c3e..0ad8ecef 100644 --- a/src/test/java/shop/kkeujeok/kkeujeokbackend/challenge/api/ChallengeControllerTest.java +++ b/src/test/java/shop/kkeujeok/kkeujeokbackend/challenge/api/ChallengeControllerTest.java @@ -419,6 +419,7 @@ void setUp(RestDocumentationContextProvider restDocumentation) { "1일 1커밋하기", Progress.NOT_STARTED, Type.CHALLENGE, + "PersonalDashboard", "2024.09.31 23:59", "2024.09.31 23:59", "동동", @@ -447,7 +448,9 @@ void setUp(RestDocumentationContextProvider restDocumentation) { fieldWithPath("data.title").description("블록 제목"), fieldWithPath("data.contents").description("블록 내용"), fieldWithPath("data.progress").description("블록 진행도"), - fieldWithPath("data.type").description("블록 타입"), + fieldWithPath("data.type").description( + "블록 타입(일반(General) 블록인지 챌린지(Challenge) 블록인지 구별)"), + fieldWithPath("data.dType").description("개인 대시보드, 팀 대시보드를 구별"), fieldWithPath("data.startDate").description("블록 시작기한"), fieldWithPath("data.deadLine").description("블록 마감기한"), fieldWithPath("data.nickname").description("블록 작성자"), diff --git a/src/test/java/shop/kkeujeok/kkeujeokbackend/dashboard/personal/api/PersonalDashboardControllerTest.java b/src/test/java/shop/kkeujeok/kkeujeokbackend/dashboard/personal/api/PersonalDashboardControllerTest.java index b2ab5d0a..3214beaf 100644 --- a/src/test/java/shop/kkeujeok/kkeujeokbackend/dashboard/personal/api/PersonalDashboardControllerTest.java +++ b/src/test/java/shop/kkeujeok/kkeujeokbackend/dashboard/personal/api/PersonalDashboardControllerTest.java @@ -36,6 +36,7 @@ import org.springframework.data.domain.PageRequest; import org.springframework.http.MediaType; import org.springframework.restdocs.RestDocumentationContextProvider; +import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import shop.kkeujeok.kkeujeokbackend.auth.api.dto.request.TokenReqDto; import shop.kkeujeok.kkeujeokbackend.common.annotation.ControllerTest; @@ -77,6 +78,10 @@ void setUp(RestDocumentationContextProvider restDocumentation) { "updateCategory"); personalDashboard = personalDashboardSaveReqDto.toEntity(member); + ReflectionTestUtils.setField(personalDashboard, "id", 1L); + ReflectionTestUtils.setField(member, "id", 1L); + ReflectionTestUtils.setField(personalDashboard, "member", member); + personalDashboardController = new PersonalDashboardController(personalDashboardService); mockMvc = MockMvcBuilders.standaloneSetup(personalDashboardController) diff --git a/src/test/java/shop/kkeujeok/kkeujeokbackend/dashboard/team/api/TeamDashboardControllerTest.java b/src/test/java/shop/kkeujeok/kkeujeokbackend/dashboard/team/api/TeamDashboardControllerTest.java index 6ce17466..0c25777e 100644 --- a/src/test/java/shop/kkeujeok/kkeujeokbackend/dashboard/team/api/TeamDashboardControllerTest.java +++ b/src/test/java/shop/kkeujeok/kkeujeokbackend/dashboard/team/api/TeamDashboardControllerTest.java @@ -37,6 +37,7 @@ import org.springframework.data.domain.PageRequest; import org.springframework.http.MediaType; import org.springframework.restdocs.RestDocumentationContextProvider; +import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import shop.kkeujeok.kkeujeokbackend.auth.api.dto.request.TokenReqDto; import shop.kkeujeok.kkeujeokbackend.common.annotation.ControllerTest; @@ -87,6 +88,10 @@ void setUp(RestDocumentationContextProvider restDocumentation) { teamDashboardUpdateReqDto = new TeamDashboardUpdateReqDto("updateTitle", "updateDescription"); teamDashboard = teamDashboardSaveReqDto.toEntity(member); + ReflectionTestUtils.setField(teamDashboard, "id", 1L); + ReflectionTestUtils.setField(member, "id", 1L); + ReflectionTestUtils.setField(teamDashboard, "member", member); + teamDashboardController = new TeamDashboardController(teamDashboardService); mockMvc = MockMvcBuilders.standaloneSetup(teamDashboardController)