Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public enum ErrorCode implements ResponseCode {
/**
* 150000 : Category error
*/
CATEGORY_NOT_FOUND(HttpStatus.NOT_FOUND, 150000, "존재하지 않는 CATEGORY 입니다.")
CATEGORY_NOT_FOUND(HttpStatus.NOT_FOUND, 150000, "존재하지 않는 CATEGORY 입니다."),
CATEGORY_NOT_MATCH(HttpStatus.BAD_REQUEST, 150001, "일치하는 카테고리 이름이 없습니다.")

;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import konkuk.thip.book.adapter.out.jpa.BookJpaEntity;
import konkuk.thip.room.adapter.out.jpa.CategoryJpaEntity;
import konkuk.thip.room.adapter.out.jpa.RoomJpaEntity;
import konkuk.thip.room.domain.Category;
import konkuk.thip.room.domain.Room;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -36,7 +37,7 @@ public Room toDomainEntity(RoomJpaEntity roomJpaEntity) {
.endDate(roomJpaEntity.getEndDate())
.recruitCount(roomJpaEntity.getRecruitCount())
.bookId(roomJpaEntity.getBookJpaEntity().getBookId())
.categoryId(roomJpaEntity.getCategoryJpaEntity().getCategoryId())
.category(Category.from(roomJpaEntity.getCategoryJpaEntity().getValue()))
.createdAt(roomJpaEntity.getCreatedAt())
.modifiedAt(roomJpaEntity.getModifiedAt())
.status(roomJpaEntity.getStatus())
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Long save(Room room) {
() -> new EntityNotFoundException(BOOK_NOT_FOUND)
);

CategoryJpaEntity categoryJpaEntity = categoryJpaRepository.findById(room.getCategoryId()).orElseThrow(
CategoryJpaEntity categoryJpaEntity = categoryJpaRepository.findByValue(room.getCategory().getValue()).orElseThrow(
() -> new EntityNotFoundException(CATEGORY_NOT_FOUND)
);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import konkuk.thip.common.exception.EntityNotFoundException;
import konkuk.thip.room.application.port.in.RoomCreateUseCase;
import konkuk.thip.room.application.port.in.dto.RoomCreateCommand;
import konkuk.thip.room.application.port.out.CategoryCommandPort;
import konkuk.thip.room.application.port.out.RoomCommandPort;
import konkuk.thip.room.domain.Category;
import konkuk.thip.room.domain.Room;
Expand All @@ -19,15 +18,14 @@
public class RoomCreateService implements RoomCreateUseCase {

private final RoomCommandPort roomCommandPort;
private final CategoryCommandPort categoryCommandPort;
private final BookCommandPort bookCommandPort;
private final BookApiQueryPort bookApiQueryPort;

@Override
@Transactional
public Long createRoom(RoomCreateCommand command, Long userId) {
// 1. Category 찾기
Category category = categoryCommandPort.findByValue(command.category());
// 1. Category 생성
Category category = Category.from(command.category());

// 2. Book 찾기, 없으면 Book 로드 및 저장
Long bookId = resolveBookAndEnsurePage(command.isbn());
Expand All @@ -42,7 +40,7 @@ public Long createRoom(RoomCreateCommand command, Long userId) {
command.progressEndDate(),
command.recruitCount(),
bookId,
category.getId()
category
);

// TODO : 방 생성한 사람 (= api 호출 토큰에 포함된 userId) 이 해당 방에 속한 멤버라는 사실을 DB에 영속화 해야함
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import konkuk.thip.common.exception.BusinessException;
import konkuk.thip.room.adapter.in.web.response.RoomSearchResponse;
import konkuk.thip.room.adapter.out.persistence.CategoryName;
import konkuk.thip.room.domain.Category;
import konkuk.thip.room.adapter.out.persistence.RoomSearchSortParam;
import konkuk.thip.room.application.port.in.RoomSearchUseCase;
import konkuk.thip.room.application.port.out.RoomQueryPort;
Expand Down Expand Up @@ -59,7 +59,7 @@ private String validateCategory(String category) {
return "";
}
try {
CategoryName cat = CategoryName.from(category);
Category cat = Category.from(category);
return cat.getValue();
} catch (IllegalArgumentException ex) {
throw new BusinessException(CATEGORY_NOT_FOUND, ex);
Expand Down
33 changes: 26 additions & 7 deletions src/main/java/konkuk/thip/room/domain/Category.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
package konkuk.thip.room.domain;

import konkuk.thip.common.entity.BaseDomainEntity;
import konkuk.thip.common.exception.InvalidStateException;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
import lombok.RequiredArgsConstructor;

import java.util.Arrays;

import static konkuk.thip.common.exception.code.ErrorCode.CATEGORY_NOT_MATCH;

@Getter
@SuperBuilder
public class Category extends BaseDomainEntity {
@RequiredArgsConstructor
public enum Category {

private Long id;
/**
* DB에 저장되어 있는 모든 카테고리들의 이름
* TODO : DB에서 value를 통해 카테고리를 조회하는것보다 id로 조회하는게 성능상 좋으니, id 값도 같이 보관 ??
*/
SCIENCE_IT("과학/IT"),
Literature("문학"),
ART("예술"),
SOCIAL_SCIENCE("사회과학"),
HUMANITY("인문학");
Comment on lines +19 to +23
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

enum 상수명의 일관성을 개선해주세요.

enum 상수명이 일관되지 않습니다. Literature만 PascalCase이고 나머지는 UPPER_SNAKE_CASE입니다.

일관성을 위해 다음과 같이 수정하는 것을 권장합니다:

-    Literature("문학"),
+    LITERATURE("문학"),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
SCIENCE_IT("과학/IT"),
Literature("문학"),
ART("예술"),
SOCIAL_SCIENCE("사회과학"),
HUMANITY("인문학");
SCIENCE_IT("과학/IT"),
LITERATURE("문학"),
ART("예술"),
SOCIAL_SCIENCE("사회과학"),
HUMANITY("인문학");
🤖 Prompt for AI Agents
In src/main/java/konkuk/thip/room/domain/Category.java around lines 19 to 23,
the enum constant 'Literature' uses PascalCase while others use
UPPER_SNAKE_CASE, causing inconsistency. Rename 'Literature' to 'LITERATURE' to
match the UPPER_SNAKE_CASE style of the other enum constants for consistency.


private String value;
private final String value;

private Long aliasId;
public static Category from(String value) {
return Arrays.stream(Category.values())
.filter(categoryName -> categoryName.getValue().equals(value))
.findFirst()
.orElseThrow(
() -> new InvalidStateException(CATEGORY_NOT_MATCH)
);
}
}
6 changes: 3 additions & 3 deletions src/main/java/konkuk/thip/room/domain/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public class Room extends BaseDomainEntity {

private Long bookId;

private Long categoryId;
private Category category;

public static Room withoutId(String title, String description, boolean isPublic, String password, LocalDate startDate, LocalDate endDate, int recruitCount, Long bookId, Long categoryId) {
public static Room withoutId(String title, String description, boolean isPublic, String password, LocalDate startDate, LocalDate endDate, int recruitCount, Long bookId, Category category) {
validateVisibilityPasswordRule(isPublic, password);
validateDates(startDate, endDate);

Expand All @@ -60,7 +60,7 @@ public static Room withoutId(String title, String description, boolean isPublic,
.endDate(endDate)
.recruitCount(recruitCount)
.bookId(bookId)
.categoryId(categoryId)
.category(category)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static BookJpaEntity createBook() {

public static CategoryJpaEntity createCategory(AliasJpaEntity alias) {
return CategoryJpaEntity.builder()
.value("카테고리1")
.value("과학/IT") // 실제 존재하는 값
.aliasForCategoryJpaEntity(alias)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private void saveUserAndCategory() {
.build());

categoryJpaRepository.save(CategoryJpaEntity.builder()
.value("소설")
.value("과학/IT") // 실제 카테고리 값
.aliasForCategoryJpaEntity(alias)
.build());
}
Expand Down Expand Up @@ -121,11 +121,11 @@ private void saveBookWithoutPageCount() {
private Map<String, Object> buildRoomCreateRequest() {
Map<String, Object> request = new HashMap<>();
request.put("isbn", "9788954682152");
request.put("category", "소설");
request.put("category", "과학/IT"); // 실제 카테고리 값
request.put("roomName", "방이름");
request.put("description", "방설명");
request.put("progressStartDate", "2025.07.10");
request.put("progressEndDate", "2025.08.10");
request.put("progressStartDate", LocalDate.now().plusDays(1).format(DateTimeFormatter.ofPattern("yyyy.MM.dd")));
request.put("progressEndDate", LocalDate.now().plusDays(30).format(DateTimeFormatter.ofPattern("yyyy.MM.dd")));
request.put("recruitCount", 3);
request.put("password", null);
request.put("isPublic", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void setUp() {
userId = user.getUserId();

CategoryJpaEntity categoryJpaEntity = categoryJpaRepository.save(CategoryJpaEntity.builder()
.value("소설")
.value("과학/IT")
.aliasForCategoryJpaEntity(alias)
.build());

Expand Down
Loading