Skip to content

Commit

Permalink
Merge dev/BE to feat/627
Browse files Browse the repository at this point in the history
  • Loading branch information
cookienc committed Nov 14, 2023
1 parent 2800652 commit 9cf7fa4
Show file tree
Hide file tree
Showing 57 changed files with 1,441 additions and 751 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/deploy-be-ci-cd-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,9 @@ jobs:
- name: Pull Latest Docker Image
run: |
sudo docker login --username ${{ secrets.DOCKERHUB_DEPLOY_USERNAME }} --password ${{ secrets.DOCKERHUB_DEPLOY_TOKEN }}
if sudo docker inspect spring-baton &>/dev/null; then
sudo docker stop spring-baton
sudo docker rm -f spring-baton
sudo docker image prune -af
fi
sudo docker pull 2023batondeploy/2023-baton-deploy:latest
- name: Docker Compose
run: |
sudo docker run --name spring-baton -v /home/ubuntu/logs:/app/logs -p 8080:8080 -e TZ=Asia/Seoul 2023batondeploy/2023-baton-deploy:latest 1>> build.log 2>> error.log &
/home/ubuntu/zero-downtime-deploy.sh
sudo docker image prune -af
64 changes: 63 additions & 1 deletion backend/baton/src/docs/asciidoc/RunnerPostReadApi.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ include::{snippets}/../../build/generated-snippets/runner-post-read-with-logined

include::{snippets}/../../build/generated-snippets/runner-post-read-with-logined-runner-api-test/read-runner-post-by-logined-runner-and-review-status/response-fields.adoc[]

==== *๋Ÿฌ๋„ˆ ๋งˆ์ดํŽ˜์ด์ง€ ๊ฒŒ์‹œ๊ธ€ ๊ฐœ์ˆ˜ ์กฐํšŒ API*

===== *Http Request*

include::{snippets}/../../build/generated-snippets/runner-post-count-with-logined-runner-api-test/count-runner-post-by-logined-runner-and-review-status/http-request.adoc[]

===== *Http Request Headers*

include::{snippets}/../../build/generated-snippets/runner-post-count-with-logined-runner-api-test/count-runner-post-by-logined-runner-and-review-status/request-headers.adoc[]

===== *Http Request Query Parameters*

include::{snippets}/../../build/generated-snippets/runner-post-count-with-logined-runner-api-test/count-runner-post-by-logined-runner-and-review-status/query-parameters.adoc[]

===== *Http Response*

include::{snippets}/../../build/generated-snippets/runner-post-count-with-logined-runner-api-test/count-runner-post-by-logined-runner-and-review-status/http-response.adoc[]

===== *Http Response Fields*

include::{snippets}/../../build/generated-snippets/runner-post-count-with-logined-runner-api-test/count-runner-post-by-logined-runner-and-review-status/response-fields.adoc[]

==== *๋ฆฌ๋ทฐ ์ง€์›ํ•œ ์„œํฌํ„ฐ ์กฐํšŒ API*

===== *Http Request*
Expand Down Expand Up @@ -94,7 +116,29 @@ include::{snippets}/../../build/generated-snippets/runner-post-read-with-logined

include::{snippets}/../../build/generated-snippets/runner-post-read-with-logined-supporter-api-test/read-runner-post-by-logined-supporter-and-review-status/response-fields.adoc[]

==== *์„œํฌํ„ฐ ๋ฆฌ๋ทฐ ์™„๋ฃŒํ•œ ๊ฒŒ์‹œ๊ธ€ ์กฐํšŒ API*
==== *์„œํฌํ„ฐ ๋งˆ์ดํŽ˜์ด์ง€ ๊ฒŒ์‹œ๊ธ€ ๊ฐœ์ˆ˜ ์กฐํšŒ API*

===== *Http Request*

include::{snippets}/../../build/generated-snippets/runner-post-count-with-logined-supporter-api-test/count-runner-post-by-logined-supporter-and-review-status/http-request.adoc[]

===== *Http Request Headers*

