-
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.
Merge pull request #1046 from BCSDLab/develop
develop -> main
- Loading branch information
Showing
116 changed files
with
4,382 additions
and
1,120 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
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
52 changes: 52 additions & 0 deletions
52
src/main/java/in/koreatech/koin/admin/keyword/controller/AdminKeywordApi.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,52 @@ | ||
package in.koreatech.koin.admin.keyword.controller; | ||
|
||
import static in.koreatech.koin.domain.user.model.UserType.ADMIN; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
|
||
import in.koreatech.koin.admin.keyword.dto.AdminFilteredKeywordsResponse; | ||
import in.koreatech.koin.admin.keyword.dto.AdminKeywordFilterRequest; | ||
import in.koreatech.koin.global.auth.Auth; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
|
||
@Tag(name = "(Admin) Keyword: 키워드", description = "키워드 알림 정보를 관리한다") | ||
public interface AdminKeywordApi { | ||
|
||
@ApiResponses( | ||
value = { | ||
@ApiResponse(responseCode = "200"), | ||
@ApiResponse(responseCode = "400", content = @Content(schema = @Schema(hidden = true))), | ||
@ApiResponse(responseCode = "401", content = @Content(schema = @Schema(hidden = true))), | ||
@ApiResponse(responseCode = "403", content = @Content(schema = @Schema(hidden = true))), | ||
} | ||
) | ||
@Operation(summary = "키워드 필터링") | ||
@PostMapping("/admin/articles/keyword/filter") | ||
ResponseEntity<Void> toggleKeywordFilter( | ||
@Valid @RequestBody AdminKeywordFilterRequest request, | ||
@Auth(permit = {ADMIN}) Integer adminId | ||
); | ||
|
||
@ApiResponses( | ||
value = { | ||
@ApiResponse(responseCode = "200"), | ||
@ApiResponse(responseCode = "400", content = @Content(schema = @Schema(hidden = true))), | ||
@ApiResponse(responseCode = "401", content = @Content(schema = @Schema(hidden = true))), | ||
@ApiResponse(responseCode = "403", content = @Content(schema = @Schema(hidden = true))), | ||
} | ||
) | ||
@Operation(summary = "필터링 된 키워드 조회") | ||
@GetMapping("/admin/articles/keyword/filtered") | ||
ResponseEntity<AdminFilteredKeywordsResponse> getFilteredKeywords( | ||
@Auth(permit = {ADMIN}) Integer adminId | ||
); | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/in/koreatech/koin/admin/keyword/controller/AdminKeywordController.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 in.koreatech.koin.admin.keyword.controller; | ||
|
||
import static in.koreatech.koin.domain.user.model.UserType.ADMIN; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
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; | ||
|
||
import in.koreatech.koin.admin.keyword.service.AdminKeywordService; | ||
import in.koreatech.koin.admin.keyword.dto.AdminFilteredKeywordsResponse; | ||
import in.koreatech.koin.admin.keyword.dto.AdminKeywordFilterRequest; | ||
import in.koreatech.koin.global.auth.Auth; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/admin/articles/keyword") | ||
public class AdminKeywordController implements AdminKeywordApi { | ||
|
||
private final AdminKeywordService adminKeywordService; | ||
|
||
@PostMapping("/filter") | ||
public ResponseEntity<Void> toggleKeywordFilter( | ||
@Valid @RequestBody AdminKeywordFilterRequest request, | ||
@Auth(permit = {ADMIN}) Integer adminId | ||
) { | ||
adminKeywordService.filterKeyword(request.keyword(), request.isFiltered()); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@GetMapping("/filtered") | ||
public ResponseEntity<AdminFilteredKeywordsResponse> getFilteredKeywords( | ||
@Auth(permit = {ADMIN}) Integer adminId | ||
) { | ||
AdminFilteredKeywordsResponse response = adminKeywordService.getFilteredKeywords(); | ||
return ResponseEntity.ok(response); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/in/koreatech/koin/admin/keyword/dto/AdminFilteredKeywordsResponse.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,39 @@ | ||
package in.koreatech.koin.admin.keyword.dto; | ||
|
||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; | ||
|
||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
|
||
import in.koreatech.koin.domain.community.keyword.model.ArticleKeyword; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
@JsonNaming(value = SnakeCaseStrategy.class) | ||
public record AdminFilteredKeywordsResponse( | ||
@Schema(description = "필터링된 키워드 목록", requiredMode = REQUIRED) | ||
List<InnerFilteredKeywordResponse> keywords | ||
) { | ||
|
||
@JsonNaming(value = SnakeCaseStrategy.class) | ||
public record InnerFilteredKeywordResponse( | ||
@Schema(description = "키워드 내용", example = "[ㅇ, ㄴ라]", requiredMode = REQUIRED) | ||
String keyword | ||
) { | ||
|
||
public static InnerFilteredKeywordResponse from(ArticleKeyword articleKeyword) { | ||
return new InnerFilteredKeywordResponse( | ||
articleKeyword.getKeyword() | ||
); | ||
} | ||
} | ||
|
||
public static AdminFilteredKeywordsResponse from(List<ArticleKeyword> filteredKeywords) { | ||
return new AdminFilteredKeywordsResponse( | ||
filteredKeywords.stream() | ||
.map(InnerFilteredKeywordResponse::from) | ||
.toList() | ||
); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/in/koreatech/koin/admin/keyword/dto/AdminKeywordFilterRequest.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,17 @@ | ||
package in.koreatech.koin.admin.keyword.dto; | ||
|
||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record AdminKeywordFilterRequest( | ||
@NotBlank(message = "키워드는 공백일 수 없습니다.") | ||
@Schema(example = "키워드", description = "필터링 할 키워드 단어", requiredMode = REQUIRED) | ||
String keyword, | ||
|
||
@Schema(example = "true", description = "필터링 여부", requiredMode = REQUIRED) | ||
Boolean isFiltered | ||
) { | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/in/koreatech/koin/admin/keyword/repository/AdminArticleKeywordRepository.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,21 @@ | ||
package in.koreatech.koin.admin.keyword.repository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.springframework.data.repository.Repository; | ||
|
||
import in.koreatech.koin.domain.community.keyword.exception.ArticleKeywordNotFoundException; | ||
import in.koreatech.koin.domain.community.keyword.model.ArticleKeyword; | ||
|
||
public interface AdminArticleKeywordRepository extends Repository<ArticleKeyword, Integer> { | ||
|
||
Optional<ArticleKeyword> findByKeyword(String keyword); | ||
|
||
default ArticleKeyword getByKeyword(String keyword) { | ||
return findByKeyword(keyword) | ||
.orElseThrow(() -> ArticleKeywordNotFoundException.withDetail("keyword : " + keyword)); | ||
} | ||
|
||
List<ArticleKeyword> findByIsFiltered(boolean isFiltered); | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/in/koreatech/koin/admin/keyword/service/AdminKeywordService.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,38 @@ | ||
package in.koreatech.koin.admin.keyword.service; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import in.koreatech.koin.admin.keyword.repository.AdminArticleKeywordRepository; | ||
import in.koreatech.koin.admin.keyword.dto.AdminFilteredKeywordsResponse; | ||
import in.koreatech.koin.domain.community.keyword.model.ArticleKeyword; | ||
import in.koreatech.koin.global.exception.KoinIllegalArgumentException; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class AdminKeywordService { | ||
|
||
private final AdminArticleKeywordRepository adminArticleKeywordRepository; | ||
|
||
@Transactional | ||
public void filterKeyword(String keyword, Boolean isFiltered) { | ||
ArticleKeyword articleKeyword = adminArticleKeywordRepository.getByKeyword(keyword); | ||
|
||
if (Objects.equals(articleKeyword.getIsFiltered(), isFiltered)) { | ||
String action = isFiltered ? "필터링 된" : "필터링이 취소된"; | ||
throw new KoinIllegalArgumentException("이미 " + action + " 키워드입니다: " + keyword); | ||
} | ||
|
||
articleKeyword.applyFiltered(isFiltered); | ||
} | ||
|
||
public AdminFilteredKeywordsResponse getFilteredKeywords() { | ||
List<ArticleKeyword> filteredKeywords = adminArticleKeywordRepository.findByIsFiltered(true); | ||
return AdminFilteredKeywordsResponse.from(filteredKeywords); | ||
} | ||
} |
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
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
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
Oops, something went wrong.