Skip to content

Commit ad9a570

Browse files
authored
Merge pull request #436 from Hi-lingual/feat/435
[feat] #435 단어장 목록 조회API에 외움 상태 반영 및 한글 뜻 노출
2 parents 05620a4 + bfa3b11 commit ad9a570

8 files changed

Lines changed: 32 additions & 13 deletions

File tree

hilingual-api/src/main/java/org/sopt/controller/voca/api/VocaController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ public class VocaController {
2323
@GetMapping
2424
public ResponseEntity<VocaListRes> getVocaList(
2525
@UserId Long userId,
26-
@RequestParam(value = "sort", required = false, defaultValue = "1") final String sortStr
26+
@RequestParam(value = "sort", required = false, defaultValue = "1") final String sortStr,
27+
@RequestParam(value = "unmemorizedOnly", required = false, defaultValue = "false") final boolean unmemorizedOnly
2728
) {
2829
int sort = parseAndValidateSortType(sortStr);
29-
return ResponseEntity.ok(vocaService.getVocaList(userId, sort));
30+
return ResponseEntity.ok(vocaService.getVocaList(userId, sort, unmemorizedOnly));
3031
}
3132

3233
// 단어장 검색

hilingual-api/src/main/java/org/sopt/controller/voca/service/VocaService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public class VocaService {
3030
private final VocaFacade vocaFacade;
3131

3232
// 단어장 목록 조회
33-
public VocaListRes getVocaList(final Long userId, final int sort) {
34-
return vocaRetriever.findGroupedVoca(userId, sort);
33+
public VocaListRes getVocaList(final Long userId, final int sort, final boolean unmemorizedOnly) {
34+
return vocaRetriever.findGroupedVoca(userId, sort, unmemorizedOnly);
3535
}
3636

3737
// 단어장 검색
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- V19__add_is_memorized_to_voca.sql
2+
3+
ALTER TABLE voca
4+
ADD COLUMN is_memorized BOOLEAN NOT NULL DEFAULT FALSE;

hilingual-domain/src/main/java/org/sopt/voca/domain/Voca.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ public class Voca extends BaseTimeEntity {
6363
@Column(name = COLUMN_WRITTEN_DATE, nullable = true)
6464
private LocalDate writtenDate;
6565

66+
@Column(name = COLUMN_IS_MEMORIZED, nullable = false)
67+
private boolean isMemorized;
68+
6669
public static Voca fromMyDiary(User user, Recommend recommend, String writtenFrom) {
6770
return new Voca(
6871
null, SavedRoot.MY, user,
@@ -71,7 +74,8 @@ public static Voca fromMyDiary(User user, Recommend recommend, String writtenFro
7174
recommend.getPhraseType(),
7275
recommend.getExplanation(),
7376
writtenFrom,
74-
recommend.getDiary().getWrittenDate()
77+
recommend.getDiary().getWrittenDate(),
78+
false
7579
);
7680
}
7781

@@ -83,7 +87,8 @@ public static Voca fromFeed(User user, Recommend recommend, String writtenFrom)
8387
recommend.getPhraseType(),
8488
recommend.getExplanation(),
8589
writtenFrom,
86-
null
90+
null,
91+
false
8792
);
8893
}
8994
}

hilingual-domain/src/main/java/org/sopt/voca/domain/VocaTableConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ public class VocaTableConstants {
1616
public static final String COLUMN_EXPLANATION = "explanation";
1717
public static final String COLUMN_WRITTEN_FROM = "written_from";
1818
public static final String COLUMN_WRITTEN_DATE = "written_date";
19+
public static final String COLUMN_IS_MEMORIZED = "is_memorized";
1920
}

hilingual-domain/src/main/java/org/sopt/voca/dto/VocaItemRes.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ public record VocaItemRes(
99
Long phraseId,
1010
String phrase,
1111
List<String> phraseType,
12-
Boolean isBookmarked
12+
String explanation,
13+
Boolean isBookmarked,
14+
Boolean isMemorized
1315
) {
1416
public static VocaItemRes from(final Voca voca) {
1517
return new VocaItemRes(
1618
voca.getRecommendId(),
1719
voca.getPhrase(),
1820
parsePhraseTypes(voca.getPhraseType()),
19-
Boolean.TRUE
21+
voca.getExplanation(),
22+
Boolean.TRUE,
23+
voca.isMemorized()
2024
);
2125
}
2226

hilingual-domain/src/main/java/org/sopt/voca/facade/VocaRetriever.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public class VocaRetriever {
1616
private final VocaRepository vocaRepository;
1717
private final VocaGroupFactory vocaGroupFactory;
1818

19-
public VocaListRes findGroupedVoca(final Long userId, final int sort) {
19+
public VocaListRes findGroupedVoca(final Long userId, final int sort, final boolean unmemorizedOnly) {
2020
List<Voca> vocas = (sort == 1)
21-
? vocaRepository.findAllByUserIdOrderByCreatedAtDesc(userId)
22-
: vocaRepository.findAllByUserIdOrderByPhraseAsc(userId);
21+
? vocaRepository.findAllByUserIdOrderByCreatedAtDesc(userId, unmemorizedOnly)
22+
: vocaRepository.findAllByUserIdOrderByPhraseAsc(userId, unmemorizedOnly);
2323

2424
return (sort == 1)
2525
? vocaGroupFactory.createByDateGroup(vocas)

hilingual-domain/src/main/java/org/sopt/voca/repository/VocaRepository.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,21 @@ int deleteByUserIdAndRecommendId(@Param("userId") long userId,
3131
@Query("""
3232
SELECT v FROM Voca v
3333
WHERE v.user.id = :userId
34+
AND (:unmemorizedOnly = false OR v.isMemorized = false)
3435
ORDER BY LOWER(v.phrase)
3536
""")
36-
List<Voca> findAllByUserIdOrderByPhraseAsc(@Param("userId") Long userId);
37+
List<Voca> findAllByUserIdOrderByPhraseAsc(@Param("userId") Long userId,
38+
@Param("unmemorizedOnly") Boolean unmemorizedOnly);
3739

3840
// 최신순 정렬 (Voca.createdAt 기반)
3941
@Query("""
4042
SELECT v FROM Voca v
4143
WHERE v.user.id = :userId
44+
AND (:unmemorizedOnly = false OR v.isMemorized = false)
4245
ORDER BY v.createdAt DESC
4346
""")
44-
List<Voca> findAllByUserIdOrderByCreatedAtDesc(@Param("userId") Long userId);
47+
List<Voca> findAllByUserIdOrderByCreatedAtDesc(@Param("userId") Long userId,
48+
@Param("unmemorizedOnly") Boolean unmemorizedOnly);
4549

4650
// 검색 (Prefix 기반)
4751
@Query("""

0 commit comments

Comments
 (0)