Skip to content

Commit

Permalink
[chore] #5 멀티 모듈 패키지 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
SunwoongH committed Nov 9, 2023
1 parent a28c96f commit 3728455
Show file tree
Hide file tree
Showing 30 changed files with 109 additions and 88 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.sopt.common;
package org.sopt.api.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import org.sopt.error.ErrorStatus;
import org.sopt.common.error.ErrorStatus;
import org.springframework.http.ResponseEntity;

@Builder(access = AccessLevel.PRIVATE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.common;
package org.sopt.api.common;

import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.sopt.error;
package org.sopt.api.error;

import lombok.extern.slf4j.Slf4j;
import org.sopt.common.ApiResponse;
import org.sopt.api.common.ApiResponse;
import org.sopt.common.error.BusinessException;
import org.sopt.common.error.ErrorStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.sopt.member.api;
package org.sopt.api.member.api;

import lombok.RequiredArgsConstructor;
import org.sopt.common.ApiResponse;
import org.sopt.common.SuccessStatus;
import org.sopt.member.dto.request.MemberSaveRequest;
import org.sopt.member.dto.request.MemberUpdateRequest;
import org.sopt.member.dto.response.MemberGetResponse;
import org.sopt.member.dto.response.MemberSaveResponse;
import org.sopt.member.service.MemberService;
import org.sopt.api.common.ApiResponse;
import org.sopt.api.common.SuccessStatus;
import org.sopt.api.member.dto.request.MemberSaveRequest;
import org.sopt.api.member.dto.request.MemberUpdateRequest;
import org.sopt.api.member.dto.response.MemberGetResponse;
import org.sopt.api.member.dto.response.MemberSaveResponse;
import org.sopt.api.member.service.MemberService;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.sopt.member.dto.request;
package org.sopt.api.member.dto.request;

import org.sopt.member.domain.Sopt;
import org.sopt.domain.member.domain.Sopt;

public record MemberSaveRequest(
String name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.sopt.member.dto.request;
package org.sopt.api.member.dto.request;

import org.sopt.member.domain.Part;
import org.sopt.domain.member.domain.Part;

public record MemberUpdateRequest(
int generation,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.sopt.member.dto.response;
package org.sopt.api.member.dto.response;

import lombok.AccessLevel;
import lombok.Builder;
import org.sopt.member.domain.Member;
import org.sopt.member.domain.Sopt;
import org.sopt.domain.member.domain.Member;
import org.sopt.domain.member.domain.Sopt;

@Builder(access = AccessLevel.PRIVATE)
public record MemberGetResponse(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.sopt.member.dto.response;
package org.sopt.api.member.dto.response;

import org.sopt.member.domain.Member;
import org.sopt.domain.member.domain.Member;

public record MemberSaveResponse(
Long memberId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package org.sopt.member.service;
package org.sopt.api.member.service;

import lombok.RequiredArgsConstructor;
import org.sopt.error.ConflictException;
import org.sopt.error.ErrorStatus;
import org.sopt.member.domain.Member;
import org.sopt.member.domain.Sopt;
import org.sopt.member.dto.request.MemberSaveRequest;
import org.sopt.member.dto.request.MemberUpdateRequest;
import org.sopt.member.dto.response.MemberGetResponse;
import org.sopt.member.dto.response.MemberSaveResponse;
import org.sopt.member.repository.MemberRepository;
import org.sopt.common.error.ConflictException;
import org.sopt.common.error.ErrorStatus;
import org.sopt.domain.member.domain.Member;
import org.sopt.domain.member.domain.Sopt;
import org.sopt.api.member.dto.request.MemberSaveRequest;
import org.sopt.api.member.dto.request.MemberUpdateRequest;
import org.sopt.api.member.dto.response.MemberGetResponse;
import org.sopt.api.member.dto.response.MemberSaveResponse;
import org.sopt.domain.member.repository.MemberRepository;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static org.sopt.member.domain.Member.createMember;
import static org.sopt.domain.member.domain.Member.createMember;

@RequiredArgsConstructor
@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.sopt.post.api;
package org.sopt.api.post.api;

import lombok.RequiredArgsConstructor;
import org.sopt.common.ApiResponse;
import org.sopt.common.SuccessStatus;
import org.sopt.post.dto.request.PostSaveOrUpdateRequest;
import org.sopt.post.dto.response.PostGetResponse;
import org.sopt.post.dto.response.PostSaveResponse;
import org.sopt.post.service.PostService;
import org.sopt.api.common.ApiResponse;
import org.sopt.api.common.SuccessStatus;
import org.sopt.api.post.dto.request.PostSaveOrUpdateRequest;
import org.sopt.api.post.dto.response.PostGetResponse;
import org.sopt.api.post.dto.response.PostSaveResponse;
import org.sopt.api.post.service.PostService;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.post.dto.request;
package org.sopt.api.post.dto.request;

public record PostSaveOrUpdateRequest(
String title,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.sopt.post.dto.response;
package org.sopt.api.post.dto.response;

import lombok.AccessLevel;
import lombok.Builder;
import org.sopt.post.domain.Category;
import org.sopt.post.domain.Post;
import org.sopt.domain.post.domain.Category;
import org.sopt.domain.post.domain.Post;

@Builder(access = AccessLevel.PRIVATE)
public record PostGetResponse(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.sopt.post.dto.response;
package org.sopt.api.post.dto.response;

import org.sopt.post.domain.Post;
import org.sopt.domain.post.domain.Post;

public record PostSaveResponse(
Long postId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package org.sopt.post.service;
package org.sopt.api.post.service;

import lombok.RequiredArgsConstructor;
import org.sopt.member.domain.Member;
import org.sopt.member.repository.MemberRepository;
import org.sopt.post.domain.Category;
import org.sopt.post.domain.Post;
import org.sopt.post.dto.request.PostSaveOrUpdateRequest;
import org.sopt.post.dto.response.PostGetResponse;
import org.sopt.post.dto.response.PostSaveResponse;
import org.sopt.post.repository.CategoryRepository;
import org.sopt.post.repository.PostRepository;
import org.sopt.common.error.ConflictException;
import org.sopt.common.error.ErrorStatus;
import org.sopt.domain.member.domain.Member;
import org.sopt.domain.member.repository.MemberRepository;
import org.sopt.domain.post.domain.Category;
import org.sopt.domain.post.domain.Post;
import org.sopt.api.post.dto.request.PostSaveOrUpdateRequest;
import org.sopt.api.post.dto.response.PostGetResponse;
import org.sopt.api.post.dto.response.PostSaveResponse;

import org.sopt.domain.post.repository.CategoryRepository;
import org.sopt.domain.post.repository.PostRepository;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static org.sopt.domain.post.domain.Category.createCategory;
import static org.sopt.domain.post.domain.Post.createPost;

@RequiredArgsConstructor
@Transactional(readOnly = true)
@Service
Expand All @@ -27,6 +33,7 @@ public class PostService {
@Transactional
public PostSaveResponse savePost(Long memberId, PostSaveOrUpdateRequest postSaveOrUpdateRequest) {
Member findMember = findMember(memberId);
validateDuplicateCategory(postSaveOrUpdateRequest.categoryContent());
Category savedCategory = createCategoryAndGetSavedCategory(postSaveOrUpdateRequest);
Post savedPost = createPostAndGetSavedPost(postSaveOrUpdateRequest, findMember, savedCategory);
return PostSaveResponse.of(savedPost);
Expand Down Expand Up @@ -60,13 +67,19 @@ private Member findMember(Long memberId) {
return memberRepository.findByIdOrThrow(memberId);
}

private void validateDuplicateCategory(String content) {
if (categoryRepository.existsByContent(content)) {
throw new ConflictException(ErrorStatus.DUPLICATE_CATEGORY);
}
}

private Category createCategoryAndGetSavedCategory(PostSaveOrUpdateRequest postSaveOrUpdateRequest) {
Category category = Category.createCategory(postSaveOrUpdateRequest.categoryContent());
Category category = createCategory(postSaveOrUpdateRequest.categoryContent());
return categoryRepository.save(category);
}

private Post createPostAndGetSavedPost(PostSaveOrUpdateRequest postSaveOrUpdateRequest, Member member, Category category) {
Post post = Post.createPost(postSaveOrUpdateRequest.title(), postSaveOrUpdateRequest.postContent(), category, member);
Post post = createPost(postSaveOrUpdateRequest.title(), postSaveOrUpdateRequest.postContent(), category, member);
return postRepository.save(post);
}

Expand Down
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ subprojects {
useJUnitPlatform()
}

jar {
bootJar {
enabled = false
}

jar {
enabled = true
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.error;
package org.sopt.common.error;

import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.error;
package org.sopt.common.error;

public class ConflictException extends BusinessException {
public ConflictException() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.error;
package org.sopt.common.error;

public class EntityNotFoundException extends BusinessException {
public EntityNotFoundException() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.error;
package org.sopt.common.error;

import lombok.AccessLevel;
import lombok.Getter;
Expand Down Expand Up @@ -30,6 +30,7 @@ public enum ErrorStatus {
*/
CONFLICT(HttpStatus.CONFLICT, "이미 존재하는 리소스입니다."),
DUPLICATE_MEMBER(HttpStatus.CONFLICT, "이미 존재하는 회원입니다."),
DUPLICATE_CATEGORY(HttpStatus.CONFLICT, "이미 존재하는 카테고리입니다."),

/**
* 500 Internal Server Error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.error;
package org.sopt.common.error;

public class InvalidValueException extends BusinessException {
public InvalidValueException() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.common;
package org.sopt.domain.common;

import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.config;
package org.sopt.domain.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.sopt.member.domain;
package org.sopt.domain.member.domain;

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.DynamicUpdate;
import org.sopt.common.BaseTimeEntity;
import org.sopt.post.domain.Post;
import org.sopt.domain.common.BaseTimeEntity;
import org.sopt.domain.post.domain.Post;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.member.domain;
package org.sopt.domain.member.domain;

import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.member.domain;
package org.sopt.domain.member.domain;

import jakarta.persistence.Embeddable;
import jakarta.persistence.EnumType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.sopt.member.repository;
package org.sopt.domain.member.repository;

import org.sopt.error.EntityNotFoundException;
import org.sopt.error.ErrorStatus;
import org.sopt.member.domain.Member;
import org.sopt.common.error.EntityNotFoundException;
import org.sopt.common.error.ErrorStatus;
import org.sopt.domain.member.domain.Member;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MemberRepository extends JpaRepository<Member, Long> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.sopt.post.domain;
package org.sopt.domain.post.domain;

import jakarta.persistence.*;
import lombok.*;
import org.sopt.common.BaseTimeEntity;
import org.sopt.domain.common.BaseTimeEntity;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -14,11 +14,11 @@
@Entity
public class Category extends BaseTimeEntity {
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "category_id")
private Short id;
private String content;
@OneToMany
@OneToMany(mappedBy = "category")
@Builder.Default
private List<Post> posts = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.sopt.post.domain;
package org.sopt.domain.post.domain;

import jakarta.persistence.*;
import lombok.*;
import org.sopt.common.BaseTimeEntity;
import org.sopt.member.domain.Member;
import org.sopt.domain.common.BaseTimeEntity;
import org.sopt.domain.member.domain.Member;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.sopt.post.repository;
package org.sopt.domain.post.repository;

import org.sopt.post.domain.Category;
import org.sopt.domain.post.domain.Category;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CategoryRepository extends JpaRepository<Category, Short> {
boolean existsByContent(String content);
}
Loading

0 comments on commit 3728455

Please sign in to comment.