Skip to content

Commit

Permalink
[feat] #78 forum에서 본인 forum 가져오기 api 구현 및 swagger 조정
Browse files Browse the repository at this point in the history
  • Loading branch information
myhyun0002 committed Feb 5, 2023
1 parent be4790f commit a32eb2f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 114 deletions.
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ dependencies {

// m1 mac os에서 dsn server 문제 해결
implementation 'io.netty:netty-resolver-dns-native-macos:4.1.68.Final:osx-aarch_64'



testImplementation('org.junit.jupiter:junit-jupiter:5.9.1')

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ public ResponseTemplate<List<ForumResponseDto.ForumDataToGetResult>> getForumByU
return forumService.getForumByUserId(user_id);
}

@ApiOperation(value = "현재 사용중인 사용자가 만든 모든 forum 조회", notes = "user-id의 사용자가 만든 모든 forum 조회")
@ResponseBody
@GetMapping("/user/me")
public ResponseTemplate<List<ForumResponseDto.ForumDataToGetResult>> getMyForums() throws ResponseException {
Long user_id = jwtService.getmemberId();
return forumService.getForumByUserId(user_id);
}

// forum_id로 조회
@ApiOperation(value = "해당 forum-id인 forum 하나 조회",notes = "해당 forum-id인 forum 하나 조회")
@ResponseBody
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ public ResponseTemplate<List<NestedCommentResponseDto.Body>> getAllNestedComment
return nestedCommentService.getAllByCommentId(comment_id);
}

@ApiOperation(value = "해당 comment-id인 comment 좋아요 수 하나 증가")
@ApiOperation(value = "해당 nested-comment-id인 대댓글 좋아요 수 하나 증가")
@PutMapping("/{nested-comment-id}/like/plus")
public ResponseTemplate<NestedCommentResponseDto.LikeResponseDto> likePlus(@PathVariable("nested-comment-id") Long nested_comment_id) throws ResponseException {
return nestedCommentService.likePlus(nested_comment_id);
}

@ApiOperation(value = "해당 comment-id인 comment 좋아요 수 하나 감소")
@ApiOperation(value = "해당 nested-comment-id인 대댓글 좋아요 수 하나 감소")
@PutMapping("/{nested-comment-id}/like/minus")
public ResponseTemplate<NestedCommentResponseDto.LikeResponseDto> likeMinus(@PathVariable("nested-comment-id") Long nested_comment_id) throws ResponseException {
return nestedCommentService.likeMinus(nested_comment_id);
}

