diff --git a/src/main/java/com/sideProject/PlanIT/config/SecurityConfig.java b/src/main/java/com/sideProject/PlanIT/config/SecurityConfig.java index 69e740d..0998bd3 100644 --- a/src/main/java/com/sideProject/PlanIT/config/SecurityConfig.java +++ b/src/main/java/com/sideProject/PlanIT/config/SecurityConfig.java @@ -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(); diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/controller/BannerController.java b/src/main/java/com/sideProject/PlanIT/domain/post/controller/BannerController.java index 0789fa4..c022063 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/controller/BannerController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/controller/BannerController.java @@ -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 createBanner(@ModelAttribute BannerRequestDto bannerRequestDto) { + @PostMapping("/admin/banner") + public ApiResponse createBanner(@ModelAttribute BannerRequestDto bannerRequestDto) { return ApiResponse.ok(bannerService.createBanner(bannerRequestDto)); } - @PutMapping("/banner/{banner_id}") - public ApiResponse editBanner(@PathVariable Long banner_id, @ModelAttribute BannerRequestDto bannerRequestDto) { + @PutMapping("admin/banner/{banner_id}") + public ApiResponse editBanner(@PathVariable Long banner_id, @ModelAttribute BannerRequestDto bannerRequestDto) { return ApiResponse.ok(bannerService.editBanner(banner_id, bannerRequestDto)); } + @DeleteMapping("/admin/banner/{banner_id}") + public ApiResponse deleteBanner(@PathVariable Long banner_id) { + return ApiResponse.ok(bannerService.deleteBanner(banner_id)); + } + @GetMapping("/admin/banner") public ApiResponse> findAllBanners() { return ApiResponse.ok(bannerService.findAllBanners()); diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/controller/NoticeController.java b/src/main/java/com/sideProject/PlanIT/domain/post/controller/NoticeController.java index d2a86d9..383cd21 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/controller/NoticeController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/controller/NoticeController.java @@ -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.*; @@ -17,15 +16,20 @@ public class NoticeController { private final NoticeService noticeService; @PostMapping("/admin/notice") - public ApiResponse createNotice(@ModelAttribute NoticeRequestDto noticeRequestDto) { + public ApiResponse createNotice(@ModelAttribute NoticeRequestDto noticeRequestDto) { return ApiResponse.ok(noticeService.createNotice(noticeRequestDto)); } @PutMapping("/admin/notice/{notice_id}") - public ApiResponse editNotice(@PathVariable Long notice_id , @ModelAttribute NoticeRequestDto noticeRequestDto) { + public ApiResponse editNotice(@PathVariable Long notice_id , @ModelAttribute NoticeRequestDto noticeRequestDto) { return ApiResponse.ok(noticeService.editNotice(notice_id, noticeRequestDto)); } + @DeleteMapping("/admin/notice/{notice_id}") + public ApiResponse deleteNotice(@PathVariable Long notice_id) { + return ApiResponse.ok(noticeService.deleteNotice(notice_id)); + } + @GetMapping("/admin/notice") public ApiResponse> findAllNotices() { return ApiResponse.ok(noticeService.findAllNotices()); @@ -37,7 +41,7 @@ public ApiResponse> findAllNoticesInTime() { } @GetMapping("/notice/{notice_id}") - public ApiResponse findNotice(Long notice_id) { + public ApiResponse findNotice(@PathVariable Long notice_id) { return ApiResponse.ok(noticeService.findNotice(notice_id)); } } diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/dto/response/BannerResponseDto.java b/src/main/java/com/sideProject/PlanIT/domain/post/dto/response/BannerResponseDto.java index 934dbec..03fcb7c 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/dto/response/BannerResponseDto.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/dto/response/BannerResponseDto.java @@ -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; @@ -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(); + } } diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/dto/response/NoticeResponseDto.java b/src/main/java/com/sideProject/PlanIT/domain/post/dto/response/NoticeResponseDto.java index 625e5fe..4901bf9 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/dto/response/NoticeResponseDto.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/dto/response/NoticeResponseDto.java @@ -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; @@ -10,6 +11,7 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class NoticeResponseDto { + private Long id; private String title; private LocalDateTime startAt; private LocalDateTime endAt; @@ -18,7 +20,8 @@ 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; @@ -26,4 +29,16 @@ public NoticeResponseDto(String title, LocalDateTime startAt, LocalDateTime endA 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(); + } } diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/entity/Banner.java b/src/main/java/com/sideProject/PlanIT/domain/post/entity/Banner.java index edbcf6f..6d15f35 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/entity/Banner.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/entity/Banner.java @@ -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.*; @@ -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; @@ -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(); - } } diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/entity/Notice.java b/src/main/java/com/sideProject/PlanIT/domain/post/entity/Notice.java index 6ec5b90..dc98b26 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/entity/Notice.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/entity/Notice.java @@ -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; @@ -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(); - } } diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/service/BannerService.java b/src/main/java/com/sideProject/PlanIT/domain/post/service/BannerService.java index 442b4ea..d8d40df 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/service/BannerService.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/service/BannerService.java @@ -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 findAllBanners(); List findAllBannersInTime(); BannerResponseDto findBanner(Long banner_id); diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/service/BannerServiceImpl.java b/src/main/java/com/sideProject/PlanIT/domain/post/service/BannerServiceImpl.java index e197c58..d7d2122 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/service/BannerServiceImpl.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/service/BannerServiceImpl.java @@ -21,26 +21,34 @@ 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 findAllBanners() { List banners = bannerRepository.findAll(); return banners.stream() - .map(Banner::toDto) + .map(BannerResponseDto::of) .collect(Collectors.toList()); } @@ -48,12 +56,12 @@ public List findAllBanners() { public List findAllBannersInTime() { List 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"))); } } diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/service/NoticeService.java b/src/main/java/com/sideProject/PlanIT/domain/post/service/NoticeService.java index 87b68bb..ef1f6c1 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/service/NoticeService.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/service/NoticeService.java @@ -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 findAllNotices(); List findAllNoticesInTime(); public NoticeResponseDto findNotice(Long notice_id); diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/service/NoticeServiceImpl.java b/src/main/java/com/sideProject/PlanIT/domain/post/service/NoticeServiceImpl.java index 5d5130a..e351e5b 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/service/NoticeServiceImpl.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/service/NoticeServiceImpl.java @@ -23,32 +23,41 @@ 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 findAllNotices() { List notices = noticeRepository.findAll(); return notices.stream() - .map(Notice::toDto) + .map(NoticeResponseDto::of) .collect(Collectors.toList()); } @@ -56,12 +65,12 @@ public List findAllNotices() { public List findAllNoticesInTime() { List 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"))); } diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/dto/response/ProgramResponse.java b/src/main/java/com/sideProject/PlanIT/domain/program/dto/response/ProgramResponse.java index 7ce513f..885ff46 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/dto/response/ProgramResponse.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/dto/response/ProgramResponse.java @@ -10,7 +10,6 @@ import lombok.Builder; import lombok.Getter; -import java.time.LocalDate; import java.util.Optional; @Getter diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/entity/Program.java b/src/main/java/com/sideProject/PlanIT/domain/program/entity/Program.java index e014d22..c5b9b66 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/entity/Program.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/entity/Program.java @@ -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; diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/entity/Registration.java b/src/main/java/com/sideProject/PlanIT/domain/program/entity/Registration.java index 5db3ff5..0f744bd 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/entity/Registration.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/entity/Registration.java @@ -17,7 +17,7 @@ public class Registration { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long Id; + private Long id; @Column private LocalDateTime registrationAt; diff --git a/src/main/java/com/sideProject/PlanIT/domain/schedule/entity/Schedule.java b/src/main/java/com/sideProject/PlanIT/domain/schedule/entity/Schedule.java index dad802f..e5639cf 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/schedule/entity/Schedule.java +++ b/src/main/java/com/sideProject/PlanIT/domain/schedule/entity/Schedule.java @@ -17,7 +17,7 @@ public class Schedule { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") - private Long Id; + private Long id; @Column(name = "schedule_name") private String name; diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/controller/AdminController.java b/src/main/java/com/sideProject/PlanIT/domain/user/controller/AdminController.java index 404a3e1..01bf26b 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/controller/AdminController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/controller/AdminController.java @@ -2,7 +2,6 @@ import com.sideProject.PlanIT.common.response.ApiResponse; import com.sideProject.PlanIT.domain.user.dto.employee.request.TrainerRequestDto; -import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerResponseDto; import com.sideProject.PlanIT.domain.user.dto.member.response.MemberResponseDto; import com.sideProject.PlanIT.domain.user.service.MemberService; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/controller/AuthController.java b/src/main/java/com/sideProject/PlanIT/domain/user/controller/AuthController.java index 47c3147..cedec03 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/controller/AuthController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/controller/AuthController.java @@ -18,7 +18,7 @@ public class AuthController { private final AuthService authService; @GetMapping("/refresh") - public ApiResponse refreshAccessToken(@RequestHeader("Authorization") String authorizationHeader) { + public ApiResponse refreshAccessToken(@RequestHeader("Authorization") String authorizationHeader) { log.info(authorizationHeader); return ApiResponse.ok(authService.refreshAccessToken(authorizationHeader)); } diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/controller/MemberController.java b/src/main/java/com/sideProject/PlanIT/domain/user/controller/MemberController.java index 8476547..2a057d7 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/controller/MemberController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/controller/MemberController.java @@ -1,7 +1,6 @@ package com.sideProject.PlanIT.domain.user.controller; import com.sideProject.PlanIT.common.response.ApiResponse; -import com.sideProject.PlanIT.domain.user.dto.employee.request.TrainerRequestDto; import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerResponseDto; import com.sideProject.PlanIT.domain.user.dto.member.request.MemberChangePasswordRequestDto; import com.sideProject.PlanIT.domain.user.dto.member.request.MemberEditRequestDto; @@ -9,7 +8,6 @@ import com.sideProject.PlanIT.domain.user.dto.member.request.MemberSignUpRequestDto; import com.sideProject.PlanIT.domain.user.dto.member.response.JwtResponseDto; import com.sideProject.PlanIT.domain.user.dto.member.response.MemberResponseDto; -import com.sideProject.PlanIT.domain.user.entity.Member; import com.sideProject.PlanIT.domain.user.service.MemberService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -18,9 +16,6 @@ import java.security.Principal; import java.util.List; - -//todo: member, admin Controller 분리 - @RestController @Slf4j @RequiredArgsConstructor @@ -45,7 +40,7 @@ public ApiResponse deleteMember(Principal principal) { } @PutMapping - public ApiResponse editMember(Principal principal, @RequestBody MemberEditRequestDto memberEditRequestDto) { + public ApiResponse editMember(Principal principal, @RequestBody MemberEditRequestDto memberEditRequestDto) { return ApiResponse.ok(memberService.editMember(Long.parseLong(principal.getName()), memberEditRequestDto)); } diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/request/TrainerRequestDto.java b/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/request/TrainerRequestDto.java index 572cfaa..44e069f 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/request/TrainerRequestDto.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/request/TrainerRequestDto.java @@ -8,4 +8,5 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class TrainerRequestDto { private String career; + private String trainerMessage; } diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/response/TrainerResponse.java b/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/response/TrainerResponse.java index d070f7a..55ae2e5 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/response/TrainerResponse.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/response/TrainerResponse.java @@ -6,22 +6,27 @@ import lombok.Getter; import lombok.NoArgsConstructor; + +// 특정 멤버 조회 시 멤버 Dto에 포함 @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class TrainerResponse { private Long id; private String career; + private String trainerMessage; @Builder - public TrainerResponse(Long id, String career) { + public TrainerResponse(Long id, String career, String trainerMessage) { this.id = id; this.career = career; + this.trainerMessage = trainerMessage; } public static TrainerResponse of(Employee employee) { return TrainerResponse.builder() .id(employee.getId()) .career(employee.getCareer()) + .trainerMessage(employee.getTrainerMessage()) .build(); } } diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/response/TrainerResponseDto.java b/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/response/TrainerResponseDto.java index e69ebb9..b0aece4 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/response/TrainerResponseDto.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/response/TrainerResponseDto.java @@ -1,6 +1,7 @@ package com.sideProject.PlanIT.domain.user.dto.employee.response; import com.sideProject.PlanIT.domain.user.entity.ENUM.MemberRole; +import com.sideProject.PlanIT.domain.user.entity.Employee; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -8,9 +9,11 @@ import java.time.LocalDate; +// 특정 트레이너 조회 시 사용 @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class TrainerResponseDto { + private Long id; private String email; private String name; private String phone_number; @@ -18,9 +21,11 @@ public class TrainerResponseDto { private String address; private MemberRole role; private String career; + private String trainerMessage; @Builder - public TrainerResponseDto(String email, String name, String phone_number, LocalDate birth, String address, MemberRole role, String career) { + public TrainerResponseDto(Long id, String email, String name, String phone_number, LocalDate birth, String address, MemberRole role, String career, String trainerMessage) { + this.id = id; this.email = email; this.name = name; this.phone_number = phone_number; @@ -28,5 +33,20 @@ public TrainerResponseDto(String email, String name, String phone_number, LocalD this.address = address; this.role = role; this.career = career; + this.trainerMessage = trainerMessage; + } + + public static TrainerResponseDto of(Employee employee) { + return TrainerResponseDto.builder() + .id(employee.getId()) + .email(employee.getMember().getEmail()) + .name(employee.getMember().getName()) + .phone_number(employee.getMember().getPhone_number()) + .birth(employee.getMember().getBirth()) + .address(employee.getMember().getAddress()) + .role(employee.getMember().getRole()) + .career(employee.getCareer()) + .trainerMessage(employee.getTrainerMessage()) + .build(); } } diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/entity/Employee.java b/src/main/java/com/sideProject/PlanIT/domain/user/entity/Employee.java index 36331b6..777a5d6 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/entity/Employee.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/entity/Employee.java @@ -1,7 +1,5 @@ package com.sideProject.PlanIT.domain.user.entity; - -import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerResponseDto; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Builder; @@ -15,30 +13,22 @@ public class Employee { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") - private Long Id; + private Long id; @Column private String career; + @Column + private String trainerMessage; + @OneToOne @JoinColumn(name = "member_id") private Member member; @Builder - public Employee(String career, Member member) { + public Employee(String career, String trainerMessage, Member member) { this.career = career; + this.trainerMessage = trainerMessage; this.member = member; } - - public TrainerResponseDto toDto() { - return TrainerResponseDto.builder() - .email(this.member.getEmail()) - .name(this.member.getName()) - .birth(this.member.getBirth()) - .address(this.member.getAddress()) - .phone_number(this.member.getPhone_number()) - .role(this.member.getRole()) - .career(this.career) - .build(); - } } diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/entity/EmployeeSchedule.java b/src/main/java/com/sideProject/PlanIT/domain/user/entity/EmployeeSchedule.java index 090bac2..d01e2b9 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/entity/EmployeeSchedule.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/entity/EmployeeSchedule.java @@ -17,7 +17,7 @@ public class EmployeeSchedule { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") - private Long Id; + private Long id; @Column private LocalDate date; diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/entity/Member.java b/src/main/java/com/sideProject/PlanIT/domain/user/entity/Member.java index b365c72..181d5cc 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/entity/Member.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/entity/Member.java @@ -18,7 +18,7 @@ public class Member { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") - private Long Id; + private Long id; @Column(name = "email", nullable = false, unique = true) private String email; @@ -66,16 +66,4 @@ public void changePassword(String newPassword) { public void grantEmployeeAuth() { this.role = MemberRole.TRAINER; } - - public MemberResponseDto toDto() { - return MemberResponseDto.builder() - .Id(this.Id) - .email(this.email) - .name(this.name) - .birth(this.birth) - .phone_number(this.phone_number) - .address(this.address) - .role(this.role) - .build(); - } } diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/entity/WorkTime.java b/src/main/java/com/sideProject/PlanIT/domain/user/entity/WorkTime.java index 382b557..93aa8e1 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/entity/WorkTime.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/entity/WorkTime.java @@ -15,7 +15,7 @@ public class WorkTime { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") - private Long Id; + private Long id; @Column private String week; // 요일 diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/service/MemberService.java b/src/main/java/com/sideProject/PlanIT/domain/user/service/MemberService.java index 195febb..72fc68e 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/service/MemberService.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/service/MemberService.java @@ -16,7 +16,8 @@ public interface MemberService { Member signUp(MemberSignUpRequestDto memberSignUpRequestDto); JwtResponseDto memberValidation(MemberSignInRequestDto memberSignInRequestDto); String deleteMember(Long member_id); - Member editMember(Long member_id, MemberEditRequestDto memberEditRequestDto); + + String editMember(Long member_id, MemberEditRequestDto memberEditRequestDto); String changePassword(Long member_id, MemberChangePasswordRequestDto memberChangePasswordRequestDto); MemberResponseDto findMember(Long member_id); String signOut(Long member_id); diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/service/MemberServiceImpl.java b/src/main/java/com/sideProject/PlanIT/domain/user/service/MemberServiceImpl.java index 1027664..9a1417d 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/service/MemberServiceImpl.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/service/MemberServiceImpl.java @@ -73,13 +73,15 @@ public String deleteMember(Long member_id) { } @Override - public Member editMember(Long member_id, MemberEditRequestDto memberEditRequestDto) { + public String editMember(Long member_id, MemberEditRequestDto memberEditRequestDto) { Member memberToEdit = memberRepository.findById(member_id).orElseThrow(() -> new IllegalArgumentException("no extist id")); memberToEdit.update(memberEditRequestDto); - return memberRepository.save(memberToEdit); + memberRepository.save(memberToEdit); + + return "수정 완료"; } @Override @@ -129,7 +131,7 @@ public String signOut(Long member_id) { public List findAllMembers() { List members = memberRepository.findAllMembers(); return members.stream() - .map(Member::toDto) + .map(member -> MemberResponseDto.of(member, null)) .collect(Collectors.toList()); } @@ -137,7 +139,7 @@ public List findAllMembers() { public List findAllEmployees() { List employees = employeeRepository.findAllTrainers(); return employees.stream() - .map(Employee::toDto) + .map(TrainerResponseDto::of) .collect(Collectors.toList()); }