Skip to content

Commit

Permalink
Merge pull request #128 from team-winey/refactor/#127
Browse files Browse the repository at this point in the history
Refactor/#127
  • Loading branch information
sss4920 authored Aug 21, 2023
2 parents 7a99526 + 942d355 commit b3c4982
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
import org.winey.server.common.dto.ApiResponse;
import org.winey.server.config.resolver.UserId;
import org.winey.server.controller.request.comment.CreateCommentRequestDto;
import org.winey.server.controller.request.feedLike.CreateFeedLikeRequestDto;
import org.winey.server.controller.response.comment.CreateCommentResponseDto;
import org.winey.server.controller.response.feedLike.CreateFeedLikeResponseDto;
import org.winey.server.controller.response.comment.CommentResponseDto;
import org.winey.server.exception.Success;
import org.winey.server.service.CommentService;
import org.winey.server.service.FeedLikeService;

import javax.validation.Valid;

Expand All @@ -27,7 +24,7 @@ public class CommentController {
@PostMapping(value = "/{feedId}")
@ResponseStatus(HttpStatus.CREATED)
@Operation(summary = "๋Œ“๊ธ€์„ ๋งŒ๋“œ๋Š” API", description = "ํ”ผ๋“œ์˜ ๋Œ“๊ธ€์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.")
public ApiResponse<CreateCommentResponseDto> createComment(
public ApiResponse<CommentResponseDto> createComment(
@UserId Long userId,
@PathVariable Long feedId,
@RequestBody @Valid CreateCommentRequestDto requestDto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.winey.server.domain.user.User;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class GetCommentResponseDto {
public class CommentResponseDto {
private Long commentId;
private Long authorId;
private String author;
private String content;
private int authorLevel;
private LocalDateTime createdAt;

public static GetCommentResponseDto of(Long commentId,Long authorId, String author, String content, int authorLevel, LocalDateTime createdAt) {
return new GetCommentResponseDto(commentId, authorId, author, content, authorLevel, createdAt);
public static CommentResponseDto of(Long commentId, Long authorId, String author, String content, int authorLevel, LocalDateTime createdAt) {
return new CommentResponseDto(commentId, authorId, author, content, authorLevel, createdAt);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.winey.server.controller.response.PageResponseDto;
import org.winey.server.controller.response.comment.CreateCommentResponseDto;
import org.winey.server.controller.response.comment.GetCommentResponseDto;
import org.winey.server.controller.response.comment.CommentResponseDto;

import java.util.List;

Expand All @@ -16,9 +14,9 @@
public class GetFeedDetailResponseDto {

private GetFeedResponseDto getFeedResponseDto;
private List<GetCommentResponseDto> getCommentResponseList;
private List<CommentResponseDto> getCommentResponseList;

public static GetFeedDetailResponseDto of(GetFeedResponseDto getFeedResponseDto, List<GetCommentResponseDto> getCommentResponseList) {
public static GetFeedDetailResponseDto of(GetFeedResponseDto getFeedResponseDto, List<CommentResponseDto> getCommentResponseList) {
return new GetFeedDetailResponseDto(getFeedResponseDto,getCommentResponseList);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/winey/server/domain/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.winey.server.domain.feed.Feed;
import org.winey.server.domain.feed.FeedLike;
import org.winey.server.domain.goal.Goal;
import org.winey.server.domain.notification.Notification;
import org.winey.server.domain.recommend.Recommend;

import javax.persistence.*;
Expand Down Expand Up @@ -54,6 +55,9 @@ public class User extends AuditingTimeEntity {
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE, mappedBy = "user", orphanRemoval = true)
private List<FeedLike> feedLikes;

@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE, mappedBy = "notiReceiver", orphanRemoval = true)
private List<Notification> notifications;

@Builder
public User(String nickname, String socialId, SocialType socialType) {
this.nickname = nickname;
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/org/winey/server/service/CommentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.winey.server.controller.response.comment.CreateCommentResponseDto;
import org.winey.server.controller.response.feedLike.CreateFeedLikeResponseDto;
import org.winey.server.controller.response.comment.CommentResponseDto;
import org.winey.server.domain.comment.Comment;
import org.winey.server.domain.notification.NotiType;
import org.winey.server.domain.notification.Notification;
Expand All @@ -29,7 +28,7 @@ public class CommentService {
private final NotiRepository notiRepository;

@Transactional
public CreateCommentResponseDto createComment(Long userId, Long feedId, String content) {
public CommentResponseDto createComment(Long userId, Long feedId, String content) {
User user = userRepository.findByUserId(userId)
.orElseThrow(() -> new NotFoundException(Error.NOT_FOUND_USER_EXCEPTION, Error.NOT_FOUND_USER_EXCEPTION.getMessage()));
Feed feed = feedRepository.findByFeedId(feedId)
Expand All @@ -53,7 +52,7 @@ public CreateCommentResponseDto createComment(Long userId, Long feedId, String c
notification.updateResponseId(comment.getCommentId());
notification.updateRequestUserId(userId);
notiRepository.save(notification);
return CreateCommentResponseDto.of(comment.getCommentId(), commentRepository.countByFeed(feed),user.getNickname(), comment.getContent());
return CommentResponseDto.of(comment.getCommentId(), userId, user.getNickname(), comment.getContent(),user.getUserLevel().getLevelNumber(),comment.getCreatedAt());
}

@Transactional
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/winey/server/service/FeedService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.winey.server.controller.request.CreateFeedRequestDto;
import org.winey.server.controller.response.PageResponseDto;
import org.winey.server.controller.response.comment.GetCommentResponseDto;
import org.winey.server.controller.response.comment.CommentResponseDto;
import org.winey.server.controller.response.feed.*;
import org.winey.server.domain.feed.Feed;
import org.winey.server.domain.goal.Goal;
Expand Down Expand Up @@ -223,8 +223,8 @@ public GetFeedDetailResponseDto getFeedDetail(Long feedId, Long userId) {
.orElseThrow(() -> new NotFoundException(Error.NOT_FOUND_FEED_EXCEPTION, Error.NOT_FOUND_FEED_EXCEPTION.getMessage()));
User connectedUser = userRepository.findByUserId(userId)
.orElseThrow(() -> new NotFoundException(Error.NOT_FOUND_USER_EXCEPTION, Error.NOT_FOUND_USER_EXCEPTION.getMessage()));
List<GetCommentResponseDto> comments = commentRepository.findAllByFeedOrderByCreatedAtAsc(detailFeed)
.stream().map(comment -> GetCommentResponseDto.of(
List<CommentResponseDto> comments = commentRepository.findAllByFeedOrderByCreatedAtAsc(detailFeed)
.stream().map(comment -> CommentResponseDto.of(
comment.getCommentId(),
comment.getUser().getUserId(),
comment.getUser().getNickname(),
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/winey/server/service/auth/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

@Service
Expand Down Expand Up @@ -55,12 +56,18 @@ public SignInResponseDto signIn(String socialAccessToken, SignInRequestDto reque
Boolean isRegistered = userRepository.existsBySocialIdAndSocialType(socialId, socialType);

if (!isRegistered) {
String randomString= new Random().ints(6, 0, 36).mapToObj(i -> Character.toString("abcdefghijklmnopqrstuvwxyz0123456789".charAt(i))).collect(Collectors.joining());
while (userRepository.existsByNickname("์œ„๋‹ˆ"+randomString)) {
randomString = new Random().ints(6, 0, 36).mapToObj(i -> Character.toString("abcdefghijklmnopqrstuvwxyz0123456789".charAt(i))).collect(Collectors.joining());
}

User newUser = User.builder()
.nickname(socialType + socialId)
.nickname("์œ„๋‹ˆ"+randomString)
.socialId(socialId)
.socialType(socialType).build();
userRepository.save(newUser);


Notification newNoti = Notification.builder()
.notiReciver(newUser)
.notiMessage(NotiType.HOWTOLEVELUP.getType())
Expand Down

0 comments on commit b3c4982

Please sign in to comment.