Skip to content

Commit

Permalink
🎨 Style: 코드 포멧팅 적용
Browse files Browse the repository at this point in the history
<body>
- code formatting
  - 자동 수정 기능을 이용하여 수정 진행

<footer>
- 관련: #28
  • Loading branch information
luke0408 committed Mar 2, 2024
1 parent fd4478d commit d2eb83e
Show file tree
Hide file tree
Showing 118 changed files with 3,755 additions and 3,455 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# namo

### ERD Cloud

https://www.erdcloud.com/d/kdtBpLtftuRiBXdvc
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repositories {
}

dependencies {
//data
// data
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.mysql:mysql-connector-j'
implementation group: 'org.hibernate', name: 'hibernate-spatial', version: '6.2.0.CR3' // point 저장
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/example/namo2/Namo2Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

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

@SpringBootApplication
@EnableJpaAuditing
public class Namo2Application {

public static void main(String[] args) {
SpringApplication.run(Namo2Application.class, args);
}
public static void main(String[] args) {
SpringApplication.run(Namo2Application.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.example.namo2.domain.category.application;

import java.util.List;

import org.springframework.stereotype.Component;

import com.example.namo2.domain.category.application.converter.CategoryConverter;
import com.example.namo2.domain.category.application.converter.CategoryResponseConverter;
import com.example.namo2.domain.category.application.impl.CategoryService;
Expand All @@ -8,44 +12,42 @@
import com.example.namo2.domain.category.domain.Palette;
import com.example.namo2.domain.category.ui.dto.CategoryRequest;
import com.example.namo2.domain.category.ui.dto.CategoryResponse;

import com.example.namo2.domain.user.application.impl.UserService;
import com.example.namo2.domain.user.domain.User;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor
public class CategoryFacade {
private final CategoryService categoryService;
private final PaletteService paletteService;
private final UserService userService;
private final CategoryService categoryService;
private final PaletteService paletteService;
private final UserService userService;

public CategoryResponse.CategoryIdDto create(Long userId, CategoryRequest.PostCategoryDto dto) {
User user = userService.getUser(userId);
Palette palette = paletteService.getPalette(dto.getPaletteId());
Category category = CategoryConverter.toCategory(dto, user, palette);
Category savedCategory = categoryService.create(category);
public CategoryResponse.CategoryIdDto create(Long userId, CategoryRequest.PostCategoryDto dto) {
User user = userService.getUser(userId);
Palette palette = paletteService.getPalette(dto.getPaletteId());
Category category = CategoryConverter.toCategory(dto, user, palette);
Category savedCategory = categoryService.create(category);

return CategoryResponseConverter.toCategoryIdDto(savedCategory);
}
return CategoryResponseConverter.toCategoryIdDto(savedCategory);
}

public List<CategoryResponse.CategoryDto> getCategories(Long userId) {
List<Category> categories = categoryService.getCategories(userId);
public List<CategoryResponse.CategoryDto> getCategories(Long userId) {
List<Category> categories = categoryService.getCategories(userId);

return CategoryResponseConverter.toCategoryDtoList(categories);
}
return CategoryResponseConverter.toCategoryDtoList(categories);
}

public CategoryResponse.CategoryIdDto modifyCategory(Long categoryId, CategoryRequest.PostCategoryDto dto) {
Palette palette = paletteService.getPalette(dto.getPaletteId());
Category modifiedCategory = categoryService.modifyCategory(categoryId, dto, palette);
public CategoryResponse.CategoryIdDto modifyCategory(Long categoryId, CategoryRequest.PostCategoryDto dto) {
Palette palette = paletteService.getPalette(dto.getPaletteId());
Category modifiedCategory = categoryService.modifyCategory(categoryId, dto, palette);

return CategoryResponseConverter.toCategoryIdDto(modifiedCategory);
}
return CategoryResponseConverter.toCategoryIdDto(modifiedCategory);
}

public void deleteCategory(Long categoryId) {
categoryService.delete(categoryId);
}
public void deleteCategory(Long categoryId) {
categoryService.delete(categoryId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,39 @@
import com.example.namo2.domain.category.domain.Category;
import com.example.namo2.domain.category.domain.Palette;
import com.example.namo2.domain.category.ui.dto.CategoryRequest;

import com.example.namo2.domain.user.domain.User;

public class CategoryConverter {

private CategoryConverter() {
throw new IllegalStateException("Utility class");
}
private CategoryConverter() {
throw new IllegalStateException("Utility class");
}

public static Category toCategory(
CategoryRequest.PostCategoryDto dto,
User user,
Palette palette
) {
return Category.builder()
.name(dto.getName())
.user(user)
.palette(palette)
.share(dto.isShare())
.build();
}
public static Category toCategory(
CategoryRequest.PostCategoryDto dto,
User user,
Palette palette
) {
return Category.builder()
.name(dto.getName())
.user(user)
.palette(palette)
.share(dto.isShare())
.build();
}

public static Category toCategory(
String name,
Palette palette,
Boolean isShare,
User user
) {
return Category.builder()
.name(name)
.palette(palette)
.share(isShare)
.user(user)
.build();
}
public static Category toCategory(
String name,
Palette palette,
Boolean isShare,
User user
) {
return Category.builder()
.name(name)
.palette(palette)
.share(isShare)
.user(user)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
package com.example.namo2.domain.category.application.converter;

import com.example.namo2.domain.category.domain.Category;
import com.example.namo2.domain.category.ui.dto.CategoryResponse;

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

import com.example.namo2.domain.category.domain.Category;
import com.example.namo2.domain.category.ui.dto.CategoryResponse;

public class CategoryResponseConverter {

private CategoryResponseConverter() {
throw new IllegalStateException("Utility class");
}
private CategoryResponseConverter() {
throw new IllegalStateException("Utility class");
}

public static CategoryResponse.CategoryIdDto toCategoryIdDto(Category category) {
return new CategoryResponse.CategoryIdDto(category.getId());
}
public static CategoryResponse.CategoryIdDto toCategoryIdDto(Category category) {
return new CategoryResponse.CategoryIdDto(category.getId());
}

public static List<CategoryResponse.CategoryDto> toCategoryDtoList(List<Category> categories) {
return categories.stream()
.map(CategoryResponseConverter::toCategoryDto)
.collect(Collectors.toList());
}
public static List<CategoryResponse.CategoryDto> toCategoryDtoList(List<Category> categories) {
return categories.stream()
.map(CategoryResponseConverter::toCategoryDto)
.collect(Collectors.toList());
}

public static CategoryResponse.CategoryDto toCategoryDto(Category category) {
return new CategoryResponse.CategoryDto(
category.getId(),
category.getName(),
category.getPalette().getId(),
category.getShare()
);
}
public static CategoryResponse.CategoryDto toCategoryDto(Category category) {
return new CategoryResponse.CategoryDto(
category.getId(),
category.getName(),
category.getPalette().getId(),
category.getShare()
);
}
}
Original file line number Diff line number Diff line change
@@ -1,50 +1,53 @@
package com.example.namo2.domain.category.application.impl;

import static com.example.namo2.global.common.response.BaseResponseStatus.*;

import java.util.List;

import org.springframework.stereotype.Service;

import com.example.namo2.domain.category.dao.repository.CategoryRepository;
import com.example.namo2.domain.category.domain.Category;
import com.example.namo2.domain.category.domain.CategoryStatus;
import com.example.namo2.domain.category.domain.Palette;
import com.example.namo2.domain.category.ui.dto.CategoryRequest;

import com.example.namo2.domain.user.domain.User;
import com.example.namo2.global.common.exception.BaseException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import com.example.namo2.global.common.exception.BaseException;

import static com.example.namo2.global.common.response.BaseResponseStatus.NOT_FOUND_CATEGORY_FAILURE;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class CategoryService {
private final CategoryRepository categoryRepository;

public Category create(Category category) {
return categoryRepository.save(category);
}

public List<Category> getCategories(Long userId) {
return categoryRepository.findCategoriesByUserIdAndStatusEquals(userId, CategoryStatus.ACTIVE);
}

public void delete(Long categoryId) {
Category category = getCategory(categoryId);
category.delete();
}


public Category getCategory(Long categoryId) {
return categoryRepository.findById(categoryId)
.orElseThrow(() -> new BaseException(NOT_FOUND_CATEGORY_FAILURE));
}

public Category modifyCategory(Long categoryId, CategoryRequest.PostCategoryDto dto, Palette palette) {
Category category = getCategory(categoryId);
category.update(dto.getName(), dto.isShare(), palette);
return category;
}

public List<Category> getMoimUsersCategories(List<User> users) {
return categoryRepository.findMoimCategoriesByUsers(users);
}
private final CategoryRepository categoryRepository;

public Category create(Category category) {
return categoryRepository.save(category);
}

public List<Category> getCategories(Long userId) {
return categoryRepository.findCategoriesByUserIdAndStatusEquals(userId, CategoryStatus.ACTIVE);
}

public void delete(Long categoryId) {
Category category = getCategory(categoryId);
category.delete();
}

public Category getCategory(Long categoryId) {
return categoryRepository.findById(categoryId)
.orElseThrow(() -> new BaseException(NOT_FOUND_CATEGORY_FAILURE));
}

public Category modifyCategory(Long categoryId, CategoryRequest.PostCategoryDto dto, Palette palette) {
Category category = getCategory(categoryId);
category.update(dto.getName(), dto.isShare(), palette);
return category;
}

public List<Category> getMoimUsersCategories(List<User> users) {
return categoryRepository.findMoimCategoriesByUsers(users);
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
package com.example.namo2.domain.category.application.impl;

import static com.example.namo2.global.common.response.BaseResponseStatus.*;

import org.springframework.stereotype.Service;

import com.example.namo2.domain.category.dao.repository.PaletteRepository;
import com.example.namo2.domain.category.domain.Palette;

import com.example.namo2.global.common.exception.BaseException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import static com.example.namo2.global.common.response.BaseResponseStatus.NOT_FOUND_PALETTE_FAILURE;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class PaletteService {

private final PaletteRepository paletteRepository;
private final PaletteRepository paletteRepository;

public Palette getPalette(Long paletteId) {
return paletteRepository.findById(paletteId)
.orElseThrow(() -> new BaseException(NOT_FOUND_PALETTE_FAILURE));
}
public Palette getPalette(Long paletteId) {
return paletteRepository.findById(paletteId)
.orElseThrow(() -> new BaseException(NOT_FOUND_PALETTE_FAILURE));
}

public Palette getReferenceById(Long id){
return paletteRepository.getReferenceById(id);
}
public Palette getReferenceById(Long id) {
return paletteRepository.getReferenceById(id);
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package com.example.namo2.domain.category.dao.repository;

import com.example.namo2.domain.category.ui.dto.MoimCategoryDto;
import com.example.namo2.domain.category.domain.Category;
import com.example.namo2.domain.category.domain.CategoryStatus;
import com.example.namo2.domain.user.domain.User;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import com.example.namo2.domain.category.domain.Category;
import com.example.namo2.domain.category.domain.CategoryStatus;

import com.example.namo2.domain.user.domain.User;

public interface CategoryRepository extends JpaRepository<Category, Long> {
public List<Category> findCategoriesByUserIdAndStatusEquals(Long userId, CategoryStatus status);
public List<Category> findCategoriesByUserIdAndStatusEquals(Long userId, CategoryStatus status);

@Query(value = "select c" +
" from Category c" +
" join fetch c.user" +
" where c.user in :users and c.name = '모임'")
List<Category> findMoimCategoriesByUsers(@Param("users") List<User> users);
@Query(value = "select c"
+ " from Category c"
+ " join fetch c.user"
+ " where c.user in :users and c.name = '모임'")
List<Category> findMoimCategoriesByUsers(@Param("users") List<User> users);
}
Loading

0 comments on commit d2eb83e

Please sign in to comment.