Skip to content

Commit

Permalink
Merge branch 'develop/BE' of https://lab.ssafy.com/s11-bigdata-recom-…
Browse files Browse the repository at this point in the history
…sub1/S11P21B304 into develop/BE
  • Loading branch information
korno1 committed Oct 7, 2024
2 parents 8441868 + d8ed244 commit 55bb03b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import chuchu.runnerway.course.dto.AreaDto;
import chuchu.runnerway.course.dto.CourseImageDto;
import chuchu.runnerway.course.dto.RecommendationDto;
import chuchu.runnerway.course.dto.response.OfficialDetailResponseDto;
import chuchu.runnerway.course.dto.response.OfficialListResponseDto;
import chuchu.runnerway.course.entity.Course;
Expand All @@ -25,10 +26,10 @@ public interface CourseMapper {
@IterableMapping(qualifiedByName = "area")
List<AreaDto> toAreaDtoList(List<Course> courses);

@Mapping(source = "course.courseImage.url", target = "courseImage.url")
// @Mapping(source = "course.courseImage.url", target = "courseImage.url")
@Named("OfficialList")
OfficialListResponseDto toOfficialListResponseDto(Course course);
RecommendationDto toRecommendationDto(Course course);

@IterableMapping(qualifiedByName = "OfficialList")
List<OfficialListResponseDto> toOfficialListResponseDtoList(List<Course> courses);
List<RecommendationDto> toRecommendationDtoList(List<Course> courses);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@

public interface OfficialCourseRepository extends JpaRepository<Course, Long> {

@Query(value = "SELECT * FROM course c " +
"WHERE (6371 * acos(cos(radians(:lat)) * cos(radians(c.lat)) * " +
"cos(radians(c.lng) - radians(:lng)) + sin(radians(:lat)) * sin(radians(c.lat)))) <= 3 " +
"and c.course_type = 'official'",
nativeQuery = true)
List<Course> findAll(@Param("lat") double lat, @Param("lng") double lng);
@Query(value = "SELECT c FROM Course c " +
"WHERE c.courseId NOT IN :existCourseId AND c.area = :area AND c.courseType='official' ORDER BY RAND() LIMIT :neededCount")
List<Course> findCourse(@Param("neededCount") int neededCount, @Param("existCourseId") List<Long> existCourseId, @Param("area") String area);

List<Course> findByCourseIdNot(Long courseId);

Expand All @@ -29,4 +26,5 @@ public interface OfficialCourseRepository extends JpaRepository<Course, Long> {
"WHERE c.courseId = :courseId")
void updateArea(Long courseId, String h3Index);


}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
Expand All @@ -46,6 +47,15 @@ public class OfficialCourseServiceImpl implements OfficialCourseService{
@Override
public List<RecommendationDto> findAllOfiicialCourse(double lat, double lng) {
List<RecommendationDto> courses = getRecommendation(lat, lng);
if(courses.size() <= 20){
List<Long> existCourseId = courses.stream()
.map(RecommendationDto::getCourseId)
.toList();
int neededCourseCount = 20 - courses.size();
String area = h3.geoToH3Address(lat, lng, resolution);
List<Course> additionalCourses = officialCourseRepository.findCourse(neededCourseCount, existCourseId, area);
courses.addAll(courseMapper.toRecommendationDtoList(additionalCourses));
}
if(courses.isEmpty()) return null;
for(RecommendationDto course : courses) {
Optional<CourseImage> courseImage = courseImageRepositoryPrimaryKey.findById(course.getCourseId());
Expand All @@ -68,6 +78,7 @@ public OfficialDetailResponseDto getOfficialCourse(Long courseId) {

public List<RecommendationDto> getRecommendation (double lat, double lng) {
Long memberId = MemberInfo.getId();
log.info("member: {}", memberId);
String area = h3.geoToH3Address(lat, lng, resolution);
log.info("area: {}", area);
Flux<RecommendationDto> dto = webClient.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ public interface RunningRecordRepository extends JpaRepository<RunningRecord, Lo
"join fetch rc.course " +
"where YEAR(rc.startDate) = :year and " +
"MONTH(rc.startDate) = :month and " +
"(DAY(rc.startDate) = :day or :day is null)")
"(DAY(rc.startDate) = :day or :day is null) and " +
"rc.member.memberId = :memberId")
List<RunningRecord> findByDate(
@Param("year") int year,
@Param("month") int month,
@Param("day") Integer day);
@Param("day") Integer day,
@Param("memberId") Long memberId);

Optional<RunningRecord> findByRecordId(Long recordId);

Expand All @@ -32,7 +34,8 @@ List<RunningRecord> findByDate(
"COUNT(*) AS totalCount " +
"FROM running_record rr " +
"WHERE YEAR(rr.start_date) = :year " +
"AND MONTH(rr.start_date) = :month",
"AND MONTH(rr.start_date) = :month " +
"AND rr.member_id = :memberId",
nativeQuery = true)
Optional<Map<String, Object>> getRecordMonthData(@Param("year") int year, @Param("month") int month);
Optional<Map<String, Object>> getRecordMonthData(@Param("year") int year, @Param("month") int month, @Param("memberId") Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public class RunningRecordServiceImpl implements RunningRecordService{

@Override
public List<RecordResponseDto> getRecords(int year, int month, Integer day) {
List<RunningRecord> runningRecords = runningRecordRepository.findByDate(year, month, day);
Long memberId = MemberInfo.getId();
List<RunningRecord> runningRecords = runningRecordRepository.findByDate(year, month, day, memberId);
if(runningRecords.isEmpty()) {
return null;
}
Expand All @@ -70,7 +71,8 @@ public RecordDetailResponseDto getRecord(Long recordId) {

@Override
public RecordMonthData getAnalysisRecord(int year, int month) {
Map<String, Object> result = runningRecordRepository.getRecordMonthData(year, month)
Long memberId = MemberInfo.getId();
Map<String, Object> result = runningRecordRepository.getRecordMonthData(year, month, memberId)
.orElseThrow(NoSuchElementException::new);
if(result.get("totalScore") == null){
return new RecordMonthData(
Expand Down
2 changes: 1 addition & 1 deletion BackEnd/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ spring:
include: key

datasource:
url: jdbc:mysql://${serverhost}:${dbport}/chutest
url: jdbc:mysql://${serverhost}:${dbport}/runnerway
username: ${mysqlusername}
password: ${mysqlpassword}
driver-class-name: com.mysql.cj.jdbc.Driver
Expand Down

0 comments on commit 55bb03b

Please sign in to comment.