@ApiOperation(value = "해당 comment-id인 comment 좋아요 수 조회")
@ApiOperation(value = "해당 nested-comment-id인 대댓글 좋아요 수 조회")
@GetMapping("/{nested-comment-id}/like")
public ResponseTemplate<NestedCommentResponseDto.LikeResponseDto> getNestedCommentLike(@PathVariable("nested-comment-id") Long nested_comment_id) throws ResponseException {
return nestedCommentService.getLike(nested_comment_id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,108 +1,62 @@
//package com.example.umc3_teamproject.service;
//
//import com.example.umc3_teamproject.config.resTemplate.ResponsePageTemplate;
//import com.example.umc3_teamproject.config.resTemplate.ResponseTemplate;
//import com.example.umc3_teamproject.domain.Member;
//import com.example.umc3_teamproject.domain.dto.request.CommentRequestDto;
//import com.example.umc3_teamproject.domain.dto.request.ForumRequestDto;
//import com.example.umc3_teamproject.domain.dto.request.ScriptRequestDto;
//import com.example.umc3_teamproject.domain.dto.response.CommentResponseDto;
//import com.example.umc3_teamproject.domain.dto.response.ForumResponseDto;
//import com.example.umc3_teamproject.dto.SignupReq;
//import com.example.umc3_teamproject.repository.MemberRepository;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.data.domain.Pageable;
//import org.springframework.data.domain.Sort;
//import org.springframework.test.context.junit4.SpringRunner;
//import org.springframework.transaction.annotation.Transactional;
//import java.util.List;
//
//@RunWith(SpringRunner.class)
//@SpringBootTest
//@Transactional
//public class CommentServiceTest {
//
// @Autowired
// private MemberRepository memberRepository;
//
// @Autowired
// private ScriptService scriptService;
//
// @Autowired
// private ForumService forumService;
//
// @Autowired
// private CommentService commentService;
//
// @Test
// public void 댓글_페이징_테스트() throws Exception{
// //given
// Long userId = memberRepository.createUser(new SignupReq("[email protected]", "sldkfj", 1, "KIM", "sldkfj"));
//
// ScriptRequestDto.Register register = new ScriptRequestDto.Register();
// register.setTitle("title");
// register.setUserId(userId);
// scriptService.writeScript(register);
//
// ResponseTemplate<ForumResponseDto.ForumDataToGetResult> forum = forumService.createForum(userId, new ForumRequestDto.createForumRequest());
// //when
//
// for(int i = 0 ; i <= 200 ; i++){
// commentService.createComment(forum.getData().getForumId(), new CommentRequestDto.createCommentRequest(userId,"comment"));
// }
// Pageable pageable = new Pageable() {
// @Override
// public int getPageNumber() {
// return 0;
// }
//
// @Override
// public int getPageSize() {
// return 0;
// }
//
// @Override
// public long getOffset() {
// return 0;
// }
//
// @Override
// public Sort getSort() {
// return null;
// }
//
// @Override
// public Pageable next() {
// return null;
// }
//
// @Override
// public Pageable previousOrFirst() {
// return null;
// }
//
// @Override
// public Pageable first() {
// return null;
// }
//
// @Override
// public Pageable withPage(int pageNumber) {
// return null;
// }
//
// @Override
// public boolean hasPrevious() {
// return false;
// }
// };
// //then
// ResponsePageTemplate<List<CommentResponseDto.Body>> allByForumId = commentService.getAllByForumId(forum.getData().getForumId(),pageable);
//
// System.out.println(allByForumId.getData().size());
// }
//
//}
package com.example.umc3_teamproject.service;

import com.example.umc3_teamproject.config.resTemplate.ResponsePageTemplate;
import com.example.umc3_teamproject.config.resTemplate.ResponseTemplate;
import com.example.umc3_teamproject.domain.Member;
import com.example.umc3_teamproject.domain.dto.request.CommentRequestDto;
import com.example.umc3_teamproject.domain.dto.request.ForumRequestDto;
import com.example.umc3_teamproject.domain.dto.request.ScriptRequestDto;
import com.example.umc3_teamproject.domain.dto.response.CommentResponseDto;
import com.example.umc3_teamproject.domain.dto.response.ForumResponseDto;
import com.example.umc3_teamproject.dto.SignupReq;
import com.example.umc3_teamproject.repository.MemberRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
public class CommentServiceTest {

@Autowired
private MemberRepository memberRepository;

@Autowired
private ScriptService scriptService;

@Autowired
private ForumService forumService;

@Autowired
private CommentService commentService;

@Test
public void 댓글_페이징_테스트() throws Exception{
//given
Long userId = memberRepository.createMember(new SignupReq("[email protected]", "sldkfj", 1, "KIM", "sldkfj"));

ScriptRequestDto.Register register = new ScriptRequestDto.Register();
register.setTitle("title");
register.setMemberId(userId);
scriptService.writeScript(register);

ResponseTemplate<ForumResponseDto.ForumDataToGetResult> forum = forumService.createForum(userId, new ForumRequestDto.createForumRequest());
//when

for(int i = 0 ; i <= 200 ; i++){
commentService.createComment(forum.getData().getForumId(), new CommentRequestDto.createCommentRequest(userId,"comment"));
}
//then
ResponsePageTemplate<List<CommentResponseDto.Body>> allByForumId = commentService.getAllByForumId(forum.getData().getForumId(),pageable);

System.out.println(allByForumId.getData().size());
}

}

0 comments on commit a32eb2f

Please sign in to comment.