Skip to content

Commit

Permalink
Rest Docs 표기 오류 해결 및 금칙어 도메인 분리 (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
juno-junho authored May 21, 2024
2 parents 684ee1e + 821ddd4 commit eb8737b
Show file tree
Hide file tree
Showing 37 changed files with 106 additions and 83 deletions.
6 changes: 3 additions & 3 deletions src/docs/asciidoc/profanity-api.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ include::{snippets}/profanity/download-csv-file/response-fields.adoc[]
:sectnums!:

==== Request
include::{snippets}/profanity/add-single-banword/http-request.adoc[]
include::{snippets}/profanity/add-banword/http-request.adoc[]

===== Request Body
include::{snippets}/profanity/add-single-banword/request-fields.adoc[]
include::{snippets}/profanity/add-banword/request-fields.adoc[]

==== Response
include::{snippets}/profanity/add-single-banword/http-response.adoc[]
include::{snippets}/profanity/add-banword/http-response.adoc[]

:sectnums:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.spaceclub.global.aws.s3.S3Folder;
import com.spaceclub.global.aws.s3.S3ImageUploader;
import com.spaceclub.global.response.PageResponse;
import com.spaceclub.global.timer.StopWatch;
import com.spaceclub.oauth.jwt.vo.JwtUser;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -66,6 +67,7 @@ public PostResponse getSingleClubBoardPost(
return PostResponse.from(postInfo, imageUploader.getBucketUrl());
}

@StopWatch
@PostMapping(value = "/{clubId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<Void> createClubBoardPost(
@RequestPart(required = false) MultipartFile image,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.spaceclub.board.controller.request;

import com.spaceclub.global.annotation.profanity.ProfanityCheck;
import com.spaceclub.profanity.ProfanityCheck;

public record CommentRequest(
@ProfanityCheck String content,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.spaceclub.board.controller.request;

import com.spaceclub.global.annotation.profanity.ProfanityCheck;
import com.spaceclub.profanity.ProfanityCheck;

public record PostRequest(
@ProfanityCheck String title,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.spaceclub.board.controller.request;

import com.spaceclub.global.annotation.profanity.ProfanityCheck;
import com.spaceclub.profanity.ProfanityCheck;

public record PostUpdateRequest(
@ProfanityCheck String title,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.spaceclub.club.controller.request;

import com.spaceclub.club.domain.Club;
import com.spaceclub.global.annotation.profanity.ProfanityCheck;
import com.spaceclub.profanity.ProfanityCheck;

public record ClubCreateRequest(
@ProfanityCheck String name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.spaceclub.club.controller.request;

import com.spaceclub.global.annotation.profanity.ProfanityCheck;
import com.spaceclub.profanity.ProfanityCheck;

public record ClubNoticeCreateRequest(
@ProfanityCheck String notice
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.spaceclub.club.controller.request;

import com.spaceclub.global.annotation.profanity.ProfanityCheck;
import com.spaceclub.profanity.ProfanityCheck;

public record ClubNoticeUpdateRequest(@ProfanityCheck String notice) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.spaceclub.club.controller.request;

import com.spaceclub.club.domain.Club;
import com.spaceclub.global.annotation.profanity.ProfanityCheck;
import com.spaceclub.profanity.ProfanityCheck;

public record ClubUpdateRequest(
@ProfanityCheck String name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.spaceclub.event.domain.EventInfo;
import com.spaceclub.event.domain.FormInfo;
import com.spaceclub.event.domain.TicketInfo;
import com.spaceclub.global.annotation.profanity.ProfanityCheck;
import com.spaceclub.profanity.ProfanityCheck;
import lombok.Builder;

import java.time.LocalDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.spaceclub.event.domain.EventInfo;
import com.spaceclub.event.domain.FormInfo;
import com.spaceclub.event.domain.TicketInfo;
import com.spaceclub.global.annotation.profanity.ProfanityCheck;
import com.spaceclub.profanity.ProfanityCheck;
import lombok.Builder;

import java.time.LocalDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import java.util.List;

import static com.spaceclub.global.annotation.profanity.ProfanityExceptionMessage.BAD_WORD_DETECTED;
import static com.spaceclub.profanity.ProfanityExceptionMessage.BAD_WORD_DETECTED;
import static com.spaceclub.global.exception.GlobalExceptionCode.INVALID_REQUEST;
import static com.spaceclub.global.exception.GlobalExceptionCode.MAX_IMAGE_SIZE_EXCEEDED;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.spaceclub.global.annotation.profanity;
package com.spaceclub.profanity;

import jakarta.validation.Constraint;
import jakarta.validation.Payload;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.spaceclub.global.annotation.profanity;
package com.spaceclub.profanity;

import com.spaceclub.global.annotation.profanity.domain.Profanity;
import com.spaceclub.global.annotation.profanity.domain.repository.ProfanityRepository;
import com.spaceclub.profanity.domain.Profanity;
import com.spaceclub.profanity.domain.repository.ProfanityRepository;
import com.spaceclub.global.timer.StopWatch;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
Expand All @@ -12,7 +12,7 @@

import java.util.List;

import static com.spaceclub.global.annotation.profanity.ProfanityExceptionMessage.BAD_WORD_DETECTED;
import static com.spaceclub.profanity.ProfanityExceptionMessage.BAD_WORD_DETECTED;

@Slf4j
@Component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.spaceclub.global.annotation.profanity;
package com.spaceclub.profanity;

import com.spaceclub.global.annotation.profanity.domain.Profanity;
import com.spaceclub.global.annotation.profanity.domain.repository.ProfanityRepository;
import com.spaceclub.profanity.domain.Profanity;
import com.spaceclub.profanity.domain.repository.ProfanityRepository;
import com.spaceclub.global.timer.StopWatch;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.spaceclub.global.annotation.profanity;
package com.spaceclub.profanity;

import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.spaceclub.global.annotation.profanity;
package com.spaceclub.profanity;

import com.googlecode.concurrenttrees.radix.node.concrete.SmartArrayBasedNodeFactory;
import com.googlecode.concurrenttrees.radix.node.concrete.voidvalue.VoidValue;
import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree;
import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree;
import com.spaceclub.global.annotation.profanity.domain.Profanity;
import com.spaceclub.global.annotation.profanity.domain.repository.ProfanityRepository;
import com.spaceclub.profanity.domain.Profanity;
import com.spaceclub.profanity.domain.repository.ProfanityRepository;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -38,4 +38,12 @@ public List<String> profanityContained(String text) {
.toList();
}

public void addProfanityToTrie(String word) {
TRIE.put(word, VoidValue.SINGLETON);
}

public void removeProfanityFromTrie(String word) {
TRIE.remove(word);
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.spaceclub.global.annotation.profanity.controller;
package com.spaceclub.profanity.controller;

import com.spaceclub.global.annotation.profanity.controller.request.BanWordRequest;
import com.spaceclub.global.annotation.profanity.controller.response.UrlResponse;
import com.spaceclub.global.annotation.profanity.service.ProfanityService;
import com.spaceclub.profanity.controller.request.BanWordRequest;
import com.spaceclub.profanity.controller.response.UrlResponse;
import com.spaceclub.profanity.service.ProfanityService;
import com.spaceclub.global.config.ProfanityConfig;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -19,7 +19,7 @@
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import static com.spaceclub.global.annotation.profanity.ProfanityExceptionMessage.INVALID_EXTENSION;
import static com.spaceclub.profanity.ProfanityExceptionMessage.INVALID_EXTENSION;

@Slf4j
@RestController
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.spaceclub.global.annotation.profanity.controller.request;
package com.spaceclub.profanity.controller.request;

import jakarta.validation.constraints.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.spaceclub.profanity.controller.response;

public record UrlResponse(String url) {

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.spaceclub.global.annotation.profanity.domain;
package com.spaceclub.profanity.domain;

import com.spaceclub.global.BaseTimeEntity;
import jakarta.persistence.Column;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.spaceclub.profanity.domain.repository;

import com.spaceclub.profanity.domain.Profanity;

import java.util.List;

public interface ProfanityCustomRepository {

void bulkInsert(List<Profanity> profanities);

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.spaceclub.global.annotation.profanity.domain.repository;
package com.spaceclub.profanity.domain.repository;

import com.spaceclub.global.annotation.profanity.domain.Profanity;
import com.spaceclub.profanity.domain.Profanity;
import lombok.RequiredArgsConstructor;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.spaceclub.global.annotation.profanity.domain.repository;
package com.spaceclub.profanity.domain.repository;

import com.spaceclub.global.annotation.profanity.domain.Profanity;
import com.spaceclub.profanity.domain.Profanity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.spaceclub.global.annotation.profanity.service;
package com.spaceclub.profanity.service;

import com.spaceclub.global.annotation.profanity.domain.Profanity;
import com.spaceclub.global.annotation.profanity.domain.repository.ProfanityRepository;
import com.spaceclub.profanity.ProfanityLoader;
import com.spaceclub.profanity.domain.Profanity;
import com.spaceclub.profanity.domain.repository.ProfanityRepository;
import com.spaceclub.global.aws.s3.S3FileUploader;
import com.spaceclub.global.timer.StopWatch;
import lombok.RequiredArgsConstructor;
Expand All @@ -19,9 +20,9 @@
import java.time.LocalDateTime;
import java.util.List;

import static com.spaceclub.global.annotation.profanity.ProfanityExceptionMessage.BAD_WORD_ALREADY_EXISTS;
import static com.spaceclub.global.annotation.profanity.ProfanityExceptionMessage.FAILED_TO_CREATE_CSV;
import static com.spaceclub.global.annotation.profanity.ProfanityExceptionMessage.FAILED_TO_SAVE;
import static com.spaceclub.profanity.ProfanityExceptionMessage.BAD_WORD_ALREADY_EXISTS;
import static com.spaceclub.profanity.ProfanityExceptionMessage.FAILED_TO_CREATE_CSV;
import static com.spaceclub.profanity.ProfanityExceptionMessage.FAILED_TO_SAVE;

@Slf4j
@Service
Expand All @@ -30,19 +31,24 @@ public class ProfanityService {

private final ProfanityRepository profanityRepository;
private final S3FileUploader s3FileUploader;
private final ProfanityLoader profanityLoader;

private String downloadUrl;
private LocalDateTime downloadDate = LocalDateTime.now();

@StopWatch
public void saveProfanitiesFromFile(MultipartFile file) {
List<Profanity> existingBanWord = profanityRepository.findAll();

try (BufferedReader reader = new BufferedReader(new InputStreamReader(file.getInputStream()))) {
List<Profanity> profanities = reader.lines()
.distinct()
.filter(word -> existingBanWord.stream().noneMatch(banWord -> banWord.getBanWord().equals(word)))
.map(Profanity::new)
.toList();

profanityRepository.bulkInsert(profanities);
profanities.forEach(profanity -> profanityLoader.addProfanityToTrie(profanity.getBanWord()));
} catch (IOException e) {
throw new IllegalStateException(FAILED_TO_SAVE.getMessage());
}
Expand All @@ -55,15 +61,16 @@ public void saveProfanity(String word) {
}

profanityRepository.save(new Profanity(word));
profanityLoader.addProfanityToTrie(word);
}

@Transactional
public void deleteProfanity(String word) {
profanityRepository.deleteByBanWord(word);
profanityLoader.removeProfanityFromTrie(word);
}

public String createCsvFile() {
// 여기에 csv 파일 생성 여부 추가
if (downloadUrl != null && profanityRepository.findLatestModifiedDate().isBefore(downloadDate)) {
return downloadUrl;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.spaceclub.user.controller.request;

import com.spaceclub.global.annotation.profanity.ProfanityCheck;
import com.spaceclub.profanity.ProfanityCheck;

public record UserProfileUpdateRequest(
@ProfanityCheck String name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.spaceclub.user.controller.request;

import com.spaceclub.global.annotation.profanity.ProfanityCheck;
import com.spaceclub.profanity.ProfanityCheck;
import com.spaceclub.user.service.vo.RequiredProfile;

public record UserRequiredInfoRequest(Long userId, @ProfanityCheck String name, String phoneNumber, String email) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import com.spaceclub.board.service.CommentService;
import com.spaceclub.board.service.vo.CommentInfo;
import com.spaceclub.global.annotation.login.UserArgumentResolver;
import com.spaceclub.global.annotation.profanity.ProfanityCheckValidator;
import com.spaceclub.global.annotation.profanity.ProfanityLoader;
import com.spaceclub.global.annotation.profanity.domain.repository.ProfanityRepository;
import com.spaceclub.profanity.ProfanityCheckValidator;
import com.spaceclub.profanity.ProfanityLoader;
import com.spaceclub.profanity.domain.repository.ProfanityRepository;
import com.spaceclub.global.config.WebConfig;
import com.spaceclub.oauth.interceptor.AuthenticationInterceptor;
import com.spaceclub.oauth.interceptor.AuthorizationInterceptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import com.spaceclub.board.service.PostService;
import com.spaceclub.board.service.vo.PostInfo;
import com.spaceclub.global.annotation.login.UserArgumentResolver;
import com.spaceclub.global.annotation.profanity.ProfanityCheckValidator;
import com.spaceclub.global.annotation.profanity.ProfanityLoader;
import com.spaceclub.global.annotation.profanity.domain.repository.ProfanityRepository;
import com.spaceclub.profanity.ProfanityCheckValidator;
import com.spaceclub.profanity.ProfanityLoader;
import com.spaceclub.profanity.domain.repository.ProfanityRepository;
import com.spaceclub.global.aws.s3.S3ImageUploader;
import com.spaceclub.global.config.WebConfig;
import com.spaceclub.oauth.interceptor.AuthenticationInterceptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import com.spaceclub.club.domain.Club;
import com.spaceclub.club.service.ClubService;
import com.spaceclub.global.annotation.login.UserArgumentResolver;
import com.spaceclub.global.annotation.profanity.ProfanityCheckValidator;
import com.spaceclub.global.annotation.profanity.ProfanityLoader;
import com.spaceclub.global.annotation.profanity.domain.repository.ProfanityRepository;
import com.spaceclub.profanity.ProfanityCheckValidator;
import com.spaceclub.profanity.ProfanityLoader;
import com.spaceclub.profanity.domain.repository.ProfanityRepository;
import com.spaceclub.global.aws.S3Properties;
import com.spaceclub.global.config.WebConfig;
import com.spaceclub.oauth.interceptor.AuthenticationInterceptor;
Expand Down
Loading

0 comments on commit eb8737b

Please sign in to comment.