Skip to content

Commit

Permalink
✨ Feature: 기본 카테고리 로직 구현 (#80)
Browse files Browse the repository at this point in the history
* ✨ Feature: 회원가입 시 기본 카테고리 생성

* ✨ Feature: 스크랩 생성 시 기본 카테고리에 추가"

* ✨ Feature: 스크랩 카테고리 목록 조회 API에서 기본 카테고리 제외
  • Loading branch information
ahnsugyeong authored May 28, 2024
1 parent e92e941 commit bb53889
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
import zzangdol.auth.presentation.dto.request.SignInRequest;
import zzangdol.auth.presentation.dto.request.SignUpRequest;
import zzangdol.auth.presentation.dto.response.EmailVerificationTokenResponse;
import zzangdol.constant.Constants;
import zzangdol.exception.custom.UserCredentialsException;
import zzangdol.jwt.JwtResponse;
import zzangdol.jwt.JwtService;
import zzangdol.response.status.ErrorStatus;
import zzangdol.scrap.implement.CategoryCommandService;
import zzangdol.scrap.presentation.dto.request.CategoryCreateRequest;
import zzangdol.ses.service.AwsSesService;
import zzangdol.user.domain.User;

Expand All @@ -26,6 +29,7 @@ public class AuthFacade {
private final AwsSesService awsSesService;
private final VerificationCodeService verificationCodeService;
private final EmailVerificationTokenService emailVerificationTokenService;
private final CategoryCommandService categoryCommandService;

public boolean sendVerificationEmail(String email) {
if (!authService.isEmailAvailable(email)) {
Expand All @@ -49,6 +53,7 @@ public JwtResponse signUp(String emailVerificationToken, SignUpRequest request)
}
emailVerificationTokenService.verifyToken(request.getEmail(), emailVerificationToken);
User user = authService.signUp(request);
categoryCommandService.createCategory(user, new CategoryCreateRequest(Constants.DEFAULT_CATEGORY_NAME));
return jwtService.issueToken(user);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import zzangdol.constant.Constants;
import zzangdol.diary.domain.Diary;
import zzangdol.scrap.business.CategoryMapper;
import zzangdol.scrap.dao.CategoryRepository;
Expand Down Expand Up @@ -43,6 +44,7 @@ public List<CategoryResponse> getCategoryResponsesByUser(User user) {
public List<ScrapCategoryResponse> getScrapCategoryResponsesByUser(User user, Long diaryId) {
List<Category> categories = getCategoriesByUser(user);
return categories.stream()
.filter(category -> !category.getName().equals(Constants.DEFAULT_CATEGORY_NAME))
.map(category -> {
boolean isScrapped = scrapRepository.existsByCategoryAndUserAndDiary(category, user, diaryId);
String latestImageUrl = categoryRepository.findLatestDiaryImageUrlByCategoryId(category.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import zzangdol.constant.Constants;
import zzangdol.diary.dao.DiaryRepository;
import zzangdol.diary.domain.Diary;
import zzangdol.exception.custom.CategoryNotFoundException;
Expand Down Expand Up @@ -33,6 +34,10 @@ public Scrap createScrap(User user, Long diaryId) {
Diary diary = diaryRepository.findById(diaryId)
.orElseThrow(() -> DiaryNotFoundException.EXCEPTION);
Scrap scrap = buildScrap(user, diary);

Category defaultCategory = categoryRepository.findCategoryByUserAndName(user, Constants.DEFAULT_CATEGORY_NAME)
.orElseThrow(() -> CategoryNotFoundException.EXCEPTION);
addCategoryToScrap(user, scrap.getId(), defaultCategory.getId());
return scrapRepository.save(scrap);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public class Constants {

public static final String DEFAULT_IMAGE_URL = "https://moodoodle-dev.s3.ap-northeast-2.amazonaws.com/default_category_image.png";
public static final String DEFAULT_CATEGORY_NAME = "모든 카테고리";

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package zzangdol.scrap.dao;

import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import zzangdol.scrap.dao.querydsl.CategoryQueryRepository;
import zzangdol.scrap.domain.Category;
Expand All @@ -12,4 +13,6 @@ public interface CategoryRepository extends JpaRepository<Category, Long>, Categ

void deleteByUser(User user);

Optional<Category> findCategoryByUserAndName(User user, String name);

}

0 comments on commit bb53889

Please sign in to comment.