Skip to content

Commit

Permalink
Merge pull request #149 from zanzanbari/feat/148
Browse files Browse the repository at this point in the history
feat : Admin ๊ณ„์ •์—์„œ ๋ฐ”๋กœ ์™ˆ์†Œ๋ฆฌ ๋”๋ฏธ ๋ฐ์ดํ„ฐ ์ถ”๊ฐ€ํ•˜๊ธฐ ๊ธฐ๋Šฅ #148
  • Loading branch information
oownahcohc authored Nov 18, 2023
2 parents f457928 + ce322ed commit f285c3d
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

import backend.wal.admin.application.port.out.RegisterItemManagePort;
import backend.wal.wal.censorWal.application.port.in.RetrieveCensorItemUseCase;
import backend.wal.wal.censorWal.application.port.in.dto.ApprovedCensorItemResponseDto;
import backend.wal.wal.censorWal.application.port.in.dto.ItemToRegisterDto;
import backend.wal.wal.censorWal.application.port.in.dto.RetrieveCensorItemRequestDto;
import backend.wal.wal.common.domain.WalCategoryType;
import backend.wal.wal.item.application.port.in.CountItemUseCase;
import backend.wal.wal.item.application.port.in.RegisterItemUseCase;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Component
public class RegisterItemManageAdapter implements RegisterItemManagePort {
Expand All @@ -28,11 +30,22 @@ public RegisterItemManageAdapter(final RetrieveCensorItemUseCase retrieveCensorI

@Override
public void registerItemsBy(WalCategoryType categoryType) {
List<ApprovedCensorItemResponseDto> approvedCensorItemInfo = retrieveCensorItemUseCase
List<ItemToRegisterDto> approvedCensorItemInfo = retrieveCensorItemUseCase
.retrieveApprovedCensorItemInfo(new RetrieveCensorItemRequestDto(categoryType));
Long countOfCategoryType = countItemUseCase.countAllCorrespondItemsByCategoryType(categoryType);
RegisterItemRequestDtoConvertor registerItemRequestDtoConvertor =
new RegisterItemRequestDtoConvertor(approvedCensorItemInfo, countOfCategoryType);
registerItemUseCase.registerNewItems(registerItemRequestDtoConvertor.convert(), categoryType);
}

@Override
public void registerAllItems(Set<String> contents, WalCategoryType categoryType) {
List<ItemToRegisterDto> itemToRegisterInfo = contents.stream()
.map(content -> new ItemToRegisterDto(categoryType, content, ""))
.collect(Collectors.toList());
Long countOfCategoryType = countItemUseCase.countAllCorrespondItemsByCategoryType(categoryType);
RegisterItemRequestDtoConvertor registerItemRequestDtoConvertor =
new RegisterItemRequestDtoConvertor(itemToRegisterInfo, countOfCategoryType);
registerItemUseCase.registerNewItems(registerItemRequestDtoConvertor.convert(), categoryType);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package backend.wal.admin.adapter;

import backend.wal.wal.censorWal.application.port.in.dto.ApprovedCensorItemResponseDto;
import backend.wal.wal.censorWal.application.port.in.dto.ItemToRegisterDto;
import backend.wal.wal.item.application.port.in.RegisterItemRequestDto;

import java.util.ArrayList;
import java.util.List;

public class RegisterItemRequestDtoConvertor {

private final List<ApprovedCensorItemResponseDto> approvedCensorItemInfo;
private final List<ItemToRegisterDto> approvedCensorItemInfo;
private final double countOfCategoryType;

public RegisterItemRequestDtoConvertor(List<ApprovedCensorItemResponseDto> approvedCensorItemInfo,
public RegisterItemRequestDtoConvertor(List<ItemToRegisterDto> approvedCensorItemInfo,
double countOfCategoryType) {
this.approvedCensorItemInfo = approvedCensorItemInfo;
this.countOfCategoryType = countOfCategoryType;
Expand All @@ -21,7 +21,7 @@ public List<RegisterItemRequestDto> convert() {
List<RegisterItemRequestDto> requestDtos = new ArrayList<>();

double categoryItemNumber = calculateStartCategoryItemNumber();
for (ApprovedCensorItemResponseDto responseDto : approvedCensorItemInfo) {
for (ItemToRegisterDto responseDto : approvedCensorItemInfo) {
RegisterItemRequestDto requestDto = new RegisterItemRequestDto(
responseDto.getContents(),
responseDto.getImageUrl(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import backend.wal.wal.common.domain.WalCategoryType;

import java.util.Set;

public interface RegisterItemManagePort {

void registerItemsBy(WalCategoryType categoryType);

void registerAllItems(Set<String> contents, WalCategoryType categoryType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Admin {
@Column(nullable = false, length = 50)
private String email;

@Column(nullable = false, length = 50)
@Column(nullable = false, length = 500)
private String password;

@Enumerated(EnumType.STRING)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package backend.wal.admin.web;

import backend.wal.admin.application.port.out.RegisterItemManagePort;
import backend.wal.admin.web.dto.RegisterAllItemRequest;
import backend.wal.admin.web.dto.RetrieveCensorItemRequest;
import backend.wal.support.Role;
import backend.wal.support.annotation.Authentication;
Expand Down Expand Up @@ -30,4 +31,11 @@ public ResponseEntity<Void> register(@Valid @RequestBody RetrieveCensorItemReque
registerItemManagePort.registerItemsBy(request.getCategoryType());
return ResponseEntity.status(HttpStatus.CREATED).build();
}

@Authentication(Role.ADMIN)
@PostMapping("/register/all")
public ResponseEntity<Void> registerAll(@Valid @RequestBody RegisterAllItemRequest request) {
registerItemManagePort.registerAllItems(request.getContents(), request.getCategoryType());
return ResponseEntity.status(HttpStatus.CREATED).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package backend.wal.admin.web.dto;

import backend.wal.wal.common.domain.WalCategoryType;

import javax.validation.constraints.NotNull;
import java.util.Set;

public class RegisterAllItemRequest {

@NotNull
private Set<String> contents;

@NotNull
private WalCategoryType categoryType;

public RegisterAllItemRequest(Set<String> contents, WalCategoryType categoryType) {
this.contents = contents;
this.categoryType = categoryType;
}

public Set<String> getContents() {
return contents;
}

public WalCategoryType getCategoryType() {
return categoryType;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package backend.wal.wal.censorWal.application.port.in;

import backend.wal.wal.censorWal.application.port.in.dto.ApprovedCensorItemResponseDto;
import backend.wal.wal.censorWal.application.port.in.dto.ItemToRegisterDto;
import backend.wal.wal.censorWal.application.port.in.dto.RetrieveCensorItemRequestDto;
import backend.wal.wal.censorWal.application.port.in.dto.UncheckedCensorItemResponseDto;

Expand All @@ -10,5 +10,5 @@ public interface RetrieveCensorItemUseCase {

List<UncheckedCensorItemResponseDto> retrieveUncheckedCensorItemInfo(RetrieveCensorItemRequestDto requestDto);

List<ApprovedCensorItemResponseDto> retrieveApprovedCensorItemInfo(RetrieveCensorItemRequestDto requestDto);
List<ItemToRegisterDto> retrieveApprovedCensorItemInfo(RetrieveCensorItemRequestDto requestDto);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import backend.wal.wal.common.domain.WalCategoryType;

public class ApprovedCensorItemResponseDto {
public class ItemToRegisterDto {

private final WalCategoryType categoryType;
private final String contents;
private final String imageUrl;

public ApprovedCensorItemResponseDto(WalCategoryType categoryType, String contents, String imageUrl) {
public ItemToRegisterDto(WalCategoryType categoryType, String contents, String imageUrl) {
this.categoryType = categoryType;
this.contents = contents;
this.imageUrl = imageUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import backend.wal.support.annotation.AppService;
import backend.wal.wal.censorWal.application.port.in.RetrieveCensorItemUseCase;
import backend.wal.wal.censorWal.application.port.in.dto.ApprovedCensorItemResponseDto;
import backend.wal.wal.censorWal.application.port.in.dto.ItemToRegisterDto;
import backend.wal.wal.censorWal.application.port.in.dto.RetrieveCensorItemRequestDto;
import backend.wal.wal.censorWal.application.port.in.dto.UncheckedCensorItemResponseDto;
import backend.wal.wal.censorWal.domain.repository.CensorItemRepository;
Expand Down Expand Up @@ -39,12 +39,12 @@ public List<UncheckedCensorItemResponseDto> retrieveUncheckedCensorItemInfo(
}

@Override
public List<ApprovedCensorItemResponseDto> retrieveApprovedCensorItemInfo(
public List<ItemToRegisterDto> retrieveApprovedCensorItemInfo(
RetrieveCensorItemRequestDto requestDto) {
return censorItemRepository
.findAllByCategoryTypeAndCheckStatus(requestDto.getCategoryType(), APPROVED)
.stream()
.map(censorItem -> new ApprovedCensorItemResponseDto(
.map(censorItem -> new ItemToRegisterDto(
censorItem.getCategoryType(),
censorItem.getContents(),
censorItem.getImageUrl())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package backend.wal.admin.adapter;

import backend.wal.wal.censorWal.application.port.in.dto.ApprovedCensorItemResponseDto;
import backend.wal.wal.censorWal.application.port.in.dto.ItemToRegisterDto;
import backend.wal.wal.item.application.port.in.RegisterItemRequestDto;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand All @@ -22,10 +22,10 @@ class RegisterItemRequestDtoConvertorTest {
@Test
void convert() {
// given
List<ApprovedCensorItemResponseDto> approvedCensorItemsInfo = List.of(
new ApprovedCensorItemResponseDto(COMEDY, "๋“œ๋ฆฝ1", ""),
new ApprovedCensorItemResponseDto(COMEDY, "๋“œ๋ฆฝ2", ""),
new ApprovedCensorItemResponseDto(COMEDY, "๋“œ๋ฆฝ3", "")
List<ItemToRegisterDto> approvedCensorItemsInfo = List.of(
new ItemToRegisterDto(COMEDY, "๋“œ๋ฆฝ1", ""),
new ItemToRegisterDto(COMEDY, "๋“œ๋ฆฝ2", ""),
new ItemToRegisterDto(COMEDY, "๋“œ๋ฆฝ3", "")
);
RegisterItemRequestDtoConvertor convertor =
new RegisterItemRequestDtoConvertor(approvedCensorItemsInfo, COUNT_OF_CATEGORY_TYPE);
Expand All @@ -45,7 +45,7 @@ void convert() {
.collect(Collectors.toUnmodifiableList());

List<String> expectContents = approvedCensorItemsInfo.stream()
.map(ApprovedCensorItemResponseDto::getContents)
.map(ItemToRegisterDto::getContents)
.collect(Collectors.toUnmodifiableList());
List<String> actualContents = registerItemRequestInfo.stream()
.map(RegisterItemRequestDto::getContents)
Expand Down

0 comments on commit f285c3d

Please sign in to comment.