diff --git a/src/main/java/team7/inplace/admin/AdminPageController.java b/src/main/java/team7/inplace/admin/AdminPageController.java index ab64e8ee..f731c7e5 100644 --- a/src/main/java/team7/inplace/admin/AdminPageController.java +++ b/src/main/java/team7/inplace/admin/AdminPageController.java @@ -8,9 +8,9 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; -import team7.inplace.admin.persistence.BannerRepository; -import team7.inplace.global.exception.ErrorLog; -import team7.inplace.global.exception.ErrorLogRepository; +import team7.inplace.admin.banner.persistence.BannerRepository; +import team7.inplace.admin.error.ErrorLog; +import team7.inplace.admin.error.ErrorLogRepository; import team7.inplace.global.kakao.config.KakaoApiProperties; import team7.inplace.video.domain.Video; import team7.inplace.video.persistence.VideoRepository; @@ -52,4 +52,9 @@ public String getBanners(Model model) { model.addAttribute("banners", banners); return "admin/banner.html"; } + + @GetMapping("/main") + public String getMainPage() { + return "admin/main.html"; + } } diff --git a/src/main/java/team7/inplace/admin/application/BannerService.java b/src/main/java/team7/inplace/admin/application/BannerService.java deleted file mode 100644 index 9f231d82..00000000 --- a/src/main/java/team7/inplace/admin/application/BannerService.java +++ /dev/null @@ -1,34 +0,0 @@ -package team7.inplace.admin.application; - -import java.time.LocalDateTime; -import java.util.List; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import team7.inplace.admin.application.command.BannerCommand; -import team7.inplace.admin.application.dto.BannerInfo; -import team7.inplace.admin.application.dto.BannerInfo.Detail; -import team7.inplace.admin.persistence.BannerRepository; -import team7.inplace.admin.persistence.BannerS3Repository; - -@Service -@RequiredArgsConstructor -public class BannerService { - private final BannerS3Repository bannerS3Repository; - private final BannerRepository bannerRepository; - - public void uploadBanner(BannerCommand.Create command) { - var imgPath = bannerS3Repository.uploadBanner(command.imgName(), command.imageFile()); - var banner = command.toEntity(imgPath); - bannerRepository.save(banner); - } - - public List getBanners() { - var now = LocalDateTime.now(); - var banners = bannerRepository.findActiveBanner(now); - - return banners.stream() - .sorted((a, b) -> Boolean.compare(b.getIsFixed(), a.getIsFixed())) - .map(BannerInfo.Detail::from) - .toList(); - } -} diff --git a/src/main/java/team7/inplace/admin/banner/application/BannerService.java b/src/main/java/team7/inplace/admin/banner/application/BannerService.java new file mode 100644 index 00000000..3faf4202 --- /dev/null +++ b/src/main/java/team7/inplace/admin/banner/application/BannerService.java @@ -0,0 +1,43 @@ +package team7.inplace.admin.banner.application; + +import java.time.LocalDateTime; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import team7.inplace.admin.banner.application.command.BannerCommand.Create; +import team7.inplace.admin.banner.application.dto.BannerInfo; +import team7.inplace.admin.banner.application.dto.BannerInfo.Detail; +import team7.inplace.admin.banner.persistence.BannerRepository; +import team7.inplace.admin.banner.persistence.BannerS3Repository; +import team7.inplace.global.exception.InplaceException; +import team7.inplace.global.exception.code.BannerErrorCode; + +@Service +@RequiredArgsConstructor +public class BannerService { + private final BannerS3Repository bannerS3Repository; + private final BannerRepository bannerRepository; + + public void uploadBanner(Create command) { + var imgPath = bannerS3Repository.uploadBanner(command.imageFile()); + var banner = command.toEntity(imgPath); + bannerRepository.save(banner); + } + + public List getBanners() { + var now = LocalDateTime.now(); + var banners = bannerRepository.findActiveBanner(now); + + return banners.stream() + .sorted((a, b) -> Boolean.compare(b.getIsFixed(), a.getIsFixed())) + .map(BannerInfo.Detail::from) + .toList(); + } + + public void deleteBanner(Long id) { + var banner = bannerRepository.findById(id) + .orElseThrow(() -> InplaceException.of(BannerErrorCode.NOT_FOUND)); + bannerS3Repository.deleteBanner(banner.getImgPath()); + bannerRepository.delete(banner); + } +} diff --git a/src/main/java/team7/inplace/admin/application/command/BannerCommand.java b/src/main/java/team7/inplace/admin/banner/application/command/BannerCommand.java similarity index 81% rename from src/main/java/team7/inplace/admin/application/command/BannerCommand.java rename to src/main/java/team7/inplace/admin/banner/application/command/BannerCommand.java index e1141bc5..ff4af7df 100644 --- a/src/main/java/team7/inplace/admin/application/command/BannerCommand.java +++ b/src/main/java/team7/inplace/admin/banner/application/command/BannerCommand.java @@ -1,8 +1,8 @@ -package team7.inplace.admin.application.command; +package team7.inplace.admin.banner.application.command; import java.time.LocalDateTime; import org.springframework.web.multipart.MultipartFile; -import team7.inplace.admin.domain.Banner; +import team7.inplace.admin.banner.domain.Banner; public class BannerCommand { public record Create( diff --git a/src/main/java/team7/inplace/admin/application/dto/BannerInfo.java b/src/main/java/team7/inplace/admin/banner/application/dto/BannerInfo.java similarity index 71% rename from src/main/java/team7/inplace/admin/application/dto/BannerInfo.java rename to src/main/java/team7/inplace/admin/banner/application/dto/BannerInfo.java index 6694e4f9..31b8900e 100644 --- a/src/main/java/team7/inplace/admin/application/dto/BannerInfo.java +++ b/src/main/java/team7/inplace/admin/banner/application/dto/BannerInfo.java @@ -1,6 +1,6 @@ -package team7.inplace.admin.application.dto; +package team7.inplace.admin.banner.application.dto; -import team7.inplace.admin.domain.Banner; +import team7.inplace.admin.banner.domain.Banner; public class BannerInfo { public record Detail( diff --git a/src/main/java/team7/inplace/admin/domain/Banner.java b/src/main/java/team7/inplace/admin/banner/domain/Banner.java similarity index 96% rename from src/main/java/team7/inplace/admin/domain/Banner.java rename to src/main/java/team7/inplace/admin/banner/domain/Banner.java index 468e1514..f7a1edd7 100644 --- a/src/main/java/team7/inplace/admin/domain/Banner.java +++ b/src/main/java/team7/inplace/admin/banner/domain/Banner.java @@ -1,4 +1,4 @@ -package team7.inplace.admin.domain; +package team7.inplace.admin.banner.domain; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; diff --git a/src/main/java/team7/inplace/admin/persistence/BannerRepository.java b/src/main/java/team7/inplace/admin/banner/persistence/BannerRepository.java similarity index 84% rename from src/main/java/team7/inplace/admin/persistence/BannerRepository.java rename to src/main/java/team7/inplace/admin/banner/persistence/BannerRepository.java index 63649214..f8a21cc7 100644 --- a/src/main/java/team7/inplace/admin/persistence/BannerRepository.java +++ b/src/main/java/team7/inplace/admin/banner/persistence/BannerRepository.java @@ -1,4 +1,4 @@ -package team7.inplace.admin.persistence; +package team7.inplace.admin.banner.persistence; import java.time.LocalDateTime; import java.util.List; @@ -6,7 +6,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; -import team7.inplace.admin.domain.Banner; +import team7.inplace.admin.banner.domain.Banner; @Repository public interface BannerRepository extends JpaRepository { diff --git a/src/main/java/team7/inplace/admin/persistence/BannerS3Repository.java b/src/main/java/team7/inplace/admin/banner/persistence/BannerS3Repository.java similarity index 62% rename from src/main/java/team7/inplace/admin/persistence/BannerS3Repository.java rename to src/main/java/team7/inplace/admin/banner/persistence/BannerS3Repository.java index 6a429701..7277f069 100644 --- a/src/main/java/team7/inplace/admin/persistence/BannerS3Repository.java +++ b/src/main/java/team7/inplace/admin/banner/persistence/BannerS3Repository.java @@ -1,21 +1,24 @@ -package team7.inplace.admin.persistence; +package team7.inplace.admin.banner.persistence; import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.model.ObjectMetadata; +import java.util.UUID; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Repository; import org.springframework.web.multipart.MultipartFile; import team7.inplace.infra.s3.AwsProperties; @Repository +@Slf4j @RequiredArgsConstructor public class BannerS3Repository { private final AmazonS3Client amazonS3Client; private final AwsProperties awsProperties; - public String uploadBanner(String bannerName, MultipartFile banner) { + public String uploadBanner(MultipartFile banner) { var bucketName = awsProperties.bucketName(); - var key = "banner/" + bannerName; + var key = "banner/" + UUID.randomUUID(); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(banner.getSize()); @@ -28,4 +31,15 @@ public String uploadBanner(String bannerName, MultipartFile banner) { throw new RuntimeException("Failed to upload banner", e); } } + + public void deleteBanner(String imgPath) { + var bucketName = awsProperties.bucketName(); + var key = imgPath.substring(imgPath.lastIndexOf("banner")); + + try { + amazonS3Client.deleteObject(bucketName, key); + } catch (Exception e) { + throw new RuntimeException("Failed to delete banner", e); + } + } } diff --git a/src/main/java/team7/inplace/admin/presentation/BannerController.java b/src/main/java/team7/inplace/admin/banner/presentation/BannerController.java similarity index 74% rename from src/main/java/team7/inplace/admin/presentation/BannerController.java rename to src/main/java/team7/inplace/admin/banner/presentation/BannerController.java index a548812d..b510a0fa 100644 --- a/src/main/java/team7/inplace/admin/presentation/BannerController.java +++ b/src/main/java/team7/inplace/admin/banner/presentation/BannerController.java @@ -1,15 +1,17 @@ -package team7.inplace.admin.presentation; +package team7.inplace.admin.banner.presentation; import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import team7.inplace.admin.application.BannerService; +import team7.inplace.admin.banner.application.BannerService; @RestController @Slf4j @@ -33,4 +35,9 @@ public ResponseEntity> getBanners() { .toList(); return new ResponseEntity<>(response, HttpStatus.OK); } + + @DeleteMapping("/{id}") + public void deleteBanner(@PathVariable Long id) { + bannerService.deleteBanner(id); + } } diff --git a/src/main/java/team7/inplace/admin/presentation/BannerRequest.java b/src/main/java/team7/inplace/admin/banner/presentation/BannerRequest.java similarity index 83% rename from src/main/java/team7/inplace/admin/presentation/BannerRequest.java rename to src/main/java/team7/inplace/admin/banner/presentation/BannerRequest.java index c110c7dc..8552327a 100644 --- a/src/main/java/team7/inplace/admin/presentation/BannerRequest.java +++ b/src/main/java/team7/inplace/admin/banner/presentation/BannerRequest.java @@ -1,8 +1,8 @@ -package team7.inplace.admin.presentation; +package team7.inplace.admin.banner.presentation; import java.time.LocalDate; import org.springframework.web.multipart.MultipartFile; -import team7.inplace.admin.application.command.BannerCommand; +import team7.inplace.admin.banner.application.command.BannerCommand; public class BannerRequest { public record Create( diff --git a/src/main/java/team7/inplace/admin/presentation/BannerResponse.java b/src/main/java/team7/inplace/admin/banner/presentation/BannerResponse.java similarity index 71% rename from src/main/java/team7/inplace/admin/presentation/BannerResponse.java rename to src/main/java/team7/inplace/admin/banner/presentation/BannerResponse.java index 7f0fed91..a75945f8 100644 --- a/src/main/java/team7/inplace/admin/presentation/BannerResponse.java +++ b/src/main/java/team7/inplace/admin/banner/presentation/BannerResponse.java @@ -1,6 +1,6 @@ -package team7.inplace.admin.presentation; +package team7.inplace.admin.banner.presentation; -import team7.inplace.admin.application.dto.BannerInfo; +import team7.inplace.admin.banner.application.dto.BannerInfo; public class BannerResponse { public record Info( diff --git a/src/main/java/team7/inplace/cicd/TestController.java b/src/main/java/team7/inplace/admin/cicd/TestController.java similarity index 90% rename from src/main/java/team7/inplace/cicd/TestController.java rename to src/main/java/team7/inplace/admin/cicd/TestController.java index 34bcc01a..9d07e49a 100644 --- a/src/main/java/team7/inplace/cicd/TestController.java +++ b/src/main/java/team7/inplace/admin/cicd/TestController.java @@ -1,4 +1,4 @@ -package team7.inplace.cicd; +package team7.inplace.admin.cicd; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; diff --git a/src/main/java/team7/inplace/crawling/application/AddressUtil.java b/src/main/java/team7/inplace/admin/crawling/application/AddressUtil.java similarity index 94% rename from src/main/java/team7/inplace/crawling/application/AddressUtil.java rename to src/main/java/team7/inplace/admin/crawling/application/AddressUtil.java index 0f38256e..8bddfe09 100644 --- a/src/main/java/team7/inplace/crawling/application/AddressUtil.java +++ b/src/main/java/team7/inplace/admin/crawling/application/AddressUtil.java @@ -1,4 +1,4 @@ -package team7.inplace.crawling.application; +package team7.inplace.admin.crawling.application; import com.fasterxml.jackson.databind.JsonNode; import lombok.NoArgsConstructor; diff --git a/src/main/java/team7/inplace/crawling/application/CrawlingFacade.java b/src/main/java/team7/inplace/admin/crawling/application/CrawlingFacade.java similarity index 93% rename from src/main/java/team7/inplace/crawling/application/CrawlingFacade.java rename to src/main/java/team7/inplace/admin/crawling/application/CrawlingFacade.java index 771eb3ef..34fac4d5 100644 --- a/src/main/java/team7/inplace/crawling/application/CrawlingFacade.java +++ b/src/main/java/team7/inplace/admin/crawling/application/CrawlingFacade.java @@ -1,8 +1,8 @@ -package team7.inplace.crawling.application; +package team7.inplace.admin.crawling.application; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import team7.inplace.crawling.application.dto.CrawlingInfo; +import team7.inplace.admin.crawling.application.dto.CrawlingInfo; import team7.inplace.global.annotation.Facade; import team7.inplace.place.application.command.PlacesCommand; import team7.inplace.video.application.VideoFacade; diff --git a/src/main/java/team7/inplace/crawling/application/KakaoCrawlingService.java b/src/main/java/team7/inplace/admin/crawling/application/KakaoCrawlingService.java similarity index 66% rename from src/main/java/team7/inplace/crawling/application/KakaoCrawlingService.java rename to src/main/java/team7/inplace/admin/crawling/application/KakaoCrawlingService.java index a3a8cb56..f9d3fd2a 100644 --- a/src/main/java/team7/inplace/crawling/application/KakaoCrawlingService.java +++ b/src/main/java/team7/inplace/admin/crawling/application/KakaoCrawlingService.java @@ -1,9 +1,9 @@ -package team7.inplace.crawling.application; +package team7.inplace.admin.crawling.application; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import team7.inplace.crawling.client.KakaoMapClient; -import team7.inplace.crawling.client.dto.PlaceNode; +import team7.inplace.admin.crawling.client.KakaoMapClient; +import team7.inplace.admin.crawling.client.dto.PlaceNode; @Service @RequiredArgsConstructor diff --git a/src/main/java/team7/inplace/crawling/application/VideoCrawlingService.java b/src/main/java/team7/inplace/admin/crawling/application/VideoCrawlingService.java similarity index 73% rename from src/main/java/team7/inplace/crawling/application/VideoCrawlingService.java rename to src/main/java/team7/inplace/admin/crawling/application/VideoCrawlingService.java index cd7bb06d..261df0a7 100644 --- a/src/main/java/team7/inplace/crawling/application/VideoCrawlingService.java +++ b/src/main/java/team7/inplace/admin/crawling/application/VideoCrawlingService.java @@ -1,10 +1,11 @@ -package team7.inplace.crawling.application; +package team7.inplace.admin.crawling.application; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import team7.inplace.crawling.application.dto.CrawlingInfo; -import team7.inplace.crawling.client.YoutubeClient; +import team7.inplace.admin.crawling.application.dto.CrawlingInfo; +import team7.inplace.admin.crawling.application.dto.CrawlingInfo.ViewInfo; +import team7.inplace.admin.crawling.client.YoutubeClient; import team7.inplace.video.persistence.VideoRepository; import java.util.List; @@ -16,7 +17,7 @@ public class VideoCrawlingService { private final YoutubeClient youtubeClient; @Transactional(readOnly = true) - public List crawlingVideoView() { + public List crawlingVideoView() { var videos = videoRepository.findAll(); var videoInfos = videos.stream().map(video -> { diff --git a/src/main/java/team7/inplace/crawling/application/YoutubeCrawlingService.java b/src/main/java/team7/inplace/admin/crawling/application/YoutubeCrawlingService.java similarity index 89% rename from src/main/java/team7/inplace/crawling/application/YoutubeCrawlingService.java rename to src/main/java/team7/inplace/admin/crawling/application/YoutubeCrawlingService.java index 93a579d2..3d1322b7 100644 --- a/src/main/java/team7/inplace/crawling/application/YoutubeCrawlingService.java +++ b/src/main/java/team7/inplace/admin/crawling/application/YoutubeCrawlingService.java @@ -1,13 +1,13 @@ -package team7.inplace.crawling.application; +package team7.inplace.admin.crawling.application; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import team7.inplace.crawling.application.dto.CrawlingInfo; -import team7.inplace.crawling.client.KakaoMapClient; -import team7.inplace.crawling.client.YoutubeClient; -import team7.inplace.crawling.persistence.YoutubeChannelRepository; +import team7.inplace.admin.crawling.client.KakaoMapClient; +import team7.inplace.admin.crawling.client.YoutubeClient; +import team7.inplace.admin.crawling.persistence.YoutubeChannelRepository; +import team7.inplace.admin.crawling.application.dto.CrawlingInfo; import team7.inplace.global.exception.InplaceException; import team7.inplace.global.exception.code.ChannelErrorCode; diff --git a/src/main/java/team7/inplace/crawling/application/dto/CrawlingInfo.java b/src/main/java/team7/inplace/admin/crawling/application/dto/CrawlingInfo.java similarity index 93% rename from src/main/java/team7/inplace/crawling/application/dto/CrawlingInfo.java rename to src/main/java/team7/inplace/admin/crawling/application/dto/CrawlingInfo.java index 62b900a4..82f72b53 100644 --- a/src/main/java/team7/inplace/crawling/application/dto/CrawlingInfo.java +++ b/src/main/java/team7/inplace/admin/crawling/application/dto/CrawlingInfo.java @@ -1,12 +1,11 @@ -package team7.inplace.crawling.application.dto; +package team7.inplace.admin.crawling.application.dto; import com.fasterxml.jackson.databind.JsonNode; -import team7.inplace.crawling.client.dto.PlaceNode; -import team7.inplace.place.application.command.PlacesCommand; -import team7.inplace.video.application.command.VideoCommand; - import java.util.List; import java.util.Objects; +import team7.inplace.admin.crawling.client.dto.PlaceNode; +import team7.inplace.place.application.command.PlacesCommand; +import team7.inplace.video.application.command.VideoCommand; public class CrawlingInfo { public record VideoPlaceInfo( diff --git a/src/main/java/team7/inplace/crawling/client/KakaoMapClient.java b/src/main/java/team7/inplace/admin/crawling/client/KakaoMapClient.java similarity index 96% rename from src/main/java/team7/inplace/crawling/client/KakaoMapClient.java rename to src/main/java/team7/inplace/admin/crawling/client/KakaoMapClient.java index 4f9ace3c..95d952e1 100644 --- a/src/main/java/team7/inplace/crawling/client/KakaoMapClient.java +++ b/src/main/java/team7/inplace/admin/crawling/client/KakaoMapClient.java @@ -1,4 +1,4 @@ -package team7.inplace.crawling.client; +package team7.inplace.admin.crawling.client; import com.fasterxml.jackson.databind.JsonNode; import lombok.RequiredArgsConstructor; @@ -9,7 +9,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; -import team7.inplace.crawling.client.dto.PlaceNode; +import team7.inplace.admin.crawling.client.dto.PlaceNode; import team7.inplace.global.exception.InplaceException; import team7.inplace.global.exception.code.PlaceErrorCode; import team7.inplace.global.kakao.config.KakaoApiProperties; diff --git a/src/main/java/team7/inplace/crawling/client/YoutubeClient.java b/src/main/java/team7/inplace/admin/crawling/client/YoutubeClient.java similarity index 98% rename from src/main/java/team7/inplace/crawling/client/YoutubeClient.java rename to src/main/java/team7/inplace/admin/crawling/client/YoutubeClient.java index ea5ffbe0..152e4bb8 100644 --- a/src/main/java/team7/inplace/crawling/client/YoutubeClient.java +++ b/src/main/java/team7/inplace/admin/crawling/client/YoutubeClient.java @@ -1,4 +1,4 @@ -package team7.inplace.crawling.client; +package team7.inplace.admin.crawling.client; import com.fasterxml.jackson.databind.JsonNode; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/team7/inplace/crawling/client/dto/PlaceNode.java b/src/main/java/team7/inplace/admin/crawling/client/dto/PlaceNode.java similarity index 84% rename from src/main/java/team7/inplace/crawling/client/dto/PlaceNode.java rename to src/main/java/team7/inplace/admin/crawling/client/dto/PlaceNode.java index 4f919cc3..397cb8dc 100644 --- a/src/main/java/team7/inplace/crawling/client/dto/PlaceNode.java +++ b/src/main/java/team7/inplace/admin/crawling/client/dto/PlaceNode.java @@ -1,4 +1,4 @@ -package team7.inplace.crawling.client.dto; +package team7.inplace.admin.crawling.client.dto; import com.fasterxml.jackson.databind.JsonNode; diff --git a/src/main/java/team7/inplace/crawling/domain/ChannelType.java b/src/main/java/team7/inplace/admin/crawling/domain/ChannelType.java similarity index 81% rename from src/main/java/team7/inplace/crawling/domain/ChannelType.java rename to src/main/java/team7/inplace/admin/crawling/domain/ChannelType.java index 1a4b47b1..5733cec5 100644 --- a/src/main/java/team7/inplace/crawling/domain/ChannelType.java +++ b/src/main/java/team7/inplace/admin/crawling/domain/ChannelType.java @@ -1,4 +1,4 @@ -package team7.inplace.crawling.domain; +package team7.inplace.admin.crawling.domain; public enum ChannelType { FOOD("FD6"); diff --git a/src/main/java/team7/inplace/crawling/domain/YoutubeChannel.java b/src/main/java/team7/inplace/admin/crawling/domain/YoutubeChannel.java similarity index 94% rename from src/main/java/team7/inplace/crawling/domain/YoutubeChannel.java rename to src/main/java/team7/inplace/admin/crawling/domain/YoutubeChannel.java index 100a896d..1b023d47 100644 --- a/src/main/java/team7/inplace/crawling/domain/YoutubeChannel.java +++ b/src/main/java/team7/inplace/admin/crawling/domain/YoutubeChannel.java @@ -1,4 +1,4 @@ -package team7.inplace.crawling.domain; +package team7.inplace.admin.crawling.domain; import jakarta.persistence.*; import lombok.AccessLevel; diff --git a/src/main/java/team7/inplace/crawling/persistence/YoutubeChannelRepository.java b/src/main/java/team7/inplace/admin/crawling/persistence/YoutubeChannelRepository.java similarity index 70% rename from src/main/java/team7/inplace/crawling/persistence/YoutubeChannelRepository.java rename to src/main/java/team7/inplace/admin/crawling/persistence/YoutubeChannelRepository.java index 0197810e..b015a0cb 100644 --- a/src/main/java/team7/inplace/crawling/persistence/YoutubeChannelRepository.java +++ b/src/main/java/team7/inplace/admin/crawling/persistence/YoutubeChannelRepository.java @@ -1,7 +1,7 @@ -package team7.inplace.crawling.persistence; +package team7.inplace.admin.crawling.persistence; import org.springframework.data.jpa.repository.JpaRepository; -import team7.inplace.crawling.domain.YoutubeChannel; +import team7.inplace.admin.crawling.domain.YoutubeChannel; import java.util.Optional; diff --git a/src/main/java/team7/inplace/crawling/presentation/CrawlingController.java b/src/main/java/team7/inplace/admin/crawling/presentation/CrawlingController.java similarity index 61% rename from src/main/java/team7/inplace/crawling/presentation/CrawlingController.java rename to src/main/java/team7/inplace/admin/crawling/presentation/CrawlingController.java index 09c111bb..f616b992 100644 --- a/src/main/java/team7/inplace/crawling/presentation/CrawlingController.java +++ b/src/main/java/team7/inplace/admin/crawling/presentation/CrawlingController.java @@ -1,4 +1,4 @@ -package team7.inplace.crawling.presentation; +package team7.inplace.admin.crawling.presentation; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -7,7 +7,7 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import team7.inplace.crawling.application.CrawlingFacade; +import team7.inplace.admin.crawling.application.CrawlingFacade; @RestController @RequestMapping("/crawling") @@ -21,4 +21,18 @@ public ResponseEntity addPlaceInfo(@PathVariable Long videoId, @PathVariab return ResponseEntity.status(HttpStatus.CREATED).build(); } + + @PostMapping("/video") + public ResponseEntity crawlingVideo() { + crawlingFacade.updateVideos(); + + return ResponseEntity.status(HttpStatus.CREATED).build(); + } + + @PostMapping("/video/view") + public ResponseEntity crawlingVideoView() { + crawlingFacade.updateVideoView(); + + return ResponseEntity.status(HttpStatus.CREATED).build(); + } } diff --git a/src/main/java/team7/inplace/global/exception/ErrorLog.java b/src/main/java/team7/inplace/admin/error/ErrorLog.java similarity index 95% rename from src/main/java/team7/inplace/global/exception/ErrorLog.java rename to src/main/java/team7/inplace/admin/error/ErrorLog.java index d385192b..28cef11b 100644 --- a/src/main/java/team7/inplace/global/exception/ErrorLog.java +++ b/src/main/java/team7/inplace/admin/error/ErrorLog.java @@ -1,4 +1,4 @@ -package team7.inplace.global.exception; +package team7.inplace.admin.error; import jakarta.persistence.*; import lombok.AccessLevel; diff --git a/src/main/java/team7/inplace/admin/ErrorLogController.java b/src/main/java/team7/inplace/admin/error/ErrorLogController.java similarity index 90% rename from src/main/java/team7/inplace/admin/ErrorLogController.java rename to src/main/java/team7/inplace/admin/error/ErrorLogController.java index 91ca7943..c093537f 100644 --- a/src/main/java/team7/inplace/admin/ErrorLogController.java +++ b/src/main/java/team7/inplace/admin/error/ErrorLogController.java @@ -1,4 +1,4 @@ -package team7.inplace.admin; +package team7.inplace.admin.error; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -6,7 +6,6 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import team7.inplace.global.exception.ErrorLogRepository; @RestController @RequiredArgsConstructor diff --git a/src/main/java/team7/inplace/global/exception/ErrorLogRepository.java b/src/main/java/team7/inplace/admin/error/ErrorLogRepository.java similarity index 84% rename from src/main/java/team7/inplace/global/exception/ErrorLogRepository.java rename to src/main/java/team7/inplace/admin/error/ErrorLogRepository.java index 31d06bc6..163ddff0 100644 --- a/src/main/java/team7/inplace/global/exception/ErrorLogRepository.java +++ b/src/main/java/team7/inplace/admin/error/ErrorLogRepository.java @@ -1,4 +1,4 @@ -package team7.inplace.global.exception; +package team7.inplace.admin.error; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/team7/inplace/global/exception/InplaceExceptionHandler.java b/src/main/java/team7/inplace/global/exception/InplaceExceptionHandler.java index 66b30c8c..49219fea 100644 --- a/src/main/java/team7/inplace/global/exception/InplaceExceptionHandler.java +++ b/src/main/java/team7/inplace/global/exception/InplaceExceptionHandler.java @@ -8,6 +8,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import team7.inplace.admin.error.ErrorLog; +import team7.inplace.admin.error.ErrorLogRepository; import java.net.URI; diff --git a/src/main/java/team7/inplace/global/exception/code/BannerErrorCode.java b/src/main/java/team7/inplace/global/exception/code/BannerErrorCode.java new file mode 100644 index 00000000..20809c4c --- /dev/null +++ b/src/main/java/team7/inplace/global/exception/code/BannerErrorCode.java @@ -0,0 +1,32 @@ +package team7.inplace.global.exception.code; + +import org.springframework.http.HttpStatus; + +public enum BannerErrorCode implements ErrorCode { + NOT_FOUND("B001", "배너를 찾을 수 없습니다.", HttpStatus.NOT_FOUND); + + private final String code; + private final String message; + private final HttpStatus httpStatus; + + BannerErrorCode(String code, String message, HttpStatus httpStatus) { + this.code = code; + this.message = message; + this.httpStatus = httpStatus; + } + + @Override + public HttpStatus httpStatus() { + return httpStatus; + } + + @Override + public String code() { + return code; + } + + @Override + public String message() { + return message; + } +} diff --git a/src/main/java/team7/inplace/video/application/VideoFacade.java b/src/main/java/team7/inplace/video/application/VideoFacade.java index 17596e4e..c37ddaef 100644 --- a/src/main/java/team7/inplace/video/application/VideoFacade.java +++ b/src/main/java/team7/inplace/video/application/VideoFacade.java @@ -1,9 +1,10 @@ package team7.inplace.video.application; +import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.transaction.annotation.Transactional; -import team7.inplace.crawling.application.YoutubeCrawlingService; +import team7.inplace.admin.crawling.application.YoutubeCrawlingService; import team7.inplace.global.annotation.Facade; import team7.inplace.global.exception.InplaceException; import team7.inplace.global.exception.code.AuthorizationErrorCode; @@ -14,8 +15,6 @@ import team7.inplace.video.application.command.VideoCommand; import team7.inplace.video.application.dto.VideoInfo; -import java.util.List; - @Facade @Slf4j @RequiredArgsConstructor diff --git a/src/main/resources/static/css/main.css b/src/main/resources/static/css/main.css new file mode 100644 index 00000000..5ed44eea --- /dev/null +++ b/src/main/resources/static/css/main.css @@ -0,0 +1,48 @@ +.loading-modal { + display: none; + position: fixed; + z-index: 1; + left: 0; + top: 0; + width: 100%; + height: 100%; + overflow: auto; + background-color: rgba(0, 0, 0, 0.5); +} + +.loading-modal-content { + background-color: #fff; + margin: 15% auto; + padding: 20px; + border: 1px solid #888; + width: 300px; + border-radius: 5px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); + text-align: center; +} + +.spinner { + width: 40px; + height: 40px; + border: 4px solid #f3f3f3; + border-top: 4px solid #3cb371; + border-radius: 50%; + animation: spin 1s linear infinite; + margin: 0 auto 15px; +} + +#loaderText { + color: #2e8b57; + font-size: 1.1em; + font-weight: bold; + margin-top: 10px; +} + +@keyframes spin { + 0% { + transform: rotate(0deg); + } + 100% { + transform: rotate(360deg); + } +} \ No newline at end of file diff --git a/src/main/resources/static/js/banner.js b/src/main/resources/static/js/banner.js index bc465854..60ef7036 100644 --- a/src/main/resources/static/js/banner.js +++ b/src/main/resources/static/js/banner.js @@ -89,4 +89,30 @@ document.getElementById('imageUploadForm').addEventListener('submit', function ( alert(error.message || '업로드 중 오류가 발생했습니다.'); console.error('Error:', error); }); -}); \ No newline at end of file +}); + +// 이미지 삭제 요청 +function deleteImage(element) { + const imageId = element.getAttribute('data-id'); + if (confirm('이미지를 삭제하시겠습니까?')) { + fetch(`/banner/${imageId}`, { + method: 'DELETE' + }) + .then(response => { + if (!response.ok) { + return response.text().then(text => { + throw new Error(text || '삭제 실패'); + }); + } + return response.text(); + }) + .then(message => { + alert(message || '이미지가 성공적으로 삭제되었습니다.'); + location.reload(); + }) + .catch(error => { + alert(error.message || '삭제 중 오류가 발생했습니다.'); + console.error('Error:', error); + }); + } +} \ No newline at end of file diff --git a/src/main/resources/static/js/main.js b/src/main/resources/static/js/main.js new file mode 100644 index 00000000..5984da1f --- /dev/null +++ b/src/main/resources/static/js/main.js @@ -0,0 +1,44 @@ +function showLoader(message = '처리 중입니다...') { + document.getElementById('loaderText').textContent = message; + document.getElementById('loader').style.display = 'block'; +} + +function hideLoader() { + document.getElementById('loader').style.display = 'none'; +} + +function forceCrawling() { + if (confirm('크롤링을 시작하시겠습니까?')) { + showLoader('크롤링중입니다.'); + $.ajax({ + url: '/crawling/video', + method: 'POST', + success: function (response) { + hideLoader(); + alert('크롤링이 완료되었습니다.'); + }, + error: function (xhr, status, error) { + hideLoader(); + alert('크롤링 시작 중 오류가 발생했습니다.'); + } + }); + } +} + +function forceViewUpdate() { + if (confirm('조회수 업데이트를 시작하시겠습니까?')) { + showLoader('조회수 업데이트중 입니다.'); + $.ajax({ + url: '/crawling/video/view', + method: 'POST', + success: function (response) { + hideLoader(); + alert('조회수 업데이트가 완료되었습니다.'); + }, + error: function (xhr, status, error) { + hideLoader(); + alert('조회수 업데이트 중 오류가 발생했습니다.'); + } + }); + } +} \ No newline at end of file diff --git a/src/main/resources/templates/admin/banner.html b/src/main/resources/templates/admin/banner.html index 38646d7c..9403f01e 100644 --- a/src/main/resources/templates/admin/banner.html +++ b/src/main/resources/templates/admin/banner.html @@ -9,8 +9,7 @@
- - 관리자 +

이미지 관리

diff --git a/src/main/resources/templates/admin/error-logs.html b/src/main/resources/templates/admin/error-logs.html index b2f34890..f2ffe854 100644 --- a/src/main/resources/templates/admin/error-logs.html +++ b/src/main/resources/templates/admin/error-logs.html @@ -9,8 +9,7 @@
- Home - Admin +

Error Logs

diff --git a/src/main/resources/templates/admin/main.html b/src/main/resources/templates/admin/main.html new file mode 100644 index 00000000..c99e6aef --- /dev/null +++ b/src/main/resources/templates/admin/main.html @@ -0,0 +1,97 @@ + + + + + 관리자 페이지 + + + + + + + +
+ +
+ +

관리자 페이지

+ + + + +
+

© 2024 관리자 시스템. All rights reserved.

+
+
+
+
+
처리 중입니다...
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/admin/video.html b/src/main/resources/templates/admin/video.html index d3434d43..05b9000a 100644 --- a/src/main/resources/templates/admin/video.html +++ b/src/main/resources/templates/admin/video.html @@ -11,8 +11,7 @@
- Home - Admin +

Video List

diff --git a/src/test/java/team7/inplace/crawling/application/AddressUtilTest.java b/src/test/java/team7/inplace/crawling/application/AddressUtilTest.java index 75ce22c3..4d0d0652 100644 --- a/src/test/java/team7/inplace/crawling/application/AddressUtilTest.java +++ b/src/test/java/team7/inplace/crawling/application/AddressUtilTest.java @@ -2,6 +2,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import team7.inplace.admin.crawling.application.AddressUtil; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/src/test/java/team7/inplace/crawling/client/KakaoMapClientTest.java b/src/test/java/team7/inplace/crawling/client/KakaoMapClientTest.java index 5ef4e603..4afc626f 100644 --- a/src/test/java/team7/inplace/crawling/client/KakaoMapClientTest.java +++ b/src/test/java/team7/inplace/crawling/client/KakaoMapClientTest.java @@ -13,7 +13,7 @@ class KakaoMapClientTest { @Autowired - public KakaoMapClient KakaoMapClient; + public team7.inplace.admin.crawling.client.KakaoMapClient KakaoMapClient; @Test @DisplayName("카카오 맵 주소 검색 테스트") diff --git a/src/test/java/team7/inplace/crawling/client/YoutubeClientTest.java b/src/test/java/team7/inplace/crawling/client/YoutubeClientTest.java index ab430aad..4f8f16bd 100644 --- a/src/test/java/team7/inplace/crawling/client/YoutubeClientTest.java +++ b/src/test/java/team7/inplace/crawling/client/YoutubeClientTest.java @@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; +import team7.inplace.admin.crawling.client.YoutubeClient; import static org.assertj.core.api.Assertions.assertThat;