Skip to content

Commit

Permalink
Merge pull request #104 from WOONGEYA/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
Woongbin06 authored Oct 1, 2024
2 parents 16cce55 + 84554f1 commit 56c500d
Show file tree
Hide file tree
Showing 24 changed files with 201 additions and 254 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package com.woongeya.zoing.domain.like.presentation.dto.response;

import lombok.Getter;

@Getter
public class LikerResponseDto {

private Long id;
private String name;

public LikerResponseDto(Long id, String name) {
this.id = id;
this.name = name;
public record LikerResponseDto (
Long id,
String name
) {
public static LikerResponseDto of(Long id, String name) {
return new LikerResponseDto(id, name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public List<LikerResponseDto> execute(Long id) {
return likes.stream()
.map(like -> userFacade.getUserById(like.getUserId()))
.map(User::getName)
.map(name -> new LikerResponseDto(id, name))
.map(name -> LikerResponseDto.of(id, name))
.collect(Collectors.toList());

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package com.woongeya.zoing.domain.notice.presetation.dto.response;

import com.woongeya.zoing.domain.notice.domain.Notification;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class NotificationResponse {

private Long id;
private String title;
private String content;
private Long applicationId;
private Long projectId;
private Long toUserId;
private Long fromUserId;

public static NotificationResponse of(Notification notification) {
public record NotificationResponse (
Long id,
String title,
String content,
Long applicationId,
Long projectId,
Long toUserId,
Long fromUserId
) {
public static NotificationResponse from(Notification notification) {
return NotificationResponse.builder()
.id(notification.getId())
.title(notification.getTitle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public List<NotificationResponse> execute() {
notifications.forEach(Notification::checkState);

return notifications.stream()
.map(NotificationResponse::of)
.map(NotificationResponse::from)
.collect(Collectors.toList());
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/woongeya/zoing/domain/post/domain/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public void createAt() {
}

public void update(CreatePostRequest request) {
this.title = request.getTitle();
this.content = request.getContent();
this.imgUrl = request.getImgUrl();
this.title = request.title();
this.content = request.content();
this.imgUrl = request.imgUrl();
}

public Boolean isWriter(User user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@

import com.woongeya.zoing.domain.post.domain.Post;
import com.woongeya.zoing.domain.user.domain.User;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import jakarta.validation.constraints.NotNull;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class CreatePostRequest {

public record CreatePostRequest(
@NotNull
private String title;

String title,
@NotNull
private String content;

private String imgUrl;

String content,
String imgUrl
) {
public Post toEntity(User user) {
return Post.builder()
.title(title)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
package com.woongeya.zoing.domain.post.presetation.dto.response;

import java.time.LocalDateTime;

import com.woongeya.zoing.domain.post.domain.Post;
import com.woongeya.zoing.domain.user.domain.User;
import com.woongeya.zoing.domain.user.presetation.dto.response.UserResponseDto;
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDateTime;
import lombok.Builder;

@Getter
@Builder
public class PostResponse {

private Long id;
private String title;
private String content;
private Integer viewCount;
private Integer commentCount;
private String postImg;
private LocalDateTime createTime;
private Long userId;
private String userNickName;
private String userImg;

public record PostResponse(
Long id,
String title,
String content,
Integer viewCount,
Integer commentCount,
String postImg,
LocalDateTime createTime,
Long userId,
String userNickName,
String userImg
) {
public static PostResponse of(Post post, User user) {
return PostResponse.builder()
.id(post.getId())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
package com.woongeya.zoing.domain.post.presetation.dto.response;

import lombok.Builder;
import lombok.Getter;

import java.util.List;

@Getter
@Builder
public class PostResponseList {

private List<PostResponse> postResponses;

public static PostResponseList of(List<PostResponse> postResponses) {
return PostResponseList.builder()
.postResponses(postResponses)
.build();
public record PostResponseList(
List<PostResponse> postResponses
) {
public static PostResponseList from(List<PostResponse> postResponses) {
return new PostResponseList(postResponses);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class QueryPostService {
public PostResponseList execute() {
List<Post> posts = postRepository.findAll();

return PostResponseList.of(
return PostResponseList.from(
posts.stream()
.map(post -> PostResponse.of(post, userFacade.getUserById(post.getWriter())))
.collect(Collectors.toList())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.woongeya.zoing.domain.post.service.qeury;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.woongeya.zoing.domain.post.domain.Post;
import com.woongeya.zoing.domain.post.domain.repository.PostRepository;
import com.woongeya.zoing.domain.post.presetation.dto.response.PostResponse;
import com.woongeya.zoing.domain.post.presetation.dto.response.PostResponseList;
import com.woongeya.zoing.domain.user.UserFacade;
import com.woongeya.zoing.domain.user.domain.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Service
Expand All @@ -24,7 +25,7 @@ public class QuerySearchPostService {
public PostResponseList execute(String q) {
List<Post> posts = postRepository.searchPost(q);

return PostResponseList.of(
return PostResponseList.from(
posts.stream()
.map(post -> PostResponse.of(post, userFacade.getUserById(post.getWriter())))
.collect(Collectors.toList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ public void createAt() {
}

public void update(CreateProjectRequestDto request) {
this.name = request.getName();
this.imgUrl = request.getImgUrl();
this.requiredPeople = request.getRequiredPeople();
this.content = request.getContent();
this.endDate = request.getEndDate();
this.name = request.name();
this.imgUrl = request.imgUrl();
this.requiredPeople = request.requiredPeople();
this.content = request.content();
this.endDate = request.endDate();
}

public void isFull() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
package com.woongeya.zoing.domain.project.presetation.dto.request;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import jakarta.validation.constraints.NotNull;
import java.time.LocalDate;
import java.util.List;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class CreateProjectRequestDto {

@NotNull
private String name;

@NotNull
private String content;

@NotNull
private Integer requiredPeople;
import com.woongeya.zoing.domain.project.domain.Project;
import com.woongeya.zoing.domain.project.domain.type.ProjectState;

@NotNull
private LocalDate endDate;

private String imgUrl;

private List<String> skills;

private List<String> coops;

private List<String> moods;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;

private List<String> positions;
public record CreateProjectRequestDto (
@NotNull String name,
@NotNull String content,
@NotNull Integer requiredPeople,
@NotNull LocalDate endDate,
String imgUrl,
List<String> skills,
List<String> coops,
List<String> moods,
List<String> positions
) {

public Project toEntity() {
return Project.builder()
.name(name)
.content(content)
.requiredPeople(requiredPeople)
.endDate(endDate)
.imgUrl(imgUrl)
.currentPeople(1)
.state(ProjectState.FINDING)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package com.woongeya.zoing.domain.project.presetation.dto.request;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class MemberRequestDto {

private Long memberId;
public record MemberRequestDto (
Long memberId
) {
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.woongeya.zoing.domain.project.presetation.dto.response;

import lombok.Getter;

@Getter
public class ImageResponseDto {

private String imgUrl;

public ImageResponseDto(String imgUrl) {
this.imgUrl = imgUrl;
public record ImageResponseDto (
String imgUrl
){
public static ImageResponseDto from(String imgUrl) {
return new ImageResponseDto(imgUrl);
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
package com.woongeya.zoing.domain.project.presetation.dto.response;

import com.woongeya.zoing.domain.project.domain.Member;
import com.woongeya.zoing.domain.user.domain.User;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class MemberResponseDto {

private Long userId;
private String name;
private String imgUrl;

public static MemberResponseDto of(User user) {
return MemberResponseDto.builder()
.userId(user.getId())
.name(user.getName())
.imgUrl(user.getImgUrl())
.build();
public record MemberResponseDto (
Long userId,
String name,
String imgUrl
){
public static MemberResponseDto from(User user) {
return new MemberResponseDto(user.getId(), user.getName(), user.getImgUrl());
}
}
Loading

0 comments on commit 56c500d

Please sign in to comment.