Skip to content

Commit

Permalink
#38 [FEAT] record 전시회 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jeonggeon committed Jan 22, 2024
1 parent e21e660 commit 6b363f7
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 41 deletions.
2 changes: 2 additions & 0 deletions src/main/java/careerfestival/career/domain/Record.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class Record extends BaseEntity {
private String topic;
@Column(length = 300, name = "topic_detail")
private String topicDetail;
@Column
private String detailEventName;

@Enumerated(EnumType.STRING)
private Category category;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import careerfestival.career.record.dto.RecordEtcDto;
import careerfestival.career.record.dto.RecordLectureSeminarDto;
import careerfestival.career.record.dto.RecordRequestDto;
import careerfestival.career.record.service.RecordConferenceExhibitionService;
import careerfestival.career.record.service.RecordService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -15,7 +18,7 @@
@RequestMapping("/record")
@RestController
public class RecordController {

private final RecordConferenceExhibitionService recordConferenceService;
private final RecordService recordService;

@PostMapping("/lecture-seminar/{userId}")
Expand All @@ -37,16 +40,25 @@ public ResponseEntity<Void> recordEtc(@PathVariable("userId") Long userId, @Requ
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
}
//기록장
// @PostMapping("/{memberId}")
// public ApiResponse<RecordResponseDto.AddRecordResponseDto>
// addRecordConference(@RequestBody @Valid RecordRequestDto.AddRecordConferenceRequestDto request
// ,@PathVariable Long memberId){
// Record record = recordCommandService.addRecord(request, memberId);
// return ApiResponse.onSuccess(RecordConverter.toAddRecordResponseDto(record));
// }


// conference 기록 추가
@PostMapping("/conference/{userId}")
public ResponseEntity<Void> addRecordConference(@RequestBody @Valid RecordRequestDto request, @PathVariable("userId") Long memberId) {
try {
recordConferenceService.recordConference(memberId, 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) {
try {
recordConferenceService.recordExhibition(memberId, request);
return new ResponseEntity<>(HttpStatus.OK);
} catch (IllegalArgumentException e) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
}

// 메인페이지
@GetMapping("/{userId}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
//package careerfestival.career.record.dto;
//
//import careerfestival.career.domain.enums.Category;
//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 Category category;
// @NotNull
// private LocalDateTime eventDate;
// //checkpoint 세션과 부스 어차피 같은 형태로 그냥 제목부스이름이던 세션이름이던 같이 받을 수 있음 그래서 event description 제목 받을 거 하나 생성
// @NotNull
// private String eventDescription;
// private String networkingName;
// private String networkingContact;
// }
//}
package careerfestival.career.record.dto;

import careerfestival.career.domain.enums.KeywordName;
import careerfestival.career.domain.Record;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.util.Collections;
import java.util.List;


@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class RecordRequestDto {
private String eventName;
private LocalDate eventDate;
private KeywordName keywordName;
private List<String> detailEventName;
private List<String> eventDescription;
private List<String> networkingName;
private List<String> networkingContact;

@Builder
public Record toEntity() {
return Record.builder()
.eventName(eventName)
.eventDate(eventDate)
.keywordName(Collections.singletonList(keywordName))
.detailEventName(detailEventName.toString())
.eventDescription(eventDescription.toString())
.networkingName(networkingName.toString())
.networkingContact(networkingContact.toString())
.build();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package careerfestival.career.record.service;

import careerfestival.career.domain.Record;
import careerfestival.career.domain.User;
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 {
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 테이블에만 저장된 상태
}
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 테이블에만 저장된 상태
}
}

0 comments on commit 6b363f7

Please sign in to comment.