Skip to content

Commit

Permalink
Merge pull request #79 from road-found-in-the-text/feature/#78/record…
Browse files Browse the repository at this point in the history
…_interview

interview record 저장
  • Loading branch information
ahyeon-github authored Feb 5, 2023
2 parents be4790f + bab055c commit f989559
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 4 deletions.
Binary file modified build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.example.umc3_teamproject.controller;


import com.example.umc3_teamproject.domain.dto.request.RecordInterviewRequestDto;
import com.example.umc3_teamproject.domain.dto.request.RecordScriptRequestDto;
import com.example.umc3_teamproject.domain.dto.response.RecordInterviewResponseDto;
import com.example.umc3_teamproject.domain.dto.response.RecordScriptResponseDto;
import com.example.umc3_teamproject.repository.RecordInterviewRepository;
import com.example.umc3_teamproject.repository.RecordRespository;
import com.example.umc3_teamproject.service.RecordInterviewService;
import com.example.umc3_teamproject.service.RecordScriptService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController // Json 형태로 객체 데이터를 반환 (@Controller + @ResponseBody)
@RequestMapping("/interview")
@RequiredArgsConstructor

public class RecordInterviewController {

private final RecordInterviewService recordinterviewService;



@PostMapping("/addRecord")
public ResponseEntity<?> recordInterview(@RequestBody RecordInterviewRequestDto.Register record_interview ){

return recordinterviewService.recordInterview(record_interview);
}

}
10 changes: 6 additions & 4 deletions src/main/java/com/example/umc3_teamproject/domain/Member.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.example.umc3_teamproject.domain;

import com.example.umc3_teamproject.config.BaseTimeEntity;
import com.example.umc3_teamproject.domain.item.Comment;
import com.example.umc3_teamproject.domain.item.Forum;
import com.example.umc3_teamproject.domain.item.RecordScript;
import com.example.umc3_teamproject.domain.item.Script;
import com.example.umc3_teamproject.domain.item.*;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
Expand Down Expand Up @@ -74,6 +71,11 @@ public class Member extends BaseTimeEntity {
@JsonBackReference
private List<RecordScript> record_script;

@OneToMany(mappedBy = "memberId", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JsonBackReference
private List<RecordInterview> record_interview;


@Builder
public Member(String socialId) {
this.socialId = socialId;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.example.umc3_teamproject.domain.dto.request;

import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotNull;

public class RecordInterviewRequestDto {
@Getter
@Setter
public static class Register {

@NotNull(message = "user id는 필수 입력값입니다.")
private Long memberId;

@NotNull(message = "record는 필수 입력값입니다.")
private Float record;

@NotNull(message = "interview id는 필수 입력값입니다.")
private Long interviewId;


}

@Getter
@Setter
public static class Update {

@NotNull(message = "record는 필수 입력값입니다.")
private Float record;


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.example.umc3_teamproject.domain.dto.response;

import com.example.umc3_teamproject.domain.item.RecordInterview;
import com.example.umc3_teamproject.repository.MemberRepository;
import lombok.Builder;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

@Component
public class RecordInterviewResponseDto {
@Autowired
MemberRepository memberRepository;

@Getter
@Builder
private static class Body {

private String result;

private Long memberId;
private Long interviewId;

private Float record;

}

public ResponseEntity<?> success(RecordInterview record_interview) {

RecordInterviewResponseDto.Body body = RecordInterviewResponseDto.Body.builder()
.result("success")
.memberId(record_interview.getMemberId().getId())
.interviewId(record_interview.getInterviewId().getInterviewId())
.record(record_interview.getRecord())
.build();
return ResponseEntity.ok(body);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ public class Interview extends BaseEntity {

@OneToMany(mappedBy = "interview",orphanRemoval = true)
private List<InterviewParagraphResult> interviewParagraphResults = new ArrayList<>();


@OneToMany(mappedBy = "interviewId", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JsonBackReference
private List<RecordInterview> record_interview;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.example.umc3_teamproject.domain.item;

import com.example.umc3_teamproject.domain.Member;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.*;
import org.hibernate.annotations.Where;

import javax.persistence.*;

import static javax.persistence.FetchType.LAZY;

@Builder
@Entity
@Table(name="record_interview")
@Where(clause = "deleted = false")
@JsonIdentityReference(alwaysAsId = true)
@AllArgsConstructor
@NoArgsConstructor
@Setter
@Getter

public class RecordInterview {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;


@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
@JsonManagedReference
private Member memberId;


@ManyToOne(fetch = LAZY)
@JoinColumn(name = "interviewId")
@JsonManagedReference
private Interview interviewId;



@Column
private Float record;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.umc3_teamproject.repository;

import com.example.umc3_teamproject.domain.item.RecordInterview;
import com.example.umc3_teamproject.domain.item.RecordScript;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.CrudRepository;

import java.util.Optional;

public interface RecordInterviewRepository extends JpaRepository<RecordInterview, Long>, CrudRepository<RecordInterview, Long> {
Optional<RecordInterview> findById(Long id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.example.umc3_teamproject.service;

import com.example.umc3_teamproject.domain.Member;
import com.example.umc3_teamproject.domain.dto.request.RecordInterviewRequestDto;
import com.example.umc3_teamproject.domain.dto.response.RecordInterviewResponseDto;
import com.example.umc3_teamproject.domain.item.Interview;
import com.example.umc3_teamproject.domain.item.RecordInterview;
import com.example.umc3_teamproject.domain.item.RecordScript;
import com.example.umc3_teamproject.repository.*;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

@Service
@RequiredArgsConstructor
public class RecordInterviewService {
@Autowired
private final MemberRepository memberRepository;
@Autowired
private final InterviewRepository interviewRepository;
@Autowired
private final RecordInterviewRepository recordinterviewRepository;

private final RecordInterviewResponseDto recordinterviewResponse;


public ResponseEntity<?> recordInterview(RecordInterviewRequestDto.Register record_interview1) {

Member interview_member = memberRepository.getUser(record_interview1.getMemberId());
Interview record1_interview = interviewRepository.getById(record_interview1.getInterviewId());


RecordInterview record_interview= RecordInterview.builder()
.memberId(interview_member)
.interviewId(record1_interview)
.record(record_interview1.getRecord())
.build();
recordinterviewRepository.save(record_interview);
return recordinterviewResponse.success(record_interview);
}
@Transactional
public void saveItem(RecordInterview recordInterview) {

recordinterviewRepository.save(recordInterview);


}

}

0 comments on commit f989559

Please sign in to comment.