Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public ResponseEntity<ApiResult<Void>> chat(@RequestBody PromptRequest promptReq
System.out.println("=== AiController.chat() 호출됨 === userInput: " + promptRequest.getUserInput());
String aiResponse = aiService.generateContent(promptRequest.getUserInput());
System.out.println("=== AiController.chat() 응답 완료 ===");

return ResponseEntity.ok(ApiResult.ok(aiResponse));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,14 @@ public ResponseEntity<ApiResult<Void>> deleteTarget(
targetService.deleteTarget(userDetails.getId(), targetId);
return ResponseEntity.ok(ApiResult.ok("대상자 정보가 삭제되었습니다."));
}

@Operation(summary = "최근 메시지 보낸날짜 갱신", description = "메시지를 보내면 최근 메시지를 보낸 날짜를 갱신합니다.")
@PutMapping("/{targetId}/message-date")
public ResponseEntity<ApiResult<Void>> updateLastMessageDate(
@AuthenticationPrincipal CustomUserDetails userDetails,
@PathVariable Long targetId
) {
targetService.updateLastMessageDate(userDetails.getId(), targetId);
return ResponseEntity.ok(ApiResult.ok("최근 메시지 보낸 날짜가 업데이트되었습니다."));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class TargetPerson extends BaseTimeEntity {
@JoinColumn(name = "chat_style_id")
private ChatStyle chatStyle;

private Instant lastMessageDate;

private Instant deletedAt;

@Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.Instant;
import java.util.Optional;
import java.util.List;

Expand All @@ -30,4 +31,10 @@ public interface TargetPersonRepository extends JpaRepository<TargetPerson, Long

@Query("SELECT t.user.id FROM TargetPerson t WHERE t.id = :id AND t.deletedAt IS NULL")
Optional<Long> findOwnerIdByIdAndDeletedAtIsNull(@Param("id") Long id);

@Modifying
@Query("UPDATE TargetPerson t SET t.lastMessageDate = :date WHERE t.id = :targetId AND t.user.id = :userId AND t.deletedAt IS NULL")
int updateLastMessageDate(@Param("targetId") Long targetId,
@Param("userId") Long userId,
@Param("date") Instant date);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ private SecurityPaths() {}
"/prompts",
"/relationships",
"/chat-styles",
"/health",
"/"
"/health"
};

public static final String[] CSRF_IGNORED = {
Expand All @@ -28,7 +27,8 @@ private SecurityPaths() {}
"/prompts",
"/users",
"/targets",
"/relationships"
"/relationships",
"/health"
};

public static final String[] PUBLIC_DOCS = {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/example/team4backend/service/TargetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.Instant;
import java.util.List;

@Service
Expand Down Expand Up @@ -150,4 +151,18 @@ public void deleteTarget(Long userId, Long targetId) {

throw new BusinessException(ErrorCode.AUTH_FORBIDDEN);
}

@Transactional
public void updateLastMessageDate(Long userId, Long targetId) {
int updated = targetPersonRepository.updateLastMessageDate(
targetId,
userId,
Instant.now()
);

if (updated == 0) {
// targetId가 존재하지 않거나 userId가 일치하지 않음
throw new BusinessException(ErrorCode.NOT_FOUND);
}
}
}