From 93152d9bfaab5afcc68b407d9de5ead3ca3e9bdb Mon Sep 17 00:00:00 2001 From: Taewan Kim Date: Fri, 6 Oct 2023 13:28:29 +0900 Subject: [PATCH] Change duplicate interfaces between backend and frontend (#238) Signed-off-by: Taewan Kim --- frontend/src/App.jsx | 4 +- frontend/src/pages/History.jsx | 8 +- frontend/src/pages/Home.jsx | 4 +- frontend/src/pages/User.jsx | 4 +- .../lpvs/controller/LPVSWebController.java | 110 +++++++++--------- 5 files changed, 68 insertions(+), 62 deletions(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index a4d1e2a8..36dba35e 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -6,12 +6,14 @@ */ import React from 'react'; +import axios from "axios"; import { BrowserRouter, Routes, Route } from "react-router-dom"; import Home from './pages/Home'; import Login from './pages/Login'; import User from './pages/User'; import History from './pages/History'; +axios.defaults.baseURL = '/api/v1/web'; function App() { return ( @@ -19,7 +21,7 @@ function App() { } /> } /> - } /> + } /> } /> } /> diff --git a/frontend/src/pages/History.jsx b/frontend/src/pages/History.jsx index 8be2e77e..2561f532 100644 --- a/frontend/src/pages/History.jsx +++ b/frontend/src/pages/History.jsx @@ -26,7 +26,7 @@ export const History= () => { const [username, setUsername] = useState(""); useEffect(() => { - axios.get("/login/check") + axios.get("/user/login") .then((loginresponse) => { if (loginresponse.data.isLoggedIn) { setIsLoggedIn(loginresponse.data.isLoggedIn); @@ -36,15 +36,15 @@ export const History= () => { }) .catch(function(error) { console.log(error.toJSON()); - navigate("/login"); + navigate("/user/login"); }); } else { - navigate("/login"); + navigate("/user/login"); } }) .catch(function(error) { console.log(error.toJSON()); - navigate("/login"); + navigate("/user/login"); }); }, []); diff --git a/frontend/src/pages/Home.jsx b/frontend/src/pages/Home.jsx index 86e19771..3b554792 100644 --- a/frontend/src/pages/Home.jsx +++ b/frontend/src/pages/Home.jsx @@ -17,7 +17,7 @@ export const Home = () => { const [username, setUsername] = useState(""); useEffect(() => { - axios.get("/login/check") + axios.get("/user/login") .then((loginresponse) => { if (loginresponse.data.isLoggedIn) { setIsLoggedIn(loginresponse.data.isLoggedIn); @@ -100,7 +100,7 @@ export const Home = () => { ) : ( - + Login )} diff --git a/frontend/src/pages/User.jsx b/frontend/src/pages/User.jsx index 414e8c1c..129ca19e 100644 --- a/frontend/src/pages/User.jsx +++ b/frontend/src/pages/User.jsx @@ -29,7 +29,7 @@ export const User = () => { }); useEffect(() => { - axios.get("/login/check") + axios.get("/user/login") .then((loginresponse) => { if (loginresponse.data.isLoggedIn) { setIsLoggedIn(loginresponse.data.isLoggedIn); @@ -37,7 +37,7 @@ export const User = () => { setUserInfo(userInfoResponse.data); }); } - else navigate("/login") + else navigate("/user/login") }) .catch(function(error) { console.log(error.toJSON()); diff --git a/src/main/java/com/lpvs/controller/LPVSWebController.java b/src/main/java/com/lpvs/controller/LPVSWebController.java index 4de264ed..72f2df60 100644 --- a/src/main/java/com/lpvs/controller/LPVSWebController.java +++ b/src/main/java/com/lpvs/controller/LPVSWebController.java @@ -57,72 +57,76 @@ public LPVSWebController(LPVSMemberRepository memberRepository, LPVSDetectedLice this.lpvsLoginCheckService = LPVSLoginCheckService; } - @GetMapping("user/info") - @ResponseBody - public LPVSMember personalInfoSettings(Authentication authentication) { - lpvsLoginCheckService.loginVerification(authentication); - return lpvsLoginCheckService.getMemberFromMemberMap(authentication); - } + @RequestMapping("/api/v1/web") + @RestController + class PublicInterface { + @GetMapping("/user/info") + @ResponseBody + public LPVSMember personalInfoSettings(Authentication authentication) { + lpvsLoginCheckService.loginVerification(authentication); + return lpvsLoginCheckService.getMemberFromMemberMap(authentication); + } - @GetMapping("login/check") - @ResponseBody - public LPVSLoginMember loginMember(Authentication authentication) { - Map oauthLoginMemberMap = lpvsLoginCheckService.getOauthLoginMemberMap(authentication); - boolean isLoggedIn = oauthLoginMemberMap == null || oauthLoginMemberMap.isEmpty(); - if (!isLoggedIn) { - LPVSMember findMember = lpvsLoginCheckService.getMemberFromMemberMap(authentication); - return new LPVSLoginMember(!isLoggedIn, findMember); - } else { - return new LPVSLoginMember(!isLoggedIn, null); + @GetMapping("/user/login") + @ResponseBody + public LPVSLoginMember loginMember(Authentication authentication) { + Map oauthLoginMemberMap = lpvsLoginCheckService.getOauthLoginMemberMap(authentication); + boolean isLoggedIn = oauthLoginMemberMap == null || oauthLoginMemberMap.isEmpty(); + if (!isLoggedIn) { + LPVSMember findMember = lpvsLoginCheckService.getMemberFromMemberMap(authentication); + return new LPVSLoginMember(!isLoggedIn, findMember); + } else { + return new LPVSLoginMember(!isLoggedIn, null); + } } - } - @PostMapping("user/update") - public ResponseEntity postSettingTest(@RequestBody Map map, Authentication authentication) { - lpvsLoginCheckService.loginVerification(authentication); - LPVSMember findMember = lpvsLoginCheckService.getMemberFromMemberMap(authentication); - try { - findMember.setNickname(map.get("nickname")); - findMember.setOrganization(map.get("organization")); - memberRepository.saveAndFlush(findMember); - } catch (DataIntegrityViolationException e) { - throw new IllegalArgumentException("DuplicatedKeyException"); + @PostMapping("/user/update") + public ResponseEntity postSettingTest(@RequestBody Map map, Authentication authentication) { + lpvsLoginCheckService.loginVerification(authentication); + LPVSMember findMember = lpvsLoginCheckService.getMemberFromMemberMap(authentication); + try { + findMember.setNickname(map.get("nickname")); + findMember.setOrganization(map.get("organization")); + memberRepository.saveAndFlush(findMember); + } catch (DataIntegrityViolationException e) { + throw new IllegalArgumentException("DuplicatedKeyException"); + } + return ResponseEntity.ok().body(findMember); } - return ResponseEntity.ok().body(findMember); - } - @ResponseBody - @GetMapping("/history/{type}/{name}") - public HistoryEntity newHistoryPageByUser(@PathVariable("type") String type, - @PathVariable("name") String name, - @PageableDefault(size = 5, sort = "date", - direction = Sort.Direction.DESC) Pageable pageable, Authentication authentication) { + @ResponseBody + @GetMapping("/history/{type}/{name}") + public HistoryEntity newHistoryPageByUser(@PathVariable("type") String type, + @PathVariable("name") String name, + @PageableDefault(size = 5, sort = "date", + direction = Sort.Direction.DESC) Pageable pageable, Authentication authentication) { - HistoryPageEntity historyPageEntity = lpvsLoginCheckService.pathCheck(type, name, pageable, authentication); - Page prPage = historyPageEntity.getPrPage(); - Long count = historyPageEntity.getCount(); + HistoryPageEntity historyPageEntity = lpvsLoginCheckService.pathCheck(type, name, pageable, authentication); + Page prPage = historyPageEntity.getPrPage(); + Long count = historyPageEntity.getCount(); - List lpvsHistories = new ArrayList<>(); - List lpvsPullRequests = prPage.getContent(); + List lpvsHistories = new ArrayList<>(); + List lpvsPullRequests = prPage.getContent(); - for (LPVSPullRequest pr : lpvsPullRequests) { - String[] pullNumberTemp = pr.getPullRequestUrl().split("/"); - LocalDateTime localDateTime = new Timestamp(pr.getDate().getTime()).toLocalDateTime(); - String formattingDateTime = lpvsLoginCheckService.dateTimeFormatting(localDateTime); + for (LPVSPullRequest pr : lpvsPullRequests) { + String[] pullNumberTemp = pr.getPullRequestUrl().split("/"); + LocalDateTime localDateTime = new Timestamp(pr.getDate().getTime()).toLocalDateTime(); + String formattingDateTime = lpvsLoginCheckService.dateTimeFormatting(localDateTime); - Boolean hasIssue = detectedLicenseRepository.existsIssue(pr); + Boolean hasIssue = detectedLicenseRepository.existsIssue(pr); - lpvsHistories.add(new LPVSHistory(formattingDateTime, pr.getRepositoryName(), pr.getId(), - pr.getPullRequestUrl(), pr.getStatus(), pr.getSender(), - pullNumberTemp[pullNumberTemp.length-2] + "/" + - pullNumberTemp[pullNumberTemp.length-1], hasIssue)); - } + lpvsHistories.add(new LPVSHistory(formattingDateTime, pr.getRepositoryName(), pr.getId(), + pr.getPullRequestUrl(), pr.getStatus(), pr.getSender(), + pullNumberTemp[pullNumberTemp.length-2] + "/" + + pullNumberTemp[pullNumberTemp.length-1], hasIssue)); + } - HistoryEntity historyEntity = new HistoryEntity(lpvsHistories, count); - return historyEntity; + HistoryEntity historyEntity = new HistoryEntity(lpvsHistories, count); + return historyEntity; + } } - @GetMapping("error") + @GetMapping("/error") public String redirect(){ return "index.html"; }