Skip to content

Commit 91cdcb3

Browse files
committed
[feat/#92] 조회수, 풀이수 업데이트 통계 업데이트 공통 서비스 구현
1 parent 235ab2a commit 91cdcb3

File tree

9 files changed

+315
-10
lines changed

9 files changed

+315
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.moplus.moplus_server.statistic.Problem.domain;
2+
3+
import static com.querydsl.core.types.PathMetadataFactory.*;
4+
5+
import com.querydsl.core.types.dsl.*;
6+
7+
import com.querydsl.core.types.PathMetadata;
8+
import javax.annotation.processing.Generated;
9+
import com.querydsl.core.types.Path;
10+
import com.querydsl.core.types.dsl.PathInits;
11+
12+
13+
/**
14+
* QChildProblemStatistic is a Querydsl query type for ChildProblemStatistic
15+
*/
16+
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
17+
public class QChildProblemStatistic extends EntityPathBase<ChildProblemStatistic> {
18+
19+
private static final long serialVersionUID = 1136828573L;
20+
21+
private static final PathInits INITS = PathInits.DIRECT2;
22+
23+
public static final QChildProblemStatistic childProblemStatistic = new QChildProblemStatistic("childProblemStatistic");
24+
25+
public final NumberPath<Long> childProblemId = createNumber("childProblemId", Long.class);
26+
27+
public final QCountStatistic countStatistic;
28+
29+
public final NumberPath<Long> id = createNumber("id", Long.class);
30+
31+
public QChildProblemStatistic(String variable) {
32+
this(ChildProblemStatistic.class, forVariable(variable), INITS);
33+
}
34+
35+
public QChildProblemStatistic(Path<? extends ChildProblemStatistic> path) {
36+
this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS));
37+
}
38+
39+
public QChildProblemStatistic(PathMetadata metadata) {
40+
this(metadata, PathInits.getFor(metadata, INITS));
41+
}
42+
43+
public QChildProblemStatistic(PathMetadata metadata, PathInits inits) {
44+
this(ChildProblemStatistic.class, metadata, inits);
45+
}
46+
47+
public QChildProblemStatistic(Class<? extends ChildProblemStatistic> type, PathMetadata metadata, PathInits inits) {
48+
super(type, metadata, inits);
49+
this.countStatistic = inits.isInitialized("countStatistic") ? new QCountStatistic(forProperty("countStatistic")) : null;
50+
}
51+
52+
}
53+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.moplus.moplus_server.statistic.Problem.domain;
2+
3+
import static com.querydsl.core.types.PathMetadataFactory.*;
4+
5+
import com.querydsl.core.types.dsl.*;
6+
7+
import com.querydsl.core.types.PathMetadata;
8+
import javax.annotation.processing.Generated;
9+
import com.querydsl.core.types.Path;
10+
11+
12+
/**
13+
* QCountStatistic is a Querydsl query type for CountStatistic
14+
*/
15+
@Generated("com.querydsl.codegen.DefaultEmbeddableSerializer")
16+
public class QCountStatistic extends BeanPath<CountStatistic> {
17+
18+
private static final long serialVersionUID = 1047466257L;
19+
20+
public static final QCountStatistic countStatistic = new QCountStatistic("countStatistic");
21+
22+
public final NumberPath<Long> submitCount = createNumber("submitCount", Long.class);
23+
24+
public final NumberPath<Long> viewCount = createNumber("viewCount", Long.class);
25+
26+
public QCountStatistic(String variable) {
27+
super(CountStatistic.class, forVariable(variable));
28+
}
29+
30+
public QCountStatistic(Path<? extends CountStatistic> path) {
31+
super(path.getType(), path.getMetadata());
32+
}
33+
34+
public QCountStatistic(PathMetadata metadata) {
35+
super(CountStatistic.class, metadata);
36+
}
37+
38+
}
39+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.moplus.moplus_server.statistic.Problem.domain;
2+
3+
import static com.querydsl.core.types.PathMetadataFactory.*;
4+
5+
import com.querydsl.core.types.dsl.*;
6+
7+
import com.querydsl.core.types.PathMetadata;
8+
import javax.annotation.processing.Generated;
9+
import com.querydsl.core.types.Path;
10+
import com.querydsl.core.types.dsl.PathInits;
11+
12+
13+
/**
14+
* QProblemSetStatistic is a Querydsl query type for ProblemSetStatistic
15+
*/
16+
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
17+
public class QProblemSetStatistic extends EntityPathBase<ProblemSetStatistic> {
18+
19+
private static final long serialVersionUID = -1319940803L;
20+
21+
private static final PathInits INITS = PathInits.DIRECT2;
22+
23+
public static final QProblemSetStatistic problemSetStatistic = new QProblemSetStatistic("problemSetStatistic");
24+
25+
public final QCountStatistic countStatistic;
26+
27+
public final NumberPath<Long> id = createNumber("id", Long.class);
28+
29+
public final NumberPath<Long> problemSetId = createNumber("problemSetId", Long.class);
30+
31+
public QProblemSetStatistic(String variable) {
32+
this(ProblemSetStatistic.class, forVariable(variable), INITS);
33+
}
34+
35+
public QProblemSetStatistic(Path<? extends ProblemSetStatistic> path) {
36+
this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS));
37+
}
38+
39+
public QProblemSetStatistic(PathMetadata metadata) {
40+
this(metadata, PathInits.getFor(metadata, INITS));
41+
}
42+
43+
public QProblemSetStatistic(PathMetadata metadata, PathInits inits) {
44+
this(ProblemSetStatistic.class, metadata, inits);
45+
}
46+
47+
public QProblemSetStatistic(Class<? extends ProblemSetStatistic> type, PathMetadata metadata, PathInits inits) {
48+
super(type, metadata, inits);
49+
this.countStatistic = inits.isInitialized("countStatistic") ? new QCountStatistic(forProperty("countStatistic")) : null;
50+
}
51+
52+
}
53+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.moplus.moplus_server.statistic.Problem.domain;
2+
3+
import static com.querydsl.core.types.PathMetadataFactory.*;
4+
5+
import com.querydsl.core.types.dsl.*;
6+
7+
import com.querydsl.core.types.PathMetadata;
8+
import javax.annotation.processing.Generated;
9+
import com.querydsl.core.types.Path;
10+
import com.querydsl.core.types.dsl.PathInits;
11+
12+
13+
/**
14+
* QProblemStatistic is a Querydsl query type for ProblemStatistic
15+
*/
16+
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
17+
public class QProblemStatistic extends EntityPathBase<ProblemStatistic> {
18+
19+
private static final long serialVersionUID = 843488641L;
20+
21+
private static final PathInits INITS = PathInits.DIRECT2;
22+
23+
public static final QProblemStatistic problemStatistic = new QProblemStatistic("problemStatistic");
24+
25+
public final QCountStatistic countStatistic;
26+
27+
public final NumberPath<Long> id = createNumber("id", Long.class);
28+
29+
public final NumberPath<Long> problemId = createNumber("problemId", Long.class);
30+
31+
public QProblemStatistic(String variable) {
32+
this(ProblemStatistic.class, forVariable(variable), INITS);
33+
}
34+
35+
public QProblemStatistic(Path<? extends ProblemStatistic> path) {
36+
this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS));
37+
}
38+
39+
public QProblemStatistic(PathMetadata metadata) {
40+
this(metadata, PathInits.getFor(metadata, INITS));
41+
}
42+
43+
public QProblemStatistic(PathMetadata metadata, PathInits inits) {
44+
this(ProblemStatistic.class, metadata, inits);
45+
}
46+
47+
public QProblemStatistic(Class<? extends ProblemStatistic> type, PathMetadata metadata, PathInits inits) {
48+
super(type, metadata, inits);
49+
this.countStatistic = inits.isInitialized("countStatistic") ? new QCountStatistic(forProperty("countStatistic")) : null;
50+
}
51+
52+
}
53+

