From 8740678a5a6c0953d4b84708c2216d9bf03a91f4 Mon Sep 17 00:00:00 2001 From: rlarlgnszx Date: Tue, 30 Jul 2024 15:18:39 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[chore]=20=ED=83=80=EC=9E=84=EB=A6=AC?= =?UTF-8?q?=ED=94=84=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?-=20#214?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dateroad-api/build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dateroad-api/build.gradle b/dateroad-api/build.gradle index b7db8e4c..9182e432 100644 --- a/dateroad-api/build.gradle +++ b/dateroad-api/build.gradle @@ -9,6 +9,10 @@ dependencies { implementation project(path: ':dateroad-external') implementation 'org.springframework.boot:spring-boot-starter-data-redis' + implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6' + implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6' + implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' + runtimeOnly 'org.postgresql:postgresql' //swagger implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0' From 3ae93c3dd932acc16aff0f4bb97741e116879ef7 Mon Sep 17 00:00:00 2001 From: rlarlgnszx Date: Tue, 30 Jul 2024 15:19:54 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[feat]=20=ED=83=80=EC=9E=84=EB=A6=AC?= =?UTF-8?q?=ED=94=84=20=ED=85=9C=ED=94=8C=EB=A6=BF=20Admin=20Page=20?= =?UTF-8?q?=EC=84=B8=ED=8C=85=20=EA=B5=AC=ED=98=84=20-=20#214?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/dateroad/admin/AdminController.java | 140 ++++++++++++++++++ .../java/org/dateroad/admin/AdminService.java | 117 +++++++++++++++ .../templates/admin/advertisements.html | 44 ++++++ .../resources/templates/admin/courses.html | 52 +++++++ .../resources/templates/admin/dashboard.html | 79 ++++++++++ .../main/resources/templates/admin/dates.html | 44 ++++++ .../templates/admin/edit-courses.html | 0 .../main/resources/templates/admin/login.html | 31 ++++ .../resources/templates/admin/points.html | 44 ++++++ .../main/resources/templates/admin/users.html | 48 ++++++ .../advertisement/domain/Advertisement.java | 2 + 11 files changed, 601 insertions(+) create mode 100644 dateroad-api/src/main/java/org/dateroad/admin/AdminController.java create mode 100644 dateroad-api/src/main/java/org/dateroad/admin/AdminService.java create mode 100644 dateroad-api/src/main/resources/templates/admin/advertisements.html create mode 100644 dateroad-api/src/main/resources/templates/admin/courses.html create mode 100644 dateroad-api/src/main/resources/templates/admin/dashboard.html create mode 100644 dateroad-api/src/main/resources/templates/admin/dates.html create mode 100644 dateroad-api/src/main/resources/templates/admin/edit-courses.html create mode 100644 dateroad-api/src/main/resources/templates/admin/login.html create mode 100644 dateroad-api/src/main/resources/templates/admin/points.html create mode 100644 dateroad-api/src/main/resources/templates/admin/users.html diff --git a/dateroad-api/src/main/java/org/dateroad/admin/AdminController.java b/dateroad-api/src/main/java/org/dateroad/admin/AdminController.java new file mode 100644 index 00000000..f4217086 --- /dev/null +++ b/dateroad-api/src/main/java/org/dateroad/admin/AdminController.java @@ -0,0 +1,140 @@ +package org.dateroad.admin; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Base64; +import lombok.RequiredArgsConstructor; +import org.dateroad.advertisement.domain.Advertisement; +import org.dateroad.date.domain.Course; +import org.dateroad.date.domain.Date; +import org.dateroad.point.domain.Point; +import org.dateroad.user.domain.User; +import org.springframework.core.io.Resource; +import org.springframework.core.io.ResourceLoader; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +// AdminController.java +@Controller +@RequestMapping("/admin") +@RequiredArgsConstructor +public class AdminController { + private final AdminService adminService; + private final ResourceLoader resourceLoader; + + @GetMapping + public String dashboard(Model model) throws IOException { + model.addAttribute("courses", adminService.getAllCourses()); + model.addAttribute("dates", adminService.getAllDates()); + model.addAttribute("users", adminService.getAllUsers()); + model.addAttribute("advertisements", adminService.getAllAdvertisements()); + model.addAttribute("points", adminService.getAllPoints()); + + Resource resource = resourceLoader.getResource("classpath:static/img.png"); + InputStream inputStream = resource.getInputStream(); + byte[] imageBytes = inputStream.readAllBytes(); + String imageBase64 = Base64.getEncoder().encodeToString(imageBytes); + model.addAttribute("imageBase64", imageBase64); + return "admin/dashboard"; + } + + // Courses + @GetMapping("/courses") + public String listCourses(Model model) { + model.addAttribute("courses", adminService.getAllCourses()); + return "admin/courses"; + } + + @GetMapping("/courses/edit/{id}") + public String editCourse(@PathVariable Long id, Model model) { + model.addAttribute("course", adminService.getCourseById(id)); + return "admin/edit-course"; + } + + @PostMapping("/courses/update/{id}") + public String updateCourse(@PathVariable Long id, @ModelAttribute Course course) { + adminService.updateCourse(id, course); + return "redirect:/admin/courses"; + } + + // Dates + @GetMapping("/dates") + public String listDates(Model model) { + model.addAttribute("dates", adminService.getAllDates()); + return "admin/dates"; + } + + @GetMapping("/dates/edit/{id}") + public String editDate(@PathVariable Long id, Model model) { + model.addAttribute("date", adminService.getDateById(id)); + return "admin/edit-date"; + } + + @PostMapping("/dates/update/{id}") + public String updateDate(@PathVariable Long id, @ModelAttribute Date date) { + adminService.updateDate(id, date); + return "redirect:/admin/dates"; + } + + // Users + @GetMapping("/users") + public String listUsers(Model model) { + model.addAttribute("users", adminService.getAllUsers()); + return "admin/users"; + } + + @GetMapping("/users/edit/{id}") + public String editUser(@PathVariable Long id, Model model) { + model.addAttribute("user", adminService.getUserById(id)); + return "admin/edit-user"; + } + + @PostMapping("/users/update/{id}") + public String updateUser(@PathVariable Long id, @ModelAttribute User user) { + adminService.updateUser(id, user); + return "redirect:/admin/users"; + } + + // Advertisements + @GetMapping("/advertisements") + public String listAdvertisements(Model model) { + model.addAttribute("advertisements", adminService.getAllAdvertisements()); + return "admin/advertisements"; + } + + @GetMapping("/advertisements/edit/{id}") + public String editAdvertisement(@PathVariable Long id, Model model) { + model.addAttribute("advertisement", adminService.getAdvertisementById(id)); + return "admin/edit-advertisement"; + } + + @PostMapping("/advertisements/update/{id}") + public String updateAdvertisement(@PathVariable Long id, @ModelAttribute Advertisement advertisement) { + adminService.updateAdvertisement(id, advertisement); + return "redirect:/admin/advertisements"; + } + + // Points + @GetMapping("/points") + public String listPoints(Model model) { + model.addAttribute("points", adminService.getAllPoints()); + return "admin/points"; + } + + @GetMapping("/points/edit/{id}") + public String editPoint(@PathVariable Long id, Model model) { + model.addAttribute("point", adminService.getPointById(id)); + return "admin/edit-point"; + } + + @PostMapping("/points/update/{id}") + public String updatePoint(@PathVariable Long id, @ModelAttribute Point point) { + adminService.updatePoint(id, point); + return "redirect:/admin/points"; + } +} diff --git a/dateroad-api/src/main/java/org/dateroad/admin/AdminService.java b/dateroad-api/src/main/java/org/dateroad/admin/AdminService.java new file mode 100644 index 00000000..a092f9f7 --- /dev/null +++ b/dateroad-api/src/main/java/org/dateroad/admin/AdminService.java @@ -0,0 +1,117 @@ +package org.dateroad.admin; + +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.dateroad.advertisement.domain.Advertisement; +import org.dateroad.advertisement.repository.AdvertisementRepository; +import org.dateroad.date.domain.Course; +import org.dateroad.date.domain.Date; +import org.dateroad.date.repository.CourseRepository; +import org.dateroad.date.service.DateRepository; +import org.dateroad.exception.EntityNotFoundException; +import org.dateroad.point.domain.Point; +import org.dateroad.point.repository.PointRepository; +import org.dateroad.user.domain.User; +import org.dateroad.user.repository.UserRepository; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class AdminService { + + private final CourseRepository courseRepository; + + private final DateRepository dateRepository; + + private final UserRepository userRepository; + + private final AdvertisementRepository advertisementRepository; + + private final PointRepository pointRepository; + + // Courses + public List getAllCourses() { + return courseRepository.findAll(); + } + + public Course getCourseById(Long id) { + return courseRepository.findById(id).orElseThrow(EntityNotFoundException::new); + } + + public void updateCourse(Long id, Course updatedCourse) { + Course course = getCourseById(id); +// course.setTitle(updatedCourse.getTitle()); +// course.setStartAt(updatedCourse.getStartAt()); +// course.setCity(updatedCourse.getCity()); +// course.setCost(updatedCourse.getCost()); + courseRepository.save(course); + } + + // Dates + public List getAllDates() { + return dateRepository.findAll(); + } + + public Date getDateById(Long id) { + return dateRepository.findById(id).orElseThrow(EntityNotFoundException::new); + } + + public void updateDate(Long id, Date updatedDate) { + Date date = getDateById(id); +// date.setTitle(updatedDate.getTitle()); +// date.setDate(updatedDate.getDate()); +// date.setStartAt(updatedDate.getStartAt()); +// date.setCity(updatedDate.getCity()); + dateRepository.save(date); + } + + // Users + public List getAllUsers() { + return userRepository.findAll(); + } + + public User getUserById(Long id) { + return userRepository.findById(id).orElseThrow(EntityNotFoundException::new); + } + + public void updateUser(Long id, User updatedUser) { + User user = getUserById(id); + user.setName(updatedUser.getName()); + userRepository.save(user); + } + + // Advertisements + public List getAllAdvertisements() { + return advertisementRepository.findAll(); + } + + public Advertisement getAdvertisementById(Long id) { + return advertisementRepository.findById(id).orElseThrow(EntityNotFoundException::new); + } + + public void updateAdvertisement(Long id, Advertisement updatedAdvertisement) { + Advertisement advertisement = getAdvertisementById(id); +// advertisement.setTitle(updatedAdvertisement.getTitle()); +// advertisement.setDescription(updatedAdvertisement.getDescription()); + advertisement.setThumbnail(updatedAdvertisement.getThumbnail()); +// advertisement.setTag(updatedAdvertisement.getTag()); + advertisementRepository.save(advertisement); + } + + // Points + public List getAllPoints() { + return pointRepository.findAll(); + } + + public Point getPointById(Long id) { + return pointRepository.findById(id).orElseThrow(EntityNotFoundException::new); + } + + public void updatePoint(Long id, Point updatedPoint) { + Point point = getPointById(id); +// point.setPoint(updatedPoint.getPoint()); +// point.setTransactionType(updatedPoint.getTransactionType()); +// point.setDescription(updatedPoint.getDescription()); + pointRepository.save(point); + } +} diff --git a/dateroad-api/src/main/resources/templates/admin/advertisements.html b/dateroad-api/src/main/resources/templates/admin/advertisements.html new file mode 100644 index 00000000..d92c1623 --- /dev/null +++ b/dateroad-api/src/main/resources/templates/admin/advertisements.html @@ -0,0 +1,44 @@ + + + + Advertisements + + + +
+

