Skip to content

Commit

Permalink
feat : category domain controller dev (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingLeeSeungHoon committed May 5, 2024
1 parent 93594ed commit 5c84440
Show file tree
Hide file tree
Showing 11 changed files with 331 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ public class CategoryVoteFilterService {
private final ConfirmCategoryChangeableAdminService confirmCategoryChangeableAdminService;

@Transactional
public void modifyFilteringRate(CategoryId categoryId, String email, int changingRate){
Category foundCategory = findExistingCategory(categoryRepository, categoryId);
public void modifyFilteringRate(String categoryId, String email, int changingRate){
Category foundCategory = findExistingCategory(categoryRepository, CategoryId.of(categoryId));
foundCategory.modifyFilteringRate(confirmCategoryChangeableAdminService, email, changingRate);
}

@Transactional
public void useFilter(CategoryId categoryId, String email){
Category foundCategory = findExistingCategory(categoryRepository, categoryId);
public void useFilter(String categoryId, String email){
Category foundCategory = findExistingCategory(categoryRepository, CategoryId.of(categoryId));
foundCategory.turnOnCommentRatingFilter(confirmCategoryChangeableAdminService, email);
}

@Transactional
public void notUseFilter(CategoryId categoryId, String email){
Category foundCategory = findExistingCategory(categoryRepository, categoryId);
public void notUseFilter(String categoryId, String email){
Category foundCategory = findExistingCategory(categoryRepository, CategoryId.of(categoryId));
foundCategory.turnOffCommentRatingFilter(confirmCategoryChangeableAdminService, email);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.neo.needeachother.category.application;

import com.neo.needeachother.category.domain.Category;
import com.neo.needeachother.category.domain.ContentRestriction;
import com.neo.needeachother.category.domain.ContentType;
import com.neo.needeachother.category.domain.repository.CategoryRepository;
import com.neo.needeachother.starpage.domain.StarPage;
import com.neo.needeachother.starpage.domain.StarPageId;
import com.neo.needeachother.starpage.domain.domainservice.CreateCategoryFromStarPageService;
import com.neo.needeachother.starpage.domain.repository.StarPageRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import static com.neo.needeachother.starpage.application.StarPageServiceHelper.*;

@Service
@RequiredArgsConstructor
public class CreateCategoryService {

private final StarPageRepository starPageRepository;
private final CreateCategoryFromStarPageService createCategoryFromStarPageService;
private final CategoryRepository categoryRepository;

public void createCategory(String starPageId, String title, String categoryType,
boolean isWriteHostOnly,
boolean isCommentWriteAble,
boolean isUsingRatingFilter,
int filteringRate){
ContentType categoryContentType = ContentType.valueOf(categoryType);
switch (categoryContentType){
case COMMON -> this.createCommonCategory(starPageId, title, isWriteHostOnly,
isCommentWriteAble, isUsingRatingFilter, filteringRate);
case ALBUM -> this.createAlbumCategory(starPageId, title, isWriteHostOnly,
isCommentWriteAble, isUsingRatingFilter, filteringRate);
case VOTE -> this.createVoteCategory(starPageId, title, isWriteHostOnly,
isCommentWriteAble, isUsingRatingFilter, filteringRate);
case GOLD_BALANCE -> this.createGoldBalanceCategory(starPageId, title, isWriteHostOnly,
isCommentWriteAble, isUsingRatingFilter, filteringRate);
}
}

@Transactional
public void createCommonCategory(String starPageId, String title,
boolean isWriteHostOnly,
boolean isCommentWriteAble,
boolean isUsingRatingFilter,
int filteringRate){
StarPage foundStarPage = findExistingStarPage(starPageRepository, StarPageId.of(starPageId));
Category createdCategory = foundStarPage
.createCommonTypeCategory(createCategoryFromStarPageService, title,
ContentRestriction.of(isWriteHostOnly, isCommentWriteAble, isUsingRatingFilter, filteringRate));
categoryRepository.save(createdCategory);
}


@Transactional
public void createAlbumCategory(String starPageId, String title,
boolean isWriteHostOnly,
boolean isCommentWriteAble,
boolean isUsingRatingFilter,
int filteringRate){
StarPage foundStarPage = findExistingStarPage(starPageRepository, StarPageId.of(starPageId));
Category createdCategory = foundStarPage
.createAlbumTypeCategory(createCategoryFromStarPageService, title,
ContentRestriction.of(isWriteHostOnly, isCommentWriteAble, isUsingRatingFilter, filteringRate));
categoryRepository.save(createdCategory);
}

@Transactional
public void createGoldBalanceCategory(String starPageId, String title,
boolean isWriteHostOnly,
boolean isCommentWriteAble,
boolean isUsingRatingFilter,
int filteringRate){
StarPage foundStarPage = findExistingStarPage(starPageRepository, StarPageId.of(starPageId));
Category createdCategory = foundStarPage
.createGoldBalanceTypeCategory(createCategoryFromStarPageService, title,
ContentRestriction.of(isWriteHostOnly, isCommentWriteAble, isUsingRatingFilter, filteringRate));
categoryRepository.save(createdCategory);
}


@Transactional
public void createVoteCategory(String starPageId, String title,
boolean isWriteHostOnly,
boolean isCommentWriteAble,
boolean isUsingRatingFilter,
int filteringRate){
StarPage foundStarPage = findExistingStarPage(starPageRepository, StarPageId.of(starPageId));
Category createdCategory = foundStarPage
.createVoteTypeCategory(createCategoryFromStarPageService, title,
ContentRestriction.of(isWriteHostOnly, isCommentWriteAble, isUsingRatingFilter, filteringRate));
categoryRepository.save(createdCategory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public class ModifyCategoryStatusService {
private final ConfirmCategoryChangeableAdminService confirmCategoryChangeableAdminService;

@Transactional
public void reOpenCategory(CategoryId id, String email){
Category foundCategory = findExistingCategory(categoryRepository, id);
public void reOpenCategory(String categoryId, String email){
Category foundCategory = findExistingCategory(categoryRepository, CategoryId.of(categoryId));
foundCategory.reOpenCategory(confirmCategoryChangeableAdminService, email);
}

@Transactional
public void deleteCategory(CategoryId id, String email){
Category foundCategory = findExistingCategory(categoryRepository, id);
public void deleteCategory(String categoryId, String email){
Category foundCategory = findExistingCategory(categoryRepository, CategoryId.of(categoryId));
foundCategory.deleteCategory(confirmCategoryChangeableAdminService, email);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.neo.needeachother.category.representation;

import com.neo.needeachother.category.application.CreateCategoryService;
import com.neo.needeachother.category.representation.dto.CategoryCreationRequest;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/category")
public class CategoryCreationController {

private final CreateCategoryService createCategoryService;

@PostMapping()
public void demandCreateCategory(@Valid @RequestBody CategoryCreationRequest categoryCreationRequest) {
createCategoryService.createCategory(
categoryCreationRequest.getStarPageId(),
categoryCreationRequest.getCategoryTitle(),
categoryCreationRequest.getCategoryType(),
categoryCreationRequest.isWriteHostOnly(),
categoryCreationRequest.isCommentWriteAble(),
categoryCreationRequest.isUsingRatingFilter(),
categoryCreationRequest.getFilteringRate()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.neo.needeachother.category.representation;

public class CategoryInfromationModifyController {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.neo.needeachother.category.representation;

import com.neo.needeachother.category.application.ModifyCategoryStatusService;
import com.neo.needeachother.category.representation.dto.CategoryStatusModifyRequest;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/category")
public class CategoryStatusModifyController {

private final ModifyCategoryStatusService modifyCategoryStatusService;

@DeleteMapping("/{category_id}")
private void demandDeleteCategory(
@PathVariable("category_id") String categoryId,
@Valid @RequestBody CategoryStatusModifyRequest categoryStatusModifyRequest
) {
modifyCategoryStatusService.deleteCategory(categoryId, categoryStatusModifyRequest.getEmail());
}

@PutMapping("/{category_id}")
private void demandOpenCategory(
@PathVariable("category_id") String categoryId,
@Valid @RequestBody CategoryStatusModifyRequest categoryStatusModifyRequest) {
modifyCategoryStatusService.reOpenCategory(categoryId, categoryStatusModifyRequest.getEmail());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.neo.needeachother.category.representation;

import com.neo.needeachother.category.application.CategoryVoteFilterService;
import com.neo.needeachother.category.representation.dto.CategoryVoteFilterRateChangeRequest;
import com.neo.needeachother.category.representation.dto.CategoryVoteFilterStatusChangeRequest;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/category")
public class CategoryVoteFilterController {

private final CategoryVoteFilterService categoryVoteFilterService;

@PutMapping("/{category_id}/filter")
public void demandUseOrNotFilter(
@PathVariable("category_id") String categoryId,
@Valid @RequestBody CategoryVoteFilterStatusChangeRequest voteFilterStatusChangeRequest,
@RequestParam("use") boolean useFilter
) {
if (useFilter) {
categoryVoteFilterService.useFilter(categoryId, voteFilterStatusChangeRequest.getEmail());
} else {
categoryVoteFilterService.notUseFilter(categoryId, voteFilterStatusChangeRequest.getEmail());
}

}

@PutMapping("/{category_id}/filter/rate")
public void demandChangeFilteringRate(
@PathVariable("category_id") String categoryId,
@Valid @RequestBody CategoryVoteFilterRateChangeRequest voteFilterRateChangeRequest) {
categoryVoteFilterService.modifyFilteringRate(
categoryId,
voteFilterRateChangeRequest.getEmail(),
voteFilterRateChangeRequest.getFilteringRate());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.neo.needeachother.category.representation.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.neo.needeachother.common.enums.NEOErrorCode;
import jakarta.validation.constraints.NotBlank;
import lombok.*;

@Getter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CategoryCreationRequest {

@NotBlank(message = NEOErrorCode.ValidationMessage.BLANK_VALUE)
@JsonProperty(value = "star_page_id", required = true)
private String starPageId;

@NotBlank(message = NEOErrorCode.ValidationMessage.BLANK_VALUE)
@JsonProperty(value = "category_title", required = true)
private String categoryTitle;

@NotBlank(message = NEOErrorCode.ValidationMessage.BLANK_VALUE)
@JsonProperty(value = "category_type", required = true)
private String categoryType;

@NotBlank(message = NEOErrorCode.ValidationMessage.BLANK_VALUE)
@JsonProperty(value = "is_write_host_only", required = true)
private boolean isWriteHostOnly;

@NotBlank(message = NEOErrorCode.ValidationMessage.BLANK_VALUE)
@JsonProperty(value = "is_comment_writeable", required = true)
private boolean isCommentWriteAble;

@NotBlank(message = NEOErrorCode.ValidationMessage.BLANK_VALUE)
@JsonProperty(value = "is_using_rating_filter", required = true)
private boolean isUsingRatingFilter;

@NotBlank(message = NEOErrorCode.ValidationMessage.BLANK_VALUE)
@JsonProperty(value = "filtering_rate", required = true)
private int filteringRate;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.neo.needeachother.category.representation.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.neo.needeachother.common.enums.NEOErrorCode;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import lombok.*;

@Getter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CategoryStatusModifyRequest {

@NotBlank(message = NEOErrorCode.ValidationMessage.BLANK_VALUE)
@Email(message = NEOErrorCode.ValidationMessage.INVALID_FORMAT_EMAIL)
@JsonProperty(value = "star_page_id", required = true)
private String email;

@NotBlank(message = NEOErrorCode.ValidationMessage.BLANK_VALUE)
@JsonProperty(value = "category_id", required = true)
private String categoryId;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.neo.needeachother.category.representation.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.neo.needeachother.common.enums.NEOErrorCode;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.*;

@Getter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CategoryVoteFilterRateChangeRequest {

@NotBlank(message = NEOErrorCode.ValidationMessage.BLANK_VALUE)
@JsonProperty(value = "category_id", required = true)
private String categoryId;

@NotBlank(message = NEOErrorCode.ValidationMessage.BLANK_VALUE)
@Email(message = NEOErrorCode.ValidationMessage.INVALID_FORMAT_EMAIL)
@JsonProperty(value = "email", required = true)
private String email;

@NotNull(message = NEOErrorCode.ValidationMessage.BLANK_VALUE)
@JsonProperty(value = "category_id", required = true)
private Integer filteringRate;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.neo.needeachother.category.representation.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.neo.needeachother.common.enums.NEOErrorCode;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import lombok.*;

@Getter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CategoryVoteFilterStatusChangeRequest {

@NotBlank(message = NEOErrorCode.ValidationMessage.BLANK_VALUE)
@JsonProperty(value = "category_id", required = true)
private String categoryId;

@NotBlank(message = NEOErrorCode.ValidationMessage.BLANK_VALUE)
@Email(message = NEOErrorCode.ValidationMessage.INVALID_FORMAT_EMAIL)
@JsonProperty(value = "email", required = true)
private String email;
}

0 comments on commit 5c84440

Please sign in to comment.