Skip to content

Commit

Permalink
Merge pull request #151 from Gongjakso/refactor/qa
Browse files Browse the repository at this point in the history
feat: 활동 완료 API
  • Loading branch information
dl-00-e8 authored May 19, 2024
2 parents 2089748 + 110507b commit 3c0310b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.gongjakso.server.domain.post.controller;

import com.gongjakso.server.domain.apply.service.ApplyService;
import com.gongjakso.server.domain.post.dto.*;
import com.gongjakso.server.domain.post.service.PostService;
import com.gongjakso.server.global.common.ApplicationResponse;
Expand Down Expand Up @@ -121,4 +120,10 @@ public ApplicationResponse<Page<GetProjectRes>> MyScrapProjectList(@PageableDefa
public ApplicationResponse<Page<GetContestRes>> MyScrapContestList(@PageableDefault(size = 6) Pageable pageable,@AuthenticationPrincipal PrincipalDetails principalDetails){
return ApplicationResponse.ok(postService.getMyScrapContest(principalDetails.getMember(), pageable));
}

@Operation(summary = "활동 종료 API", description = "팀장이 활동 중인 프로젝트 공고를 활동 종료할 때 사용하는 API로, 활동 종료된 공고의 정보가 반환")
@PatchMapping("/complete/{post_id}")
public ApplicationResponse<PostSimpleRes> completePost(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("post_id") Long postId) {
return ApplicationResponse.ok(postService.completePost(principalDetails.getMember(), postId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,8 @@ public void modify(PostModifyReq req) {
public void updatePostView(Long postView) {
this.postView = postView + 1;
}

public void updateStatus(PostStatus status) {
this.status = status;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.gongjakso.server.domain.post.entity.PostScrap;
import com.gongjakso.server.domain.post.entity.StackName;
import com.gongjakso.server.domain.post.enumerate.CategoryType;
import com.gongjakso.server.domain.post.enumerate.PostStatus;
import com.gongjakso.server.domain.post.enumerate.StackNameType;
import com.gongjakso.server.domain.post.repository.PostRepository;
import com.gongjakso.server.domain.post.repository.PostScrapRepository;
Expand Down Expand Up @@ -423,8 +424,19 @@ public Page<GetContestRes> getMyScrapContest(Member member, Pageable page){
return new PageImpl<>(filteredContests, pageable, scrapPageList.getTotalElements());
}

// @Transactional
// public ? completePost() {
//
// }
@Transactional
public PostSimpleRes completePost(Member member, Long postId) {
// Validation: Post 논리적 삭제 및 사용자의 권한 여부 확인
Post post = postRepository.findByPostIdAndDeletedAtIsNull(postId).orElseThrow(() -> new ApplicationException(NOT_FOUND_POST_EXCEPTION));
if(!post.getMember().getMemberId().equals(member.getMemberId())){
throw new ApplicationException(UNAUTHORIZED_EXCEPTION);
}

// Business Logic
post.updateStatus(PostStatus.COMPLETE);
Post savePost = postRepository.save(post);

// Response
return PostSimpleRes.of(savePost);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
package com.gongjakso.server.domain.post.service;

import com.gongjakso.server.domain.post.entity.Post;
import com.gongjakso.server.domain.post.repository.PostRepository;
import com.gongjakso.server.domain.post.util.PostUtilTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class PostServiceTest {

@Autowired
PostService postService;
Post post = null;
@InjectMocks
private PostService postService;

@Mock
private PostRepository postRepository;

@BeforeEach
void beforeEach() {

Post post = PostUtilTest.buildPost();
}

@Test
Expand Down

0 comments on commit 3c0310b

Please sign in to comment.