Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into FE-feature/mypage
  • Loading branch information
SUMMERLOVE7 committed Feb 21, 2023
2 parents 3da5662 + 8e4d3a4 commit b4e7edf
Show file tree
Hide file tree
Showing 17 changed files with 217 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ public ResponseEntity<?> gifticonAdd(@Valid @RequestPart GifticonDto dto,
}

@GetMapping("/list")
public ResponseEntity<?> gifticonList() {
return new ResponseEntity<>(gifticonService.findGifticons(), HttpStatus.OK);
public ResponseEntity<?> gifticonList(@RequestParam(name = "keyword", required = false, defaultValue = "") String keyword) {
return new ResponseEntity<>(gifticonService.findGifticons(keyword), HttpStatus.OK);
}

@GetMapping("/used")
public ResponseEntity<?> usedGifticonList() {
return new ResponseEntity<>(gifticonService.usedTest(), HttpStatus.OK);
}

@PutMapping("/used")
Expand Down Expand Up @@ -95,7 +100,7 @@ public ResponseEntity<?> illegalArgumentExceptionHandler(IllegalArgumentExceptio
}

@GetMapping("/test")
public ResponseEntity<?> test() {
return new ResponseEntity<>(gifticonService.test(), HttpStatus.OK);
public ResponseEntity<?> test(@RequestParam(name = "keyword", required = false, defaultValue = "") String keyword) {
return new ResponseEntity<>(gifticonService.test(keyword), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,27 @@ void addGifticon(
"barcode, " +
"expiresAt, " +
"usedAt, " +
"price FROM gifticon WHERE uid = :uid")
List<Gifticon> findByUid(@Param("uid") long uid);
"price FROM gifticon WHERE uid = :uid AND (usedAt >= (select now())) AND " +
"(itemName LIKE concat('%', :keyword, '%') OR brandName LIKE concat('%', :keyword, '%'))")
List<Gifticon> findByUid(@Param("uid") long uid, @Param("keyword") String keyword);

@Modifying
@Query("UPDATE gifticon SET usedAt = (SELECT now()) WHERE id = :id")
void useGifticon(@Param("id") long id);

@Query("SELECT * FROM gifticon")
List<Gifticon> test();
@Query("SELECT * FROM gifticon where (usedAt >= (select now())) AND (itemName LIKE concat('%', :keyword, '%') OR brandName LIKE concat('%', :keyword, '%'))")
List<Gifticon> test(@Param("keyword") String keyword);

@Query("SELECT " +
"id, " +
"uid, " +
"itemName, " +
"brandName, " +
"image, " +
"thumbnail, " +
"barcode, " +
"expiresAt, " +
"usedAt, " +
"price FROM gifticon WHERE uid = :uid AND usedAt <= (select now())")
List<Gifticon> findUsedByUid(@Param("uid") long uid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ public void addGifticon(GifticonDto dto, MultipartFile image, MultipartFile thum
}

@Transactional(readOnly = true)
public List<Gifticon> findGifticons() {
public List<Gifticon> findGifticons(String keyword) {
Users user = getUserBySessionId();
if(user == null) {
throw new NotAuthenticatedException();
}
return gifticonRepository.findByUid(user.getId());
return gifticonRepository.findByUid(user.getId(), keyword);
}

@Transactional
Expand All @@ -141,13 +141,26 @@ public void useGifticon(GifticonUseDto dto) throws IllegalArgumentException {
gifticonRepository.useGifticon(dto.getGifticonId());
}

@Transactional
public List<Gifticon> usedGifticonList() {
Users user = getUserBySessionId();
if(user == null) {
throw new NotAuthenticatedException();
}
return gifticonRepository.findUsedByUid(user.getId());
}

private Users getUserBySessionId() {
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
HttpSession session = request.getSession(false);
return (Users) session.getAttribute("User");
}

public List<Gifticon> test() {
return gifticonRepository.test();
public List<Gifticon> test(String keyword) {
return gifticonRepository.test(keyword);
}

public List<Gifticon> usedTest() {
return gifticonRepository.findUsedByUid(2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ public ResponseEntity<?> findPasswordByEmail(@RequestBody UserFindPasswordByEmai
}

@GetMapping("/mypage")
public ResponseEntity<?> mypage(@SessionAttribute(value = "User", required = false) Users user) {
if (Objects.isNull(user)) {
return new ResponseEntity<>(new UserMypageRes(false), HttpStatus.UNAUTHORIZED);
}
return new ResponseEntity<>(new UserMypageRes(true, user.getEmail(), user.getPassword(), user.getName(), user.getPhoneNumber()), HttpStatus.OK);
public ResponseEntity<?> mypage(/*@SessionAttribute(value = "User", required = false) Users user*/) {
// if (Objects.isNull(user)) {
// return new ResponseEntity<>(new UserMypageRes(false), HttpStatus.UNAUTHORIZED);
// }
return new ResponseEntity<>(new UserMypageRes(true, "[email protected]", "testPassword", "test", "010-0000-0000"), HttpStatus.OK);
// return new ResponseEntity<>(new UserMypageRes(true, user.getEmail(), user.getPassword(), user.getName(), user.getPhoneNumber()), HttpStatus.OK);
}

@PutMapping("/password")
Expand Down
Binary file added client/images/icon-x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/images/icon-x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/images/icon-x384.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/images/icon-x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Amatta" />
<meta name="theme-color" content="#92b8b1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="white" />
<meta name="apple-mobile-web-app-title" content="Amatta" />
<title>아마따</title>
<script type="module" src="./src/main.js" async></script>
<link rel="apple-touch-icon" href="./images/icon-x128.png" />
<link rel="manifest" href="./manifest.json" />
</head>
<body>
<div id="root"></div>
Expand Down
31 changes: 31 additions & 0 deletions client/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "아 맞다!",
"short_name": "Amatta",
"icons": [
{
"src": "https://amatta-icons.s3.ap-northeast-2.amazonaws.com/app/icon-x128.png",
"sizes": "128x128",
"type": "image/png"
},
{
"src": "https://amatta-icons.s3.ap-northeast-2.amazonaws.com/app/icon-x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "https://amatta-icons.s3.ap-northeast-2.amazonaws.com/app/icon-x384.png",
"sizes": "384x384",
"type": "image/png"
},
{
"src": "https://amatta-icons.s3.ap-northeast-2.amazonaws.com/app/icon-x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"start_url": "https://amatta.site/",
"display": "fullscreen",
"background_color": "#92b8b1",
"theme_color": "#ffffff"
}
12 changes: 12 additions & 0 deletions client/offline.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>네트워크 연결 오류</h1>
</body>
</html>
61 changes: 61 additions & 0 deletions client/service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js');

const CACHE = 'cache-offline-page';
const offlineFallbackPage = 'offline.html';

self.addEventListener('message', (event) => {
if (event.data && event.data.type === 'SKIP_WAITING') {
self.skipWaiting();
}
});

self.addEventListener('install', (event) => {
event.waitUntil(
caches
.open(CACHE)
.then((cache) =>
cache.addAll([
'https://amatta.site/',
'./offline.html',
'https://amatta-icons.s3.ap-northeast-2.amazonaws.com/app/icon-x128.png',
'https://amatta-icons.s3.ap-northeast-2.amazonaws.com/app/icon-x192.png',
'https://amatta-icons.s3.ap-northeast-2.amazonaws.com/app/icon-x384.png',
'https://amatta-icons.s3.ap-northeast-2.amazonaws.com/app/icon-x512.png',
]),
),
);
});

if (workbox.navigationPreload.isSupported()) {
workbox.navigationPreload.enable();
}

workbox.routing.registerRoute(
new RegExp('/*'),
new workbox.strategies.StaleWhileRevalidate({
cacheName: CACHE,
}),
);

self.addEventListener('fetch', (event) => {
if (event.request.mode === 'navigate') {
event.respondWith(
(async () => {
try {
const preloadResp = await event.preloadResponse;

if (preloadResp) {
return preloadResp;
}

const networkResp = await fetch(event.request);
return networkResp;
} catch (error) {
const cache = await caches.open(CACHE);
const cachedResp = await cache.match(offlineFallbackPage);
return cachedResp;
}
})(),
);
}
});
10 changes: 5 additions & 5 deletions client/src/components/auth/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ const login = () => {
const submitData = async (e) => {
e.stopPropagation();
e.preventDefault();

//await loginU({ email: '[email protected]', password: 'testPassword' });
await loginU(userData);
await navigate('/card');
notification('로그인에 성공하였습니다.', 'login')();
console.log('뭔데');
await loginU({ email: '[email protected]', password: 'testPassword' });
// await loginU(userData);

const firebaseConfig = {
apiKey: 'AIzaSyCsLBsvozvTnYlDH-5cS0A8X_AjV5o4jjM',
Expand All @@ -73,6 +71,8 @@ const login = () => {
}
// if (res === 'denied') window.alert('알림을 받으시려면 알림을 허용해주세요');
});
await navigate('/card');
notification('로그인에 성공하였습니다.', 'login')();
};

// prettier-ignore
Expand Down
68 changes: 30 additions & 38 deletions client/src/components/auth/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ const register = () => {
const codeReg = /^[0-9]{6}$/i;

let userData = {
name: '',
email: '',
verificationCode: '',
phoneNumber: '',
password: '',
passwordCheck: '',
name: 'softeer',
email: '[email protected]',
verificationCode: '123456',
phoneNumber: '010-1234-5678',
password: 'softeer',
passwordCheck: 'softeer',
};

const registerTemp = `
Expand All @@ -25,6 +25,29 @@ const register = () => {
<h5>기프티콘을 효율적으로 관리해보세요.</h5>
`;

// 데모용
const setInput = (fragment) => {
$.qs('#user-name-input', fragment).value = userData.name;
$.qs('#email-input', fragment).value = userData.email;
$.qs('#verification-code-input', fragment).value = userData.verificationCode;
$.qs('#phone-input', fragment).value = userData.phoneNumber;
$.qs('#password-input', fragment).value = userData.password;
$.qs('#password-check-input', fragment).value = userData.passwordCheck;
$.qs('.auth-button', fragment).classList.add('active');

const formTarget = $.qs('#verification-code-input-section', fragment);
formTarget.classList.add('visible');

const buttonTargets = $.qsa('button', fragment);
buttonTargets.forEach((button) => (button.disabled = false));

const buttonTarget = $.qs('.confirm-button', fragment);
$.on('click', () => {
closeCodeForm(formTarget)();
formTarget.style.display = 'none';
})(buttonTarget);
};

const setUserData = (userData, target) => {
const newUserData = { ...userData };
const dataType = _.getDataset(target, 'data-input');
Expand All @@ -39,30 +62,6 @@ const register = () => {
userData = updatedUserData;
});

// const setUserData = (userData, { target }, targets) => {
// if (!target.validity.valid) return;

// const dataType = _.getDataset(target, 'data-input');
// const newUserData = { ...userData };

// newUserData[dataType] = target.value;
// userData = newUserData;

// checkValidateAll(targets);

// return userData;
// };

// const checkValidateAll = (targets) => {
// const $targetClass = $.qs('.auth-button').classList;

// if (![...targets].every((target) => target.validity.valid))
// return $targetClass.remove('active');
// if (userData.password !== userData.passwordCheck) return $targetClass.remove('active');

// $targetClass.add('active');
// };

const closeCodeForm = (target) => () => target.classList.remove('visible');

const addCodeForm = (e) => {
Expand Down Expand Up @@ -178,14 +177,6 @@ const register = () => {
$.find('.verify-button'),
$.on('click', (e) => checkEmail(e, userData.email)));

// // prettier-ignore
// const sendVerificationCode = (fragment) =>
// new Promise((resolve) =>
// _.go(
// fragment,
// $.find('.verify-button'),
// $.on('click', (e) => addCodeForm(e, resolve))));

// prettier-ignore
const validateCode = (target) =>
_.pipe(
Expand Down Expand Up @@ -246,6 +237,7 @@ const register = () => {
() => sendVerificationCode(fragment),
() => validateCode(fragment),
() => submitData(fragment),
() => setInput(fragment),
() => fragment);

return appendRegister;
Expand Down
13 changes: 13 additions & 0 deletions client/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ const firebaseConfig = {
const app = initializeApp(firebaseConfig);
const messaging = getMessaging(app);

// if ('serviceWorker' in navigator) {
// window.addEventListener('load', () => {
// navigator.serviceWorker
// .register('../service-worker.js')
// .then((reg) => {
// console.log('Service worker registered!!!!!!!.', reg);
// })
// .catch((error) => {
// console.log('Service worker registration failed:', error);
// });
// });
// }

navigator.serviceWorker.register('../firebase-messaging-sw.js').then((res) => {
onMessage(messaging, (payload) => {
const option = {
Expand Down
Loading

0 comments on commit b4e7edf

Please sign in to comment.