Skip to content

Commit

Permalink
refactor: 카테고리 웹소켓 api 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
yechop committed Feb 12, 2025
1 parent b66a3ad commit a818470
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public List<CategoryReadResponse> createCategory(@DestinationVariable("accessCod
return categoryService.findAllByPairRoomAccessCode(accessCode);
}

@MessageMapping("/{accessCode}/category/update")
@MessageMapping("/{accessCode}/category/update/{categoryId}")
@SendTo("/topic/{accessCode}/category")
public List<CategoryReadResponse> updateCategory(@DestinationVariable("accessCode") final String accessCode,
@DestinationVariable("categoryId") final long categoryId,
@Valid @RequestBody final CategoryUpdateRequest request) {
categoryService.updateCategoryName(accessCode, request);
categoryService.updateCategoryName(accessCode, categoryId, request);
return categoryService.findAllByPairRoomAccessCode(accessCode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public List<CategoryReadResponse> findAllByPairRoomAccessCode(final String acces
public CategoryCreateResponse createCategory(final String accessCode, final CategoryCreateRequest request) {
final PairRoomEntity pairRoomEntity = pairRoomRepository.fetchByAccessCode(new AccessCode(accessCode));
checkPairRoomIsActive(pairRoomEntity);
validateDuplicated(request.categoryName(), pairRoomEntity);
validateDuplicated(request.value(), pairRoomEntity);
final CategoryEntity categoryEntity = categoryRepository.save(
new CategoryEntity(pairRoomEntity, new Category(request.categoryName())));
new CategoryEntity(pairRoomEntity, new Category(request.value())));

return CategoryCreateResponse.from(categoryEntity);
}
Expand All @@ -56,13 +56,14 @@ private void validateDuplicated(final String categoryName, final PairRoomEntity
}
}

public CategoryUpdateResponse updateCategoryName(final String accessCode, final CategoryUpdateRequest request) {
public CategoryUpdateResponse updateCategoryName(final String accessCode,
final long categoryId,
final CategoryUpdateRequest request) {
final PairRoomEntity pairRoomEntity = pairRoomRepository.fetchByAccessCode(new AccessCode(accessCode));
checkPairRoomIsActive(pairRoomEntity);
validateDuplicated(request.categoryName(), pairRoomEntity);
final CategoryEntity category = categoryRepository.fetchByPairRoomAndCategoryId(pairRoomEntity,
request.categoryId());
category.updateCategoryName(request.categoryName());
validateDuplicated(request.value(), pairRoomEntity);
final CategoryEntity category = categoryRepository.fetchByPairRoomAndCategoryId(pairRoomEntity, categoryId);
category.updateCategoryName(request.value());
return new CategoryUpdateResponse(category.getCategoryName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
public record CategoryCreateRequest(
@Schema(description = "카테고리 값", example = "스프링")
@NotBlank(message = "빈 카테고리는 허용하지 않습니다.")
String categoryName
String value
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public record CategoryReadResponse(
String id,

@Schema(description = "카테고리 값", example = "카테고리 없음")
String categoryName
String value
) {

public static CategoryReadResponse from(final CategoryEntity category) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package site.coduo.referencelink.service.dto;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "카테고리 수정 요청 바디")
public record CategoryUpdateRequest(
@Schema(description = "변경하고자 하는 카테고리 id", example = "자바")
@NotNull(message = "빈 카테고리는 허용하지 않습니다.")
Long categoryId,

@Schema(description = "수정할 카테고리 값", example = "스프링")
@NotBlank(message = "빈 카테고리는 허용하지 않습니다.")
String categoryName
String value
) {
}

0 comments on commit a818470

Please sign in to comment.