-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…_script script record 저장
- Loading branch information
Showing
9 changed files
with
258 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
52 changes: 52 additions & 0 deletions
52
src/main/java/com/example/umc3_teamproject/controller/RecordController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.example.umc3_teamproject.controller; | ||
import com.example.umc3_teamproject.domain.dto.request.RecordScriptRequestDto; | ||
import com.example.umc3_teamproject.domain.dto.request.ScriptRequestDto; | ||
import com.example.umc3_teamproject.domain.dto.response.RecordScriptResponseDto; | ||
import com.example.umc3_teamproject.domain.dto.response.ScriptResponseDto; | ||
import com.example.umc3_teamproject.domain.item.RecordScript; | ||
import com.example.umc3_teamproject.domain.item.Script; | ||
import com.example.umc3_teamproject.repository.RecordRespository; | ||
import com.example.umc3_teamproject.repository.ScriptRepository; | ||
import com.example.umc3_teamproject.service.RecordScriptService; | ||
import com.example.umc3_teamproject.service.ScriptService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.Optional; | ||
|
||
@Slf4j | ||
@RestController // Json 형태로 객체 데이터를 반환 (@Controller + @ResponseBody) | ||
@RequestMapping("/script") | ||
@RequiredArgsConstructor | ||
|
||
public class RecordController { | ||
|
||
private final RecordScriptService recordscriptService; | ||
private final RecordRespository recordscriptRepository; | ||
|
||
private final RecordScriptResponseDto recordscriptResponseDto; | ||
|
||
|
||
@PostMapping("/addRecord") | ||
public ResponseEntity<?> recordScript(@RequestBody RecordScriptRequestDto.Register record_script ){ | ||
|
||
return recordscriptService.recordScript(record_script); | ||
} | ||
|
||
|
||
|
||
@GetMapping("/record/{id}") | ||
public ResponseEntity<?> readRecordScriptById(@PathVariable("id") Long id) { | ||
|
||
|
||
Optional<RecordScript> optionalProduct=recordscriptRepository.findById(id); | ||
if (optionalProduct.isPresent()) { | ||
RecordScript record_script1 = optionalProduct.get(); | ||
return recordscriptResponseDto.success(record_script1); | ||
} | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/com/example/umc3_teamproject/domain/dto/request/RecordScriptRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 RecordScriptRequestDto { | ||
@Getter | ||
@Setter | ||
public static class Register { | ||
|
||
@NotNull(message = "user id는 필수 입력값입니다.") | ||
private Long memberId; | ||
|
||
@NotNull(message = "record는 필수 입력값입니다.") | ||
private Float record; | ||
|
||
@NotNull(message = "script id는 필수 입력값입니다.") | ||
private Long scriptId; | ||
|
||
|
||
} | ||
|
||
@Getter | ||
@Setter | ||
public static class Update { | ||
|
||
@NotNull(message = "record는 필수 입력값입니다.") | ||
private Float record; | ||
|
||
|
||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/example/umc3_teamproject/domain/dto/response/RecordScriptResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.example.umc3_teamproject.domain.dto.response; | ||
|
||
import com.example.umc3_teamproject.domain.item.RecordScript; | ||
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 RecordScriptResponseDto { | ||
@Autowired | ||
MemberRepository memberRepository; | ||
|
||
@Getter | ||
@Builder | ||
private static class Body { | ||
|
||
private String result; | ||
|
||
private Long memberId; | ||
private Long scriptId; | ||
|
||
private Float record; | ||
|
||
} | ||
|
||
public ResponseEntity<?> success(RecordScript record_script) { | ||
|
||
Body body = Body.builder() | ||
.result("success") | ||
.memberId(record_script.getMemberId().getId()) | ||
.scriptId(record_script.getScriptId().getScriptId()) | ||
.record(record_script.getRecord()) | ||
.build(); | ||
return ResponseEntity.ok(body); | ||
} | ||
|
||
|
||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/example/umc3_teamproject/domain/item/RecordScript.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.example.umc3_teamproject.domain.item.Forum; | ||
import com.example.umc3_teamproject.domain.item.Interview; | ||
import com.example.umc3_teamproject.domain.item.Script; | ||
import com.fasterxml.jackson.annotation.JsonIdentityReference; | ||
import com.fasterxml.jackson.annotation.JsonManagedReference; | ||
import lombok.*; | ||
import org.hibernate.annotations.Where; | ||
|
||
import javax.persistence.*; | ||
import javax.validation.constraints.NotNull; | ||
|
||
import static javax.persistence.FetchType.LAZY; | ||
@Builder | ||
@Entity | ||
@Table(name="record_script") | ||
@Where(clause = "deleted = false") | ||
@JsonIdentityReference(alwaysAsId = true) | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Setter | ||
@Getter | ||
public class RecordScript { | ||
@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 = "script_id") | ||
@JsonManagedReference | ||
private Script scriptId; | ||
|
||
@Column | ||
private Float record; | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/com/example/umc3_teamproject/repository/RecordRespository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.example.umc3_teamproject.repository; | ||
import com.example.umc3_teamproject.domain.item.RecordScript; | ||
import com.example.umc3_teamproject.domain.item.Script; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface RecordRespository extends JpaRepository<RecordScript, Long>, CrudRepository<RecordScript, Long> { | ||
Optional<RecordScript> findById(Long id); | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/example/umc3_teamproject/service/RecordScriptService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.example.umc3_teamproject.service; | ||
|
||
|
||
import com.example.umc3_teamproject.domain.Member; | ||
import com.example.umc3_teamproject.domain.dto.request.RecordScriptRequestDto; | ||
import com.example.umc3_teamproject.domain.dto.request.ScriptRequestDto; | ||
import com.example.umc3_teamproject.domain.dto.response.RecordScriptResponseDto; | ||
import com.example.umc3_teamproject.domain.dto.response.ScriptResponseDto; | ||
import com.example.umc3_teamproject.domain.item.Paragraph; | ||
import com.example.umc3_teamproject.domain.item.RecordScript; | ||
import com.example.umc3_teamproject.domain.item.Script; | ||
import com.example.umc3_teamproject.repository.MemberRepository; | ||
import com.example.umc3_teamproject.repository.RecordRespository; | ||
import com.example.umc3_teamproject.repository.ScriptRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.persistence.EntityManager; | ||
import javax.transaction.Transactional; | ||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class RecordScriptService { | ||
@Autowired | ||
private final MemberRepository memberRepository; | ||
@Autowired | ||
private final ScriptRepository scriptRepository; | ||
@Autowired | ||
private final RecordRespository recordscriptRepository; | ||
private final RecordScriptResponseDto recordscriptResponse; | ||
|
||
|
||
public ResponseEntity<?> recordScript(RecordScriptRequestDto.Register record_script1) { | ||
|
||
Member script_member = memberRepository.getUser(record_script1.getMemberId()); | ||
Script record1_script = scriptRepository.getById(record_script1.getScriptId()); | ||
|
||
|
||
RecordScript record_script= RecordScript.builder() | ||
.memberId(script_member) | ||
.scriptId(record1_script) | ||
.record(record_script1.getRecord()) | ||
.build(); | ||
recordscriptRepository.save(record_script); | ||
return recordscriptResponse.success(record_script); | ||
} | ||
@Transactional | ||
public void saveItem(RecordScript recordScript) { | ||
|
||
recordscriptRepository.save(recordScript); | ||
|
||
|
||
} | ||
|
||
|
||
|
||
} |