From 40aad54f9902277f6d9517e0fdf589e6362e0c39 Mon Sep 17 00:00:00 2001 From: jeonggeon Date: Wed, 17 Jan 2024 18:24:25 +0900 Subject: [PATCH] =?UTF-8?q?#24=20[feat]=20=ED=95=99=EC=88=A0=EB=8C=80?= =?UTF-8?q?=ED=9A=8C=20record=20=EA=B4=80=EB=A0=A8=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../careerfestival/career/domain/Record.java | 11 +++++++ .../careerfestival/career/domain/User.java | 9 +++++ .../record/controller/RecordController.java | 19 ++++++++++- .../record/converter/RecordConverter.java | 31 +++++++++++++++++ .../career/record/dto/RecordRequestDto.java | 33 +++++++++++++++++++ .../career/record/dto/RecordResponseDto.java | 21 ++++++++++++ .../record/service/RecordCommandService.java | 12 +++++++ .../service/RecordCommandServiceImpl.java | 31 +++++++++++++++++ src/main/resources/application.yml | 2 +- 9 files changed, 167 insertions(+), 2 deletions(-) create mode 100644 src/main/java/careerfestival/career/record/converter/RecordConverter.java create mode 100644 src/main/java/careerfestival/career/record/dto/RecordRequestDto.java create mode 100644 src/main/java/careerfestival/career/record/dto/RecordResponseDto.java create mode 100644 src/main/java/careerfestival/career/record/service/RecordCommandService.java create mode 100644 src/main/java/careerfestival/career/record/service/RecordCommandServiceImpl.java diff --git a/src/main/java/careerfestival/career/domain/Record.java b/src/main/java/careerfestival/career/domain/Record.java index 541292ec..a9be1571 100644 --- a/src/main/java/careerfestival/career/domain/Record.java +++ b/src/main/java/careerfestival/career/domain/Record.java @@ -8,6 +8,7 @@ import careerfestival.career.domain.mapping.RecordKeyword; import java.util.ArrayList; import java.util.List; +import java.util.Optional; @Entity @Getter @@ -40,4 +41,14 @@ public class Record extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY) private User user; + + public void user(Optional user){ + //checkpoint + /* Optional.ofNullable(this.user) + .ifPresent(oldUser -> oldUser.removeRecord(this)); + + this.user = user; + user.addRecord(this);*/ + } + } \ No newline at end of file diff --git a/src/main/java/careerfestival/career/domain/User.java b/src/main/java/careerfestival/career/domain/User.java index 6be21047..d37c5277 100644 --- a/src/main/java/careerfestival/career/domain/User.java +++ b/src/main/java/careerfestival/career/domain/User.java @@ -88,6 +88,9 @@ public class User extends BaseEntity { @OneToMany(mappedBy = "user", cascade = CascadeType.ALL) private List follow = new ArrayList<>(); + @OneToMany(mappedBy = "user", cascade = CascadeType.ALL) + private List records = new ArrayList<>(); + public void updatePassword(String password) { this.password = password; @@ -108,4 +111,10 @@ public void updateAge(int age) { public void updatePhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; } + + + public void addRecord(Record record){ + records.add(record); + } + } \ No newline at end of file diff --git a/src/main/java/careerfestival/career/record/controller/RecordController.java b/src/main/java/careerfestival/career/record/controller/RecordController.java index 01493143..a60306f0 100644 --- a/src/main/java/careerfestival/career/record/controller/RecordController.java +++ b/src/main/java/careerfestival/career/record/controller/RecordController.java @@ -1,8 +1,15 @@ package careerfestival.career.record.controller; +import careerfestival.career.apiPayload.ApiResponse; +import careerfestival.career.domain.Record; +import careerfestival.career.record.converter.RecordConverter; import careerfestival.career.record.dto.RecordEtcDto; import careerfestival.career.record.dto.RecordLectureSeminarDto; +import careerfestival.career.record.dto.RecordRequestDto; +import careerfestival.career.record.dto.RecordResponseDto; +import careerfestival.career.record.service.RecordCommandService; import careerfestival.career.record.service.RecordService; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -13,7 +20,7 @@ @RestController public class RecordController { private final RecordService recordService; - + private final RecordCommandService recordCommandService; @PostMapping("/lecture-seminar") public ResponseEntity recordLectureSeminar(@RequestParam("userId") Long userId, @RequestBody RecordLectureSeminarDto recordLectureSeminarDto) { try { @@ -34,5 +41,15 @@ public ResponseEntity recordEtc(@RequestParam("userId") Long userId, @Requ return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } } + //기록장 + @PostMapping("/{memberId}") + public ApiResponse + addRecordConference(@RequestBody @Valid RecordRequestDto.AddRecordConferenceRequestDto request + ,@PathVariable Long memberId){ + Record record = recordCommandService.addRecord(request, memberId); + return ApiResponse.onSuccess(RecordConverter.toAddRecordResponseDto(record)); + } + + } diff --git a/src/main/java/careerfestival/career/record/converter/RecordConverter.java b/src/main/java/careerfestival/career/record/converter/RecordConverter.java new file mode 100644 index 00000000..1182feb4 --- /dev/null +++ b/src/main/java/careerfestival/career/record/converter/RecordConverter.java @@ -0,0 +1,31 @@ +package careerfestival.career.record.converter; +import careerfestival.career.domain.Record; +import careerfestival.career.record.dto.RecordRequestDto; +import careerfestival.career.record.dto.RecordResponseDto; + +import java.time.LocalDate; +import java.time.LocalDateTime; + + + +public class RecordConverter { + public static Record toRecord(RecordRequestDto.AddRecordConferenceRequestDto request){ + + return Record.builder() + .eventName(request.getEventName()) + .eventDate(request.getEventDate()) + .eventDescription(request.getEventDescription()) + .networkingName(request.getNetworkingName()) + .networkingContact(request.getNetworkingContact()) + .build(); + } + public static RecordResponseDto.AddRecordResponseDto toAddRecordResponseDto(Record record){ + return RecordResponseDto.AddRecordResponseDto.builder() + .recordId(record.getId()) + .createdAt(LocalDate.from(LocalDateTime.now())) + .build(); + } +//checkpoint localdatetime + + +} diff --git a/src/main/java/careerfestival/career/record/dto/RecordRequestDto.java b/src/main/java/careerfestival/career/record/dto/RecordRequestDto.java new file mode 100644 index 00000000..3cb228b0 --- /dev/null +++ b/src/main/java/careerfestival/career/record/dto/RecordRequestDto.java @@ -0,0 +1,33 @@ +package careerfestival.career.record.dto; + +import careerfestival.career.domain.Category; +import careerfestival.career.domain.mapping.RecordKeyword; +import jakarta.persistence.Column; +import jakarta.validation.constraints.NotNull; +import lombok.Getter; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; + +public class RecordRequestDto { + + @Getter + public static class AddRecordConferenceRequestDto{ + @NotNull + private String eventName; + @NotNull + private LocalDate deadline; + @NotNull + private List recordKeywords; + @NotNull + private Category category; + @NotNull + private LocalDateTime eventDate; + //checkpoint 세션과 부스 어차피 같은 형태로 그냥 제목부스이름이던 세션이름이던 같이 받을 수 있음 그래서 event description 제목 받을 거 하나 생성 + @NotNull + private String eventDescription; + private String networkingName; + private String networkingContact; + } +} diff --git a/src/main/java/careerfestival/career/record/dto/RecordResponseDto.java b/src/main/java/careerfestival/career/record/dto/RecordResponseDto.java new file mode 100644 index 00000000..1644949d --- /dev/null +++ b/src/main/java/careerfestival/career/record/dto/RecordResponseDto.java @@ -0,0 +1,21 @@ +package careerfestival.career.record.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +public class RecordResponseDto { + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class AddRecordResponseDto{ + private Long recordId; + private Long userId; + private LocalDate createdAt; + + } +} diff --git a/src/main/java/careerfestival/career/record/service/RecordCommandService.java b/src/main/java/careerfestival/career/record/service/RecordCommandService.java new file mode 100644 index 00000000..656c6c41 --- /dev/null +++ b/src/main/java/careerfestival/career/record/service/RecordCommandService.java @@ -0,0 +1,12 @@ +package careerfestival.career.record.service; + +import careerfestival.career.record.dto.RecordRequestDto; + +import careerfestival.career.domain.Record; + ; + + +public interface RecordCommandService { + + Record addRecord(RecordRequestDto.AddRecordConferenceRequestDto request, Long userId); +} diff --git a/src/main/java/careerfestival/career/record/service/RecordCommandServiceImpl.java b/src/main/java/careerfestival/career/record/service/RecordCommandServiceImpl.java new file mode 100644 index 00000000..a3fa53c4 --- /dev/null +++ b/src/main/java/careerfestival/career/record/service/RecordCommandServiceImpl.java @@ -0,0 +1,31 @@ +package careerfestival.career.record.service; + +import careerfestival.career.domain.Record; +import careerfestival.career.domain.User; +import careerfestival.career.record.converter.RecordConverter; +import careerfestival.career.record.dto.RecordRequestDto; +import careerfestival.career.repository.RecordRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import careerfestival.career.repository.UserRepository; + + + +@Service +@RequiredArgsConstructor +@Transactional +public class RecordCommandServiceImpl implements RecordCommandService{ + private final UserRepository userRepository; + private final RecordRepository recordRepository; + @Override + public Record addRecord(RecordRequestDto.AddRecordConferenceRequestDto request, Long userId){ + Record newRecord = RecordConverter.toRecord(request); + //checkpoint userid에 맞게 저장하는방법? + //Optional user = userRepository.findById(userId); + //checkpoint 리스트 + // newRecord.user(user); + return recordRepository.save(newRecord); + }; + +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 7fffe5a3..fe4449af 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -3,7 +3,7 @@ spring: datasource: url: jdbc:mysql://localhost:3306/careerfestival username: root - password: swtndhks12 + password: 12345678! driver-class-name: com.mysql.cj.jdbc.Driver