Skip to content

Commit

Permalink
Merge branch 'main' into fix/#105/JPA
Browse files Browse the repository at this point in the history
  • Loading branch information
Youngseo-Jeon0313 authored Apr 1, 2023
2 parents 77398f9 + cbf0fbf commit 7103e3f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'

implementation 'org.springframework.boot:spring-boot-devtools'
implementation 'org.projectlombok:lombok'

implementation 'junit:junit:4.13.2'
implementation 'com.github.gavlyukovskiy:datasource-proxy-spring-boot-starter:1.8.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import com.example.umc3_teamproject.config.resTemplate.ResponseException;
import com.example.umc3_teamproject.domain.dto.request.ScriptRequestDto;
import com.example.umc3_teamproject.domain.dto.response.ScriptResponseDto;
import com.example.umc3_teamproject.domain.item.Paragraph;
import com.example.umc3_teamproject.domain.item.Script;
import com.example.umc3_teamproject.repository.ScriptRepository;
import com.example.umc3_teamproject.service.JwtService;
import com.example.umc3_teamproject.service.ParagraphService;
import com.example.umc3_teamproject.service.ScriptService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
Expand All @@ -34,7 +37,10 @@
@Api(tags = {"Script Api"})
public class ScriptController {

@Autowired
private final ScriptService scriptService;
@Autowired
private final ParagraphService paragraphService;
private final ScriptRepository scriptRepository;
private final ScriptResponseDto scriptResponseDto;
private final JwtService jwtService;
Expand All @@ -48,12 +54,25 @@ public ResponseEntity<?> writeScript(@RequestBody ScriptRequestDto.Register scri
public ResponseEntity<?> readScriptById(@PathVariable("id") Long id) {

// 참고 문헌: https://jogeum.net/9
/*
Optional<Script> optionalProduct=scriptRepository.findById(id);
if (optionalProduct.isPresent()) {
Script script1 = optionalProduct.get();
return scriptResponseDto.successScript(script1);
}
return null;
*/

List<Paragraph> paragraphList=paragraphService.findByScriptId(id);
//model.addAttribute("scriptList", scriptList);

Map<String, Object> result=new HashMap<>();
result.put("scripts", paragraphList);
result.put("count", paragraphList.size());

return ResponseEntity.ok().body(result);

}

@GetMapping("/member/me")
Expand All @@ -72,6 +91,21 @@ public ResponseEntity<?> findScriptByUser() throws ResponseException {

}

@GetMapping("/script/{scriptId}")
public ResponseEntity<?> findParagraphByScript(@PathVariable("scriptId") Long scriptId) {
// @PageableDefault(page=0, size=10, sort="id", direction = Sort.Direction.DESC) Pageable pageable) {

List<Paragraph> paragraphList=paragraphService.findByScriptId(scriptId);
//model.addAttribute("scriptList", scriptList);

Map<String, Object> result=new HashMap<>();
result.put("scripts", paragraphList);
result.put("count", paragraphList.size());

return ResponseEntity.ok().body(result);

}

@GetMapping("/all")
public ResponseEntity<Map<String, Object>> getScriptListAll() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;


@Service
Expand Down Expand Up @@ -57,15 +58,14 @@ public Paragraph updateParagraph(Long id, String title) {
return toChangeParagraph;
}





@Transactional
public void saveItem(Paragraph paragraph) {

paragraphRepository.save(paragraph);


}

public List<Paragraph> findByScriptId(Long scriptId){
return em.createQuery("select s from Paragraph s where s.scriptId.id= :id", Paragraph.class)
.setParameter("id", scriptId)
.getResultList();
};
}

0 comments on commit 7103e3f

Please sign in to comment.