Skip to content

Commit 70bfa7a

Browse files
committed
feat : 메시지 프롬프트 변경, db구조 변경, 가상친구 생성 시 입력 데이터 변경
1 parent 54d724c commit 70bfa7a

File tree

14 files changed

+175
-176
lines changed

14 files changed

+175
-176
lines changed

api/src/main/java/com/mbtips/domain/fastfriend/controller/FastFriendController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.mbtips.common.response.ApiResponse;
44
import com.mbtips.domain.fastfriend.controller.dto.request.FastFriendMessageRequest;
55
import com.mbtips.domain.fastfriend.controller.dto.request.FastFriendRequest;
6-
import com.mbtips.domain.fastfriend.service.FastFriendService;
6+
//import com.mbtips.domain.fastfriend.service.FastFriendService;
77
import com.mbtips.domain.message.dto.request.CreateMessageRequestDto;
88
import com.mbtips.domain.user.User;
99
import com.mbtips.domain.virtualfriend.VirtualFriendService;
@@ -22,7 +22,7 @@
2222
@RequestMapping("/api/fast-friend")
2323
public class FastFriendController {
2424

25-
private final FastFriendService fastFriendService;
25+
// private final FastFriendService fastFriendService;
2626
private final VirtualFriendService virtualFriendService;
2727
private final MessageManager manager;
2828

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,27 @@
11
package com.mbtips.domain.fastfriend.controller.dto.request;
22

33
import com.mbtips.domain.virtualfriend.enums.Gender;
4-
import com.mbtips.fastfriend.entity.FastFriend;
54
import jakarta.validation.constraints.Pattern;
65

7-
import java.util.List;
86

97
public record FastFriendRequest(
108

119
String fastFriendName,
1210

1311
int fastFriendAge,
1412

15-
String fastFriendRelationship,
16-
1713
Gender gender,
1814

19-
2015
@Pattern(
2116
regexp = "^(INTJ|INTP|ENTJ|ENTP|INFJ|INFP|ENFJ|ENFP|ISTJ|ISFJ|ESTJ|ESFJ|ISTP|ISFP|ESTP|ESFP)$",
2217
message = "유효하지 않은 mbti입니다. 16가지중 하나를 입력해주세요."
2318
)
2419
String mbti,
2520

21+
String fastFriendJob,
2622

27-
List<String> interests
23+
String freeSetting
2824

2925
) {
3026

31-
public FastFriend toEntity(FastFriendRequest request) {
32-
return FastFriend.builder()
33-
.mbti(request.mbti)
34-
.fastFriendName(request.fastFriendName)
35-
.fastFriendAge(request.fastFriendAge)
36-
.fastFriendSex(request.gender)
37-
.fastFriendRelationship(request.fastFriendRelationship)
38-
.build();
39-
}
4027
}
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.mbtips.domain.fastfriend.controller.dto.response;
22

33
import com.mbtips.domain.virtualfriend.enums.Gender;
4-
import com.mbtips.fastfriend.entity.FastFriend;
54

65
public record FastFriendResponse (
76
Long fastFriendId,
@@ -12,14 +11,14 @@ public record FastFriendResponse (
1211
String fastFriendRelationship
1312
){
1413

15-
public static FastFriendResponse from(FastFriend saveFriend) {
16-
return new FastFriendResponse(
17-
saveFriend.getFastFriendId(),
18-
saveFriend.getMbti(),
19-
saveFriend.getFastFriendName(),
20-
saveFriend.getFastFriendAge(),
21-
saveFriend.getFastFriendSex(),
22-
saveFriend.getFastFriendRelationship()
23-
);
24-
}
14+
// public static FastFriendResponse from(FastFriend saveFriend) {
15+
// return new FastFriendResponse(
16+
// saveFriend.getFastFriendId(),
17+
// saveFriend.getMbti(),
18+
// saveFriend.getFastFriendName(),
19+
// saveFriend.getFastFriendAge(),
20+
// saveFriend.getFastFriendSex(),
21+
// saveFriend.getFastFriendRelationship()
22+
// );
23+
// }
2524
}
Lines changed: 58 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,58 @@
1-
package com.mbtips.domain.fastfriend.service;
2-
3-
import com.mbtips.clova.client.ClovaApiFeignClient;
4-
import com.mbtips.common.exception.CustomException;
5-
import com.mbtips.common.mbtiinfo.MbtiTraits;
6-
import com.mbtips.common.mbtiinfo.MbtiType;
7-
import com.mbtips.common.provider.ClovaApiKeyProvider;
8-
import com.mbtips.domain.fastfriend.controller.dto.request.FastFriendMessageRequest;
9-
import com.mbtips.domain.fastfriend.controller.dto.request.FastFriendRequest;
10-
import com.mbtips.domain.fastfriend.exception.FastFriendException;
11-
import com.mbtips.fastfriend.FastFriendRepository;
12-
import com.mbtips.fastfriend.entity.FastFriend;
13-
import com.mbtips.message.application.manager.MessageManager;
14-
import lombok.RequiredArgsConstructor;
15-
import lombok.extern.slf4j.Slf4j;
16-
import org.springframework.stereotype.Service;
17-
18-
import java.util.Optional;
19-
20-
21-
@Service
22-
@RequiredArgsConstructor
23-
@Slf4j
24-
public class FastFriendService {
25-
private final FastFriendRepository fastFriendRepository;
26-
private final ClovaApiFeignClient clovaApiFeignClient;
27-
private final ClovaApiKeyProvider clovaApiKeyProvider;
28-
private final MessageManager messageManager;
29-
30-
public Long createFastFriend(FastFriendRequest fastFriendRequest) {
31-
FastFriend friend = fastFriendRequest.toEntity(fastFriendRequest);
32-
FastFriend saveFriend = fastFriendRepository.save(friend);
33-
Long result = saveFriend.getFastFriendId();
34-
log.debug("빠른 친구 생성이 완료되었습니다. {}", result);
35-
return result;
36-
}
37-
38-
public String messageRequest(FastFriendMessageRequest request) {
39-
FastFriend fastFriend = fastFriendRepository.findById(request.fastFriendId()).orElseThrow(() ->
40-
new CustomException(FastFriendException.NOT_FOUND));
41-
String prompt = getfastFriendPrompt(fastFriend);
42-
String result = messageManager.messageRequest(prompt + request.content());
43-
log.debug(result);
44-
return result;
45-
}
46-
47-
private String getfastFriendPrompt(FastFriend fastFriend) {
48-
StringBuilder result = new StringBuilder();
49-
50-
if(fastFriend.getFastFriendName() != null) result.append(" 너의 이름은 " + fastFriend.getFastFriendName() +"이야. 명심해!");
51-
MbtiType mbtiType = MbtiType.valueOf(fastFriend.getMbti());
52-
result.append(MbtiTraits.getTrait(mbtiType));
53-
if(fastFriend.getFastFriendAge() != 0) result.append(" 너의 나이는 " + fastFriend.getFastFriendAge() + "이야. ");
54-
if(fastFriend.getFastFriendSex() != null) result.append(" 너의 성별은 " + fastFriend.getFastFriendSex() + "이야. ");
55-
if(fastFriend.getFastFriendRelationship() != null) result.append("너와 나의 관계는 " + fastFriend.getFastFriendRelationship() + "이야");
56-
result.append("이제 대화를 시작해보자. 20~40자로 짧게해줘. ");
57-
58-
log.debug("fastfriend prompt : {}", result.toString());
59-
return result.toString();
60-
}
61-
}
1+
//package com.mbtips.domain.fastfriend.service;
2+
//
3+
//import com.mbtips.clova.client.ClovaApiFeignClient;
4+
//import com.mbtips.common.exception.CustomException;
5+
//import com.mbtips.common.mbtiinfo.MbtiTraits;
6+
//import com.mbtips.common.mbtiinfo.MbtiType;
7+
//import com.mbtips.common.provider.ClovaApiKeyProvider;
8+
//import com.mbtips.domain.fastfriend.controller.dto.request.FastFriendMessageRequest;
9+
//import com.mbtips.domain.fastfriend.controller.dto.request.FastFriendRequest;
10+
//import com.mbtips.domain.fastfriend.exception.FastFriendException;
11+
//import com.mbtips.message.application.manager.MessageManager;
12+
//import lombok.RequiredArgsConstructor;
13+
//import lombok.extern.slf4j.Slf4j;
14+
//import org.springframework.stereotype.Service;
15+
//
16+
//import java.util.Optional;
17+
//
18+
//
19+
//@Service
20+
//@RequiredArgsConstructor
21+
//@Slf4j
22+
//public class FastFriendService {
23+
// private final ClovaApiFeignClient clovaApiFeignClient;
24+
// private final ClovaApiKeyProvider clovaApiKeyProvider;
25+
// private final MessageManager messageManager;
26+
//
27+
// public Long createFastFriend(FastFriendRequest fastFriendRequest) {
28+
// FastFriend friend = fastFriendRequest.toEntity(fastFriendRequest);
29+
// FastFriend saveFriend = fastFriendRepository.save(friend);
30+
// Long result = saveFriend.getFastFriendId();
31+
// log.debug("빠른 친구 생성이 완료되었습니다. {}", result);
32+
// return result;
33+
// }
34+
//
35+
// public String messageRequest(FastFriendMessageRequest request) {
36+
// FastFriend fastFriend = fastFriendRepository.findById(request.fastFriendId()).orElseThrow(() ->
37+
// new CustomException(FastFriendException.NOT_FOUND));
38+
// String prompt = getfastFriendPrompt(fastFriend);
39+
// String result = messageManager.messageRequest(prompt + request.content());
40+
// log.debug(result);
41+
// return result;
42+
// }
43+
//
44+
// private String getfastFriendPrompt(FastFriend fastFriend) {
45+
// StringBuilder result = new StringBuilder();
46+
//
47+
// if(fastFriend.getFastFriendName() != null) result.append(" 너의 이름은 " + fastFriend.getFastFriendName() +"이야. 명심해!");
48+
// MbtiType mbtiType = MbtiType.valueOf(fastFriend.getMbti());
49+
// result.append(MbtiTraits.getTrait(mbtiType));
50+
// if(fastFriend.getFastFriendAge() != 0) result.append(" 너의 나이는 " + fastFriend.getFastFriendAge() + "이야. ");
51+
// if(fastFriend.getFastFriendSex() != null) result.append(" 너의 성별은 " + fastFriend.getFastFriendSex() + "이야. ");
52+
// if(fastFriend.getFastFriendRelationship() != null) result.append("너와 나의 관계는 " + fastFriend.getFastFriendRelationship() + "이야");
53+
// result.append("이제 대화를 시작해보자. 20~40자로 짧게해줘. ");
54+
//
55+
// log.debug("fastfriend prompt : {}", result.toString());
56+
// return result.toString();
57+
// }
58+
//}

api/src/main/java/com/mbtips/domain/virtualfriend/VirtualFriendService.java

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,21 @@ public VirtualFriendResponse createVirtualFriend(VirtualFriendRequest req, User
5757
.mbti(req.mbti())
5858
.age(req.age())
5959
.gender(req.gender())
60-
.relationship(req.relationship())
6160
.friendType(type)
61+
.job(req.job())
62+
.freeSetting(req.freeSetting())
6263
.build();
6364

6465
VirtualFriend saveVirtualFriend = virtualFriendRepository.save(virtualFriend);
6566

66-
List<Interest> interests = req.interests()
67-
.stream()
68-
.map(topic -> Interest.builder()
69-
.virtualFriend(saveVirtualFriend)
70-
.topic(topic)
71-
.build())
72-
.toList();
73-
interestRepository.saveAll(interests);
67+
// List<Interest> interests = req.interests()
68+
// .stream()
69+
// .map(topic -> Interest.builder()
70+
// .virtualFriend(saveVirtualFriend)
71+
// .topic(topic)
72+
// .build())
73+
// .toList();
74+
// interestRepository.saveAll(interests);
7475

7576
Conversation conversation = conversationService.createConversation(saveVirtualFriend, user);
7677
return VirtualFriendResponse.from(saveVirtualFriend, conversation.getConversationId());
@@ -105,7 +106,7 @@ public VirtualFriendInfoResponse findFriendInfoById(Long virtualFriendId) {
105106
VirtualFriend virtualFriend = virtualFriendRepository.findById(virtualFriendId);
106107
List<String> interest = interestRepository.findTopicsByVirtualFriendId(virtualFriendId);
107108
log.debug("interest : {}", interest);
108-
VirtualFriendInfoResponse result = VirtualFriendInfoResponse.from(virtualFriend, interest);
109+
VirtualFriendInfoResponse result = VirtualFriendInfoResponse.from(virtualFriend);
109110
return result;
110111
}
111112

@@ -117,21 +118,22 @@ public VirtualFriendInfoResponse updateVirtualFriend(Long virtualFriendId, Virtu
117118
.mbti(req.mbti())
118119
.age(req.age())
119120
.gender(req.gender())
120-
.relationship(req.relationship())
121+
.job(req.job())
122+
.freeSetting(req.freeSetting())
121123
.build();
122124
VirtualFriend updateFriend = virtualFriendRepository.update(virtualFriendId, virtualFriend);
123125
interestRepository.deleteInterestByVirtualFriend(updateFriend);
124-
List<Interest> interests = req.interests()
125-
.stream()
126-
.map(topic -> Interest.builder()
127-
.virtualFriend(updateFriend)
128-
.topic(topic)
129-
.build())
130-
.toList();
131-
interestRepository.saveAll(interests);
132-
133-
List<String> topics = interests.stream().map(Interest::getTopic).collect(Collectors.toList());
134-
return VirtualFriendInfoResponse.from(updateFriend, topics);
126+
// List<Interest> interests = req.interests()
127+
// .stream()
128+
// .map(topic -> Interest.builder()
129+
// .virtualFriend(updateFriend)
130+
// .topic(topic)
131+
// .build())
132+
// .toList();
133+
// interestRepository.saveAll(interests);
134+
135+
// List<String> topics = interests.stream().map(Interest::getTopic).collect(Collectors.toList());
136+
return VirtualFriendInfoResponse.from(updateFriend);
135137
}
136138

137139
public CreateMessageRequestDto createMessageRequestDto(FastFriendMessageRequest request) {

api/src/main/java/com/mbtips/domain/virtualfriend/request/VirtualFriendRequest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import java.util.List;
1414
import java.util.Optional;
15+
import java.util.Spliterator;
1516

1617
@JsonIgnoreProperties(ignoreUnknown = true)
1718
public record VirtualFriendRequest(
@@ -20,8 +21,6 @@ public record VirtualFriendRequest(
2021

2122
int age,
2223

23-
String relationship,
24-
2524
Gender gender,
2625

2726
@Pattern(
@@ -30,7 +29,10 @@ public record VirtualFriendRequest(
3029
)
3130
String mbti,
3231

33-
List<String> interests
32+
String job,
33+
34+
String freeSetting
35+
3436
){
3537

3638

@@ -39,7 +41,6 @@ public static VirtualFriendEntity toEntity(VirtualFriendRequest req, UserEntity
3941
.user(userEntity)
4042
.virtualFriendName(req.friendName)
4143
.virtualFriendAge(req.age)
42-
.virtualFriendRelationship(req.relationship)
4344
.virtualFriendSex(req.gender)
4445
.mbti(req.mbti)
4546
.build();
@@ -50,10 +51,10 @@ public static VirtualFriendRequest from(FastFriendRequest fastFriendRequest) {
5051
return new VirtualFriendRequest(
5152
Optional.ofNullable(fastFriendRequest.fastFriendName()).orElse("빠른친구"),
5253
Optional.ofNullable(fastFriendRequest.fastFriendAge()).orElse(20),
53-
Optional.ofNullable(fastFriendRequest.fastFriendRelationship()).orElse(null),
5454
Optional.ofNullable(fastFriendRequest.gender()).orElse(null),
5555
Optional.ofNullable(fastFriendRequest.mbti()).orElse(null),
56-
Optional.ofNullable(fastFriendRequest.interests()).orElse(null)
56+
Optional.ofNullable(fastFriendRequest.fastFriendJob()).orElse(null),
57+
Optional.ofNullable(fastFriendRequest.freeSetting()).orElse(null)
5758
);
5859
}
5960
}

api/src/main/java/com/mbtips/domain/virtualfriend/response/VirtualFriendInfoResponse.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ public record VirtualFriendInfoResponse(
1111
String name,
1212
int age,
1313
Gender gender,
14-
String relationship,
15-
List<String> interest
14+
String job,
15+
String freeSetting
1616
) {
17-
public static VirtualFriendInfoResponse from(VirtualFriend virtualFriend, List<String> interest){
17+
public static VirtualFriendInfoResponse from(VirtualFriend virtualFriend){
1818
return new VirtualFriendInfoResponse(
1919
virtualFriend.getVirtualFriendId(),
2020
virtualFriend.getMbti(),
2121
virtualFriend.getName(),
2222
virtualFriend.getAge(),
2323
virtualFriend.getGender(),
24-
virtualFriend.getRelationship(),
25-
interest
24+
virtualFriend.getJob(),
25+
virtualFriend.getFreeSetting()
2626
);
2727
}
2828
}

api/src/main/java/com/mbtips/domain/virtualfriend/response/VirtualFriendResponse.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ public record VirtualFriendResponse (
1111
String virtualFriendName,
1212
int virtualFriendAge,
1313
Gender virtualFriendSex,
14-
String virtualFriendRelationship
14+
String virtualFriendJob,
15+
String freeSetting
1516
){
1617
public static VirtualFriendResponse from(VirtualFriend virtualFriend , long conversationId) {
1718
return new VirtualFriendResponse(
@@ -21,7 +22,8 @@ public static VirtualFriendResponse from(VirtualFriend virtualFriend , long conv
2122
virtualFriend.getName(),
2223
virtualFriend.getAge(),
2324
virtualFriend.getGender(),
24-
virtualFriend.getRelationship()
25+
virtualFriend.getJob(),
26+
virtualFriend.getFreeSetting()
2527
);
2628
}
2729

0 commit comments

Comments
 (0)