Skip to content

Commit

Permalink
[fix] #37 script 수정: type 삭제, paragraph null 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
kyungminlee-12 committed Jan 20, 2023
1 parent 1c2861f commit 09739a4
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 160 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ dependencies {
implementation 'mysql:mysql-connector-java'

//로그인
implementation 'io.jsonwebtoken:jjwt:0.10.7'
// implementation 'io.jsonwebtoken:jjwt:0.10.7'
runtimeOnly 'io.jsonwebtoken:jjwt:0.10.7'
implementation 'org.apache.httpcomponents:httpclient:4.5.10'
implementation 'com.google.code.gson:gson:2.8.6'
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ public class ScriptController {

@PostMapping("/new")
public ResponseEntity<?> writeScript(@Validated ScriptRequestDto.Register write){
// List<ScriptDto> result = productRepository.search(condition);
// System.out.println(result);
// return new ResponseEntity<List<ScriptDto>>(result, HttpStatus.OK);

return scriptService.writeScript(write);
}
Expand All @@ -48,11 +45,8 @@ public ResponseEntity<?> readScriptById(@PathVariable("id") Long id) {
Optional<Script> optionalProduct=scriptRepository.findById(id);
if (optionalProduct.isPresent()) {
Script script1 = optionalProduct.get();
log.info("gather test success");
return scriptResponseDto.success(script1);
}

log.info("gather test fail");
return null;
}

Expand Down Expand Up @@ -99,7 +93,7 @@ public ResponseEntity<?> update(@PathVariable Long id, @Valid ScriptRequestDto.U
log.info("gather test success");

before_script.setTitle(script_new.getTitle());
before_script.setType(script_new.getType());
//before_script.setType(script_new.getType());

return scriptResponseDto.success(before_script);
}
Expand All @@ -109,16 +103,6 @@ public ResponseEntity<?> update(@PathVariable Long id, @Valid ScriptRequestDto.U

@DeleteMapping("/delete/{id}")
public String deleteScript(@PathVariable Long id) {

// Script script= scriptRepository.findById(id);
// String result=scriptService.remove(id);
// script.deleteScript();

return scriptService.remove(id);
/*
if (script==null) {
throw new ScriptNotFoundException(String.format("ID[%s] not found", id));
}
*/
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.umc3_teamproject.domain.dto.request;

import com.example.umc3_teamproject.domain.Member;
import lombok.Getter;
import lombok.Setter;
import javax.validation.constraints.NotNull;
Expand All @@ -11,13 +12,13 @@ public class ScriptRequestDto {
public static class Register {

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

@NotNull(message = "title은 필수 입력값입니다.")
private String title;

// @NotNull(message = "type은 필수 입력값입니다.")
private String type;
// private String type;

}

Expand All @@ -29,7 +30,7 @@ public static class Update {
private String title;

// @NotNull(message = "type은 필수 입력값입니다.")
private String type;
// private String type;

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.umc3_teamproject.domain.dto.response;

import com.example.umc3_teamproject.domain.Member;
import com.example.umc3_teamproject.domain.item.Paragraph;
import com.example.umc3_teamproject.domain.item.Script;
import lombok.Builder;
Expand All @@ -20,7 +21,7 @@ private static class Body {

private String result;

private Long userId;
private Member userId;
private Long scriptId;

private String title;
Expand All @@ -35,15 +36,23 @@ public ResponseEntity<?> success(Script script) {

List<Paragraph> paragraphList = new ArrayList<>();
paragraphList=script.getParagraphList();
Paragraph firstP= paragraphList.get(0);

String firestScriptContent;

if (paragraphList.size()!=0) {
Paragraph firstP= paragraphList.get(0);
firestScriptContent=firstP.getContents();
} else {
firestScriptContent="";
}

Body body = Body.builder()
.result("success")
.userId(script.getUserId())
.scriptId(script.getScriptId())
.title(script.getTitle())
.contents(firstP.getContents())
.type(script.getType())
.contents(firestScriptContent)
//.type(script.getType())
.createdDate(script.getCreatedDate())
.modifiedDate(script.getModifiedDate())
.build();
Expand Down
29 changes: 9 additions & 20 deletions src/main/java/com/example/umc3_teamproject/domain/item/Script.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@

import static javax.persistence.FetchType.LAZY;


import com.fasterxml.jackson.annotation.JsonBackReference;
import lombok.*;
import org.hibernate.annotations.Where;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@Builder
@Entity
@Table(name = "script")
Expand All @@ -29,31 +21,28 @@
@NoArgsConstructor
public class Script extends BaseEntity {

@Id // Primary Key와 연결
@GeneratedValue(strategy = GenerationType.AUTO) // 식별자 값을 자동 생성
@Id // Primary Key와 연결
@GeneratedValue(strategy = GenerationType.AUTO) // 식별자 값을 자동 생성
@Column(name="scriptId", updatable = false)
private Long scriptId;

@Column(name="userId", updatable = false)
private Long userId;

// @Column(name="userId", updatable = false)
// private Long userId;

// @ManyToOne(fetch = LAZY)
// @JoinColumn(name = "user_id")
// private Member user_id;
@ManyToOne(fetch = LAZY)
@JoinColumn(name = "userId")
private Member userId;


@Column
private String title;

@Column
private String type;
// @Column
// private String type;

@Column
private boolean deleted;

// @Column
// private String contents;

// paragraph를 list로 추가
@OneToMany(mappedBy = "scriptId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,5 @@ public void updatePassword(Long id, String pwd ) {
}


}

}
117 changes: 3 additions & 114 deletions src/main/java/com/example/umc3_teamproject/service/ScriptService.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ResponseEntity<?> writeScript(ScriptRequestDto.Register script1) {
Script script=Script.builder()
.userId(script1.getUserId())
.title(script1.getTitle())
.type(script1.getType())
// .type(script1.getType())
.deleted(false)
.build();
scriptRepository.save(script);
Expand All @@ -52,33 +52,13 @@ public Script updateScript(Long id, ScriptRequestDto.Update script1) {
updatedScript.setUserId(before_script.getUserId());
updatedScript.setCreatedDate(before_script.getCreatedDate());
updatedScript.setTitle(script1.getTitle());
updatedScript.setType(script1.getType());
// updatedScript.setType(script1.getType());
scriptRepository.save(updatedScript);

return updatedScript;

}

return null;

/*
Optional<Script> optionalProduct=scriptRepository.findById(id);
if (optionalProduct.isPresent()) {
Script update_script = optionalProduct.get();
update_script.setTitle(script1.getTitle());
update_script.setType(script1.getType());
// 새로운 것은 persist, 수정은 merge
// entityManager.merge(update_script);
return update_script;
}
*/

// return null;
}

public String remove(Long id){
Expand All @@ -92,104 +72,13 @@ public String remove(Long id){
deletedScript.setUserId(before_script.getUserId());
deletedScript.setCreatedDate(before_script.getCreatedDate());
deletedScript.setTitle(before_script.getTitle());
deletedScript.setType(before_script.getType());
// deletedScript.setType(before_script.getType());
deletedScript.setDeleted(true);
scriptRepository.save(deletedScript);

return id+" deleted success";

}

return null;
}

/*
public Script deleteScriptById(Long id) {
Optional<Script> optionalProduct=scriptRepository.findById(id);
// Script delete_script = optionalProduct.get();
optionalProduct.delete();
return optionalProduct.orElse(null);
Iterator<Script> iterator = scripts.iterator();
while(iterator.hasNext()) {
Script script = iterator.next();
if(Objects.equals(script.getScriptId(), id)) {
iterator.remove();
return script;
}
}
}
*/






/* search */
/*
@Transactional
public List<Script> search(String keyword) {
List<Script> scriptList = scriptRepository.findByTitleContaining(keyword);
return scriptList;
}
*/

@Transactional
public void saveItem(Script script) {
scriptRepository.save(script);
}


/*
@Transactional
public List<Script> findUserScript(Long userId) {
return scriptRepository.findByUserId(userId);
}
*/

/*
@Transactional
public List<Script> findScriptOfUser(Long userId, Long id) {
return scriptRepository.findByScriptId(userId, id);
}
*/
/*
@Transactional(readOnly = true)
public Script getUserById(Long userId) {
return scriptRepository.findByUserId(userId)
.orElseThrow(()-> new IllegalArgumentException("User id를 확인해주세요."));
}
@Transactional(readOnly = true)
public Script getScriptById(Long userId, Long id) {
return scriptRepository.findByScriptId(userId, id)
.orElseThrow(()-> new IllegalArgumentException("Script id를 확인해주세요."));
}
*/

// 변경 감지에 의해 data를 변경
/*
@Transactional
public void updateItem(Long scriptId, Script scriptItem) {
Script findItem= scriptRepository.findOne(scriptId);
findItem.setTitle(scriptItem.getTitle());
findItem.setType(scriptItem.getType());
}
*/

/*
public List<Script> findScripts() {
return scriptRepository.findAll();
}
*/

/*
public Script findOne(Long scriptId) {
return scriptRepository.findOne(scriptId);
}
*/
}

0 comments on commit 09739a4

Please sign in to comment.