include::{snippets}/../../build/generated-snippets/runner-post-count-with-logined-supporter-api-test/count-runner-post-by-logined-supporter-and-review-status/request-headers.adoc[]

===== *Http Request Query Parameters*

include::{snippets}/../../build/generated-snippets/runner-post-count-with-logined-supporter-api-test/count-runner-post-by-logined-supporter-and-review-status/query-parameters.adoc[]

===== *Http Response*

include::{snippets}/../../build/generated-snippets/runner-post-count-with-logined-supporter-api-test/count-runner-post-by-logined-supporter-and-review-status/http-response.adoc[]

===== *Http Response Fields*

include::{snippets}/../../build/generated-snippets/runner-post-count-with-logined-supporter-api-test/count-runner-post-by-logined-supporter-and-review-status/response-fields.adoc[]

==== *์„œํฌํ„ฐ์˜ ๋ฆฌ๋ทฐ ์™„๋ฃŒํ•œ ๊ฒŒ์‹œ๊ธ€ ์กฐํšŒ API*

===== *Http Request*

Expand All @@ -112,6 +156,24 @@ include::{snippets}/../../build/generated-snippets/runner-post-read-of-supporter

include::{snippets}/../../build/generated-snippets/runner-post-read-of-supporter-by-guest-api-test/read-runner-post-by-supporter-id-and-review-status/response-fields.adoc[]

==== *์„œํฌํ„ฐ์˜ ๋ฆฌ๋ทฐ ์™„๋ฃŒํ•œ ๊ฒŒ์‹œ๊ธ€ ๊ฐœ์ˆ˜ ์กฐํšŒ API*

===== *Http Request*

include::{snippets}/../../build/generated-snippets/runner-post-count-of-supporter-by-guest-api-test/count-runner-post-by-supporter-id-and-review-status/http-request.adoc[]

===== *Http Request Query Parameters*

include::{snippets}/../../build/generated-snippets/runner-post-count-of-supporter-by-guest-api-test/count-runner-post-by-supporter-id-and-review-status/query-parameters.adoc[]

===== *Http Response*

include::{snippets}/../../build/generated-snippets/runner-post-count-of-supporter-by-guest-api-test/count-runner-post-by-supporter-id-and-review-status/http-response.adoc[]

===== *Http Response Fields*

include::{snippets}/../../build/generated-snippets/runner-post-count-of-supporter-by-guest-api-test/count-runner-post-by-supporter-id-and-review-status/response-fields.adoc[]

==== *ํƒœ๊ทธ ์ด๋ฆ„๊ณผ ๋ฆฌ๋ทฐ ์ƒํƒœ๋ฅผ ์กฐ๊ฑด์œผ๋กœ ๋Ÿฌ๋„ˆ ๊ฒŒ์‹œ๊ธ€ ํŽ˜์ด์ง• ์กฐํšŒ API*

