diff --git a/src/main/java/careerfestival/career/domain/ContactDetail.java b/src/main/java/careerfestival/career/domain/ContactDetail.java new file mode 100644 index 00000000..0e724397 --- /dev/null +++ b/src/main/java/careerfestival/career/domain/ContactDetail.java @@ -0,0 +1,19 @@ +package careerfestival.career.domain; + +import jakarta.persistence.Embeddable; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Embeddable +public class ContactDetail { + + private String networkingName; + private String networkingContact; + +} \ No newline at end of file diff --git a/src/main/java/careerfestival/career/domain/Record.java b/src/main/java/careerfestival/career/domain/Record.java index 29acb060..5ba43523 100644 --- a/src/main/java/careerfestival/career/domain/Record.java +++ b/src/main/java/careerfestival/career/domain/Record.java @@ -8,7 +8,9 @@ import lombok.*; import java.time.LocalDate; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Optional; @Entity @@ -54,4 +56,20 @@ public class Record extends BaseEntity { @OneToOne(mappedBy = "record", cascade = CascadeType.ALL) private ImageData imageData; + + @ElementCollection + @CollectionTable(name="record_details", joinColumns = @JoinColumn(name="record_id")) + @MapKeyColumn(name="record_key") + @Column(name = "record_value") + //RECORD MAPPING으로 수정 + private Map recordDetails; + + + @ElementCollection + @CollectionTable(name="record_contacts", joinColumns = @JoinColumn(name="record_id")) + @MapKeyColumn(name="contact_key") + @Column(name = "contact_value") + //RECORD MAPPING으로 수정 + private Map contactDetails; + } \ No newline at end of file diff --git a/src/main/java/careerfestival/career/domain/RecordDetail.java b/src/main/java/careerfestival/career/domain/RecordDetail.java new file mode 100644 index 00000000..6e92eeff --- /dev/null +++ b/src/main/java/careerfestival/career/domain/RecordDetail.java @@ -0,0 +1,19 @@ +package careerfestival.career.domain; + +import jakarta.persistence.Embeddable; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Embeddable +public class RecordDetail { + + private String detailRecordName; + private String recordDescription; + +} \ 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 c63a402c..df95761c 100644 --- a/src/main/java/careerfestival/career/record/controller/RecordController.java +++ b/src/main/java/careerfestival/career/record/controller/RecordController.java @@ -42,18 +42,18 @@ public ResponseEntity recordEtc(@PathVariable("userId") Long userId, @Requ } // conference 기록 추가 @PostMapping("/conference/{userId}") - public ResponseEntity addRecordConference(@RequestBody @Valid RecordRequestDto request, @PathVariable("userId") Long memberId) { + public ResponseEntity addRecordConference(@RequestBody @Valid RecordRequestDto request, @PathVariable("userId") Long userId) { try { - recordConferenceService.recordConference(memberId, request); + recordConferenceService.recordConference(userId,request); return new ResponseEntity<>(HttpStatus.OK); } catch (IllegalArgumentException e) { return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } } @PostMapping("/exhibition/{memberId}") - public ResponseEntity addRecordExhibition(@RequestBody @Valid RecordRequestDto request, @PathVariable("userId") Long memberId) { + public ResponseEntity addRecordExhibition(@RequestBody @Valid RecordRequestDto request, @PathVariable("userId") Long userId) { try { - recordConferenceService.recordExhibition(memberId, request); + recordConferenceService.recordExhibition(userId, request); return new ResponseEntity<>(HttpStatus.OK); } catch (IllegalArgumentException e) { diff --git a/src/main/java/careerfestival/career/record/dto/RecordRequestDto.java b/src/main/java/careerfestival/career/record/dto/RecordRequestDto.java index 4966ede9..b44f49e4 100644 --- a/src/main/java/careerfestival/career/record/dto/RecordRequestDto.java +++ b/src/main/java/careerfestival/career/record/dto/RecordRequestDto.java @@ -1,5 +1,8 @@ package careerfestival.career.record.dto; +import careerfestival.career.domain.ContactDetail; +import careerfestival.career.domain.RecordDetail; +import careerfestival.career.domain.enums.Category; import careerfestival.career.domain.enums.KeywordName; import careerfestival.career.domain.Record; import jakarta.validation.constraints.NotNull; @@ -10,7 +13,10 @@ import java.time.LocalDate; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; @Getter @@ -18,25 +24,63 @@ @AllArgsConstructor @Builder public class RecordRequestDto { + private Category category; private String eventName; private LocalDate eventDate; - private KeywordName keywordName; -<<<<<<< HEAD - private List detailEventName; - private List eventDescription; - private List networkingName; - private List networkingContact; + private List keywordName; + private List> recordDetails; + private List> contactDetails; + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class RecordDetailDto { + private String detailRecordName; + private String recordDescription; + } + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class ContactDetailDto { + private String networkingName; + private String networkingContact; + } @Builder public Record toEntity() { - return Record.builder() + Record.RecordBuilder recordBuilder = Record.builder() + .category(category) .eventName(eventName) .eventDate(eventDate) - .keywordName(Collections.singletonList(keywordName)) - .detailEventName(detailEventName.toString()) - .eventDescription(eventDescription.toString()) - .networkingName(networkingName.toString()) - .networkingContact(networkingContact.toString()) - .build(); + .keywordName(keywordName) + .recordDetails((Map) mapToRecordDetails(recordDetails)) + .contactDetails((Map) mapToContactDetails(contactDetails)); + + return recordBuilder.build(); + // Checkpoint 글의 제목도 추가해저야함 + } + private List mapToRecordDetails(List> recordDetails) { + + return recordDetails.stream() + .map(detailDto -> { + RecordDetail recordDetail = RecordDetail.builder() + .detailRecordName(detailDto.keySet().iterator().next().getDetailRecordName()) + .recordDescription(detailDto.values().iterator().next().getRecordDescription()) + .build(); + return recordDetail; + }) + .collect(Collectors.toList()); + } + + private List mapToContactDetails(List> contactDetails) { + + return contactDetails.stream() + .map(detailDto -> { + ContactDetail contactDetail = ContactDetail.builder() + .networkingName(detailDto.keySet().iterator().next().getNetworkingName()) + .networkingContact(detailDto.values().iterator().next().getNetworkingContact()) + .build(); + return contactDetail; + }) + .collect(Collectors.toList()); } -} \ No newline at end of file +} diff --git a/src/main/java/careerfestival/career/record/service/RecordConferenceExhibitionService.java b/src/main/java/careerfestival/career/record/service/RecordConferenceExhibitionService.java index dbd42c5b..5c0dbcde 100644 --- a/src/main/java/careerfestival/career/record/service/RecordConferenceExhibitionService.java +++ b/src/main/java/careerfestival/career/record/service/RecordConferenceExhibitionService.java @@ -1,13 +1,14 @@ package careerfestival.career.record.service; -import careerfestival.career.domain.Record; import careerfestival.career.domain.User; +import careerfestival.career.domain.Record; import careerfestival.career.record.dto.RecordRequestDto; import careerfestival.career.repository.RecordRepository; import careerfestival.career.repository.UserRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; + @Service @RequiredArgsConstructor public class RecordConferenceExhibitionService { @@ -19,32 +20,11 @@ public void recordConference(Long userId, RecordRequestDto request) { User user = userRepository.findById(userId) .orElseThrow(() -> new RuntimeException("User not found with id: " + userId)); - Record record = request.toEntity(); record.setUser(user); - record.setEventName(request.getEventName()); - record.setEventDate(request.getEventDate()); - record.setDetailEventName(request.getDetailEventName()); - record.setEventDescription(request.getEventDescription()); - record.setNetworkingName(request.getNetworkingName()); - record.setNetworkingContact(request.getNetworkingContact()); recordRepository.save(record); // Record 테이블에만 저장된 상태 } - public void recordExhibition(Long userId, RecordRequestDto request) { - - User user = userRepository.findById(userId) - .orElseThrow(() -> new RuntimeException("User not found with id: " + userId)); - Record record = request.toEntity(); - record.setUser(user); - record.setEventName(request.getEventName()); - record.setEventDate(request.getEventDate()); - record.setDetailEventName(request.getDetailEventName()); - record.setEventDescription(request.getEventDescription()); - record.setNetworkingName(request.getNetworkingName()); - record.setNetworkingContact(request.getNetworkingContact()); - recordRepository.save(record); - // Record 테이블에만 저장된 상태 } -} \ No newline at end of file + diff --git a/src/main/java/careerfestival/career/record/service/RecordConferenceService.java b/src/main/java/careerfestival/career/record/service/RecordConferenceService.java deleted file mode 100644 index 706e7081..00000000 --- a/src/main/java/careerfestival/career/record/service/RecordConferenceService.java +++ /dev/null @@ -1,40 +0,0 @@ -package careerfestival.career.record.service; - -import careerfestival.career.domain.Record; -import careerfestival.career.domain.User; -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.repository.RecordRepository; -import careerfestival.career.repository.UserRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.stream.Collectors; - -@Service -@RequiredArgsConstructor -public class RecordConferenceService { - private final RecordRepository recordRepository; - private final UserRepository userRepository; - - - public void recordConference(Long userId, RecordRequestDto request) { - - User user = userRepository.findById(userId) - .orElseThrow(()->new RuntimeException("User not found with id: " + userId)); - - Record record = request.toEntity(); - record.setUser(user); - record.setEventName(request.getEventName()); - record.setEventDate(request.getEventDate()); - record.setDetailEventName(request.getDetailEventName()); - record.setEventDescription(request.getEventDescription()); - record.setNetworkingName(request.getNetworkingName()); - record.setNetworkingContact(request.getNetworkingContact()); - recordRepository.save(record); - // Record 테이블에만 저장된 상태 - } -}