Skip to content

Commit

Permalink
Merge pull request #69 from PlanIt-Project/BE
Browse files Browse the repository at this point in the history
Be
  • Loading branch information
moonjin-kim authored Mar 18, 2024
2 parents f596c74 + 14e5bab commit 1df4610
Show file tree
Hide file tree
Showing 27 changed files with 153 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
exceptionHandling.authenticationEntryPoint(jwtAuthenticationEntryPoint))
.authorizeHttpRequests((authorizeRequests) -> authorizeRequests
.requestMatchers("/member/signin", "/member/signup", "/refresh").permitAll()
.requestMatchers("/admin/**").hasAnyAuthority("ADMIN")
.anyRequest().authenticated()
// .requestMatchers("/admin/**").hasAnyAuthority("ADMIN")
// .anyRequest().authenticated()
.anyRequest().permitAll()
)
.addFilterBefore(jwtTokenFilter, UsernamePasswordAuthenticationFilter.class)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,35 @@
import com.sideProject.PlanIT.common.response.ApiResponse;
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 com.sideProject.PlanIT.domain.post.service.BannerService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


//todo: Banner, Notice 둘 다 Edit 발생 시 기존 첨부파일 삭제 후 다시 저장
@RestController
@AllArgsConstructor
public class BannerController {

private final BannerService bannerService;

@PostMapping("admin/banner")
public ApiResponse<Banner> createBanner(@ModelAttribute BannerRequestDto bannerRequestDto) {
@PostMapping("/admin/banner")
public ApiResponse<String> createBanner(@ModelAttribute BannerRequestDto bannerRequestDto) {
return ApiResponse.ok(bannerService.createBanner(bannerRequestDto));
}

@PutMapping("/banner/{banner_id}")
public ApiResponse<Banner> editBanner(@PathVariable Long banner_id, @ModelAttribute BannerRequestDto bannerRequestDto) {
@PutMapping("admin/banner/{banner_id}")
public ApiResponse<String> editBanner(@PathVariable Long banner_id, @ModelAttribute BannerRequestDto bannerRequestDto) {
return ApiResponse.ok(bannerService.editBanner(banner_id, bannerRequestDto));
}

@DeleteMapping("/admin/banner/{banner_id}")
public ApiResponse<String> deleteBanner(@PathVariable Long banner_id) {
return ApiResponse.ok(bannerService.deleteBanner(banner_id));
}

@GetMapping("/admin/banner")
public ApiResponse<List<BannerResponseDto>> findAllBanners() {
return ApiResponse.ok(bannerService.findAllBanners());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.sideProject.PlanIT.common.response.ApiResponse;
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 com.sideProject.PlanIT.domain.post.service.NoticeService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
Expand All @@ -17,15 +16,20 @@ public class NoticeController {
private final NoticeService noticeService;

@PostMapping("/admin/notice")
public ApiResponse<Notice> createNotice(@ModelAttribute NoticeRequestDto noticeRequestDto) {
public ApiResponse<String> createNotice(@ModelAttribute NoticeRequestDto noticeRequestDto) {
return ApiResponse.ok(noticeService.createNotice(noticeRequestDto));
}

@PutMapping("/admin/notice/{notice_id}")
public ApiResponse<Notice> editNotice(@PathVariable Long notice_id , @ModelAttribute NoticeRequestDto noticeRequestDto) {
public ApiResponse<String> editNotice(@PathVariable Long notice_id , @ModelAttribute NoticeRequestDto noticeRequestDto) {
return ApiResponse.ok(noticeService.editNotice(notice_id, noticeRequestDto));
}

@DeleteMapping("/admin/notice/{notice_id}")
public ApiResponse<String> deleteNotice(@PathVariable Long notice_id) {
return ApiResponse.ok(noticeService.deleteNotice(notice_id));
}

@GetMapping("/admin/notice")
public ApiResponse<List<NoticeResponseDto>> findAllNotices() {
return ApiResponse.ok(noticeService.findAllNotices());
Expand All @@ -37,7 +41,7 @@ public ApiResponse<List<NoticeResponseDto>> findAllNoticesInTime() {
}

@GetMapping("/notice/{notice_id}")
public ApiResponse<NoticeResponseDto> findNotice(Long notice_id) {
public ApiResponse<NoticeResponseDto> findNotice(@PathVariable Long notice_id) {
return ApiResponse.ok(noticeService.findNotice(notice_id));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sideProject.PlanIT.domain.post.dto.response;

import com.sideProject.PlanIT.domain.post.entity.Banner;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -10,16 +11,28 @@
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class BannerResponseDto {
private Long id;
private String title;
private LocalDateTime startAt;
private LocalDateTime endAt;
private String imagePath;

@Builder
public BannerResponseDto(String title, LocalDateTime startAt, LocalDateTime endAt, String imagePath) {
public BannerResponseDto(Long id, String title, LocalDateTime startAt, LocalDateTime endAt, String imagePath) {
this.id = id;
this.title = title;
this.startAt = startAt;
this.endAt = endAt;
this.imagePath = imagePath;
}

public static BannerResponseDto of(Banner banner) {
return BannerResponseDto.builder()
.id(banner.getId())
.title(banner.getTitle())
.startAt(banner.getStartAt())
.endAt(banner.getEndAt())
.imagePath(banner.getImagePath())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sideProject.PlanIT.domain.post.dto.response;

import com.sideProject.PlanIT.domain.post.entity.Notice;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -10,6 +11,7 @@
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class NoticeResponseDto {
private Long id;
private String title;
private LocalDateTime startAt;
private LocalDateTime endAt;
Expand All @@ -18,12 +20,25 @@ public class NoticeResponseDto {
private String content;

@Builder
public NoticeResponseDto(String title, LocalDateTime startAt, LocalDateTime endAt, String attachmentPath, String imagePath, String content) {
public NoticeResponseDto(Long id, String title, LocalDateTime startAt, LocalDateTime endAt, String attachmentPath, String imagePath, String content) {
this.id = id;
this.title = title;
this.startAt = startAt;
this.endAt = endAt;
this.attachmentPath = attachmentPath;
this.imagePath = imagePath;
this.content = content;
}

public static NoticeResponseDto of(Notice notice) {
return NoticeResponseDto.builder()
.id(notice.getId())
.title(notice.getTitle())
.startAt(notice.getStartAt())
.endAt(notice.getEndAt())
.attachmentPath(notice.getAttachmentPath())
.imagePath(notice.getImagePath())
.content(notice.getContent())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.sideProject.PlanIT.domain.post.entity;

import com.sideProject.PlanIT.domain.post.dto.request.BannerRequestDto;
import com.sideProject.PlanIT.domain.post.dto.response.BannerResponseDto;
import jakarta.persistence.*;
import lombok.*;

Expand All @@ -14,7 +13,7 @@ public class Banner {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long Id;
private Long id;

@Column
private String title;
Expand Down Expand Up @@ -46,13 +45,4 @@ public Banner update(BannerRequestDto bannerRequestDto) {

return this;
}

public static BannerResponseDto toDto(Banner banner) {
return BannerResponseDto.builder()
.title(banner.title)
.startAt(banner.startAt)
.endAt(banner.endAt)
.imagePath(banner.imagePath)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Notice {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long Id;
private Long id;

@Column
private String title;
Expand Down Expand Up @@ -58,15 +58,4 @@ public Notice update(NoticeRequestDto noticeRequestDto) {

return this;
}

public static NoticeResponseDto toDto(Notice notice) {
return NoticeResponseDto.builder()
.title(notice.title)
.startAt(notice.startAt)
.endAt(notice.endAt)
.attachmentPath(notice.attachmentPath)
.imagePath(notice.imagePath)
.content(notice.content)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import java.util.List;

public interface BannerService {
Banner createBanner(BannerRequestDto bannerRequestDto);
Banner editBanner(Long banner_id, BannerRequestDto bannerRequestDto);
String createBanner(BannerRequestDto bannerRequestDto);
String editBanner(Long banner_id, BannerRequestDto bannerRequestDto);
String deleteBanner(Long banner_id);
List<BannerResponseDto> findAllBanners();
List<BannerResponseDto> findAllBannersInTime();
BannerResponseDto findBanner(Long banner_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,47 @@ public class BannerServiceImpl implements BannerService{
@Autowired
private FileHandler fileHandler;

public Banner createBanner(BannerRequestDto bannerRequestDto) {
return bannerRepository.save(Banner.builder()
.title(bannerRequestDto.getTitle())
.startAt(bannerRequestDto.getStartAt())
.endAt(bannerRequestDto.getEndAt())
.imagePath(fileHandler.saveFile(bannerRequestDto.getImage()))
.build());
public String createBanner(BannerRequestDto bannerRequestDto) {
bannerRepository.save(Banner.builder()
.title(bannerRequestDto.getTitle())
.startAt(bannerRequestDto.getStartAt())
.endAt(bannerRequestDto.getEndAt())
.imagePath(fileHandler.saveFile(bannerRequestDto.getImage()))
.build());
return "생성 완료";
}

@Override
public Banner editBanner(Long banner_id, BannerRequestDto bannerRequestDto) {
public String editBanner(Long banner_id, BannerRequestDto bannerRequestDto) {
Banner bannerToEdit = bannerRepository.findById(banner_id).orElseThrow(() -> new IllegalStateException("no exist id"));
return bannerRepository.save(bannerToEdit.update(bannerRequestDto));
bannerRepository.save(bannerToEdit.update(bannerRequestDto));
return "수정 완료";
}

@Override
public String deleteBanner(Long banner_id) {
bannerRepository.deleteById(banner_id);
return "삭제 완료";
}

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

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

@Override
public BannerResponseDto findBanner(Long banner_id) {
return Banner.toDto(bannerRepository.findById(banner_id).orElseThrow(() -> new IllegalArgumentException("no exist id")));
return BannerResponseDto.of(bannerRepository.findById(banner_id).orElseThrow(() -> new IllegalArgumentException("no exist id")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@


public interface NoticeService {
Notice createNotice(NoticeRequestDto noticeRequestDto);
Notice editNotice(Long notice_id, NoticeRequestDto noticeRequestDto);
String createNotice(NoticeRequestDto noticeRequestDto);
String editNotice(Long notice_id, NoticeRequestDto noticeRequestDto);
String deleteNotice(Long notice_id);
List<NoticeResponseDto> findAllNotices();
List<NoticeResponseDto> findAllNoticesInTime();
public NoticeResponseDto findNotice(Long notice_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,45 +23,54 @@ public class NoticeServiceImpl implements NoticeService{
private FileHandler fileHandler;

@Override
public Notice createNotice(NoticeRequestDto noticeRequestDto) {
return noticeRepository.save(Notice.builder()
.title(noticeRequestDto.getTitle())
.startAt(noticeRequestDto.getStartAt())
.endAt(noticeRequestDto.getEndAt())
.attachmentPath(fileHandler.saveFile(noticeRequestDto.getAttachment()))
.imagePath(fileHandler.saveFile(noticeRequestDto.getImage()))
.content(noticeRequestDto.getContent())
.build());
public String createNotice(NoticeRequestDto noticeRequestDto) {
noticeRepository.save(Notice.builder()
.title(noticeRequestDto.getTitle())
.startAt(noticeRequestDto.getStartAt())
.endAt(noticeRequestDto.getEndAt())
.attachmentPath(fileHandler.saveFile(noticeRequestDto.getAttachment()))
.imagePath(fileHandler.saveFile(noticeRequestDto.getImage()))
.content(noticeRequestDto.getContent())
.build());
return "생성 완료";
}

@Override
public Notice editNotice(Long notice_id, NoticeRequestDto noticeRequestDto) {
public String editNotice(Long notice_id, NoticeRequestDto noticeRequestDto) {
Notice noticeToEdit = noticeRepository.findById(notice_id).orElseThrow(() -> new IllegalArgumentException("no exist Id"));
fileHandler.saveFile(noticeRequestDto.getAttachment());
fileHandler.saveFile(noticeRequestDto.getImage());
//todo: 기존 저장된 파일 제거?

return noticeRepository.save(noticeToEdit.update(noticeRequestDto));
noticeRepository.save(noticeToEdit.update(noticeRequestDto));

return "수정 완료";
}

@Override
public String deleteNotice(Long notice_id) {
noticeRepository.deleteById(notice_id);
return "삭제 완료";
}

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

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

public NoticeResponseDto findNotice(Long notice_id) {
return Notice.toDto(noticeRepository.findById(notice_id).orElseThrow(() -> new IllegalArgumentException("no exist Id")));
return NoticeResponseDto.of(noticeRepository.findById(notice_id).orElseThrow(() -> new IllegalArgumentException("no exist Id")));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDate;
import java.util.Optional;

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Program extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long Id;
private Long id;

@ColumnDefault("0")
private int remainedNumber;
Expand Down
Loading

0 comments on commit 1df4610

Please sign in to comment.