Skip to content

Commit fab8be9

Browse files
committed
feat: 금칙어 조회 isUsed 추가
1 parent 6d7f43e commit fab8be9

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/main/java/io/crops/warmletter/domain/badword/dto/response/BadWordResponse.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.crops.warmletter.domain.badword.dto.response;
22

3+
import com.fasterxml.jackson.annotation.JsonProperty;
34
import io.swagger.v3.oas.annotations.media.Schema;
45
import lombok.AllArgsConstructor;
56
import lombok.Getter;
@@ -11,4 +12,7 @@ public class BadWordResponse {
1112
private Long id;
1213
@Schema(description = "금지어 단어", example = "비속어")
1314
private String word;
15+
16+
@JsonProperty("isUsed")
17+
private boolean isUsed;
1418
}

src/main/java/io/crops/warmletter/domain/badword/repository/BadWordRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
public interface BadWordRepository extends JpaRepository<BadWord, Long> {
1313
boolean existsByWord(String word);
1414

15-
@Query("SELECT new io.crops.warmletter.domain.badword.dto.response.BadWordResponse(b.id, b.word) FROM BadWord b WHERE b.isUsed = true")
15+
@Query("SELECT new io.crops.warmletter.domain.badword.dto.response.BadWordResponse(b.id, b.word, b.isUsed) FROM BadWord b ")
1616
List<BadWordResponse> findAllBadWords();
1717

1818
}

src/main/java/io/crops/warmletter/domain/badword/service/BadWordService.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,19 @@ public List<Map<String, String>> getBadWords() {
7171
return entries.entrySet().stream()
7272
.map(e -> {
7373
Map<String, String> map = new HashMap<>();
74-
map.put("id", e.getKey().toString());
74+
// 여기서 id 변수를 선언합니다.
75+
String id = e.getKey().toString();
76+
map.put("id", id);
7577
map.put("word", e.getValue().toString());
78+
// DB에서 조회한 isUsed 값을 포함 (없으면 기본값 false)
79+
Optional<BadWord> optional = badWordRepository.findById(Long.valueOf(id));
80+
map.put("isUsed", optional.map(bw -> Boolean.toString(bw.isUsed())).orElse("false"));
7681
return map;
7782
})
78-
.toList();
83+
.collect(Collectors.toList());
7984
}
8085

86+
8187
@Transactional
8288
public UpdateBadWordResponse updateBadWord(Long id, UpdateBadWordRequest request) {
8389
BadWord badWord = badWordRepository.findById(id)

0 commit comments

Comments
 (0)