Advertisements

+
+ + + + + + + + + + + + + + + + + + + +
TitleDescriptionThumbnailTagActions
+
+
+
+
+
+
+
+
+ Edit +
+
+
+ + diff --git a/dateroad-api/src/main/resources/templates/admin/courses.html b/dateroad-api/src/main/resources/templates/admin/courses.html new file mode 100644 index 00000000..232815a0 --- /dev/null +++ b/dateroad-api/src/main/resources/templates/admin/courses.html @@ -0,0 +1,52 @@ + + + + Courses + + + +
+

Courses

+
+ + + + + + + + + + + + + + + + + + + + + + + +
TitleStart DateLocationPrice썸네일만든 사람Actions
+
+
+
+
+
+
+
+
+
+
+
+
+ Edit +
+
+
+ + diff --git a/dateroad-api/src/main/resources/templates/admin/dashboard.html b/dateroad-api/src/main/resources/templates/admin/dashboard.html new file mode 100644 index 00000000..ff6e7e79 --- /dev/null +++ b/dateroad-api/src/main/resources/templates/admin/dashboard.html @@ -0,0 +1,79 @@ + + + + Admin Dashboard + + + +
+ + + + +
+ +
+
+

Dashboard

+
+
+ + +
+ +
+
+
+ + diff --git a/dateroad-api/src/main/resources/templates/admin/dates.html b/dateroad-api/src/main/resources/templates/admin/dates.html new file mode 100644 index 00000000..fe7feab6 --- /dev/null +++ b/dateroad-api/src/main/resources/templates/admin/dates.html @@ -0,0 +1,44 @@ + + + + Dates + + + +
+

