Skip to content

Commit d33f340

Browse files
authored
Merge branch 'dev' into feat#59
2 parents b1dd5b4 + d6fbaf1 commit d33f340

File tree

72 files changed

+2197
-157
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2197
-157
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ name: deploy
55
# =========================
66
env:
77
IMAGE_REPOSITORY: backend # GHCR 이미지 리포지토리명(소유자 포함 X)
8-
CONTAINER_1_NAME: backend_1
8+
CONTAINER_1_NAME: backend
99
EC2_INSTANCE_TAG_NAME: team2-ec2-1 # 배포 대상 EC2 Name 태그
1010
DOCKER_NETWORK: common # 도커 네트워크
1111
BACKEND_DIR: . # Dockerfile 위치

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,8 @@ terraform.tfstate
5050
terraform.tfstate.backup
5151
.terraform.tfstate.lock.info
5252
terraform/secrets.tf
53+
54+
55+
### Claude AI ###
56+
CLAUDE.md
57+
.claude/

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dependencies {
2828
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
2929
implementation("org.springframework.boot:spring-boot-starter-validation")
3030
implementation("org.springframework.boot:spring-boot-starter-web")
31+
implementation("org.springframework.boot:spring-boot-starter-webflux")
3132
implementation("io.github.cdimascio:java-dotenv:5.2.2")
3233
implementation("org.springframework.boot:spring-boot-starter-security")
3334
implementation("org.springframework.boot:spring-boot-starter-oauth2-client")

src/main/java/com/back/BackApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import io.github.cdimascio.dotenv.Dotenv;
44
import org.springframework.boot.SpringApplication;
55
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.cache.annotation.EnableCaching;
67
import org.springframework.scheduling.annotation.EnableScheduling;
78

89
@SpringBootApplication
910
@EnableScheduling
11+
@EnableCaching
1012
public class BackApplication {
1113

1214
public static void main(String[] args) {
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.back.domain.chatbot.controller;
2+
3+
import com.back.domain.chatbot.dto.ChatRequestDto;
4+
import com.back.domain.chatbot.dto.ChatResponseDto;
5+
import com.back.domain.chatbot.entity.ChatConversation;
6+
import com.back.domain.chatbot.service.ChatbotService;
7+
import com.back.global.rsData.RsData;
8+
import jakarta.validation.Valid;
9+
import lombok.RequiredArgsConstructor;
10+
import lombok.extern.slf4j.Slf4j;
11+
import org.springframework.http.ResponseEntity;
12+
import org.springframework.web.bind.annotation.*;
13+
14+
import java.util.List;
15+
16+
@RestController
17+
@RequestMapping("/api/chatbot")
18+
@RequiredArgsConstructor
19+
@Slf4j
20+
public class ChatbotController {
21+
22+
private final ChatbotService chatbotService;
23+
24+
@PostMapping("/chat")
25+
public ResponseEntity<RsData<ChatResponseDto>> sendMessage(@Valid @RequestBody ChatRequestDto requestDto) {
26+
try {
27+
ChatResponseDto response = chatbotService.sendMessage(requestDto);
28+
return ResponseEntity.ok(RsData.successOf(response));
29+
} catch (Exception e) {
30+
log.error("채팅 메시지 처리 중 오류 발생: ", e);
31+
return ResponseEntity.internalServerError()
32+
.body(RsData.failOf("서버 오류가 발생했습니다."));
33+
}
34+
}
35+
36+
@GetMapping("/history/{sessionId}")
37+
public ResponseEntity<RsData<List<ChatConversation>>> getChatHistory(@PathVariable String sessionId) {
38+
try {
39+
List<ChatConversation> history = chatbotService.getChatHistory(sessionId);
40+
return ResponseEntity.ok(RsData.successOf(history));
41+
} catch (Exception e) {
42+
log.error("채팅 기록 조회 중 오류 발생: ", e);
43+
return ResponseEntity.internalServerError()
44+
.body(RsData.failOf("서버 오류가 발생했습니다."));
45+
}
46+
}
47+
48+
@GetMapping("/history/user/{userId}/session/{sessionId}")
49+
public ResponseEntity<RsData<List<ChatConversation>>> getUserChatHistory(
50+
@PathVariable Long userId,
51+
@PathVariable String sessionId) {
52+
try {
53+
List<ChatConversation> history = chatbotService.getUserChatHistory(userId, sessionId);
54+
return ResponseEntity.ok(RsData.successOf(history));
55+
} catch (Exception e) {
56+
log.error("사용자 채팅 기록 조회 중 오류 발생: ", e);
57+
return ResponseEntity.internalServerError()
58+
.body(RsData.failOf("서버 오류가 발생했습니다."));
59+
}
60+
}
61+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.back.domain.chatbot.dto;
2+
3+
import jakarta.validation.constraints.NotBlank;
4+
import lombok.Getter;
5+
import lombok.NoArgsConstructor;
6+
import lombok.Setter;
7+
8+
@Getter
9+
@Setter
10+
@NoArgsConstructor
11+
public class ChatRequestDto {
12+
13+
@NotBlank(message = "메시지는 필수입니다.")
14+
private String message;
15+
16+
private String sessionId;
17+
18+
private Long userId;
19+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.back.domain.chatbot.dto;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
import lombok.NoArgsConstructor;
6+
import lombok.Setter;
7+
8+
import java.time.LocalDateTime;
9+
10+
@Getter
11+
@Setter
12+
@NoArgsConstructor
13+
@AllArgsConstructor
14+
public class ChatResponseDto {
15+
16+
private String response;
17+
private String sessionId;
18+
private LocalDateTime timestamp;
19+
20+
public ChatResponseDto(String response, String sessionId) {
21+
this.response = response;
22+
this.sessionId = sessionId;
23+
this.timestamp = LocalDateTime.now();
24+
}
25+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.back.domain.chatbot.dto;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
import java.util.List;
7+
8+
@Getter
9+
@Setter
10+
public class GeminiRequestDto {
11+
12+
private List<Content> contents;
13+
14+
@Getter
15+
@Setter
16+
public static class Content {
17+
private List<Part> parts;
18+
19+
public Content(String text) {
20+
this.parts = List.of(new Part(text));
21+
}
22+
}
23+
24+
@Getter
25+
@Setter
26+
public static class Part {
27+
private String text;
28+
29+
public Part(String text) {
30+
this.text = text;
31+
}
32+
}
33+
34+
public GeminiRequestDto(String message) {
35+
this.contents = List.of(new Content(message));
36+
}
37+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.back.domain.chatbot.dto;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
import java.util.List;
7+
8+
@Getter
9+
@Setter
10+
public class GeminiResponseDto {
11+
12+
private List<Candidate> candidates;
13+
14+
@Getter
15+
@Setter
16+
public static class Candidate {
17+
private Content content;
18+
}
19+
20+
@Getter
21+
@Setter
22+
public static class Content {
23+
private List<Part> parts;
24+
}
25+
26+
@Getter
27+
@Setter
28+
public static class Part {
29+
private String text;
30+
}
31+
32+
public String getGeneratedText() {
33+
if (candidates != null && !candidates.isEmpty() &&
34+
candidates.get(0).content != null &&
35+
candidates.get(0).content.parts != null &&
36+
!candidates.get(0).content.parts.isEmpty()) {
37+
return candidates.get(0).content.parts.get(0).text;
38+
}
39+
return "응답을 생성할 수 없습니다.";
40+
}
41+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.back.domain.chatbot.entity;
2+
3+
import jakarta.persistence.*;
4+
import lombok.*;
5+
6+
import java.time.LocalDateTime;
7+
8+
import static jakarta.persistence.GenerationType.IDENTITY;
9+
10+
@Getter
11+
@Setter
12+
@NoArgsConstructor
13+
@AllArgsConstructor
14+
@Builder
15+
@ToString
16+
@Entity
17+
public class ChatConversation {
18+
@Id
19+
@GeneratedValue(strategy = IDENTITY)
20+
private Long id;
21+
22+
private Long userId;
23+
24+
@Column(columnDefinition = "TEXT")
25+
private String userMessage;
26+
27+
@Column(columnDefinition = "TEXT")
28+
private String botResponse;
29+
30+
private String sessionId;
31+
32+
private LocalDateTime createdAt;
33+
34+
@PrePersist
35+
protected void onCreate() {
36+
createdAt = LocalDateTime.now();
37+
}
38+
}

0 commit comments

Comments
 (0)