Skip to content

Commit

Permalink
Merge pull request #616 from woowacourse-teams/develop
Browse files Browse the repository at this point in the history
Version 4.2.0 배포
  • Loading branch information
woose28 authored Oct 20, 2022
2 parents e39e504 + 077812a commit f16faa7
Show file tree
Hide file tree
Showing 183 changed files with 5,767 additions and 59,340 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ https://www.smody.co.kr

<img width="528" alt="image" src="https://user-images.githubusercontent.com/59413128/185350085-f0dfdfc8-f28e-41a2-a637-9426e5217f78.png">

- [Figma 링크](https://www.figma.com/file/HQinpzR8FuXUFxTZzzzCpf/Smody-Design-System)
- [Storybook 링크](https://woowacourse-teams.github.io/2022-smody)

### Backend

<img width="528" alt="image" src="https://user-images.githubusercontent.com/59413128/195751494-9f596b69-f515-4ee3-907b-7c56dc976350.png">
<img width="529" alt="image" src="https://user-images.githubusercontent.com/59413128/196944126-2cd8cb03-b261-4555-828f-29d9f0173d98.png">


### Infra

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.woowacourse.smody;

import java.util.TimeZone;

import javax.annotation.PostConstruct;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;


@SpringBootApplication
@EnableJpaAuditing
public class SmodyApplication {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
@EqualsAndHashCode
public class TokenPayload {

public static final TokenPayload NOT_LOGIN_TOKEN_PAYLOAD = new TokenPayload(0L);

private Long id;

public Map<String, Object> toMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ public ResponseEntity<List<ChallengeTabResponse>> findAllWithChallengerCountByFi
@RequiredLogin
public ResponseEntity<List<ChallengeTabResponse>> findAllWithChallengerCountByFilter(
@LoginMember TokenPayload tokenPayload,
@ModelAttribute PagingParams pagingParams) {
@ModelAttribute PagingParams pagingParams
) {
return ResponseEntity.ok(challengeApiService.findAllWithChallengerCountByFilter(
tokenPayload, LocalDateTime.now(), pagingParams)
);
tokenPayload, LocalDateTime.now(), pagingParams
));
}

@GetMapping(value = "/me")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ChallengingRecord(List<Cycle> cycles) {
.count();
}

/*
/**
* QueryDSL Projection 을 위한 생성자
*/
public ChallengingRecord(Cycle cycle, Long successCount) {
Expand Down Expand Up @@ -104,7 +104,7 @@ public Cycle getLatestCycle() {

public Integer getCycleDetailCount() {
return cycles.stream()
.mapToInt(cycle -> cycle.getCycleDetailsOrderByProgress().size())
.mapToInt(Cycle::getCycleDetailCount)
.sum();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package com.woowacourse.smody.challenge.repository;

import com.woowacourse.smody.challenge.domain.Challenge;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface ChallengeRepository extends JpaRepository<Challenge, Long>, DynamicChallengeRepository {

Optional<Challenge> findByName(String name);

@Query("select c.id from Challenge c")
List<Long> findAllIds();

List<Challenge> findAllByIdIn(List<Long> challengeIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.woowacourse.smody.member.domain.Member;
import com.woowacourse.smody.member.service.MemberService;
import java.time.LocalDateTime;
import java.util.Comparator;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -36,7 +35,7 @@ public class ChallengeApiService {

public List<ChallengeTabResponse> findAllWithChallengerCountByFilter(LocalDateTime searchTime,
PagingParams pagingParams) {
return findAllWithChallengerCountByFilter(new TokenPayload(0L), searchTime, pagingParams);
return findAllWithChallengerCountByFilter(TokenPayload.NOT_LOGIN_TOKEN_PAYLOAD, searchTime, pagingParams);
}

public List<ChallengeTabResponse> findAllWithChallengerCountByFilter(TokenPayload tokenPayload,
Expand All @@ -46,6 +45,9 @@ public List<ChallengeTabResponse> findAllWithChallengerCountByFilter(TokenPayloa
if (pagingParams.getSort().equals("popular")) {
return getChallengeTabResponsesWhenPopular(searchTime, pagingParams, member);
}
if (pagingParams.getSort().equals("random")) {
return getChallengeTabResponsesWhenRandom(searchTime, pagingParams, member);
}
List<Challenge> challenges = challengeService.findAllByFilter(pagingParams);
List<Cycle> cycles = cycleService.findInProgressByChallenges(searchTime, challenges);
ChallengingRecords challengingRecords = ChallengingRecords.from(cycles);
Expand All @@ -62,6 +64,15 @@ private List<ChallengeTabResponse> getChallengeTabResponsesWhenPopular(LocalDate
return getChallengeTabResponses(pagedChallenges, member, challengingRecords);
}

private List<ChallengeTabResponse> getChallengeTabResponsesWhenRandom(final LocalDateTime searchTime,
final PagingParams pagingParams, final Member member) {
List<Challenge> randomChallenges = challengeService.findRandomChallenges(pagingParams.getSize());
List<Cycle> cycles = cycleService.findInProgress(searchTime);
ChallengingRecords challengingRecords = ChallengingRecords.from(cycles);
List<Challenge> pagedChallenges = CursorPaging.apply(randomChallenges, null, pagingParams.getSize());
return getChallengeTabResponses(pagedChallenges, member, challengingRecords);
}

private List<ChallengeTabResponse> getChallengeTabResponses(List<Challenge> challenges,
Member member,
ChallengingRecords challengingRecords) {
Expand All @@ -74,7 +85,7 @@ private List<ChallengeTabResponse> getChallengeTabResponses(List<Challenge> chal
}

public ChallengeResponse findWithChallengerCount(LocalDateTime searchTime, Long challengeId) {
return findWithChallengerCount(new TokenPayload(0L), searchTime, challengeId);
return findWithChallengerCount(TokenPayload.NOT_LOGIN_TOKEN_PAYLOAD, searchTime, challengeId);
}

public ChallengeResponse findWithChallengerCount(
Expand All @@ -99,7 +110,7 @@ public List<ChallengeOfMineResponse> findAllByMeAndFilter(TokenPayload tokenPayl
);
List<ChallengingRecord> sortedRecords = challengingRecords.sortByLatestProgressTime();

ChallengingRecord cursorChallengingRecord = getCursorMemberChallenge(pagingParams, sortedRecords);
ChallengingRecord cursorChallengingRecord = getCursorChallengeRecord(pagingParams, sortedRecords);
List<ChallengingRecord> pagedMyChallengeHistories = CursorPaging.apply(
sortedRecords, cursorChallengingRecord, pagingParams.getSize()
);
Expand All @@ -109,7 +120,7 @@ public List<ChallengeOfMineResponse> findAllByMeAndFilter(TokenPayload tokenPayl
.collect(toList());
}

private ChallengingRecord getCursorMemberChallenge(PagingParams pagingParams,
private ChallengingRecord getCursorChallengeRecord(PagingParams pagingParams,
List<ChallengingRecord> myChallengeHistories) {
return challengeService.findById(pagingParams.getCursorId())
.map(cursor -> extractMatchChallenge(myChallengeHistories, cursor))
Expand All @@ -134,7 +145,7 @@ public List<ChallengersResponse> findAllChallengers(Long challengeId) {
}

public ChallengeHistoryResponse findByMeAndChallenge(TokenPayload tokenPayload, Long challengeId) {
List<Cycle> cycles = cycleService.findAllByChallengeIdAndMemberId(challengeId, tokenPayload.getId());
List<Cycle> cycles = cycleService.findAllByChallengeAndMember(challengeId, tokenPayload.getId());
ChallengingRecord challengingRecord = new ChallengingRecord(cycles);
return new ChallengeHistoryResponse(
challengingRecord.getChallenge(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import com.woowacourse.smody.challenge.domain.Challenge;
import com.woowacourse.smody.challenge.repository.ChallengeRepository;
import com.woowacourse.smody.cycle.domain.Cycle;
import com.woowacourse.smody.db_support.PagingParams;
import com.woowacourse.smody.exception.BusinessException;
import com.woowacourse.smody.exception.ExceptionData;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -55,4 +54,11 @@ private void validateDuplicatedName(String name) {
throw new BusinessException(ExceptionData.DUPLICATE_NAME);
}
}

public List<Challenge> findRandomChallenges(Integer size) {
List<Long> allIds = challengeRepository.findAllIds();
Collections.shuffle(allIds);
List<Long> randomIds = allIds.subList(0, Math.min(size, allIds.size()));
return challengeRepository.findAllByIdIn(randomIds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.woowacourse.smody.comment.dto.CommentResponse;
import com.woowacourse.smody.comment.dto.CommentUpdateRequest;
import com.woowacourse.smody.comment.service.CommentApiService;
import com.woowacourse.smody.comment.service.CommentService;
import java.net.URI;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand All @@ -28,7 +27,8 @@ public class CommentController {

@PostMapping("/feeds/{cycleDetailId}/comments")
@RequiredLogin
public ResponseEntity<Void> create(@LoginMember TokenPayload tokenPayload, @PathVariable Long cycleDetailId,
public ResponseEntity<Void> create(@LoginMember TokenPayload tokenPayload,
@PathVariable Long cycleDetailId,
@RequestBody CommentRequest commentRequest) {
Long commentId = commentApiService.create(tokenPayload, cycleDetailId, commentRequest);
return ResponseEntity.created(URI.create("/comments/" + commentId)).build();
Expand All @@ -52,7 +52,9 @@ public ResponseEntity<Void> delete(@LoginMember TokenPayload tokenPayload, @Path

@GetMapping("/feeds/{cycleDetailId}/comments")
public ResponseEntity<List<CommentResponse>> findAllByCycleDetailId(@PathVariable Long cycleDetailId) {
return ResponseEntity.ok(commentApiService.findAllByCycleDetailId(new TokenPayload(0L), cycleDetailId));
return ResponseEntity.ok(
commentApiService.findAllByCycleDetailId(TokenPayload.NOT_LOGIN_TOKEN_PAYLOAD, cycleDetailId)
);
}

@GetMapping("/feeds/{cycleDetailId}/comments/auth")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void validateContent(String content) {
}
}

public boolean isCommentByMemberId(Long memberId) {
public boolean isWriter(Long memberId) {
return this.member.getId().equals(memberId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import com.woowacourse.smody.comment.domain.Comment;
import java.util.List;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface CommentRepository extends JpaRepository<Comment, Long> {

@EntityGraph(attributePaths = {"member", "cycleDetail"})
List<Comment> findAllByCycleDetailId(Long cycleDetailId);
@Query("select cm from Comment cm "
+ "join fetch cm.member join fetch cm.cycleDetail "
+ "where cm.cycleDetail.id = :cycleDetailId")
List<Comment> findAllByCycleDetailId(@Param("cycleDetailId") Long cycleDetailId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.woowacourse.smody.comment.dto.CommentRequest;
import com.woowacourse.smody.comment.dto.CommentResponse;
import com.woowacourse.smody.comment.dto.CommentUpdateRequest;
import com.woowacourse.smody.comment.repository.CommentRepository;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
Expand All @@ -19,13 +18,6 @@ public class CommentApiService {

private final CommentService commentService;

public List<CommentResponse> findAllByCycleDetailId(TokenPayload tokenPayload, Long cycleDetailId) {
List<Comment> comments = commentService.findAllByCycleDetailId(cycleDetailId);
return comments.stream()
.map(comment -> new CommentResponse(comment, comment.isCommentByMemberId(tokenPayload.getId())))
.collect(Collectors.toList());
}

@Transactional
public Long create(TokenPayload tokenPayload, Long cycleDetailId, CommentRequest commentRequest) {
Comment comment = commentService.create(
Expand All @@ -35,14 +27,19 @@ public Long create(TokenPayload tokenPayload, Long cycleDetailId, CommentRequest
}

@Transactional
public void update(
TokenPayload tokenPayload, Long commentId, CommentUpdateRequest commentUpdateRequest
) {
public void update(TokenPayload tokenPayload, Long commentId, CommentUpdateRequest commentUpdateRequest) {
commentService.update(tokenPayload.getId(), commentId, commentUpdateRequest.getContent());
}

@Transactional
public void delete(TokenPayload tokenPayload, Long commentId) {
commentService.delete(tokenPayload.getId(), commentId);
}

public List<CommentResponse> findAllByCycleDetailId(TokenPayload tokenPayload, Long cycleDetailId) {
List<Comment> comments = commentService.findAllByCycleDetailId(cycleDetailId);
return comments.stream()
.map(comment -> new CommentResponse(comment, comment.isWriter(tokenPayload.getId())))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.woowacourse.smody.comment.service;

import com.woowacourse.smody.auth.dto.TokenPayload;
import com.woowacourse.smody.comment.domain.Comment;
import com.woowacourse.smody.comment.domain.CommentCreateEvent;
import com.woowacourse.smody.comment.dto.CommentRequest;
import com.woowacourse.smody.comment.dto.CommentUpdateRequest;
import com.woowacourse.smody.comment.repository.CommentRepository;
import com.woowacourse.smody.cycle.domain.CycleDetail;
import com.woowacourse.smody.cycle.service.CycleService;
import com.woowacourse.smody.exception.BusinessException;
import com.woowacourse.smody.exception.ExceptionData;
import com.woowacourse.smody.feed.repository.FeedRepository;
import com.woowacourse.smody.member.domain.Member;
import com.woowacourse.smody.member.service.MemberService;
import java.util.List;
Expand All @@ -24,17 +21,15 @@
public class CommentService {

private final MemberService memberService;
private final CycleService cycleService;
private final CommentRepository commentRepository;
private final FeedRepository feedRepository;
private final ApplicationEventPublisher applicationEventPublisher;

@Transactional
public Comment create(Long memberId, Long cycleDetailId, String content) {
Member member = memberService.search(memberId);
CycleDetail cycleDetail = feedRepository.findById(cycleDetailId)
.orElseThrow(() -> new BusinessException(ExceptionData.NOT_FOUND_CYCLE_DETAIL));
CycleDetail cycleDetail = cycleService.searchCycleDetail(cycleDetailId);
Comment comment = commentRepository.save(new Comment(cycleDetail, member, content));

applicationEventPublisher.publishEvent(new CommentCreateEvent(comment));
return comment;
}
Expand All @@ -46,6 +41,12 @@ public void update(Long memberId, Long commentId, String content) {
comment.updateContent(content);
}

private void validateMember(Long memberId, Comment comment) {
if (!comment.isWriter(memberId)) {
throw new BusinessException(ExceptionData.UNAUTHORIZED_MEMBER);
}
}

@Transactional
public void delete(Long memberId, Long commentId) {
Comment comment = search(commentId);
Expand All @@ -58,12 +59,6 @@ public Comment search(Long commentId) {
.orElseThrow(() -> new BusinessException(ExceptionData.NOT_FOUND_COMMENT));
}

private void validateMember(Long memberId, Comment comment) {
if (!comment.isCommentByMemberId(memberId)) {
throw new BusinessException(ExceptionData.UNAUTHORIZED_MEMBER);
}
}

public List<Comment> findAllByCycleDetailId(Long cycleDetailId) {
return commentRepository.findAllByCycleDetailId(cycleDetailId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
@EnableAsync
public class AsyncConfig {

@Value("${async.threads.max}")
private Integer threadMax;
@Value("${async.threads.max}")
private Integer threadMax;

@Bean
public TaskExecutor asyncExecutor() {
ThreadPoolTaskExecutor asyncExecutor = new ThreadPoolTaskExecutor();
asyncExecutor.setThreadNamePrefix("async-pool");
asyncExecutor.setCorePoolSize(threadMax);
asyncExecutor.initialize();
return asyncExecutor;
}
@Bean
public TaskExecutor asyncExecutor() {
ThreadPoolTaskExecutor asyncExecutor = new ThreadPoolTaskExecutor();
asyncExecutor.setThreadNamePrefix("async-pool");
asyncExecutor.setCorePoolSize(threadMax);
asyncExecutor.initialize();
return asyncExecutor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class WebConfig implements WebMvcConfigurer {
private final AuthInterceptor authInterceptor;
private final LogInterceptor logInterceptor;
private final LoginMemberArgumentResolver loginMemberArgumentResolver;

private final TokenChekcerArgumentResolver tokenChekcerArgumentResolver;

@Override
Expand Down
Loading

0 comments on commit f16faa7

Please sign in to comment.