33import com .google .gson .JsonElement ;
44import com .google .gson .JsonParser ;
55import koreatech .in .service .KakaoBotService ;
6- import koreatech .in .skillresponse .KakaoBotEnum ;
6+ import koreatech .in .skillresponse .KakaoBot ;
77import koreatech .in .skillresponse .SkillResponse ;
88import org .springframework .http .HttpStatus ;
99import org .springframework .http .ResponseEntity ;
@@ -25,66 +25,66 @@ public class KakaoBotController {
2525
2626 @ RequestMapping (value = "/dinings" , method = RequestMethod .POST , produces = "application/json;charset=UTF-8" )
2727 public @ ResponseBody
28- ResponseEntity requestDinings (@ RequestBody String body ) {
29- JsonParser jsonParser = new JsonParser ();
30- JsonElement jsonElement = jsonParser .parse (body );
31-
32- // ['action']['params']['mealtime']
33- JsonElement action = jsonElement .getAsJsonObject ().get ("action" );
34- JsonElement params = action .getAsJsonObject ().get ("params" );
35- String mealtime = params .getAsJsonObject ().get ("mealtime" ).getAsString ();
36-
28+ ResponseEntity <String > requestDinings (@ RequestBody String body ) {
3729 String result ;
3830 try {
31+ JsonParser jsonParser = new JsonParser ();
32+ JsonElement jsonElement = jsonParser .parse (body );
33+
34+ // ['action']['params']['mealtime']
35+ JsonElement action = jsonElement .getAsJsonObject ().get ("action" );
36+ JsonElement params = action .getAsJsonObject ().get ("params" );
37+ String mealtime = params .getAsJsonObject ().get ("mealtime" ).getAsString ();
38+
3939 result = kakaoBotService .crawlHaksik (mealtime );
4040 } catch (Exception e ) {
4141 SkillResponse errorMsg = new SkillResponse ();
4242 errorMsg .addSimpleText ("API 오류가 발생하였습니다." );
4343 result = errorMsg .getSkillPayload ().toString ();
4444 }
4545
46- return new ResponseEntity <String >(result , HttpStatus .OK );
46+ return new ResponseEntity <>(result , HttpStatus .OK );
4747 }
4848
4949 @ RequestMapping (value = "/buses/request" , method = RequestMethod .POST , produces = "application/json;charset=UTF-8" )
5050 public @ ResponseBody
51- ResponseEntity requestBuses (@ RequestBody String body ) {
51+ ResponseEntity < String > requestBuses (@ RequestBody String body ) {
5252 SkillResponse busSkill = new SkillResponse ();
53- busSkill .addQujckReplies ("한기대→야우리" , KakaoBotEnum .QuickRepliesActionType .MESSAGE .getTypeText (), "한기대→야우리" );
54- busSkill .addQujckReplies ("한기대→천안역" , KakaoBotEnum .QuickRepliesActionType .MESSAGE .getTypeText (), "한기대→천안역" );
55- busSkill .addQujckReplies ("야우리→한기대" , KakaoBotEnum .QuickRepliesActionType .MESSAGE .getTypeText (), "야우리→한기대" );
56- busSkill .addQujckReplies ("야우리→천안역" , KakaoBotEnum .QuickRepliesActionType .MESSAGE .getTypeText (), "야우리→천안역" );
57- busSkill .addQujckReplies ("천안역→한기대" , KakaoBotEnum .QuickRepliesActionType .MESSAGE .getTypeText (), "천안역→한기대" );
58- busSkill .addQujckReplies ("천안역→야우리" , KakaoBotEnum .QuickRepliesActionType .MESSAGE .getTypeText (), "천안역→야우리" );
53+ busSkill .addQujckReplies ("한기대→야우리" , KakaoBot .QuickRepliesActionType .MESSAGE .getTypeText (), "한기대→야우리" );
54+ busSkill .addQujckReplies ("한기대→천안역" , KakaoBot .QuickRepliesActionType .MESSAGE .getTypeText (), "한기대→천안역" );
55+ busSkill .addQujckReplies ("야우리→한기대" , KakaoBot .QuickRepliesActionType .MESSAGE .getTypeText (), "야우리→한기대" );
56+ busSkill .addQujckReplies ("야우리→천안역" , KakaoBot .QuickRepliesActionType .MESSAGE .getTypeText (), "야우리→천안역" );
57+ busSkill .addQujckReplies ("천안역→한기대" , KakaoBot .QuickRepliesActionType .MESSAGE .getTypeText (), "천안역→한기대" );
58+ busSkill .addQujckReplies ("천안역→야우리" , KakaoBot .QuickRepliesActionType .MESSAGE .getTypeText (), "천안역→야우리" );
5959
6060 busSkill .addSimpleText ("선택하세요!" );
6161
6262 String busSkillStr = busSkill .getSkillPayload ().toString ();
6363
64- return new ResponseEntity <String >(busSkillStr , HttpStatus .OK );
64+ return new ResponseEntity <>(busSkillStr , HttpStatus .OK );
6565 }
6666
6767 @ RequestMapping (value = "/buses" , method = RequestMethod .POST , produces = "application/json;charset=UTF-8" )
6868 public @ ResponseBody
69- ResponseEntity returnBuses (@ RequestBody String body ) {
70- JsonParser jsonParser = new JsonParser ();
71- JsonElement jsonElement = jsonParser .parse (body );
72-
73- // ['action']['params']['place'], ['action']['params']['place1']
74- JsonElement action = jsonElement .getAsJsonObject ().get ("action" );
75- JsonElement params = action .getAsJsonObject ().get ("params" );
76- String depart = params .getAsJsonObject ().get ("place" ).getAsString ();
77- String arrival = params .getAsJsonObject ().get ("place1" ).getAsString ();
78-
69+ ResponseEntity <String > returnBuses (@ RequestBody String body ) {
7970 String result ;
8071 try {
72+ JsonParser jsonParser = new JsonParser ();
73+ JsonElement jsonElement = jsonParser .parse (body );
74+
75+ // ['action']['params']['place'], ['action']['params']['place1']
76+ JsonElement action = jsonElement .getAsJsonObject ().get ("action" );
77+ JsonElement params = action .getAsJsonObject ().get ("params" );
78+ String depart = params .getAsJsonObject ().get ("place" ).getAsString ();
79+ String arrival = params .getAsJsonObject ().get ("place1" ).getAsString ();
80+
8181 result = kakaoBotService .calculateBus (depart , arrival );
8282 } catch (Exception e ) {
8383 SkillResponse errorMsg = new SkillResponse ();
8484 errorMsg .addSimpleText ("API 오류가 발생하였습니다." );
8585 result = errorMsg .getSkillPayload ().toString ();
8686 }
8787
88- return new ResponseEntity <String >(result , HttpStatus .OK );
88+ return new ResponseEntity <>(result , HttpStatus .OK );
8989 }
9090}
0 commit comments