-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : category domain controller dev (#53)
- Loading branch information
1 parent
93594ed
commit 5c84440
Showing
11 changed files
with
331 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...other/src/main/java/com/neo/needeachother/category/application/CreateCategoryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...c/main/java/com/neo/needeachother/category/representation/CategoryCreationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...va/com/neo/needeachother/category/representation/CategoryInfromationModifyController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.neo.needeachother.category.representation; | ||
|
||
public class CategoryInfromationModifyController { | ||
} |
30 changes: 30 additions & 0 deletions
30
...in/java/com/neo/needeachother/category/representation/CategoryStatusModifyController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...main/java/com/neo/needeachother/category/representation/CategoryVoteFilterController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
.../main/java/com/neo/needeachother/category/representation/dto/CategoryCreationRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
25 changes: 25 additions & 0 deletions
25
...n/java/com/neo/needeachother/category/representation/dto/CategoryStatusModifyRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...om/neo/needeachother/category/representation/dto/CategoryVoteFilterRateChangeRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
24 changes: 24 additions & 0 deletions
24
.../neo/needeachother/category/representation/dto/CategoryVoteFilterStatusChangeRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |