Skip to content

Commit

Permalink
Merge pull request #269 from Mile-Writings/feat/#257
Browse files Browse the repository at this point in the history
#257 [feat] 관리자페이지 글감 LIST 조회
  • Loading branch information
parkheeddong authored Apr 3, 2024
2 parents 6057a75 + fcfb0f9 commit 2ef5934
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.mile.moim.service.dto.MoimCuriousPostListResponse;
import com.mile.moim.service.dto.MoimInfoOwnerResponse;
import com.mile.moim.service.dto.MoimInfoResponse;
import com.mile.moim.service.dto.MoimTopicInfoListResponse;
import com.mile.moim.service.dto.MoimNameConflictCheckResponse;
import com.mile.moim.service.dto.MoimInvitationInfoResponse;
import com.mile.moim.service.dto.MoimInfoModifyRequest;
Expand Down Expand Up @@ -174,6 +175,15 @@ public SuccessResponse<TemporaryPostExistResponse> getTemporaryPost(
return SuccessResponse.of(SuccessMessage.IS_TEMPORARY_POST_EXIST_GET_SUCCESS, moimService.getTemporaryPost(moimId, principalHandler.getUserIdFromPrincipal()));
}

@Override
@GetMapping("/{moimId}/admin/topicList")
public ResponseEntity<SuccessResponse<MoimTopicInfoListResponse>> getMoimTopicList(
@MoimIdPathVariable final Long moimId,
@RequestParam final int page,
@PathVariable("moimId") final String moimUrl
) {
return ResponseEntity.ok(SuccessResponse.of(SuccessMessage.MOIM_TOPIC_LIST_GET_SUCCESS, moimService.getMoimTopicList(moimId, principalHandler.getUserIdFromPrincipal(), page)));
}

@Override
@PutMapping("/{moimId}/info")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.mile.moim.service.dto.MoimCuriousPostListResponse;
import com.mile.moim.service.dto.MoimInfoOwnerResponse;
import com.mile.moim.service.dto.MoimInfoResponse;
import com.mile.moim.service.dto.MoimTopicInfoListResponse;
import com.mile.moim.service.dto.MoimNameConflictCheckResponse;
import com.mile.moim.service.dto.MoimInvitationInfoResponse;
import com.mile.moim.service.dto.MoimNameConflictCheckResponse;
import com.mile.moim.service.dto.MoimInfoModifyRequest;
Expand Down Expand Up @@ -214,6 +216,21 @@ ResponseEntity<SuccessResponse> joinMoim(
@PathVariable("moimId") final String moimUrl
);