===== *Http Request*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class FilterConfig implements WebMvcConfigurer {
public FilterRegistrationBean<Filter> getFilterRegistrationBean() {
final FilterRegistrationBean<Filter> registrationBean = new FilterRegistrationBean<>(new MDCLoggingFilter());
registrationBean.setOrder(Integer.MIN_VALUE);
registrationBean.setUrlPatterns(List.of("/api/**"));
registrationBean.setUrlPatterns(List.of("/api/*"));
return registrationBean;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.core.config.Order;
import org.slf4j.MDC;
import org.springframework.core.Ordered;
Expand All @@ -17,8 +19,9 @@ class MDCLoggingFilter implements Filter {

@Override
public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException {
final UUID uuid = UUID.randomUUID();
MDC.put("request_id", uuid.toString());
final String requestId = ((HttpServletRequest) servletRequest).getHeader("X-Request-ID");

MDC.put("request_id", StringUtils.defaultString(requestId, UUID.randomUUID().toString()));
filterChain.doFilter(servletRequest, servletResponse);
MDC.clear();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
package touch.baton.domain.member.command.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import touch.baton.domain.member.command.SupporterRunnerPost;

import java.util.Optional;

public interface SupporterRunnerPostCommandRepository extends JpaRepository<SupporterRunnerPost, Long> {

@Query("""
select count(1)
from SupporterRunnerPost srp
group by srp.runnerPost.id
having srp.runnerPost.id = :runnerPostId
""")
Optional<Long> countByRunnerPostId(@Param("runnerPostId") final Long runnerPostId);

boolean existsByRunnerPostId(final Long runnerPostId);

boolean existsByRunnerPostIdAndSupporterId(final Long runnerPostId, final Long supporterId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@

public interface SupporterRunnerPostQueryRepository extends JpaRepository<SupporterRunnerPost, Long> {

@Query("""
select count(1)
from SupporterRunnerPost srp
group by srp.runnerPost.id
having srp.runnerPost.id in (:runnerPostIds)
""")
List<Long> countByRunnerPostIdIn(@Param("runnerPostIds") final List<Long> runnerPostIds);

@Query("""
select count(1)
from SupporterRunnerPost srp
Expand All @@ -26,20 +18,6 @@ select count(1)
""")
Optional<Long> countByRunnerPostId(@Param("runnerPostId") final Long runnerPostId);

@Query("""
select case when exists (
select 1 from SupporterRunnerPost srp
where srp.runnerPost.id = rp.id)
then (
select count(srp.id) from SupporterRunnerPost srp
where srp.runnerPost.id = rp.id
) else 0 end
from RunnerPost rp
where rp.id in :runnerPostIds
order by rp.id desc
""")
List<Long> countByRunnerPostIds(@Param("runnerPostIds") final List<Long> runnerPostIds);

@Query("""
select (count(1) >= 1)
from SupporterRunnerPost srp
Expand All @@ -49,11 +27,13 @@ select count(srp.id) from SupporterRunnerPost srp
""")
boolean existsByRunnerPostIdAndMemberId(@Param("runnerPostId") final Long runnerPostId, @Param("memberId") final Long memberId);

boolean existsByRunnerPostId(final Long runnerPostId);

void deleteBySupporterIdAndRunnerPostId(final Long supporterId, final Long runnerPostId);

boolean existsByRunnerPostIdAndSupporterId(final Long runnerPostId, final Long supporterId);

List<SupporterRunnerPost> readByRunnerPostId(final Long runnerPostId);

@Query("""
select count(1)
from SupporterRunnerPost srp
join fetch RunnerPost rp on rp.id = srp.runnerPost.id
where rp.reviewStatus = 'NOT_STARTED' and srp.supporter.id = :supporterId
""")
long countRunnerPostBySupporterIdByReviewStatusNotStarted(@Param("supporterId") final Long supporterId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ public Long createRunnerPostApplicant(final Supporter supporter,
final Long runnerPostId
) {
final RunnerPost foundRunnerPost = getRunnerPostOrThrowException(runnerPostId);
final boolean isApplicantHistoryExist = supporterRunnerPostCommandRepository.existsByRunnerPostIdAndSupporterId(runnerPostId, supporter.getId());
if (isApplicantHistoryExist) {
if (isApplySupporter(foundRunnerPost, supporter)) {
throw new RunnerPostBusinessException("Supporter ๋Š” ์ด๋ฏธ ํ•ด๋‹น RunnerPost ์— ๋ฆฌ๋ทฐ ์‹ ์ฒญ์„ ํ•œ ์ด๋ ฅ์ด ์žˆ์Šต๋‹ˆ๋‹ค.");
}

Expand Down Expand Up @@ -160,7 +159,7 @@ public void updateRunnerPostAppliedSupporter(final Runner runner,
final RunnerPost foundRunnerPost = runnerPostCommandRepository.findById(runnerPostId)
.orElseThrow(() -> new RunnerPostBusinessException("RunnerPost ์˜ ์‹๋ณ„์ž๊ฐ’์œผ๋กœ ๋Ÿฌ๋„ˆ ๊ฒŒ์‹œ๊ธ€์„ ์กฐํšŒํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."));

if (isApplySupporter(runnerPostId, foundApplySupporter)) {
if (!isApplySupporter(foundRunnerPost, foundApplySupporter)) {
throw new RunnerPostBusinessException("๊ฒŒ์‹œ๊ธ€์— ๋ฆฌ๋ทฐ๋ฅผ ์ œ์•ˆํ•œ ์„œํฌํ„ฐ๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.");
}
if (foundRunnerPost.isNotOwner(runner)) {
Expand All @@ -172,7 +171,7 @@ public void updateRunnerPostAppliedSupporter(final Runner runner,
eventPublisher.publishEvent(new RunnerPostAssignSupporterEvent(foundRunnerPost.getId()));
}

private boolean isApplySupporter(final Long runnerPostId, final Supporter foundSupporter) {
return !supporterRunnerPostCommandRepository.existsByRunnerPostIdAndSupporterId(runnerPostId, foundSupporter.getId());
private boolean isApplySupporter(final RunnerPost runnerPost, final Supporter supporter) {
return supporterRunnerPostCommandRepository.existsByRunnerPostIdAndSupporterId(runnerPost.getId(), supporter.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ResponseEntity<RunnerPostResponse.Detail> readByRunnerPostId(
@PathVariable final Long runnerPostId
) {
final RunnerPost foundRunnerPost = runnerPostQueryService.readByRunnerPostId(runnerPostId);
final long applicantCount = runnerPostQueryService.readCountByRunnerPostId(foundRunnerPost.getId());
final long applicantCount = runnerPostQueryService.countApplicantsByRunnerPostId(foundRunnerPost.getId());
final boolean isApplicantHistoryExist = runnerPostQueryService.existsRunnerPostApplicantByRunnerPostIdAndMemberId(runnerPostId, member.getId());

runnerPostQueryService.increaseWatchedCount(foundRunnerPost);
Expand All @@ -70,6 +70,14 @@ public ResponseEntity<PageResponse<RunnerPostResponse.Simple>> readRunnerPostByS
return ResponseEntity.ok(runnerPostQueryService.pageRunnerPostBySupporterIdAndReviewStatus(pageParams, supporterId, ReviewStatus.DONE));
}

@GetMapping("/search/count")
public ResponseEntity<RunnerPostResponse.Count> countRunnerPostBySupporterIdAndReviewStatusDone(
@RequestParam final Long supporterId
) {
final long count = runnerPostQueryService.countRunnerPostBySupporterIdAndReviewStatus(supporterId, ReviewStatus.DONE);
return ResponseEntity.ok(RunnerPostResponse.Count.from(count));
}

@GetMapping("/{runnerPostId}/supporters")
public ResponseEntity<SupporterRunnerPostResponses.Detail> readSupporterRunnerPostsByRunnerPostId(
@AuthRunnerPrincipal final Runner runner,
Expand All @@ -91,11 +99,30 @@ public ResponseEntity<PageResponse<RunnerPostResponse.Simple>> readRunnerPostByL
return ResponseEntity.ok(runnerPostQueryService.pageRunnerPostBySupporterIdAndReviewStatus(pageParams, supporter.getId(), reviewStatus));
}

@GetMapping("/me/runner") public ResponseEntity<PageResponse<RunnerPostResponse.SimpleByRunner>> readRunnerPostByLoginedRunnerAndReviewStatus(
@GetMapping("/me/runner")
public ResponseEntity<PageResponse<RunnerPostResponse.SimpleByRunner>> readRunnerPostByLoginedRunnerAndReviewStatus(
@AuthRunnerPrincipal final Runner runner,
@Valid @ModelAttribute final PageParams pageParams,
@RequestParam(required = false) final ReviewStatus reviewStatus
) {
return ResponseEntity.ok(runnerPostQueryService.pageRunnerPostByRunnerIdAndReviewStatus(pageParams, runner.getId(), reviewStatus));
}

@GetMapping("/me/supporter/count")
public ResponseEntity<RunnerPostResponse.Count> countRunnerPostByLoginedSupporterAndReviewStatus(
@AuthSupporterPrincipal final Supporter supporter,
@RequestParam final ReviewStatus reviewStatus
) {
final long runnerPostCount = runnerPostQueryService.countRunnerPostBySupporterIdAndReviewStatus(supporter.getId(), reviewStatus);
return ResponseEntity.ok(RunnerPostResponse.Count.from(runnerPostCount));
}

@GetMapping("/me/runner/count")
public ResponseEntity<RunnerPostResponse.Count> countRunnerPostByLoginedRunnerAndReviewStatus(
@AuthRunnerPrincipal final Runner runner,
@RequestParam final ReviewStatus reviewStatus
) {
final long runnerPostCount = runnerPostQueryService.countRunnerPostByRunnerIdAndReviewStatus(runner.getId(), reviewStatus);
return ResponseEntity.ok(RunnerPostResponse.Count.from(runnerPostCount));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ public Long extractId() {
}
}

public record Count(Long count) {

public static Count from(final long count) {
return new Count(count);
}
}

private static List<String> convertToTags(final RunnerPost runnerPost) {
return runnerPost.getRunnerPostTags()
.getRunnerPostTags()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.data.repository.query.Param;
import touch.baton.domain.runnerpost.command.RunnerPost;
import touch.baton.domain.runnerpost.command.repository.dto.RunnerPostApplicantCountDto;
import touch.baton.domain.runnerpost.command.vo.ReviewStatus;

import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -39,4 +40,18 @@ public interface RunnerPostQueryRepository extends JpaRepository<RunnerPost, Lon
group by rp.id
""")
List<RunnerPostApplicantCountDto> countApplicantsByRunnerPostIds(@Param("runnerPostIds") final List<Long> runnerPostIds);

@Query("""
select count(1)
from RunnerPost rp
where rp.runner.id = :runnerId and rp.reviewStatus = :reviewStatus
""")
long countByRunnerIdAndReviewStatus(@Param("runnerId") final Long runnerId, @Param("reviewStatus") final ReviewStatus reviewStatus);

@Query("""
select count(1)
from RunnerPost rp
where rp.supporter.id = :supporterId and rp.reviewStatus = :reviewStatus
""")
long countBySupporterIdAndReviewStatus(@Param("supporterId") final Long supporterId, @Param("reviewStatus") final ReviewStatus reviewStatus);
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,21 @@ public boolean existsRunnerPostApplicantByRunnerPostIdAndMemberId(final Long run
return supporterRunnerPostQueryRepository.existsByRunnerPostIdAndMemberId(runnerPostId, memberId);
}

public long readCountByRunnerPostId(final Long runnerPostId) {
public long countApplicantsByRunnerPostId(final Long runnerPostId) {
return supporterRunnerPostQueryRepository.countByRunnerPostId(runnerPostId).orElse(0L);
}

public long countRunnerPostByRunnerIdAndReviewStatus(final Long runnerId, final ReviewStatus reviewStatus) {
return runnerPostQueryRepository.countByRunnerIdAndReviewStatus(runnerId, reviewStatus);
}

public long countRunnerPostBySupporterIdAndReviewStatus(final Long supporterId, final ReviewStatus reviewStatus) {
if (reviewStatus.isNotStarted()) {
return supporterRunnerPostQueryRepository.countRunnerPostBySupporterIdByReviewStatusNotStarted(supporterId);
}
return runnerPostQueryRepository.countBySupporterIdAndReviewStatus(supporterId, reviewStatus);
}

@Transactional
public void increaseWatchedCount(final RunnerPost runnerPost) {
runnerPost.increaseWatchedCount();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
package touch.baton.domain.tag.command.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import touch.baton.domain.common.vo.TagName;
import touch.baton.domain.tag.command.Tag;
import touch.baton.domain.tag.command.vo.TagReducedName;

import java.util.List;
import java.util.Optional;

public interface TagCommandRepository extends JpaRepository<Tag, Long> {

Optional<Tag> findByTagName(final TagName tagName);

@Query("""
select t
from Tag t
where t.tagReducedName like :tagReducedName%
order by t.tagReducedName asc
limit 10
""")
List<Tag> readTagsByReducedName(@Param("tagReducedName") TagReducedName tagReducedName);
}
Loading

0 comments on commit 9cf7fa4

Please sign in to comment.