Skip to content

Commit

Permalink
Merge pull request #149 from PlanIt-Project/BE
Browse files Browse the repository at this point in the history
Be
  • Loading branch information
moonjin-kim authored Apr 5, 2024
2 parents 27a29a8 + daded1d commit 00a2ed3
Show file tree
Hide file tree
Showing 41 changed files with 488 additions and 286 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.UUID;

@Component
@Slf4j

//todo: 파일명 중복 처리
public class FileHandler {
@Value("${spring.fileStorage.dir}")
private String fileStorageDir;
Expand All @@ -25,13 +25,13 @@ public String saveFile(MultipartFile file) {
return null;
}
try {
String fileName = file.getOriginalFilename();
String fileName = getUniqueFileName(file.getOriginalFilename());
File dest = new File(fileStorageDir + File.separator + fileName);
file.transferTo(dest);

return fileName;
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage());
return "이미지 업로드 오류 발생";
}
}
Expand All @@ -51,4 +51,9 @@ private byte[] readFileBytes(String filePath) throws IOException {
throw new CustomException("파일이 존재하지 않습니다.", ErrorCode.FILE_NOT_FOUND);
}
}

private String getUniqueFileName(String fileName) {
return UUID.randomUUID() + fileName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public enum ErrorCode {
TrainerSchedule_NOT_FOUND(404, "트레이너 일정을 찾을 수 없습니다"),

NOT_SUSPEND_PROGRAM(422, "일시정지 요청이 거부되었습니다."),
IS_WORK_TIME(422, "근무 시간에는 예약설정이 불가능합니다."),
SUSPEND_REQUEST_DENIED(422, "일시정지 요청이 거부되었습니다.");


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import com.sideProject.PlanIT.domain.post.dto.response.BannerResponseDto;
import com.sideProject.PlanIT.domain.post.service.BannerService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/admin/banner")
@Slf4j
Expand All @@ -36,7 +37,9 @@ public ApiResponse<String> deleteBanner(@PathVariable Long banner_id) {
}

@GetMapping
public ApiResponse<List<BannerResponseDto>> findAllBanners() {
return ApiResponse.ok(bannerService.findAllBanners());
public ApiResponse<Page<BannerResponseDto>> findAllBanners(
@PageableDefault(size = 10) Pageable pageable
) {
return ApiResponse.ok(bannerService.findAllBanners(pageable));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import com.sideProject.PlanIT.domain.post.dto.response.BannerResponseDto;
import com.sideProject.PlanIT.domain.post.service.BannerService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


//todo: Banner, Notice 둘 다 Edit 발생 시 기존 첨부파일 삭제 후 다시 저장
@RestController
Expand All @@ -21,8 +22,10 @@ public class BannerController {
private final BannerService bannerService;

@GetMapping
public ApiResponse<List<BannerResponseDto>> findAllBannersInTime() {
return ApiResponse.ok(bannerService.findAllBannersInTime());
public ApiResponse<Page<BannerResponseDto>> findAllBannersInTime(
@PageableDefault(size = 10) Pageable pageable
) {
return ApiResponse.ok(bannerService.findAllBannersInTime(pageable));
}

@GetMapping("/{banner_id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import com.sideProject.PlanIT.domain.post.dto.response.NoticeResponseDto;
import com.sideProject.PlanIT.domain.post.service.NoticeService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/notice")
@RequiredArgsConstructor
Expand All @@ -31,7 +32,9 @@ public ApiResponse<String> deleteNotice(@PathVariable Long notice_id) {
}

@GetMapping
public ApiResponse<List<NoticeResponseDto>> findAllNotices() {
return ApiResponse.ok(noticeService.findAllNotices());
public ApiResponse<Page<NoticeResponseDto>> findAllNotices(
@PageableDefault(size = 10) Pageable pageable
) {
return ApiResponse.ok(noticeService.findAllNotices(pageable));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@
import com.sideProject.PlanIT.domain.post.dto.response.NoticeResponseDto;
import com.sideProject.PlanIT.domain.post.service.NoticeService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/notice")
public class NoticeController {
private final NoticeService noticeService;

@GetMapping
public ApiResponse<List<NoticeResponseDto>> findAllNoticesInTime() {
return ApiResponse.ok(noticeService.findAllNoticesInTime());
public ApiResponse<Page<NoticeResponseDto>> findAllNoticesInTime(
@PageableDefault(size = 10) Pageable pageable
) {
return ApiResponse.ok(noticeService.findAllNoticesInTime(pageable));
}

@GetMapping("/{notice_id}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.sideProject.PlanIT.domain.post.repository;

import com.sideProject.PlanIT.domain.post.entity.Banner;
import com.sideProject.PlanIT.domain.post.entity.Notice;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface BannerRepository extends JpaRepository<Banner, Long> {
@Query("SELECT b FROM Banner b WHERE b.startAt <= CURRENT_TIMESTAMP AND b.endAt >= CURRENT_TIMESTAMP ")
List<Banner> findByStartAtBeforeAndEndAtAfter();
Page<Banner> findByStartAtBeforeAndEndAtAfter(Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.sideProject.PlanIT.domain.post.repository;

import com.sideProject.PlanIT.domain.post.entity.Notice;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface NoticeRepository extends JpaRepository<Notice, Long> {
@Query("SELECT n FROM Notice n WHERE n.startAt <= CURRENT_TIMESTAMP AND n.endAt >= CURRENT_TIMESTAMP ")
List<Notice> findByStartAtBeforeAndEndAtAfter();
Page<Notice> findByStartAtBeforeAndEndAtAfter(Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

import com.sideProject.PlanIT.domain.post.dto.request.BannerRequestDto;
import com.sideProject.PlanIT.domain.post.dto.response.BannerResponseDto;
import com.sideProject.PlanIT.domain.post.entity.Banner;

import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

public interface BannerService {
String createBanner(BannerRequestDto bannerRequestDto);
String editBanner(Long banner_id, BannerRequestDto bannerRequestDto);
String deleteBanner(Long banner_id);
List<BannerResponseDto> findAllBanners();
List<BannerResponseDto> findAllBannersInTime();
Page<BannerResponseDto> findAllBanners(Pageable pageable);
Page<BannerResponseDto> findAllBannersInTime(Pageable pageable);
BannerResponseDto findBanner(Long banner_id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
import com.sideProject.PlanIT.domain.post.repository.BannerRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class BannerServiceImpl implements BannerService{
Expand Down Expand Up @@ -47,19 +46,15 @@ public String deleteBanner(Long banner_id) {
}

@Override
public List<BannerResponseDto> findAllBanners() {
List<Banner> banners = bannerRepository.findAll();
return banners.stream()
.map(BannerResponseDto::of)
.collect(Collectors.toList());
public Page<BannerResponseDto> findAllBanners(Pageable pageable) {
Page<Banner> banners = bannerRepository.findAll(pageable);
return banners.map(BannerResponseDto::of);
}

@Override
public List<BannerResponseDto> findAllBannersInTime() {
List<Banner> banners = bannerRepository.findByStartAtBeforeAndEndAtAfter();
return banners.stream()
.map(BannerResponseDto::of)
.collect(Collectors.toList());
public Page<BannerResponseDto> findAllBannersInTime(Pageable pageable) {
Page<Banner> banners = bannerRepository.findByStartAtBeforeAndEndAtAfter(pageable);
return banners.map(BannerResponseDto::of);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@

import com.sideProject.PlanIT.domain.post.dto.request.NoticeRequestDto;
import com.sideProject.PlanIT.domain.post.dto.response.NoticeResponseDto;
import com.sideProject.PlanIT.domain.post.entity.Notice;

import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;


public interface NoticeService {
String createNotice(NoticeRequestDto noticeRequestDto);
String editNotice(Long notice_id, NoticeRequestDto noticeRequestDto);
String deleteNotice(Long notice_id);
List<NoticeResponseDto> findAllNotices();
List<NoticeResponseDto> findAllNoticesInTime();
Page<NoticeResponseDto> findAllNotices(Pageable pageable);
Page<NoticeResponseDto> findAllNoticesInTime(Pageable pageable);
public NoticeResponseDto findNotice(Long notice_id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
import com.sideProject.PlanIT.domain.post.repository.NoticeRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class NoticeServiceImpl implements NoticeService{
Expand Down Expand Up @@ -56,19 +55,15 @@ public String deleteNotice(Long notice_id) {
}

@Override
public List<NoticeResponseDto> findAllNotices() {
List<Notice> notices = noticeRepository.findAll();
return notices.stream()
.map(NoticeResponseDto::of)
.collect(Collectors.toList());
public Page<NoticeResponseDto> findAllNotices(Pageable pageable) {
Page<Notice> notices = noticeRepository.findAll(pageable);
return notices.map(NoticeResponseDto::of);
}

@Override
public List<NoticeResponseDto> findAllNoticesInTime() {
List<Notice> notices = noticeRepository.findByStartAtBeforeAndEndAtAfter();
return notices.stream()
.map(NoticeResponseDto::of)
.collect(Collectors.toList());
public Page<NoticeResponseDto> findAllNoticesInTime(Pageable pageable) {
Page<Notice> notices = noticeRepository.findByStartAtBeforeAndEndAtAfter(pageable);
return notices.map(NoticeResponseDto::of);
}

public NoticeResponseDto findNotice(Long notice_id) {
Expand Down
Loading

0 comments on commit 00a2ed3

Please sign in to comment.