Skip to content

Commit

Permalink
Merge pull request #220 from dionisos198/Refactor/#219-bug-refactor
Browse files Browse the repository at this point in the history
Refactor/#219 bug refactor
  • Loading branch information
dionisos198 authored Nov 30, 2024
2 parents 4227bab + 5d3185d commit d73a726
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package com.gaduationproject.cre8.app.community.controller;
package com.gaduationproject.cre8.adminapp.communityBoard.controller;

import com.gaduationproject.cre8.app.auth.interfaces.CurrentMemberLoginId;
import com.gaduationproject.cre8.app.community.dto.request.CommunityBoardSaveRequestDto;
import com.gaduationproject.cre8.app.community.dto.response.CommunityBoardResponseDto;
import com.gaduationproject.cre8.app.community.service.CommunityBoardService;
import com.gaduationproject.cre8.adminapp.communityBoard.dto.CommunityBoardResponseDto;
import com.gaduationproject.cre8.adminapp.communityBoard.service.CommunityBoardService;
import com.gaduationproject.cre8.app.response.BaseResponse;
import com.gaduationproject.cre8.domain.community.entity.CommunityBoard;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.gaduationproject.cre8.app.community.dto.response;
package com.gaduationproject.cre8.adminapp.communityBoard.dto;

import com.gaduationproject.cre8.domain.community.entity.CommunityBoard;
import lombok.AccessLevel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.gaduationproject.cre8.app.community.service;
package com.gaduationproject.cre8.adminapp.communityBoard.service;

import com.gaduationproject.cre8.app.community.dto.request.CommunityBoardSaveRequestDto;
import com.gaduationproject.cre8.app.community.dto.response.CommunityBoardResponseDto;
import com.gaduationproject.cre8.adminapp.communityBoard.dto.CommunityBoardResponseDto;
import com.gaduationproject.cre8.common.response.error.ErrorCode;
import com.gaduationproject.cre8.common.response.error.exception.NotFoundException;
import com.gaduationproject.cre8.domain.community.entity.CommunityBoard;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,14 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
"/api/v1/*/profile","/api/v1/members/pk","/api/v1/portfolios/*","/api/v1/portfolios/member/*","/api/v1/tags",
"/api/v1/tags/subcategory/*","/api/v1/tags/child/*","/api/v1/employer-posts/search","/api/v1/employee-posts/search",
"/api/v1/employer-posts/search/keyword","/api/v1/employee-posts/search/keyword","/api/v1/employee-posts/search/test","/api/v1/employer-posts/search/test",
"/api/v1/community/boards","/api/v1/community/posts/search/*","/api/v1/community/posts/*","/api/v1/community/posts/search/*/2").permitAll()
"/api/v1/community/boards","/api/v1/community/posts/search/*","/api/v1/community/posts/*","/api/v1/community/posts/search/my-post").permitAll()
.requestMatchers(HttpMethod.POST,"/api/v1/test","/api/v1/redis/test","/api/v1/auth/login","/api/v1/mail",
"/api/v1/mail/check","/api/v1/members","/api/v1/mail/temp/password").permitAll()
.requestMatchers("/ws-stomp").permitAll()
.requestMatchers(HttpMethod.POST,"/api/v1/community/boards","/api/v1/tags","/api/v1/tags/category","/api/v1/tags/categories",
"/api/v1/tags/child","/api/v1/tags/childs").hasAuthority(Authority.MANAGER.toString())
.requestMatchers(HttpMethod.DELETE,"/api/v1/community/boards/*","/api/v1/tags/*","/api/v1/tags/category/*","/api/v1/tags/child/*")
.hasAuthority(Authority.MANAGER.toString())
.anyRequest().authenticated())


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,44 +53,46 @@ public ResponseEntity<BaseResponse<CommunityPostSearchWithSliceResponseDto>> com
.createSuccess(communityPostSearchService.searchCommunityPostByCommunityBoardIdAndLastPostId(communityBoardId,lastPostId,pageable)));
}

@GetMapping("/{communityBoardId}/2")
@Operation(summary = "커뮤니티 게시글 리스트",description = "커뮤니티 게시글을 커뮤니티 게시판 최신순으로 조회할 수 있습니다. ")


@GetMapping("/like/my-Post")
@Operation(summary = "내가 좋아요한 커뮤니티 게시글 조회",description = "내가 좋아요한 커뮤니티 게시글을 조회합니다")
@ApiResponses(value = {
@ApiResponse(responseCode = "200",description = "커뮤니티 게시글 리스트 조회 성공2")
@ApiResponse(responseCode = "200",description = "내가 좋아요한 커뮤니티 게시글 성공적 조회"),
})
@Parameters({
@Parameter(name = "page", description = "페이지 번호(0부터 시작)", in = ParameterIn.QUERY),
@Parameter(name = "direction", description = "내림차순과 오름차순(desc,asc)", in = ParameterIn.QUERY),
@Parameter(name = "sort", description = "정렬기준(createdAt)", in = ParameterIn.QUERY),
@Parameter(name = "size", description = "페이지당 아이템 갯수", in = ParameterIn.QUERY)
}
)
public ResponseEntity<BaseResponse<CommunityPostSearchWithSliceResponseDto>> communityPostSearchResponse2(
@PathVariable("communityBoardId") final Long communityBoardId,
@PageableDefault(size = 10,sort = "createdAt",direction = Direction.DESC,page = 0) final Pageable pageable) {
})
public ResponseEntity<BaseResponse<CommunityPostSearchWithSliceResponseDto>> showMyLikeCommunityPost
(@CurrentMemberLoginId final String loginId,
@PageableDefault(size = 10,sort = "createdAt",direction = Direction.DESC,page = 0) final Pageable pageable
){

return ResponseEntity.ok(BaseResponse
.createSuccess(communityPostSearchService.searchCommunityPostByCommunityBoardId(communityBoardId,pageable)));

return ResponseEntity.ok(BaseResponse.createSuccess(communityPostSearchService.searchMyLikeCommunityPost(loginId,pageable)));
}