src/main/java/com/moplus/moplus_server/statistic/Problem/domain/ChildProblemStatistic.java

+8
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@ public void addViewCount() {
3939
public void addSubmitCount() {
4040
this.countStatistic.addSubmitCount();
4141
}
42+
43+
public Long getViewCount() {
44+
return this.countStatistic.getViewCount();
45+
}
46+
47+
public Long getSubmitCount() {
48+
return this.countStatistic.getSubmitCount();
49+
}
4250
}

src/main/java/com/moplus/moplus_server/statistic/Problem/domain/CountStatistic.java

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.moplus.moplus_server.statistic.Problem.domain;
22

33
import jakarta.persistence.Embeddable;
4+
import lombok.Getter;
45

6+
@Getter
57
@Embeddable
68
public class CountStatistic implements StatisticCounter {
79
private Long viewCount;

src/main/java/com/moplus/moplus_server/statistic/Problem/domain/ProblemSetStatistic.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@ public class ProblemSetStatistic implements StatisticCounter {
2121
private Long id;
2222

2323
private Long problemSetId;
24-
private Long viewCount;
25-
private Long submitCount;
2624

2725
@Embedded
2826
private CountStatistic countStatistic;
2927

30-
public ProblemSetStatistic(Long problemSetId, Long viewCount, Long submitCount) {
28+
public ProblemSetStatistic(Long problemSetId) {
3129
this.problemSetId = problemSetId;
32-
this.viewCount = viewCount;
33-
this.submitCount = submitCount;
30+
this.countStatistic = new CountStatistic();
3431
}
3532

3633
@Override
@@ -42,4 +39,12 @@ public void addViewCount() {
4239
public void addSubmitCount() {
4340
this.countStatistic.addSubmitCount();
4441
}
42+
43+
public Long getViewCount() {
44+
return this.countStatistic.getViewCount();
45+
}
46+
47+
public Long getSubmitCount() {
48+
return this.countStatistic.getSubmitCount();
49+
}
4550
}

src/main/java/com/moplus/moplus_server/statistic/Problem/domain/ProblemStatistic.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,14 @@ public class ProblemStatistic implements StatisticCounter {
2222
private Long id;
2323

2424
private Long problemId;
25-
private Long viewCount;
26-
private Long submitCount;
2725

2826
@Embedded
2927
private CountStatistic countStatistic;
3028

3129
@Builder
32-
public ProblemStatistic(Long problemId, Long viewCount, Long submitCount) {
30+
public ProblemStatistic(Long problemId) {
3331
this.problemId = problemId;
34-
this.viewCount = viewCount;
35-
this.submitCount = submitCount;
32+
this.countStatistic = new CountStatistic();
3633
}
3734

3835
@Override
@@ -44,4 +41,12 @@ public void addViewCount() {
4441
public void addSubmitCount() {
4542
this.countStatistic.addSubmitCount();
4643
}
44+
45+
public Long getViewCount() {
46+
return this.countStatistic.getViewCount();
47+
}
48+
49+
public Long getSubmitCount() {
50+
return this.countStatistic.getSubmitCount();
51+
}
4752
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.moplus.moplus_server.statistic.Problem.service;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.mockito.BDDMockito.given;
5+
import static org.mockito.Mockito.verify;
6+
7+
import com.moplus.moplus_server.statistic.Problem.domain.ChildProblemStatistic;
8+
import com.moplus.moplus_server.statistic.Problem.domain.ProblemSetStatistic;
9+
import com.moplus.moplus_server.statistic.Problem.domain.ProblemStatistic;
10+
import com.moplus.moplus_server.statistic.Problem.domain.StatisticEntityTarget;
11+
import com.moplus.moplus_server.statistic.Problem.domain.StatisticFieldType;
12+
import com.moplus.moplus_server.statistic.Problem.repository.ChildProblemStatisticRepository;
13+
import com.moplus.moplus_server.statistic.Problem.repository.ProblemSetStatisticRepository;
14+
import com.moplus.moplus_server.statistic.Problem.repository.ProblemStatisticRepository;
15+
import org.junit.jupiter.api.Test;
16+
import org.junit.jupiter.api.extension.ExtendWith;
17+
import org.mockito.InjectMocks;
18+
import org.mockito.Mock;
19+
import org.mockito.junit.jupiter.MockitoExtension;
20+
21+
@ExtendWith(MockitoExtension.class)
22+
class CountStatisticsUpdateServiceTest {
23+
24+
@InjectMocks
25+
private CountStatisticsUpdateService countStatisticsUpdateService;
26+
27+
@Mock
28+
private ProblemStatisticRepository problemStatisticRepository;
29+
@Mock
30+
private ProblemSetStatisticRepository problemSetStatisticRepository;
31+
@Mock
32+
private ChildProblemStatisticRepository childProblemStatisticRepository;
33+
34+
@Test
35+
void 문항_조회수_증가() {
36+
// given
37+
Long problemId = 1L;
38+
ProblemStatistic problemStatistic = new ProblemStatistic(problemId);
39+
given(problemStatisticRepository.findByIdElseThrow(problemId))
40+
.willReturn(problemStatistic);
41+
42+
// when
43+
countStatisticsUpdateService.updateStatistics(problemId, StatisticFieldType.VIEW,
44+
StatisticEntityTarget.PROBLEM);
45+
46+
// then
47+
verify(problemStatisticRepository).findByIdElseThrow(problemId);
48+
assertThat(problemStatistic.getViewCount()).isEqualTo(1L);
49+
assertThat(problemStatistic.getSubmitCount()).isEqualTo(0L);
50+
}
51+
52+
@Test
53+
void 문항세트_풀이수_증가() {
54+
// given
55+
Long problemSetId = 1L;
56+
ProblemSetStatistic problemSetStatistic = new ProblemSetStatistic(problemSetId);
57+
given(problemSetStatisticRepository.findByIdElseThrow(problemSetId))
58+
.willReturn(problemSetStatistic);
59+
60+
// when
61+
countStatisticsUpdateService.updateStatistics(problemSetId, StatisticFieldType.SUBMIT,
62+
StatisticEntityTarget.PROBLEM_SET);
63+
64+
// then
65+
verify(problemSetStatisticRepository).findByIdElseThrow(problemSetId);
66+
assertThat(problemSetStatistic.getSubmitCount()).isEqualTo(1L);
67+
assertThat(problemSetStatistic.getViewCount()).isEqualTo(0L);
68+
}
69+
70+
@Test
71+
void 새끼문항_조회수_증가() {
72+
// given
73+
Long childProblemId = 1L;
74+
ChildProblemStatistic childProblemStatistic = new ChildProblemStatistic(childProblemId);
75+
given(childProblemStatisticRepository.findByIdElseThrow(childProblemId))
76+
.willReturn(childProblemStatistic);
77+
78+
// when
79+
countStatisticsUpdateService.updateStatistics(childProblemId, StatisticFieldType.VIEW,
80+
StatisticEntityTarget.CHILD_PROBLEM);
81+
82+
// then
83+
verify(childProblemStatisticRepository).findByIdElseThrow(childProblemId);
84+
assertThat(childProblemStatistic.getViewCount()).isEqualTo(1L);
85+
assertThat(childProblemStatistic.getSubmitCount()).isEqualTo(0L);
86+
}
87+
}

0 commit comments

Comments
 (0)