-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] : 로그인한 유저가 북마크한 survey 조회 기능을 추가한다 (#390)
- Loading branch information
Showing
9 changed files
with
344 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
POST http://nalab-server:8080/v1/oauth/default # Default provider를 통해서 로그인 진행 | ||
{ | ||
"nickname": "find_bookmakred_survey1", | ||
"email": "find_bookmakred_survey1@12345" | ||
} | ||
|
||
HTTP 200 | ||
[Asserts] | ||
header "Content-type" == "application/json" | ||
|
||
jsonpath "$.access_token" exists | ||
jsonpath "$.token_type" exists | ||
|
||
[Captures] | ||
token_type_1: jsonpath "$.token_type" | ||
auth_token_1: jsonpath "$.access_token" | ||
|
||
########## | ||
|
||
POST http://nalab-server:8080/v1/surveys # 발급받은 토큰으로 survey를 생성한다. | ||
Authorization: {{ token_type_1 }} {{ auth_token_1 }} | ||
{ | ||
"question_count": 2, | ||
"question": [ | ||
{ | ||
"type": "choice", | ||
"form_type": "tendency", | ||
"title": "저는 UI, UI, GUI 중에 어떤 분야를 가장 잘하는 것 같나요?", | ||
"choices": [ | ||
{ | ||
"content": "UI", | ||
"order": 1 | ||
}, | ||
{ | ||
"content": "UX", | ||
"order": 2 | ||
}, | ||
{ | ||
"content": "GUI", | ||
"order": 3 | ||
} | ||
], | ||
"max_selectable_count": 1, | ||
"order": 1 | ||
}, | ||
{ | ||
"type": "short", | ||
"form_type": "strength", | ||
"title": "저는 UX, UI, GUI 중에 어떤 분야에 더 강점이 있나요?", | ||
"order": 2 | ||
} | ||
] | ||
} | ||
|
||
HTTP 201 | ||
[Asserts] | ||
header "Content-type" == "application/json" | ||
|
||
jsonpath "$.survey_id" exists | ||
|
||
[Captures] | ||
survey_id_1: jsonpath "$.survey_id" | ||
|
||
########## | ||
|
||
POST http://nalab-server:8080/v1/oauth/default # Default provider를 통해서 로그인 진행 | ||
{ | ||
"nickname": "find_bookmakred_survey2", | ||
"email": "find_bookmakred_survey2@12345" | ||
} | ||
|
||
HTTP 200 | ||
[Asserts] | ||
header "Content-type" == "application/json" | ||
|
||
jsonpath "$.access_token" exists | ||
jsonpath "$.token_type" exists | ||
|
||
[Captures] | ||
token_type_2: jsonpath "$.token_type" | ||
auth_token_2: jsonpath "$.access_token" | ||
|
||
########## | ||
|
||
POST http://nalab-server:8080/v1/surveys # 발급받은 토큰으로 survey를 생성한다. | ||
Authorization: {{ token_type_2 }} {{ auth_token_2 }} | ||
{ | ||
"question_count": 2, | ||
"question": [ | ||
{ | ||
"type": "choice", | ||
"form_type": "tendency", | ||
"title": "저는 UI, UI, GUI 중에 어떤 분야를 가장 잘하는 것 같나요?", | ||
"choices": [ | ||
{ | ||
"content": "UI", | ||
"order": 1 | ||
}, | ||
{ | ||
"content": "UX", | ||
"order": 2 | ||
}, | ||
{ | ||
"content": "GUI", | ||
"order": 3 | ||
} | ||
], | ||
"max_selectable_count": 1, | ||
"order": 1 | ||
}, | ||
{ | ||
"type": "short", | ||
"form_type": "strength", | ||
"title": "저는 UX, UI, GUI 중에 어떤 분야에 더 강점이 있나요?", | ||
"order": 2 | ||
} | ||
] | ||
} | ||
|
||
HTTP 201 | ||
[Asserts] | ||
header "Content-type" == "application/json" | ||
|
||
jsonpath "$.survey_id" exists | ||
|
||
[Captures] | ||
survey_id_2: jsonpath "$.survey_id" | ||
|
||
########## | ||
|
||
POST http://nalab-server:8080/v1/surveys/{{ survey_id_1 }}/bookmarks | ||
Authorization: {{ token_type_1 }} {{ auth_token_1 }} | ||
|
||
HTTP 200 | ||
[Asserts] | ||
header "Content-type" == "application/json" | ||
|
||
jsonpath "$.survey_id" == {{ survey_id_1 }} | ||
|
||
########## | ||
|
||
POST http://nalab-server:8080/v1/surveys/{{ survey_id_2 }}/bookmarks | ||
Authorization: {{ token_type_1 }} {{ auth_token_1 }} | ||
|
||
HTTP 200 | ||
[Asserts] | ||
header "Content-type" == "application/json" | ||
|
||
jsonpath "$.survey_id" == {{ survey_id_2 }} | ||
|
||
########## | ||
|
||
GET http://nalab-server:8080/v1/surveys/bookmarks | ||
Authorization: {{ token_type_1 }} {{ auth_token_1 }} | ||
|
||
HTTP 200 | ||
[Asserts] | ||
header "Content-type" == "application/json" | ||
|
||
jsonpath "$.bookmarked_surveys.[0].survey_id" == {{ survey_id_1 }} | ||
jsonpath "$.bookmarked_surveys.[0].nickname" == "find_bookmakred_survey1" | ||
|
||
jsonpath "$.bookmarked_surveys.[1].survey_id" == {{ survey_id_2 }} | ||
jsonpath "$.bookmarked_surveys.[1].nickname" == "find_bookmakred_survey2" | ||
|
||
########## | ||
|
||
GET http://nalab-server:8080/v1/surveys/bookmarks | ||
Authorization: {{ token_type_1 }} {{ auth_token_1 }} | ||
|
||
[QueryStringParams] | ||
last-survey-id: {{ survey_id_1 }} | ||
count: 1 | ||
|
||
HTTP 200 | ||
[Asserts] | ||
header "Content-type" == "application/json" | ||
|
||
jsonpath "$.bookmarked_surveys.[0].survey_id" == {{ survey_id_2 }} | ||
jsonpath "$.bookmarked_surveys.[0].nickname" == "find_bookmakred_survey2" |
13 changes: 13 additions & 0 deletions
13
...in/java/me/nalab/survey/application/port/in/web/bookmark/BookmarkedSurveyFindUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package me.nalab.survey.application.port.in.web.bookmark; | ||
|
||
import java.util.List; | ||
import me.nalab.survey.application.common.survey.dto.SurveyBookmarkDto; | ||
|
||
public interface BookmarkedSurveyFindUseCase { | ||
|
||
/** | ||
* targetId를 입력받아 SurveyBookmarkDto를 반환합니다. | ||
*/ | ||
List<SurveyBookmarkDto> findBookmarkedSurveysByTargetId(Long targetId, Long lastSurveyId, Integer count); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...c/main/java/me/nalab/survey/application/service/bookmark/BookmarkedSurveyFindService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package me.nalab.survey.application.service.bookmark; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import me.nalab.survey.application.common.survey.dto.SurveyBookmarkDto; | ||
import me.nalab.survey.application.port.in.web.bookmark.BookmarkedSurveyFindUseCase; | ||
import me.nalab.survey.application.port.out.persistence.findtarget.TargetFindPort; | ||
import me.nalab.survey.application.port.out.persistence.survey.find.SurveyFindPort; | ||
import me.nalab.survey.domain.target.SurveyBookmark; | ||
import me.nalab.survey.domain.target.Target; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class BookmarkedSurveyFindService implements BookmarkedSurveyFindUseCase { | ||
|
||
private final TargetFindPort targetFindPort; | ||
private final SurveyFindPort surveyFindPort; | ||
|
||
@Override | ||
@Transactional(readOnly = true) | ||
public List<SurveyBookmarkDto> findBookmarkedSurveysByTargetId(Long targetId, Long lastSurveyId, Integer count) { | ||
var target = targetFindPort.getTargetById(targetId); | ||
var bookmarkedTargets = targetFindPort.findAllTargetBySurveyIds(getSurveyIds(target, lastSurveyId, count)); | ||
|
||
return bookmarkedTargets.stream() | ||
.map(bookmarkedTarget -> { | ||
var surveyId = bookmarkedTarget.getSurveyList().get(0).getId(); | ||
return SurveyBookmarkDto.from(surveyId, bookmarkedTarget); | ||
}) | ||
.toList(); | ||
} | ||
|
||
private Set<Long> getSurveyIds(Target target, Long lastSurveyId, Integer count) { | ||
return target.getBookmarkedSurveys().stream() | ||
.map(SurveyBookmark::surveyId) | ||
.filter(aLong -> aLong > lastSurveyId) | ||
.limit(count) | ||
.collect(Collectors.toSet()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...or/src/main/java/me/nalab/survey/web/adaptor/bookmark/BookmarkedSurveyFindController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package me.nalab.survey.web.adaptor.bookmark; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import me.nalab.survey.application.port.in.web.bookmark.BookmarkedSurveyFindUseCase; | ||
import me.nalab.survey.web.adaptor.bookmark.response.SurveyBookmarksResponse; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestAttribute; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/v1") | ||
@RequiredArgsConstructor | ||
public class BookmarkedSurveyFindController { | ||
|
||
private final BookmarkedSurveyFindUseCase bookmarkedSurveyFindUseCase; | ||
|
||
@GetMapping("/surveys/bookmarks") | ||
@ResponseStatus(HttpStatus.OK) | ||
public SurveyBookmarksResponse findBookmarkedSurveys( | ||
@RequestAttribute("logined") Long loginedTargetId, | ||
@RequestParam(value = "last-survey-id", defaultValue = "0") Long lastSurveyId, | ||
@RequestParam(value = "count", defaultValue = "20") Integer count | ||
) { | ||
var bookmarkedSurveys = bookmarkedSurveyFindUseCase.findBookmarkedSurveysByTargetId(loginedTargetId, | ||
lastSurveyId, count); | ||
return SurveyBookmarksResponse.of(bookmarkedSurveys); | ||
} | ||
|
||
} |
Oops, something went wrong.