Skip to content

Commit

Permalink
#53 [FEAT] 기록장 리스트 기능
Browse files Browse the repository at this point in the history
  • Loading branch information
jeonggeon committed Jan 26, 2024
1 parent b294e72 commit 00e1ed2
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 81 deletions.
19 changes: 19 additions & 0 deletions src/main/java/careerfestival/career/domain/ContactDetail.java
Original file line number Diff line number Diff line change
@@ -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;

}
18 changes: 18 additions & 0 deletions src/main/java/careerfestival/career/domain/Record.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<RecordDetail, RecordDetail> recordDetails;


@ElementCollection
@CollectionTable(name="record_contacts", joinColumns = @JoinColumn(name="record_id"))
@MapKeyColumn(name="contact_key")
@Column(name = "contact_value")
//RECORD MAPPING으로 수정
private Map<ContactDetail, ContactDetail> contactDetails;

}
19 changes: 19 additions & 0 deletions src/main/java/careerfestival/career/domain/RecordDetail.java
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ public ResponseEntity<Void> recordEtc(@PathVariable("userId") Long userId, @Requ
}
// conference 기록 추가
@PostMapping("/conference/{userId}")
public ResponseEntity<Void> addRecordConference(@RequestBody @Valid RecordRequestDto request, @PathVariable("userId") Long memberId) {
public ResponseEntity<Void> 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<Void> addRecordExhibition(@RequestBody @Valid RecordRequestDto request, @PathVariable("userId") Long memberId) {
public ResponseEntity<Void> 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) {

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,33 +13,74 @@

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
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class RecordRequestDto {
private Category category;
private String eventName;
private LocalDate eventDate;
private KeywordName keywordName;
<<<<<<< HEAD
private List<String> detailEventName;
private List<String> eventDescription;
private List<String> networkingName;
private List<String> networkingContact;
private List<KeywordName> keywordName;
private List<Map<RecordDetail, RecordDetail>> recordDetails;
private List<Map<ContactDetail, ContactDetail>> 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<RecordDetail, RecordDetail>) mapToRecordDetails(recordDetails))
.contactDetails((Map<ContactDetail, ContactDetail>) mapToContactDetails(contactDetails));

return recordBuilder.build();
// Checkpoint 글의 제목도 추가해저야함
}
private List<RecordDetail> mapToRecordDetails(List<Map<RecordDetail, RecordDetail>> 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<ContactDetail> mapToContactDetails(List<Map<ContactDetail, ContactDetail>> 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());
}
}
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 테이블에만 저장된 상태
}
}

This file was deleted.

0 comments on commit 00e1ed2

Please sign in to comment.