Skip to content

Commit

Permalink
#24 [feat] 학술대회 record 관련 기능
Browse files Browse the repository at this point in the history
  • Loading branch information
jeonggeon committed Jan 17, 2024
1 parent 48767d5 commit 40aad54
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/main/java/careerfestival/career/domain/Record.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import careerfestival.career.domain.mapping.RecordKeyword;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Entity
@Getter
Expand Down Expand Up @@ -40,4 +41,14 @@ public class Record extends BaseEntity {

@ManyToOne(fetch = FetchType.LAZY)
private User user;

public void user(Optional<User> user){
//checkpoint
/* Optional.ofNullable(this.user)
.ifPresent(oldUser -> oldUser.removeRecord(this));
this.user = user;
user.addRecord(this);*/
}

}
9 changes: 9 additions & 0 deletions src/main/java/careerfestival/career/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public class User extends BaseEntity {
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
private List<Follow> follow = new ArrayList<>();

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
private List<Record> records = new ArrayList<>();


public void updatePassword(String password) {
this.password = password;
Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,7 +20,7 @@
@RestController
public class RecordController {
private final RecordService recordService;

private final RecordCommandService recordCommandService;
@PostMapping("/lecture-seminar")
public ResponseEntity<Void> recordLectureSeminar(@RequestParam("userId") Long userId, @RequestBody RecordLectureSeminarDto recordLectureSeminarDto) {
try {
Expand All @@ -34,5 +41,15 @@ public ResponseEntity<Void> recordEtc(@RequestParam("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));
}



}
Original file line number Diff line number Diff line change
@@ -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


}
Original file line number Diff line number Diff line change
@@ -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<RecordKeyword> recordKeywords;
@NotNull
private Category category;
@NotNull
private LocalDateTime eventDate;
//checkpoint 세션과 부스 어차피 같은 형태로 그냥 제목부스이름이던 세션이름이던 같이 받을 수 있음 그래서 event description 제목 받을 거 하나 생성
@NotNull
private String eventDescription;
private String networkingName;
private String networkingContact;
}
}
Original file line number Diff line number Diff line change
@@ -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;

}
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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> user = userRepository.findById(userId);
//checkpoint 리스트
// newRecord.user(user);
return recordRepository.save(newRecord);
};

}
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 40aad54

Please sign in to comment.