-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat oauth 로그인 Controller 생성 - moveOauthLoginPage 로그인 페이지로 이동 - oauthLogin 토큰 인가 코드로 토큰 발급받아 넘겨준다 * feat 사용자가 알림을 원하는 정보 받기 - jackson 상속으로 type값에 따라 다른 Dto 생성 * build lombok 추가 * refactor api 파싱 구조 변경 및 변수에 final 추가 - 챗봇 api맞는 구조로 변경 * refactor Json 역직렬화시에 생성자 또는 팩토리 메서드 찾지 못하는 현상 제거 - @JsonCreator로 데이터 파싱 * feat 챗봇 스킬 반환값 만들기 * docs out 폴더 지우기 * test mock mvc를 이용해 Json 데이터 파싱 테스트 작성 * refactor 컨트롤러 이름 및 패키지 구조변경 - 기존 InfoController를 SimpleController로 변경 - api 응답값 수정(SimpleTextContentDto클래스 추가) - test json데이터 수정 * feat text card controller생성 - 응답 예제 추가 * test text card 테스트 추가 * refactor 코드 리펙토링 - method readJsonFile resources 하위 파일 읽는 메소드 변경 - 상수 인터페이스 삭제
- Loading branch information
Showing
22 changed files
with
500 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ build/ | |
|
||
#intellij | ||
.idea | ||
out/ |
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
37 changes: 37 additions & 0 deletions
37
api/src/main/java/com/kth/mssage/info/web/controller/SimpleTextController.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,37 @@ | ||
package com.kth.mssage.info.web.controller; | ||
|
||
import com.kth.mssage.info.web.dto.request.ParamDto; | ||
import com.kth.mssage.info.web.dto.request.RequestActionDto; | ||
import com.kth.mssage.info.web.dto.request.skill.WeatherDto; | ||
import com.kth.mssage.info.web.dto.response.ResponseResultDto; | ||
import com.kth.mssage.info.web.dto.response.TemplateDto; | ||
import com.kth.mssage.info.web.dto.response.skill.simpletext.SimpleTextContentDto; | ||
import com.kth.mssage.info.web.dto.response.skill.simpletext.SimpleTextDto; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RequestMapping("/simple-text") | ||
@RestController | ||
public class SimpleTextController { | ||
|
||
@ResponseStatus(value = HttpStatus.OK) | ||
@PostMapping("/message") | ||
public ResponseResultDto<SimpleTextDto> requestMessageInfo(@RequestBody RequestActionDto<ParamDto> requestActionDto) { | ||
WeatherDto weatherDto = (WeatherDto) requestActionDto.getAction().getParamDto(); | ||
|
||
SimpleTextContentDto textDto = SimpleTextContentDto.builder() | ||
.text(weatherDto.getLocation() + " 날씨가 좋아요") | ||
.build(); | ||
|
||
SimpleTextDto simpleTextDto = SimpleTextDto.builder() | ||
.simpleText(textDto) | ||
.build(); | ||
|
||
TemplateDto<SimpleTextDto> templateDto = TemplateDto.<SimpleTextDto>builder() | ||
.build(); | ||
|
||
templateDto.addOutput(simpleTextDto); | ||
|
||
return ResponseResultDto.createResultMessage(templateDto); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
api/src/main/java/com/kth/mssage/info/web/controller/TextCardController.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,48 @@ | ||
package com.kth.mssage.info.web.controller; | ||
|
||
|
||
import com.kth.mssage.info.web.dto.request.ParamDto; | ||
import com.kth.mssage.info.web.dto.request.RequestActionDto; | ||
import com.kth.mssage.info.web.dto.request.skill.WeatherDto; | ||
import com.kth.mssage.info.web.dto.response.ResponseResultDto; | ||
import com.kth.mssage.info.web.dto.response.TemplateDto; | ||
import com.kth.mssage.info.web.dto.response.skill.textcard.TextCardButtonDto; | ||
import com.kth.mssage.info.web.dto.response.skill.textcard.TextCardContentDto; | ||
import com.kth.mssage.info.web.dto.response.skill.textcard.TextCardDto; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RequestMapping("/text-card") | ||
@RestController | ||
public class TextCardController { | ||
|
||
@ResponseStatus(value = HttpStatus.OK) | ||
@PostMapping("/message") | ||
public ResponseResultDto<TextCardDto> requestMessageInfo(@RequestBody RequestActionDto<ParamDto> requestActionDto) { | ||
WeatherDto weatherDto = (WeatherDto) requestActionDto.getAction().getParamDto(); | ||
|
||
TextCardButtonDto textCardButtonDto = TextCardButtonDto.builder() | ||
.action("webLink") | ||
.label(weatherDto.getLocation() + "보러가기") | ||
.webLinkUrl("https://i.kakao.com/docs/skill-response-format#basiccard") | ||
.build(); | ||
|
||
TextCardContentDto textCardContentDto = TextCardContentDto.builder() | ||
.title("날씨를 보여주는 text card 입니다.") | ||
.description("링크를 누르시면 web으로 이동됩니다.") | ||
.build(); | ||
|
||
textCardContentDto.addButton(textCardButtonDto); | ||
|
||
TextCardDto textCardDto = TextCardDto.builder() | ||
.textCard(textCardContentDto) | ||
.build(); | ||
|
||
TemplateDto<TextCardDto> templateDto = TemplateDto.<TextCardDto>builder() | ||
.build(); | ||
|
||
templateDto.addOutput(textCardDto); | ||
|
||
return ResponseResultDto.createResultMessage(templateDto); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
api/src/main/java/com/kth/mssage/info/web/dto/request/ActionDto.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,18 @@ | ||
package com.kth.mssage.info.web.dto.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class ActionDto<T extends ParamDto> { | ||
|
||
private final T paramDto; | ||
|
||
@JsonCreator | ||
public ActionDto(@JsonProperty("params") T paramDto) { | ||
this.paramDto = paramDto; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
api/src/main/java/com/kth/mssage/info/web/dto/request/ParamDto.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,32 @@ | ||
package com.kth.mssage.info.web.dto.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo.As; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; | ||
import com.kth.mssage.info.web.dto.request.skill.WeatherDto; | ||
import lombok.Getter; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
@JsonTypeInfo( | ||
use = Id.NAME, | ||
include = As.EXISTING_PROPERTY, | ||
property = "type", | ||
visible = true | ||
) | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(name = "날씨", value = WeatherDto.class) | ||
}) | ||
@Getter | ||
@SuperBuilder | ||
public class ParamDto { | ||
|
||
private final String type; | ||
|
||
@JsonCreator | ||
public ParamDto(@JsonProperty("type") String type) { | ||
this.type = type; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
api/src/main/java/com/kth/mssage/info/web/dto/request/RequestActionDto.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,18 @@ | ||
package com.kth.mssage.info.web.dto.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class RequestActionDto<T extends ParamDto> { | ||
|
||
private final ActionDto<T> action; | ||
|
||
@JsonCreator | ||
public RequestActionDto(@JsonProperty("action") ActionDto<T> action) { | ||
this.action = action; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
api/src/main/java/com/kth/mssage/info/web/dto/request/skill/WeatherDto.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,21 @@ | ||
package com.kth.mssage.info.web.dto.request.skill; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.kth.mssage.info.web.dto.request.ParamDto; | ||
import lombok.Getter; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
@Getter | ||
@SuperBuilder | ||
public class WeatherDto extends ParamDto { | ||
|
||
private final String location; | ||
|
||
@JsonCreator | ||
public WeatherDto(@JsonProperty("type") String type, | ||
@JsonProperty("location") String location) { | ||
super(type); | ||
this.location = location; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
api/src/main/java/com/kth/mssage/info/web/dto/response/ResponseResultDto.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,18 @@ | ||
package com.kth.mssage.info.web.dto.response; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class ResponseResultDto<T> { | ||
|
||
private final String version = "2.0"; | ||
private final TemplateDto<T> template; | ||
|
||
public static <T> ResponseResultDto<T> createResultMessage(TemplateDto<T> templateDto) { | ||
return ResponseResultDto.<T>builder() | ||
.template(templateDto) | ||
.build(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
api/src/main/java/com/kth/mssage/info/web/dto/response/TemplateDto.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,17 @@ | ||
package com.kth.mssage.info.web.dto.response; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class TemplateDto<T> { | ||
|
||
private final List<T> outputs = new ArrayList<>(); | ||
|
||
public void addOutput(T output) { | ||
this.outputs.add(output); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...main/java/com/kth/mssage/info/web/dto/response/skill/simpletext/SimpleTextContentDto.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,11 @@ | ||
package com.kth.mssage.info.web.dto.response.skill.simpletext; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class SimpleTextContentDto { | ||
|
||
private final String text; | ||
} |
11 changes: 11 additions & 0 deletions
11
api/src/main/java/com/kth/mssage/info/web/dto/response/skill/simpletext/SimpleTextDto.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,11 @@ | ||
package com.kth.mssage.info.web.dto.response.skill.simpletext; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class SimpleTextDto { | ||
|
||
private final SimpleTextContentDto simpleText; | ||
} |
12 changes: 12 additions & 0 deletions
12
api/src/main/java/com/kth/mssage/info/web/dto/response/skill/textcard/TextCardButtonDto.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,12 @@ | ||
package com.kth.mssage.info.web.dto.response.skill.textcard; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class TextCardButtonDto { | ||
private final String action; | ||
private final String label; | ||
private final String webLinkUrl; | ||
} |
20 changes: 20 additions & 0 deletions
20
...src/main/java/com/kth/mssage/info/web/dto/response/skill/textcard/TextCardContentDto.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,20 @@ | ||
package com.kth.mssage.info.web.dto.response.skill.textcard; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Getter | ||
@Builder | ||
public class TextCardContentDto { | ||
|
||
private final String title; | ||
private final String description; | ||
private final List<TextCardButtonDto> buttons = new ArrayList<>(); | ||
|
||
public void addButton(TextCardButtonDto textCardButtonDto) { | ||
this.buttons.add(textCardButtonDto); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
api/src/main/java/com/kth/mssage/info/web/dto/response/skill/textcard/TextCardDto.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,11 @@ | ||
package com.kth.mssage.info.web.dto.response.skill.textcard; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class TextCardDto { | ||
|
||
private final TextCardContentDto textCard; | ||
} |
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,8 @@ | ||
package com.kth.mssage; | ||
|
||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest | ||
class MessageApplicationTest { | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...rc/test/java/com/kth/mssage/info/web/controller/integration/SimpleTextControllerTest.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,40 @@ | ||
package com.kth.mssage.info.web.controller.integration; | ||
|
||
import com.kth.mssage.info.web.controller.util.JsonReader; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@AutoConfigureMockMvc | ||
@SpringBootTest | ||
class SimpleTextControllerTest { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
private String jsonRequest; | ||
private String jsonResponse; | ||
|
||
@BeforeEach | ||
public void setup() throws Exception { | ||
jsonRequest = JsonReader.readJsonFile("__files/payload/chatbot-message-request.json"); | ||
jsonResponse = JsonReader.readJsonFile("__files/payload/simple-text-message-response.json"); | ||
} | ||
|
||
@Test | ||
public void testSimpleTextController() throws Exception { | ||
mockMvc.perform(post("/simple-text/message") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(jsonRequest)) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().json(jsonResponse)); | ||
} | ||
} |
Oops, something went wrong.