diff --git a/src/main/java/careerfestival/career/domain/Record.java b/src/main/java/careerfestival/career/domain/Record.java index c572dd59..c26306be 100644 --- a/src/main/java/careerfestival/career/domain/Record.java +++ b/src/main/java/careerfestival/career/domain/Record.java @@ -8,6 +8,7 @@ import java.time.LocalDate; import java.util.List; +import java.util.Optional; @Entity @Getter @@ -38,4 +39,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 3b28861a..a9ea1f04 100644 --- a/src/main/java/careerfestival/career/domain/User.java +++ b/src/main/java/careerfestival/career/domain/User.java @@ -101,6 +101,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; @@ -121,4 +124,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 4a29fa1f..49b6d631 100644 --- a/src/main/java/careerfestival/career/record/controller/RecordController.java +++ b/src/main/java/careerfestival/career/record/controller/RecordController.java @@ -1,13 +1,20 @@ 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.RecordMainResponseDto; +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; import org.springframework.web.bind.annotation.*; +import careerfestival.career.record.dto.RecordMainResponseDto; import java.util.List; @@ -16,7 +23,6 @@ @RestController public class RecordController { private final RecordService recordService; - // @PostMapping("/lecture-seminar/{userId}") public ResponseEntity recordLectureSeminar(@PathVariable("userId") Long userId, @RequestBody RecordLectureSeminarDto recordLectureSeminarDto) { @@ -37,6 +43,16 @@ public ResponseEntity recordEtc(@PathVariable("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)); + } + + // 메인페이지 1차 구현 완료 @GetMapping("/{userId}") 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 eee9389b..45a08fc3 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: "0000" + password: 12345678! driver-class-name: com.mysql.cj.jdbc.Driver