From 5ed7e3d3031ad9ccdf3a0739bcb41da1952f8b03 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 28 Jul 2024 02:17:58 +0900 Subject: [PATCH 01/13] =?UTF-8?q?refactor:=20=EC=A4=91=EB=B3=B5=EB=90=98?= =?UTF-8?q?=EB=8A=94=20=EB=82=A0=EC=9D=98=20=EA=B2=BD=EC=9A=B0=20=EA=B0=99?= =?UTF-8?q?=EC=9D=80=20=EC=B6=9C=EC=84=9D=20=EC=BD=94=EB=93=9C=EB=A5=BC=20?= =?UTF-8?q?=EC=A7=80=EB=8B=88=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/AttendanceEventService.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/leets/weeth/domain/event/attendanceEvent/service/AttendanceEventService.java b/src/main/java/leets/weeth/domain/event/attendanceEvent/service/AttendanceEventService.java index 07622015..4d234acc 100644 --- a/src/main/java/leets/weeth/domain/event/attendanceEvent/service/AttendanceEventService.java +++ b/src/main/java/leets/weeth/domain/event/attendanceEvent/service/AttendanceEventService.java @@ -45,15 +45,22 @@ public void createAttendanceEvent(RequestAttendanceEvent requestDto, Long userId eventRepository.save(mapper.fromAttendanceEventDto(requestDto, user)); } - // 출석 일정 + Code 한 번에 조회 @Transactional(readOnly = true) public List getAttendanceEvents() { + // 이벤트를 타입별로 정렬된 목록으로 조회 List events = eventRepository.findAllByType(Type.ATTENDANCE, Sort.by(Sort.Direction.ASC, "startDateTime")); + // 모든 주간 데이터를 조회 List weeks = weekRepository.findAll(); + // 중복된 날짜를 가진 주간 데이터가 있을 경우, 하나의 주간 데이터만 유지 Map weekMap = weeks.stream() - .collect(Collectors.toMap(Week::getDate, week -> week)); + .collect(Collectors.toMap( + Week::getDate, + week -> week, + (existing, replacement) -> existing // 중복 키가 발생할 경우 기존 값을 유지 + )); + // 이벤트 목록을 순회하며 주간 데이터와 매핑하여 DTO로 변환 return events.stream() .map(event -> { Week matchingWeek = weekMap.get(event.getStartDateTime().toLocalDate()); From f6639b10fd6a762c2d7a92ba9ccc094731dab01a Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 28 Jul 2024 02:18:26 +0900 Subject: [PATCH 02/13] =?UTF-8?q?refactor:=20=EB=B8=8C=EB=9D=BC=EC=9A=B0?= =?UTF-8?q?=EC=A0=80=20=ED=83=AD=EC=97=90=20=ED=91=9C=EC=8B=9C=EB=90=98?= =?UTF-8?q?=EB=8A=94=20=EC=A0=95=EB=B3=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/ThymeLeafController.java | 19 +++++++++++++------ .../resources/templates/fragments/header.html | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/java/leets/weeth/domain/admin/controller/ThymeLeafController.java b/src/main/java/leets/weeth/domain/admin/controller/ThymeLeafController.java index 755fe0d2..6ae4c495 100644 --- a/src/main/java/leets/weeth/domain/admin/controller/ThymeLeafController.java +++ b/src/main/java/leets/weeth/domain/admin/controller/ThymeLeafController.java @@ -1,6 +1,7 @@ package leets.weeth.domain.admin.controller; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -9,32 +10,38 @@ public class ThymeLeafController { @GetMapping("/home") - public String home() { + public String home(Model model) { + model.addAttribute("pageTitle", "weeth admin"); return "home"; } @GetMapping("/login") - public String login() { + public String loginPage(Model model) { + model.addAttribute("pageTitle", "Login"); return "login-html"; } @GetMapping("/members") - public String members() { + public String members(Model model) { + model.addAttribute("pageTitle", "멤버 관리"); return "members"; } @GetMapping("/attendance") - public String attendance() { + public String attendance(Model model) { + model.addAttribute("pageTitle", "출석 관리"); return "attendance"; } @GetMapping("/penalty") - public String penalty() { + public String penalty(Model model) { + model.addAttribute("pageTitle", "패널티 관리"); return "penalty"; } @GetMapping("/account") - public String account() { + public String account(Model model) { + model.addAttribute("pageTitle", "weeth admin 회비"); return "account"; } } diff --git a/src/main/resources/templates/fragments/header.html b/src/main/resources/templates/fragments/header.html index 0ee83245..3cba0660 100644 --- a/src/main/resources/templates/fragments/header.html +++ b/src/main/resources/templates/fragments/header.html @@ -7,7 +7,7 @@ - Hello, world! + Default Title From a91aa3c8f1ed9bfb2011efa6b7ca5cb35b3e015f Mon Sep 17 00:00:00 2001 From: hyxklee Date: Tue, 30 Jul 2024 16:03:59 +0900 Subject: [PATCH 03/13] =?UTF-8?q?feat:=20=ED=9A=8C=EB=B9=84=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=20=ED=8E=98=EC=9D=B4=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/static/js/account.js | 179 +++++++++++--------- src/main/resources/templates/account.html | 189 +++++++++++++--------- 2 files changed, 215 insertions(+), 153 deletions(-) diff --git a/src/main/resources/static/js/account.js b/src/main/resources/static/js/account.js index 670fdf75..77be27af 100644 --- a/src/main/resources/static/js/account.js +++ b/src/main/resources/static/js/account.js @@ -2,19 +2,12 @@ const apiEndpoint = (window.location.hostname === 'localhost') ? 'http://localhost:8080' : 'https://api.weeth.site'; -document.getElementById('totalAccountButton').addEventListener('click', function() { - const form = document.getElementById('totalAccountForm'); - form.style.display = (form.style.display === 'block') ? 'none' : 'block'; +document.getElementById('receiptForm').addEventListener('submit', function(event) { + event.preventDefault(); // 기본 폼 제출 동작 방지 + confirmAction('영수증 제출', submitReceipt); }); -document.getElementById('closeTotalAccountFormButton').addEventListener('click', function() { - document.getElementById('totalAccountForm').style.display = 'none'; -}); - -document.getElementById('submitTotalAccountButton').addEventListener('click', function() { - if (!confirm('총 회비 정보를 제출하시겠습니까?')) { - return; - } +function submitTotalAccount() { const cardinal = document.getElementById('totalCardinal').value; const description = document.getElementById('totalDescription').value; @@ -26,70 +19,17 @@ document.getElementById('submitTotalAccountButton').addEventListener('click', fu cardinal: parseInt(cardinal) }; - apiRequest(`${apiEndpoint}/admin/account`, { + return apiRequest(`${apiEndpoint}/admin/account`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) - }) - .then(response => response.text()) - .then(message => { - alert(`Success: ${message}`); - document.getElementById('totalAccountForm').style.display = 'none'; - }) - .catch(error => { - alert(`Error: ${error.message}`); - }); -}); - -document.getElementById('manageAccountButton').addEventListener('click', function() { - const form = document.getElementById('manageAccountForm'); - form.style.display = (form.style.display === 'block') ? 'none' : 'block'; -}); - -document.getElementById('closeAccountFormButton').addEventListener('click', function() { - document.getElementById('manageAccountForm').style.display = 'none'; -}); - -document.getElementById('submitAccountButton').addEventListener('click', function() { - if (!confirm('회비 정보를 제출하시겠습니까?')) { - return; - } - - const cardinal = document.getElementById('cardinal').value; - const amount = document.getElementById('amount').value; - const description = document.getElementById('description').value; - const date = document.getElementById('date').value; - const fileInput = document.getElementById('file'); - const files = fileInput.files; - - const formData = new FormData(); - formData.append('dto', new Blob([JSON.stringify({ - amount: parseInt(amount), - description: description, - date: date - })], { type: 'application/json' })); + }).then(response => response.json()); +} - for (let i = 0; i < files.length; i++) { - formData.append('files', files[i]); - } - apiRequest(`${apiEndpoint}/admin/account/${cardinal}`, { - method: 'POST', - body: formData - }) - .then(response => response.text()) - .then(message => { - alert(`Success: ${message}`); - document.getElementById('manageAccountForm').style.display = 'none'; - }) - .catch(error => { - alert(`Error: ${error.message}`); - }); -}); - -document.getElementById('checkAccountButton').addEventListener('click', function() { +function checkAccount() { const cardinal = document.getElementById('checkCardinal').value; apiRequest(`${apiEndpoint}/account/${cardinal}`, { @@ -105,7 +45,8 @@ document.getElementById('checkAccountButton').addEventListener('click', function .catch(error => { alert(`Error: ${error.message}`); }); -}); +} + function displayAccountInfo(account) { const accountInfoDiv = document.getElementById('accountInfo'); @@ -137,6 +78,47 @@ function displayAccountInfo(account) { `; } +function submitReceipt() { + + const cardinal = document.getElementById('cardinal').value; + const amount = document.getElementById('amount').value; + const description = document.getElementById('description').value; + const date = document.getElementById('date').value; + const fileInput = document.getElementById('file'); + const files = fileInput.files; + + const formData = new FormData(); + formData.append('dto', new Blob([JSON.stringify({ + amount: parseInt(amount), + description: description, + date: date + })], { type: 'application/json' })); + + for (let i = 0; i < files.length; i++) { + formData.append('files', files[i]); + } + + apiRequest(`${apiEndpoint}/admin/account/${cardinal}`, { + method: 'POST', + body: formData + }) + .then(response => { + return response.json(); + }) + .then(data => { + if (data.code === 200) { + alert(`성공: ${data.message}`); + } else { + throw new Error(data.message); + } + }) + .catch(error => { + console.error('Request failed:', error); + alert(`Error: ${error.message}`); + }); +} + + function deleteReceipt(receiptId) { if (confirm('삭제하시겠습니까?')) { apiRequest(`${apiEndpoint}/admin/account/${receiptId}`, { @@ -145,11 +127,11 @@ function deleteReceipt(receiptId) { 'Content-Type': 'application/json' } }) - .then(response => response.text()) + .then(response => response.json()) .then(message => { - alert(`Success: ${message}`); + alert(`삭제 성공`); const cardinal = document.getElementById('checkCardinal').value; - apiRequest(`${apiEndpoint}/admin/account/${cardinal}`, { + apiRequest(`${apiEndpoint}/account/${cardinal}`, { method: 'GET', headers: { 'Content-Type': 'application/json' @@ -157,7 +139,11 @@ function deleteReceipt(receiptId) { }) .then(response => response.json()) .then(data => { - displayAccountInfo(data.data); + if(data.code===200) { + displayAccountInfo(data.data); + }else { + throw new Error(data.message); + } }) .catch(error => { alert(`Error: ${error.message}`); @@ -167,4 +153,51 @@ function deleteReceipt(receiptId) { alert(`Error: ${error.message}`); }); } +} + +function setModalContent(type) { + let modalBodyContent = document.getElementById('modal-body-content'); + let modalSubmitButton = document.getElementById('modalSubmitButton'); + if (type === 'total') { + modalBodyContent.innerHTML = ` +
+
+ + +
+
+ + +
+
+ + +
+
+ `; + modalSubmitButton.onclick = function() { + const form = document.getElementById('totalAccountForm'); + if (form.checkValidity()) { + confirmAction('총 회비 등록', submitTotalAccount); + } else { + form.reportValidity(); + } + }; + } +} + +function confirmAction(actionName, actionFunction, ...args) { + if (confirm(`${actionName} 하시겠습니까?`)) { + actionFunction(...args) + .then(response => { + if (response.code === 200) { + alert(`${actionName} 성공: ${response.message}`); + } else { + throw new Error(response.message); + } + }) + .catch(error => { + alert(`${actionName} 실패: ${error.message}`); + }); + } } \ No newline at end of file diff --git a/src/main/resources/templates/account.html b/src/main/resources/templates/account.html index 6e2efc78..b0556d7c 100644 --- a/src/main/resources/templates/account.html +++ b/src/main/resources/templates/account.html @@ -1,94 +1,123 @@ - - - - - Account Management - + + + - -
-
-
-

회비 관리

-
-
-
- - - -
- -
-
-
- -