@GetMapping("/like/my-Post")
@Operation(summary = "내가 좋아요한 커뮤니티 게시글 조회",description = "내가 좋아요한 커뮤니티 게시글을 조회합니다")
@GetMapping("/my-Post")
@Operation(summary = "내가 작성한 커뮤니티 게시글 조회",description = "내가 작성한 커뮤니티 게시글을 조회합니다")
@ApiResponses(value = {
@ApiResponse(responseCode = "200",description = "내가 좋아요한 커뮤니티 게시글 성공적 조회"),
@ApiResponse(responseCode = "200",description = "내가 작성한 커뮤니티 게시글 성공적 조회"),
})
@Parameters({
@Parameter(name = "page", description = "페이지 번호(0부터 시작)", in = ParameterIn.QUERY),
@Parameter(name = "direction", description = "내림차순과 오름차순(desc,asc)", in = ParameterIn.QUERY),
@Parameter(name = "sort", description = "정렬기준(createdAt)", in = ParameterIn.QUERY),
@Parameter(name = "size", description = "페이지당 아이템 갯수", in = ParameterIn.QUERY)
})
public ResponseEntity<BaseResponse<CommunityPostSearchWithSliceResponseDto>> showMyLikeCommunityPost
public ResponseEntity<BaseResponse<CommunityPostSearchWithSliceResponseDto>> showMyCommunityPost
(@CurrentMemberLoginId final String loginId,
@PageableDefault(size = 10,sort = "createdAt",direction = Direction.DESC,page = 0) final Pageable pageable
){


return ResponseEntity.ok(BaseResponse.createSuccess(communityPostSearchService.searchMyLikeCommunityPost(loginId,pageable)));
return ResponseEntity.ok(BaseResponse.createSuccess(communityPostSearchService.searchMyCommunityPost(loginId,pageable)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,6 @@ public class CommunityPostSearchService {
private final LikeCommunityPostRepository likeCommunityPostRepository;


public CommunityPostSearchWithSliceResponseDto searchCommunityPostByCommunityBoardId(final Long communityBoardId,
final Pageable pageable){

Slice<CommunityPostSearchDBResponseDto> communityPosts =
communityPostRepository.findCommunityPostKeyWordSearchDBByCommunityBoardId(communityBoardId,pageable);


List<CommunityPostSearchResponseDto> communityPostSearchResponseDtoList =
communityPosts.stream().map(communityPostSearchDBResponseDto -> {
return CommunityPostSearchResponseDto.of(communityPostSearchDBResponseDto.getCommunityPostId(),
communityPostSearchDBResponseDto.getTitle(),
replyRepository.totalReplyCount(communityPostSearchDBResponseDto.getCommunityPostId()),
communityPostSearchDBResponseDto.getWriterNickName(),
communityPostSearchDBResponseDto.getCreatedAt());
}).collect(Collectors.toList());

return CommunityPostSearchWithSliceResponseDto.of(communityPostSearchResponseDtoList,communityPosts.hasNext());

}

public CommunityPostSearchWithSliceResponseDto searchCommunityPostByCommunityBoardIdAndLastPostId(final Long communityBoardId,
final Long lastPostId, final Pageable pageable){

Expand Down Expand Up @@ -97,6 +77,23 @@ public CommunityPostSearchWithSliceResponseDto searchMyLikeCommunityPost(final S

}

public CommunityPostSearchWithSliceResponseDto searchMyCommunityPost(final String loginId, final Pageable pageable){

Member member = getLoginMember(loginId);

Slice<CommunityPostSearchDBResponseDto> myCommunityPost = communityPostRepository.findMyCommunityPost(
member.getId(), pageable);

return CommunityPostSearchWithSliceResponseDto.of(myCommunityPost.getContent().stream().map(communityPostSearchDBResponseDto -> {

return CommunityPostSearchResponseDto.of(communityPostSearchDBResponseDto.getCommunityPostId(),
communityPostSearchDBResponseDto.getTitle(),
replyRepository.totalReplyCount(communityPostSearchDBResponseDto.getCommunityPostId()),
communityPostSearchDBResponseDto.getWriterNickName(),
communityPostSearchDBResponseDto.getCreatedAt());
}).toList(),myCommunityPost.hasNext());
}

private Member getLoginMember(final String loginId){

return memberRepository.findMemberByLoginId(loginId).orElseThrow(()->new NotFoundException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ Slice<CommunityPostSearchDBResponseDto> findCommunityPostKeyWordSearchDBByCommun
List<CommunityPost> findByWriter(final Member member);


@Query("select new com.gaduationproject.cre8.domain.community.dto.CommunityPostSearchDBResponseDto(cp.id,cp.title,m.nickName,cp.createdAt)"
+ "from CommunityPost cp join cp.writer m where cp.writer.id=:memberId")
Slice<CommunityPostSearchDBResponseDto> findMyCommunityPost(@Param("memberId") final Long memberId,
final Pageable pageable);


}

0 comments on commit d73a726

Please sign in to comment.