Dates

+
+ + + + + + + + + + + + + + + + + + + +
TitleDateStart AtLocationActions
+
+
+
+
+
+
+
+
+ Edit +
+
+
+ + diff --git a/dateroad-api/src/main/resources/templates/admin/edit-courses.html b/dateroad-api/src/main/resources/templates/admin/edit-courses.html new file mode 100644 index 00000000..e69de29b diff --git a/dateroad-api/src/main/resources/templates/admin/login.html b/dateroad-api/src/main/resources/templates/admin/login.html new file mode 100644 index 00000000..d043043e --- /dev/null +++ b/dateroad-api/src/main/resources/templates/admin/login.html @@ -0,0 +1,31 @@ + + + + Login + + + +
+
+
+
+
+ Admin Login +
+
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+ + diff --git a/dateroad-api/src/main/resources/templates/admin/points.html b/dateroad-api/src/main/resources/templates/admin/points.html new file mode 100644 index 00000000..69cfceec --- /dev/null +++ b/dateroad-api/src/main/resources/templates/admin/points.html @@ -0,0 +1,44 @@ + + + + Points + + + +
+

Points

+
+ + + + + + + + + + + + + + + + + + + +
UserPointsTransaction TypeDescriptionActions
+
+
+
+
+
+
+
+
+ Edit +
+
+
+ + diff --git a/dateroad-api/src/main/resources/templates/admin/users.html b/dateroad-api/src/main/resources/templates/admin/users.html new file mode 100644 index 00000000..5cec1512 --- /dev/null +++ b/dateroad-api/src/main/resources/templates/admin/users.html @@ -0,0 +1,48 @@ + + + + Users + + + +
+

Courses

+
+ + + + + + + + + + + + + + + + + + + + + +
NamePlatform썸네일무료이용권포인트Action
+
+
+
+
+
+
+
+
+
+
+ Edit +
+
+
+ + diff --git a/dateroad-domain/src/main/java/org/dateroad/advertisement/domain/Advertisement.java b/dateroad-domain/src/main/java/org/dateroad/advertisement/domain/Advertisement.java index a1713786..ef12f019 100644 --- a/dateroad-domain/src/main/java/org/dateroad/advertisement/domain/Advertisement.java +++ b/dateroad-domain/src/main/java/org/dateroad/advertisement/domain/Advertisement.java @@ -14,6 +14,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; import org.dateroad.common.BaseTimeEntity; @Entity @@ -38,6 +39,7 @@ public class Advertisement extends BaseTimeEntity { @Column(name = "thumbnail") @NotNull + @Setter private String thumbnail; @Column(name = "tag")