Skip to content

Commit

Permalink
[FIX] 커뮤니티 API 관련 수정 (#15)
Browse files Browse the repository at this point in the history
* [FIX] 커뮤니티 API 관련 수정

* [FIX] 커뮤니티 API 관련 수정
  • Loading branch information
sangminee authored Feb 22, 2024
1 parent 70b737f commit 5446ecb
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.oya.kr.community.controller.dto.response.CommunityResponse;
import com.oya.kr.community.controller.dto.response.StatisticsResponse;
import com.oya.kr.community.service.CommunityService;
import com.oya.kr.global.dto.Pagination;
import com.oya.kr.global.dto.request.PaginationRequest;
import com.oya.kr.global.dto.response.ApplicationResponse;

import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -89,7 +89,7 @@ public ResponseEntity<ApplicationResponse<String>> delete(Principal principal, @
*/
@GetMapping
public ResponseEntity<ApplicationResponse<CommunityResponse>> reads(Principal principal,
@RequestParam("type") String type, Pagination pagination) {
@RequestParam("type") String type, PaginationRequest pagination) {
return ResponseEntity.ok(ApplicationResponse.success(communityService.reads(type, principal.getName(), pagination)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public interface CommunityMapper {
void saveVote(SaveVoteMapperRequest saveVoteMapperRequest);
Optional<CommunityBasicMapperResponse> findById(long communityId);
List<CommunityBasicMapperResponse> findByAll(ReadCommunityMapperRequest readCommunityMapperRequest);
List<CommunityBasicMapperResponse> findByType(ReadCommunityMapperRequest readCommunityMapperRequest);
void delete(long communityId);
void deleteByUserId(Long userId);
void saveImage(@Param("imageUrl") String imageUrl, @Param("communityId") long communityId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public CommunityBasicMapperResponse findById(Long id) {
* @since 2024.02.18
*/
public CommunityBasicMapperResponse findByIdWithView(Long id, Long userId) {
communityViewMapper.createOrUpdateCommunityView(id, userId); // 조회수 증가
CommunityBasicMapperResponse response = communityMapper.findById(id)
.orElseThrow(() -> new ApplicationException(CommunityErrorCodeList.NOT_EXIST_COMMUNITY));
communityViewMapper.createOrUpdateCommunityView(id, userId); // 조회수 증가
if (response.isDeleted()) {
throw new ApplicationException(CommunityErrorCodeList.DELETED_COMMUNITY);
}
Expand All @@ -87,8 +87,20 @@ public List<String> findImageById(Long id) {
* @author 김유빈
* @since 2024.02.21
*/
public List<CommunityBasicMapperResponse> findAll(String communityType, int pageNo, int amount) {
return communityMapper.findByAll(new ReadCommunityMapperRequest(false, communityType, pageNo, amount));
public List<CommunityBasicMapperResponse> findAll(String userType, int pageNo, int amount) {
return communityMapper.findByAll(new ReadCommunityMapperRequest(false, userType, pageNo, amount));
}

/**
* 게시글 type 에 따른 호출
*
* @parameter Long, int, int
* @return List<CommunityBasicMapperResponse>
* @author 이상민
* @since 2024.02.22
*/
public List<CommunityBasicMapperResponse> findByType(String userType, int pageNo, int amount) {
return communityMapper.findByType(new ReadCommunityMapperRequest(false, userType, pageNo, amount));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
import com.oya.kr.community.mapper.dto.response.StatisticsResponseMapper;
import com.oya.kr.community.repository.CommunityRepository;
import com.oya.kr.community.repository.VoteRepository;
import com.oya.kr.global.dto.Pagination;
import com.oya.kr.global.dto.request.PaginationRequest;
import com.oya.kr.global.exception.ApplicationException;
import com.oya.kr.global.support.StorageConnector;
import com.oya.kr.popup.domain.enums.Category;
import com.oya.kr.user.domain.User;
import com.oya.kr.user.domain.enums.UserType;
import com.oya.kr.user.repository.UserRepository;

import lombok.AccessLevel;
Expand Down Expand Up @@ -139,16 +140,16 @@ public String delete(String email, long communityId) {
* @since 2024.02.18
*/
@Transactional(readOnly = true)
public CommunityResponse reads(String type,String email, Pagination pagination) {
public CommunityResponse reads(String type,String email, PaginationRequest pagination) {
User loginUser = userRepository.findByEmail(email);
List<CommunityBasicMapperResponse> responseList;
if(type.equals("all")){
responseList = communityRepository.findAll(null, pagination.getPageNo(), pagination.getAmount());
}else if(type.equals("collections")){
responseList = communityRepository.findAllCollections(loginUser.getId(), pagination.getPageNo(), pagination.getAmount());
}else{
String communityType = CommunityType.from(type).getName();
responseList = communityRepository.findAll(communityType, pagination.getPageNo(), pagination.getAmount());
String userType = UserType.from(type).getName();
responseList = communityRepository.findByType(userType, pagination.getPageNo(), pagination.getAmount());
}
return mapToCommunityResponses(loginUser, responseList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class VoteService {
*/
public String check(String email, long votedId) {
User loginUser = userRepository.findByEmail(email);
voteRepository.save(loginUser.getId(), votedId);
voteRepository.save(votedId, loginUser.getId());
return "투표를 체크했습니다.";
}

Expand Down
14 changes: 0 additions & 14 deletions src/main/java/com/oya/kr/global/dto/Pagination.java

This file was deleted.

7 changes: 7 additions & 0 deletions src/main/java/com/oya/kr/user/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ private String getAccessToken() {
return authentication.getCredentials().toString();
}

/**
* 로그아웃 (리프레시 토큰의 기간 만료 처리, 삭제)
*
* @header principal
* @author 이상민
* @since 2024.02.13
*/
@GetMapping("/mypage")
public void me(Principal principal) {
logger.info(principal.getName());
Expand Down
18 changes: 18 additions & 0 deletions src/main/resources/com/oya/kr/community/mapper/CommunityMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@
<include refid="offsetForPaging" />
</select>

<select id="findByType" parameterType="readCommunityMapperRequest" resultType="communityBasicMapperResponse">
<include refid="selecCommunity" />
<![CDATA[
FROM
COMMUNITY c
LEFT JOIN USERS u on c.WRITE_ID = u.ID
LEFT JOIN COMMUNITY_VIEW cv ON c.ID = cv.COMMUNITY_ID
WHERE
c.DELETED = #{deleted}
AND u.USER_TYPE = #{userType}
AND cv.DELETED = #{deleted}
GROUP BY
c.ID, TITLE, DESCRIPTION, COMMUNITY_TYPE, WRITE_ID, CATEGORY_CODE, c.CREATED_DATE, c.MODIFIED_DATE, c.DELETED
ORDER BY c.MODIFIED_DATE DESC
]]>
<include refid="offsetForPaging" />
</select>

<update id="delete">
UPDATE COMMUNITY
SET DELETED = '1'
Expand Down

0 comments on commit 5446ecb

Please sign in to comment.