Skip to content

Commit

Permalink
Merge pull request #32 from Career-Festival/feature/24-recordcreate
Browse files Browse the repository at this point in the history
#24 [feat] 학술대회 record 관련 기능
  • Loading branch information
oznchex authored Jan 18, 2024
2 parents d905ae4 + 98d286d commit dfebb51
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 3 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 java.time.LocalDate;
import java.util.List;
import java.util.Optional;

@Entity
@Getter
Expand Down Expand Up @@ -38,4 +39,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 @@ -101,6 +101,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 @@ -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);
}

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

Expand All @@ -16,7 +23,6 @@
@RestController
public class RecordController {
private final RecordService recordService;

//
@PostMapping("/lecture-seminar/{userId}")
public ResponseEntity<Void> recordLectureSeminar(@PathVariable("userId") Long userId, @RequestBody RecordLectureSeminarDto recordLectureSeminarDto) {
Expand All @@ -37,6 +43,16 @@ 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));
}



// 메인페이지 1차 구현 완료
@GetMapping("/{userId}")
Expand Down
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: "0000"
password: 12345678!
driver-class-name: com.mysql.cj.jdbc.Driver


Expand Down

0 comments on commit dfebb51

Please sign in to comment.