Skip to content

Commit

Permalink
Merge branch 'BE' into BE_fix#147
Browse files Browse the repository at this point in the history
  • Loading branch information
moonjin-kim authored Apr 4, 2024
2 parents c3ff919 + a0507ef commit 7733c28
Show file tree
Hide file tree
Showing 37 changed files with 252 additions and 255 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 @@ -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
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.sideProject.PlanIT.domain.program.controller;

import com.sideProject.PlanIT.common.response.ApiResponse;
import com.sideProject.PlanIT.domain.program.dto.request.ApproveRequest;
import com.sideProject.PlanIT.domain.program.dto.request.ProgramModifyRequest;
import com.sideProject.PlanIT.domain.program.dto.response.ProgramResponse;
import com.sideProject.PlanIT.domain.program.dto.response.FindRegistrationResponse;
import com.sideProject.PlanIT.domain.program.dto.request.ApproveRequestDto;
import com.sideProject.PlanIT.domain.program.dto.request.ProgramModifyRequestDto;
import com.sideProject.PlanIT.domain.program.dto.response.ProgramResponseDto;
import com.sideProject.PlanIT.domain.program.dto.response.FindRegistrationResponseDto;
import com.sideProject.PlanIT.domain.program.entity.enums.ProgramSearchStatus;
import com.sideProject.PlanIT.domain.program.entity.enums.RegistrationSearchStatus;
import com.sideProject.PlanIT.domain.program.service.ProgramService;
Expand All @@ -31,7 +31,7 @@ public class ProgramAdminController {

//어드민이 전부 검색
@GetMapping("")
public ApiResponse<Page<ProgramResponse>> find(
public ApiResponse<Page<ProgramResponseDto>> find(
@RequestParam(value = "option", required = false, defaultValue = "VALID") ProgramSearchStatus option,
@PageableDefault(size = 10) Pageable pageable,
Principal principal) {
Expand All @@ -44,7 +44,7 @@ public ApiResponse<Page<ProgramResponse>> find(

//어드민이 유저 id로 검색
@GetMapping("/by-user/{id}")
public ApiResponse<Page<ProgramResponse>> find(
public ApiResponse<Page<ProgramResponseDto>> find(
@PathVariable("id") Long id,
@PageableDefault(size = 10) Pageable pageable,
@RequestParam(value = "option", required = false, defaultValue = "VALID") ProgramSearchStatus option) {
Expand All @@ -54,7 +54,7 @@ public ApiResponse<Page<ProgramResponse>> find(
}

@GetMapping("/{id}")
public ApiResponse<ProgramResponse> find(
public ApiResponse<ProgramResponseDto> find(
@PathVariable("id") Long id) {
Authentication loggedInUser = SecurityContextHolder.getContext().getAuthentication();
Long userId = Long.parseLong(loggedInUser.getName());
Expand All @@ -75,22 +75,22 @@ public ApiResponse<String> refund(@PathVariable("id") Long id) {
@PutMapping("/{id}")
public ApiResponse<String> modify(
@PathVariable("id") Long id,
ProgramModifyRequest request) {
ProgramModifyRequestDto request) {
return ApiResponse.ok(
programService.modify(id, request)
);
}

@PostMapping("/approve/{id}")
public ApiResponse<Long> approve(@PathVariable("id") Long id, @RequestBody ApproveRequest request) {
public ApiResponse<Long> approve(@PathVariable("id") Long id, @RequestBody ApproveRequestDto request) {
LocalDateTime now = LocalDateTime.now();
return ApiResponse.ok(
programService.approve(id, request.getTrainer(), now)
);
}

@GetMapping("/registration")
public ApiResponse<Page<FindRegistrationResponse>> findRegistration(
public ApiResponse<Page<FindRegistrationResponseDto>> findRegistration(
@RequestParam(value = "option", required = false, defaultValue = "READY") RegistrationSearchStatus option,
@PageableDefault(size = 10) Pageable pageable,
Principal principal) {
Expand All @@ -102,7 +102,7 @@ public ApiResponse<Page<FindRegistrationResponse>> findRegistration(


@GetMapping("/registration/{id}")
public ApiResponse<Page<FindRegistrationResponse>> findRegistrationByUser(
public ApiResponse<Page<FindRegistrationResponseDto>> findRegistrationByUser(
@PathVariable("id") Long id,
@PageableDefault(size = 10) Pageable pageable,
@RequestParam(value = "option", required = false, defaultValue = "READY") RegistrationSearchStatus option) {
Expand Down
Loading

0 comments on commit 7733c28

Please sign in to comment.