Skip to content

Commit 1bed0c7

Browse files
authored
[feat] 다중 DB 구축 및 사용자 로그 구현
[feat] 다중 DB 구축 및 사용자 로그 구현
2 parents 9d3bf3a + da15ec0 commit 1bed0c7

32 files changed

Lines changed: 867 additions & 56 deletions

MathCaptain/weakness/build.gradle

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ dependencies {
3838
implementation 'org.springframework.boot:spring-boot-starter-websocket'
3939
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
4040
implementation 'io.jsonwebtoken:jjwt-api:0.12.3'
41-
implementation 'commons-codec:commons-codec:1.5'
42-
implementation 'org.springframework.ai:spring-ai-openai-spring-boot-starter'
41+
implementation 'commons-codec:commons-codec:1.13'
42+
implementation 'org.webjars:webjars-locator-core'
43+
implementation 'org.webjars:sockjs-client:1.5.1'
44+
implementation 'org.webjars:stomp-websocket:2.3.4'
4345
implementation 'com.h2database:h2'
4446
runtimeOnly 'mysql:mysql-connector-java:8.0.33'
47+
implementation 'org.postgresql:postgresql:42.7.1'
4548
implementation 'com.auth0:java-jwt:3.13.0'
4649
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.3'
4750
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.3'
@@ -57,11 +60,6 @@ dependencies {
5760
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.0'
5861
}
5962

60-
dependencyManagement {
61-
imports {
62-
mavenBom "org.springframework.ai:spring-ai-bom:$springAiVersion"
63-
}
64-
}
6563

6664
tasks.named('test') {
6765
useJUnitPlatform()

MathCaptain/weakness/src/main/java/MathCaptain/weakness/TestInit.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
import MathCaptain.weakness.domain.Group.entity.Group;
55
import MathCaptain.weakness.domain.Group.entity.RelationBetweenUserAndGroup;
66
import MathCaptain.weakness.domain.Group.enums.CategoryStatus;
7-
import MathCaptain.weakness.domain.Group.enums.GroupRole;
87
import MathCaptain.weakness.domain.Group.repository.GroupRepository;
98
import MathCaptain.weakness.domain.Group.repository.RelationRepository;
109
import MathCaptain.weakness.domain.Record.entity.ActivityRecord;
11-
import MathCaptain.weakness.domain.Record.repository.RecordRepository;
10+
import MathCaptain.weakness.domain.Record.repository.record.RecordRepository;
1211
import MathCaptain.weakness.domain.Recruitment.dto.request.CreateRecruitmentRequest;
1312
import MathCaptain.weakness.domain.Recruitment.entity.Comment;
1413
import MathCaptain.weakness.domain.Recruitment.entity.Recruitment;
15-
import MathCaptain.weakness.domain.Recruitment.enums.RecruitmentStatus;
1614
import MathCaptain.weakness.domain.Recruitment.repository.CommentRepository;
1715
import MathCaptain.weakness.domain.Recruitment.repository.RecruitmentRepository;
1816
import MathCaptain.weakness.domain.User.dto.request.SaveUserRequest;
@@ -33,7 +31,7 @@
3331
@Component
3432
@RequiredArgsConstructor
3533
@Transactional
36-
@DependsOn("entityManagerFactory")
34+
@DependsOn("primaryEntityManagerFactory")
3735
public class TestInit {
3836

3937
private final UserRepository userRepository;
@@ -104,7 +102,7 @@ public void init() {
104102
CategoryStatus.FITNESS, 2, 3, 0L, null, "test2", 3, 4);
105103

106104
GroupCreateRequest groupCreateRequest3 = GroupCreateRequest.of(users1.getUserId(), "testGroup3",
107-
CategoryStatus.READING, 2, 3, 0L, null, "test3", 3, 4);
105+
CategoryStatus.RUNNING, 2, 3, 0L, null, "test3", 3, 4);
108106

109107
Group group1 = Group.of(groupCreateRequest1);
110108
Group group2 = Group.of(groupCreateRequest2);

MathCaptain/weakness/src/main/java/MathCaptain/weakness/WeaknessApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
6+
import org.springframework.context.annotation.ComponentScan;
67
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
78

89
@EnableJpaAuditing
910
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
11+
@ComponentScan(basePackages = "MathCaptain")
1012
public class WeaknessApplication {
1113

1214
public static void main(String[] args) {

MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Group/entity/Group.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class Group {
6161
@CollectionTable(name = "group_weekly_goal_achieve", joinColumns = @JoinColumn(name = "group_id"))
6262
@MapKeyColumn(name = "day_of_week") // 요일을 키로 사용
6363
@Column(name = "goal_count") // 카운트를 값으로 사용
64-
private Map<DayOfWeek, Integer> weeklyGoalAchieveMap = new EnumMap<>(DayOfWeek.class);
64+
private final Map<DayOfWeek, Integer> weeklyGoalAchieveMap = new EnumMap<>(DayOfWeek.class);
6565

6666
@OneToMany(mappedBy = "recruitGroup")
6767
private List<Recruitment> recruitments;

MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Group/enums/CategoryStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
public enum CategoryStatus {
44
FITNESS,
55
STUDY,
6-
READING
6+
RUNNING
77
}

MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Group/service/RelationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import MathCaptain.weakness.domain.Group.dto.response.GroupResponse;
77
import MathCaptain.weakness.domain.Group.dto.response.RelationResponse;
88
import MathCaptain.weakness.domain.Group.repository.GroupRepository;
9-
import MathCaptain.weakness.domain.Record.repository.RecordRepository;
9+
import MathCaptain.weakness.domain.Record.repository.record.RecordRepository;
1010
import MathCaptain.weakness.domain.User.dto.response.UserResponse;
1111
import MathCaptain.weakness.domain.Group.enums.GroupRole;
1212
import MathCaptain.weakness.domain.Group.repository.RelationRepository;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package MathCaptain.weakness.domain.Record.controller;
2+
3+
import MathCaptain.weakness.domain.Record.service.ActivityDetailService;
4+
import MathCaptain.weakness.global.Api.ApiResponse;
5+
import lombok.RequiredArgsConstructor;
6+
import org.springframework.web.bind.annotation.*;
7+
8+
@RestController
9+
@RequiredArgsConstructor
10+
@RequestMapping("/record/detail")
11+
public class ActivityDetailController {
12+
13+
private final ActivityDetailService activityDetailService;
14+
15+
@GetMapping("/fitness/{activityId}")
16+
public ApiResponse<?> getFitnessLog(@PathVariable Long activityId) {
17+
return ApiResponse.ok(activityDetailService.getFitnessLog(activityId));
18+
}
19+
20+
@GetMapping("/study/{activityId}")
21+
public ApiResponse<?> getStudyLog(@PathVariable Long activityId) {
22+
return ApiResponse.ok(activityDetailService.getStudyLog(activityId));
23+
}
24+
25+
@GetMapping("/running/{activityId}")
26+
public ApiResponse<?> getRunningLog(@PathVariable Long activityId) {
27+
return ApiResponse.ok(activityDetailService.getRunningLog(activityId));
28+
}
29+
}
Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package MathCaptain.weakness.domain.Record.controller;
22

3-
import MathCaptain.weakness.domain.Record.dto.request.recordEndRequest;
3+
import MathCaptain.weakness.domain.Record.dto.request.FitnessLogEnrollRequest;
4+
import MathCaptain.weakness.domain.Record.dto.request.RecordEndRequest;
5+
import MathCaptain.weakness.domain.Record.dto.request.RunningLogEnrollRequest;
6+
import MathCaptain.weakness.domain.Record.dto.request.StudyLogEnrollRequest;
47
import MathCaptain.weakness.domain.Record.dto.response.RecordSummaryResponse;
58
import MathCaptain.weakness.domain.Record.service.RecordService;
69
import MathCaptain.weakness.domain.User.entity.Users;
@@ -10,15 +13,36 @@
1013
import lombok.RequiredArgsConstructor;
1114
import org.springframework.web.bind.annotation.*;
1215

16+
import static MathCaptain.weakness.domain.Group.enums.CategoryStatus.*;
17+
1318
@RestController
1419
@RequiredArgsConstructor
15-
@RequestMapping("/record/")
20+
@RequestMapping("/record")
1621
public class RecordController {
1722

1823
private final RecordService recordService;
1924

20-
@PostMapping("/end/{groupId}")
21-
public ApiResponse<RecordSummaryResponse> endActivity(@Valid @LoginUser Users loginUser, @PathVariable Long groupId, @RequestBody recordEndRequest requestDto) {
22-
return ApiResponse.ok(recordService.endActivity(loginUser, groupId, requestDto));
25+
@PostMapping("/end/fitness/{groupId}")
26+
public ApiResponse<RecordSummaryResponse> endFitnessActivity(
27+
@Valid @LoginUser Users loginUser,
28+
@PathVariable Long groupId,
29+
@RequestBody FitnessLogEnrollRequest logRequest) {
30+
return ApiResponse.ok(recordService.endActivity(loginUser, groupId, logRequest, FITNESS));
31+
}
32+
33+
@PostMapping("/end/running/{groupId}")
34+
public ApiResponse<RecordSummaryResponse> endRunningActivity(
35+
@Valid @LoginUser Users loginUser,
36+
@PathVariable Long groupId,
37+
@RequestBody RunningLogEnrollRequest logRequest) {
38+
return ApiResponse.ok(recordService.endActivity(loginUser, groupId, logRequest, RUNNING));
39+
}
40+
41+
@PostMapping("/end/study/{groupId}")
42+
public ApiResponse<RecordSummaryResponse> endStudyActivity(
43+
@Valid @LoginUser Users loginUser,
44+
@PathVariable Long groupId,
45+
@RequestBody StudyLogEnrollRequest logRequest) {
46+
return ApiResponse.ok(recordService.endActivity(loginUser, groupId, logRequest, STUDY));
2347
}
2448
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package MathCaptain.weakness.domain.Record.dto.request;
2+
3+
import lombok.Getter;
4+
import lombok.NoArgsConstructor;
5+
6+
import java.time.LocalDateTime;
7+
8+
@Getter
9+
@NoArgsConstructor
10+
public class ActivityLogEnrollRequest {
11+
12+
private Long activityTime;
13+
14+
private LocalDateTime startTime;
15+
16+
private LocalDateTime endTime;
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package MathCaptain.weakness.domain.Record.dto.request;
2+
3+
import MathCaptain.weakness.domain.Record.entity.UserLog.ExerciseInfo;
4+
import lombok.Getter;
5+
import lombok.NoArgsConstructor;
6+
7+
import java.time.LocalDateTime;
8+
import java.util.List;
9+
10+
@Getter
11+
@NoArgsConstructor
12+
public class FitnessLogEnrollRequest extends ActivityLogEnrollRequest {
13+
14+
private Long activityTime;
15+
16+
private LocalDateTime startTime;
17+
18+
private LocalDateTime endTime;
19+
20+
private List<ExerciseInfo> exerciseInfoList;
21+
}

0 commit comments

Comments
 (0)