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
11 changes: 10 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
---
name: Bug report
about: Create a report to help us improve
title: "[FIX]"
labels: ''
assignees: EunbeenDev

---

## 🍀 Summary
> 어떤 문제인가요?
-
Expand All @@ -6,4 +15,4 @@
-

## ☁️ Reference
-
-
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/custom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Task request
about: Suggest an idea for this project
title: ""
labels:
assignees: EunbeenDev

---
## 🍀 Summary
> 어떤 기능인가요?
-
## ✔️ Task & Description
> 상세 작업 내용을 설명해주세요.
-

## ☁️ Reference
-
13 changes: 13 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
---
name: Feature request
about: Suggest an idea for this project
title: "[FEAT]"
labels: feature ✨
assignees: EunbeenDev

---

## 🍀 Summary
> 어떤 기능인가요?
-
Expand All @@ -7,3 +16,7 @@

## ☁️ Reference
-


**Additional context**
Add any other context or screenshots about the feature request here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.movelog.domain.record.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
public class Recent5RecordImagesRes {

@Schema( type = "String", example ="https://movelog.com/record/1/image/1", description="최근 5개의 기록 이미지 URL")
private String imageUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import com.movelog.domain.news.dto.response.NewsCalendarRes;
import com.movelog.domain.record.dto.request.CreateRecordReq;
import com.movelog.domain.record.dto.request.SearchKeywordReq;
import com.movelog.domain.record.dto.response.RecentRecordImagesRes;
import com.movelog.domain.record.dto.response.RecordCalendarRes;
import com.movelog.domain.record.dto.response.SearchKeywordRes;
import com.movelog.domain.record.dto.response.TodayRecordStatus;
import com.movelog.domain.record.dto.response.*;
import com.movelog.domain.record.service.RecordService;
import com.movelog.global.config.security.token.UserPrincipal;
import com.movelog.global.payload.Message;
Expand Down Expand Up @@ -97,9 +94,9 @@ public ResponseEntity<?> retrieveRecentRecordImages(
@GetMapping("/search")
public ResponseEntity<?> searchKeyword(
@Parameter(description = "User의 토큰을 입력해주세요.", required = true) @AuthenticationPrincipal UserPrincipal userPrincipal,
@Parameter(description = "검색할 명사를 입력해주세요.", required = true) @RequestBody SearchKeywordReq searchKeywordReq
@Parameter(description = "검색할 명사를 입력해주세요.", required = true) @RequestParam String keyword
) {
List<SearchKeywordRes> result = recordService.searchKeyword(userPrincipal, searchKeywordReq);
List<SearchKeywordRes> result = recordService.searchKeyword(userPrincipal, keyword);
return ResponseEntity.ok(ApiResponseUtil.success(result));
}

Expand All @@ -125,4 +122,22 @@ public ResponseEntity<?> getRecordByDate(
}


@Operation(summary = "사용자 기록 이미지 중 최신 5개 목록 조회 API", description = "사용자가 생성한 기록 이미지 중 최신 5개 목록을 조회하는 API입니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "최신 5개 기록 이미지 목록 조회 성공",
content = @Content(mediaType = "application/json",
schema = @Schema(type = "array", implementation = Recent5RecordImagesRes.class))),
@ApiResponse(responseCode = "400", description = "최신 5개 기록 이미지 목록 조회 실패",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class)))
})
@GetMapping("/current")
public ResponseEntity<?> retrieveCurrentRecordImages(
@Parameter(description = "User의 토큰을 입력해주세요.", required = true) @AuthenticationPrincipal UserPrincipal userPrincipal
) {
List<Recent5RecordImagesRes> result = recordService.retrieveCurrentRecordImages(userPrincipal);
return ResponseEntity.ok(ApiResponseUtil.success(result));
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ public interface RecordRepository extends JpaRepository<Record,Long> {
"AND r.actionTime BETWEEN :start AND :end " +
"ORDER BY r.actionTime ASC")
Page<Record> findRecordByUserAndCreatedAtBetween(User user, LocalDateTime start, LocalDateTime end, Pageable pageable);


// 사용자가 등록한 기록 중 가장 최근 5개의 기록을 조회, 이미지가 있는 경우만 조회
// 5개의 기록만 조회
List<Record> findTop5ByKeywordUserAndRecordImageNotNullOrderByActionTimeDesc(User user);

}
21 changes: 15 additions & 6 deletions src/main/java/com/movelog/domain/record/service/RecordService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import com.movelog.domain.record.domain.VerbType;
import com.movelog.domain.record.dto.request.CreateRecordReq;
import com.movelog.domain.record.dto.request.SearchKeywordReq;
import com.movelog.domain.record.dto.response.RecentRecordImagesRes;
import com.movelog.domain.record.dto.response.RecordCalendarRes;
import com.movelog.domain.record.dto.response.SearchKeywordRes;
import com.movelog.domain.record.dto.response.TodayRecordStatus;
import com.movelog.domain.record.dto.response.*;
import com.movelog.domain.record.repository.KeywordRepository;
import com.movelog.domain.record.repository.RecordRepository;
import com.movelog.domain.user.application.UserService;
Expand Down Expand Up @@ -145,10 +142,9 @@ public List<RecentRecordImagesRes> retrieveRecentRecordImages(UserPrincipal user
}


public List<SearchKeywordRes> searchKeyword(UserPrincipal userPrincipal, SearchKeywordReq searchKeywordReq) {
public List<SearchKeywordRes> searchKeyword(UserPrincipal userPrincipal, String keyword) {
User user = validUserById(userPrincipal);
// User user = validUserById(5L);
String keyword = searchKeywordReq.getSearchKeyword();
List<Keyword> keywords = keywordRepository.findAllByUserAndKeywordContaining(user, keyword);
keywords.forEach(k -> log.info("Keyword in DB: {}", k.getKeyword()));

Expand Down Expand Up @@ -190,6 +186,19 @@ public Page<RecordCalendarRes> getRecordByDate(UserPrincipal userPrincipal, Stri

}

public List<Recent5RecordImagesRes> retrieveCurrentRecordImages(UserPrincipal userPrincipal) {
User user = validUserById(userPrincipal);
// User user = userRepository.findById(5L).orElseThrow(UserNotFoundException::new);

List<Record> records = recordRepository.findTop5ByKeywordUserAndRecordImageNotNullOrderByActionTimeDesc(user);

return records.stream()
.map(record -> Recent5RecordImagesRes.builder()
.imageUrl((record.getRecordImage()))
.build())
.toList();
}


private User validUserById(UserPrincipal userPrincipal) {
Optional<User> userOptional = userService.findById(userPrincipal.getId());
Expand Down