Skip to content

Commit

Permalink
feat: #25 나의 게시글 목록 가져오기 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
bngsh committed Oct 5, 2023
1 parent beb1bb2 commit fde4535
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.whyranoid.walkie.controller;

import com.whyranoid.walkie.dto.PostDto;
import com.whyranoid.walkie.dto.request.MyInfoRequest;
import com.whyranoid.walkie.dto.request.WalkieSignUpRequest;
import com.whyranoid.walkie.dto.response.MyInfoResponse;
Expand All @@ -8,6 +9,7 @@
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.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand All @@ -21,6 +23,8 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "WalkieController")
@RequiredArgsConstructor
@RequestMapping("/api/walkies")
Expand Down Expand Up @@ -73,4 +77,17 @@ public ResponseEntity<MyInfoResponse> changeMyInfo(@RequestParam Long walkieId,
walkieService.changeMyInfo(walkieId, myInfoRequest)
);
}

@Operation(summary = "나의 게시글 불러오기", description = "내가 작성한 게시글들을 가져옵니다.")
@ApiResponse(responseCode = "200", content = @Content(array = @ArraySchema(schema = @Schema(implementation = PostDto.class))),
description = "내가 작성한 게시글 정보 리스트를 반환")
@Parameters({
@Parameter(name = "walkieId", required = true, description = "유저 아이디", example = "123"),
@Parameter(name = "pagingSize", description = "페이징 사이즈", example = "30"),
@Parameter(name = "pagingStart", description = "페이징 오프셋", example = "0")
})
@GetMapping("/listup-my-post")
public ResponseEntity<List<PostDto>> getPostList(@RequestParam Long walkieId, @RequestParam(required = false) Integer pagingSize, @RequestParam(required = false) Integer pagingStart) {
return ResponseEntity.ok(walkieService.getMyPostList(walkieId, pagingSize, pagingStart));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
public interface PostRepositoryCustom {

List<PostDto> findCurrentPosts(JPQLQuery<Long> following, Long viewerId, Integer pagingSize, Integer pagingStart);

List<PostDto> findMyPosts(Long viewerId, Integer pagingSize, Integer pagingStart);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,18 @@ public List<PostDto> findCurrentPosts(JPQLQuery<Long> following, Long viewerId,
.limit(pagingSize)
.fetch();
}

// TODO: 나의 좋아요 여부 반영
// TODO: 좋아요 누른 사람 목록 반영
@Override
public List<PostDto> findMyPosts(Long viewerId, Integer pagingSize, Integer pagingStart) {
return queryFactory
.select(new QPostDto(post, Expressions.asNumber(viewerId)))
.from(post)
.where(post.user.userId.eq(viewerId))
.orderBy(post.date.desc())
.offset(pagingStart)
.limit(pagingSize)
.fetch();
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/whyranoid/walkie/service/WalkieService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@

import com.whyranoid.walkie.domain.Agreement;
import com.whyranoid.walkie.domain.Walkie;
import com.whyranoid.walkie.dto.PostDto;
import com.whyranoid.walkie.dto.request.MyInfoRequest;
import com.whyranoid.walkie.dto.request.WalkieSignUpRequest;
import com.whyranoid.walkie.dto.response.MyInfoResponse;
import com.whyranoid.walkie.dto.response.WalkieSignUpResponse;
import com.whyranoid.walkie.repository.AgreementRepository;
import com.whyranoid.walkie.repository.PostRepository;
import com.whyranoid.walkie.repository.WalkieRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityNotFoundException;
import java.util.List;

@Service
@Transactional
@RequiredArgsConstructor
public class WalkieService {

private final WalkieRepository walkieRepository;
private final AgreementRepository agreementRepository;
private final PostRepository postRepository;

public WalkieSignUpResponse joinWalkie(WalkieSignUpRequest walkieSignUpRequest) {
if (checkNameDuplication(walkieSignUpRequest.getUserName())) {
Expand Down Expand Up @@ -77,4 +83,13 @@ public MyInfoResponse changeMyInfo(Long walkieId, MyInfoRequest myInfoRequest) {
.nickname(walkie.getUserName())
.build();
}

public List<PostDto> getMyPostList(Long walkieId, Integer _pagingSize, Integer _pagingStart) {
Walkie walkie = walkieRepository.findById(walkieId).orElseThrow(EntityNotFoundException::new);

Integer pagingSize = _pagingSize == null ? 30 : _pagingSize;
Integer pagingStart = _pagingStart == null ? 0 : _pagingStart;

return postRepository.findMyPosts(walkieId, pagingSize, pagingStart);
}
}

0 comments on commit fde4535

Please sign in to comment.