@Operation(summary = "관리자 페이지 글감 조회")
@ApiResponses(
value = {
@ApiResponse(responseCode = "200", description = "글감 리스트 조회가 완료되었습니다."),
@ApiResponse(responseCode = "404", description = "해당 모임은 존재하지 않습니다."),
@ApiResponse(responseCode = "403", description = "사용자는 해당 모임의 모임장이 아닙니다."),
@ApiResponse(responseCode = "500", description = "서버 내부 오류입니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
}
)
ResponseEntity<SuccessResponse<MoimTopicInfoListResponse>> getMoimTopicList(
@Parameter(schema = @Schema(implementation = String.class), in = ParameterIn.PATH) final Long moimId,
final int page,
@PathVariable("moimId") final String moimUrl
);


@Operation(summary = "관리자 페이지 모임 정보 수정")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public enum ErrorMessage {
Forbidden
*/
COMMENT_ACCESS_ERROR(HttpStatus.FORBIDDEN.value(), "해당 사용자는 댓글에 접근 권한이 없습니다."),
OWNER_AUTHENTICATE_ERROR(HttpStatus.FORBIDDEN.value(), "사용자는 해당 모임의 모임장이 아닙니다."),
/*
Method Not Supported
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public enum SuccessMessage {
IS_TEMPORARY_POST_EXIST_GET_SUCCESS(HttpStatus.OK.value(), "임시저장 글 존재 여부 조회가 완료되었습니다."),
MOIM_INVITE_INFO_GET_SUCCESS(HttpStatus.OK.value(), "모임의 초대 정보 조회가 완료되었습니다."),
IS_CONFLICT_WRITER_NAME_GET_SUCCESS(HttpStatus.OK.value(), "댓글 중복 여부가 조회되었습니다."),
MOIM_TOPIC_LIST_GET_SUCCESS(HttpStatus.OK.value(), "글감 리스트 조회가 완료되었습니다."),
TOPIC_PUT_SUCCESS(HttpStatus.OK.value(), "글감 수정이 완료되었습니다."),
TOPIC_DETAIL_GET_SUCCESS(HttpStatus.OK.value(), "글감 상세 정보 조회가 완료되었습니다."),
MOIM_INFORMATION_PUT_SUCCESS(HttpStatus.OK.value(), "모임 정보 수정이 완료되었습니다."),
Expand Down
23 changes: 23 additions & 0 deletions module-domain/src/main/java/com/mile/moim/service/MoimService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.mile.moim.service.dto.MoimInfoModifyRequest;
import com.mile.moim.service.dto.MoimInfoOwnerResponse;
import com.mile.moim.service.dto.MoimInfoResponse;
import com.mile.moim.service.dto.MoimTopicInfoListResponse;
import com.mile.moim.service.dto.MoimNameConflictCheckResponse;
import com.mile.moim.service.dto.MoimInvitationInfoResponse;
import com.mile.moim.service.dto.MoimTopicResponse;
Expand All @@ -34,6 +35,8 @@
import com.mile.utils.SecureUrlUtil;
import com.mile.writername.domain.WriterName;
import com.mile.writername.service.WriterNameService;
import com.mile.moim.service.dto.PopularWriterListResponse;
import java.util.stream.Collectors;
import com.mile.writername.service.dto.WriterNameInfoResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -178,6 +181,26 @@ public TemporaryPostExistResponse getTemporaryPost(
return TemporaryPostExistResponse.of(!secureUrlUtil.decodeUrl(postId).equals(0L), postId);
}

public MoimTopicInfoListResponse getMoimTopicList(
final Long moimId,
final Long userId,
final int page
) {
getAuthenticateOwnerOfMoim(moimId, userId);
return topicService.getTopicListFromMoim(moimId, page);
}

private void getAuthenticateOwnerOfMoim(
final Long moimId,
final Long userId
) {
Long writerNameId = writerNameService.getWriterNameIdByMoimIdAndUserId(moimId, userId);
Moim moim = findById(moimId);
if (!moim.getOwner().getId().equals(writerNameId)) {
throw new ForbiddenException(ErrorMessage.OWNER_AUTHENTICATE_ERROR);
}
}

@Transactional
public void modifyMoimInforation(
final Long moimId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.mile.moim.service.dto;

import java.util.List;

public record MoimTopicInfoListResponse(
int pageNumber,
Long topicCount,
List<MoimTopicInfoResponse> topics
) {
public static MoimTopicInfoListResponse of (
final int pageNumber,
final Long topicCount,
final List<MoimTopicInfoResponse> moimTopicInfoResponses
) {
return new MoimTopicInfoListResponse(
pageNumber,
topicCount,
moimTopicInfoResponses
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mile.moim.service.dto;

import com.mile.topic.domain.Topic;
import com.mile.utils.DateUtil;

public record MoimTopicInfoResponse(
String topicId,
String topicName,
String topicTag,
String topicDescription,
String createdAt
) {
public static MoimTopicInfoResponse of(
final Topic topic
) {
return new MoimTopicInfoResponse(
topic.getIdUrl(),
topic.getContent(),
topic.getKeyword(),
topic.getDescription(),
DateUtil.getStringDateOfLocalDate(topic.getCreatedAt())
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mile.topic.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import com.mile.topic.domain.Topic;
import org.springframework.data.jpa.repository.JpaRepository;

Expand All @@ -8,4 +9,6 @@
public interface TopicRepository extends JpaRepository<Topic, Long>, TopicRepositoryCustom {

List<Topic> findByMoimId(final Long moimId);
Page<Topic> findByMoimIdOrderByCreatedAtDesc(Long moimId, Pageable pageable);
Long countByMoimId(final Long moimId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.mile.exception.model.ForbiddenException;
import com.mile.exception.model.NotFoundException;
import com.mile.moim.domain.Moim;
import com.mile.moim.service.dto.MoimTopicInfoListResponse;
import com.mile.moim.service.dto.MoimTopicInfoResponse;
import com.mile.moim.service.dto.TopicCreateRequest;
import com.mile.post.service.PostGetService;
import com.mile.post.service.dto.PostListResponse;
Expand All @@ -23,6 +25,9 @@
import com.mile.utils.SecureUrlUtil;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
import org.springframework.stereotype.Service;

Expand All @@ -34,6 +39,8 @@
@RequiredArgsConstructor
public class TopicService {

private static final int TOPIC_PER_PAGE_SIZE = 4;

private final TopicRepository topicRepository;
private final CommentService commentService;
private final UserService userService;
Expand Down Expand Up @@ -141,6 +148,38 @@ public PostListInTopicResponse getPostListByTopic(
postGetService.findByTopic(topic).stream().map(p -> PostListResponse.of(p, commentService.findCommentCountByPost(p))).collect(Collectors.toList()));
}

public MoimTopicInfoListResponse getTopicListFromMoim(
final Long moimId,
final int page
) {

PageRequest pageRequest = PageRequest.of(page-1, TOPIC_PER_PAGE_SIZE, Sort.by(Sort.Direction.DESC, "createdAt"));
Page<Topic> topicPage = topicRepository.findByMoimIdOrderByCreatedAtDesc(moimId, pageRequest);

isContentsEmpty(topicPage.getContent());

return getTopicResponsesFromPage(topicPage, moimId);
}

public MoimTopicInfoListResponse getTopicResponsesFromPage(Page<Topic> topicPage, final Long moimId) {
List<MoimTopicInfoResponse> infoResponses = topicPage.getContent()
.stream()
.map(MoimTopicInfoResponse::of)
.collect(Collectors.toList());

return MoimTopicInfoListResponse.of(
topicPage.getTotalPages(),
getNumberOfTopicFromMoim(moimId),
infoResponses
);
}

public Long getNumberOfTopicFromMoim(
final Long moimId
) {
return topicRepository.countByMoimId(moimId);
}

public TopicDetailResponse getTopicDetail(
final Long userId,
final Long topicId
Expand Down

0 comments on commit 2ef5934

Please sign in to comment.