Skip to content

Commit

Permalink
Change duplicate interfaces between backend and frontend (#238)
Browse files Browse the repository at this point in the history
Signed-off-by: Taewan Kim <[email protected]>
  • Loading branch information
tiokim authored Oct 6, 2023
1 parent d0dd462 commit 93152d9
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 62 deletions.
4 changes: 3 additions & 1 deletion frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@
*/

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 (
<BrowserRouter>
<div className='App'>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/home" element={<Home />} />
<Route path="/login" element={<Login />} />
<Route path="/user/login" element={<Login />} />
<Route path="/user/setting" element={<User />} />
<Route path="/history/:type/:name" element={<History />} />
</Routes>
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/pages/History.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
});
}, []);

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -100,7 +100,7 @@ export const Home = () => {
</Link>
</span>
) : (
<Link to={"/login"} style={{ color: "black", textDecoration: "none" }}>
<Link to={"/user/login"} style={{ color: "black", textDecoration: "none" }}>
Login
</Link>
)}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/User.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ export const User = () => {
});

useEffect(() => {
axios.get("/login/check")
axios.get("/user/login")
.then((loginresponse) => {
if (loginresponse.data.isLoggedIn) {
setIsLoggedIn(loginresponse.data.isLoggedIn);
axios.get("/user/info").then((userInfoResponse) => {
setUserInfo(userInfoResponse.data);
});
}
else navigate("/login")
else navigate("/user/login")
})
.catch(function(error) {
console.log(error.toJSON());
Expand Down
110 changes: 57 additions & 53 deletions src/main/java/com/lpvs/controller/LPVSWebController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> 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<String, Object> 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<LPVSMember> postSettingTest(@RequestBody Map<String, String> 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<LPVSMember> postSettingTest(@RequestBody Map<String, String> 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<LPVSPullRequest> prPage = historyPageEntity.getPrPage();
Long count = historyPageEntity.getCount();
HistoryPageEntity historyPageEntity = lpvsLoginCheckService.pathCheck(type, name, pageable, authentication);
Page<LPVSPullRequest> prPage = historyPageEntity.getPrPage();
Long count = historyPageEntity.getCount();

List<LPVSHistory> lpvsHistories = new ArrayList<>();
List<LPVSPullRequest> lpvsPullRequests = prPage.getContent();
List<LPVSHistory> lpvsHistories = new ArrayList<>();
List<LPVSPullRequest> 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";
}
Expand Down

0 comments on commit 93152d9

Please sign in to comment.