Skip to content

Commit

Permalink
[fix] #37 script 최종 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kyungminlee-12 committed Jan 26, 2023
1 parent d22be0b commit 56fa8f0
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,12 @@ public class MailController {
@Autowired
SendEmailService sendEmailService;

@Autowired
EmailService emailService;

// MimeMessageTest sendEmailService;

//등록된 이메일로 임시비밀번호를 발송하고 발송된 임시비밀번호로 사용자의 pw를 변경하는 컨트롤러
@PostMapping("/check/findPw/sendEmail")
public String sendEmail(@RequestBody EmailRequestDto.Register emailRequestDto) throws ResponseException {
MailDto sentMail= sendEmailService.createMailAndChangePassword(emailRequestDto.getEmail());
// MailDto dto = sendEmailService.createMailAndChangePassword(userEmail, userName);
// System.out.println("dto: "+dto.getAddress());
// return "email sent to ["+dto.getAddress()+"] done";
// emailService.sendSimpleMessage(mailDto);

return "done";

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

Expand All @@ -21,6 +22,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

@Slf4j
@RestController // Json 형태로 객체 데이터를 반환 (@Controller + @ResponseBody)
Expand Down Expand Up @@ -51,9 +53,33 @@ public ResponseEntity<?> readScriptById(@PathVariable("id") Long id) {
}

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

List<Script> scriptList=scriptService.findByMemberId(memberId);
//model.addAttribute("scriptList", scriptList);

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

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

/*
List<Script> scriptList=scriptRepository.findAll()
.stream()
.filter(user -> user.getMemberId().equals(memberId))
.collect(Collectors.toList());
Map<String, Object> result=new HashMap<>();
result.put("scripts", scriptList);
result.put("count", scriptList.size());
return ResponseEntity.ok().body(result);
*/

/*
List<Script> scriptList=null;
if (memberId==null) {
Expand All @@ -68,6 +94,8 @@ public ResponseEntity<?> readScriptByUser(@PathVariable("memberId") Long memberI
return ResponseEntity.ok().body(result);
}
*/
}

@GetMapping("/all")
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/com/example/umc3_teamproject/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import com.example.umc3_teamproject.domain.item.Comment;
import com.example.umc3_teamproject.domain.item.Forum;
import com.example.umc3_teamproject.domain.item.Script;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;

import javax.persistence.*;
Expand All @@ -13,6 +16,7 @@
@Getter @Setter @Entity
@NoArgsConstructor @AllArgsConstructor
@Table(name="Member")
@JsonIdentityReference(alwaysAsId = true)
public class Member extends BaseTimeEntity {

@Id //Primary Key
Expand All @@ -22,10 +26,13 @@ public class Member extends BaseTimeEntity {
@Column(nullable = false) //unique true
private String email;
@Column(nullable = false)
@JsonIgnore
private String pw;
@Column(nullable = false, length=30)
@JsonIgnore
private String nickName;
@Column(nullable = true)
@JsonIgnore
private String imageUrl;
@Column(nullable = false)
private int tier ;
Expand All @@ -36,16 +43,20 @@ public class Member extends BaseTimeEntity {

private int blockStatus;

@OneToMany(mappedBy = "memberId", cascade = CascadeType.ALL)
private List<Script> scripts = new ArrayList<>();
@OneToMany(mappedBy = "memberId", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JsonBackReference
private List<Script> scripts;
// private List<Script> scripts = new ArrayList<>();
//
// @OneToMany(mappedBy = "member", cascade = CascadeType.ALL)
// private List<Interview> interviews = new ArrayList<>();
//
@OneToMany(mappedBy = "member", cascade = CascadeType.ALL)
@JsonBackReference
private List<Comment> comments = new ArrayList<>();

@OneToMany(mappedBy = "member", cascade = CascadeType.ALL)
@JsonBackReference
private List<Forum> forums = new ArrayList<>();


Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.example.umc3_teamproject.domain.item;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.*;
import org.hibernate.annotations.Where;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

import static javax.persistence.FetchType.LAZY;

@Builder
@Entity
@Table(name = "paragraph")
Expand All @@ -13,6 +19,8 @@
@Where(clause = "deleted = false")
@AllArgsConstructor
@NoArgsConstructor
@JsonIdentityReference(alwaysAsId = true)
// @JsonIgnoreProperties({"hibernateLazyInitializer"})
public class Paragraph extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Expand All @@ -22,11 +30,13 @@ public class Paragraph extends BaseEntity {
private Long paragraphId;

// @Column(name="scriptId", updatable = false)
@ManyToOne()
@ManyToOne(fetch = LAZY)
@JoinColumn(name="scriptId")
@JsonManagedReference
private Script scriptId;

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

@Column
Expand Down
24 changes: 10 additions & 14 deletions src/main/java/com/example/umc3_teamproject/domain/item/Script.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.example.umc3_teamproject.domain.item;

import com.example.umc3_teamproject.domain.Member;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.*;
import lombok.*;
import org.hibernate.annotations.Where;
import javax.persistence.*;
Expand All @@ -17,6 +17,8 @@
@Setter
// @SQLDelete(sql = "UPDATE umc3.script SET deleted = true WHERE script_id = ?") // JPA Soft Delete
@Where(clause = "deleted = false")
@JsonIdentityReference(alwaysAsId = true)
// @JsonIgnoreProperties({"hibernateLazyInitializer"})
@AllArgsConstructor
@NoArgsConstructor
public class Script extends BaseEntity {
Expand All @@ -26,28 +28,22 @@ public class Script extends BaseEntity {
@Column(name="scriptId", updatable = false)
private Long scriptId;

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

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


@Column
private String title;

// @Column
// private String type;

@Column
private boolean deleted;


// paragraph를 list로 추가
@OneToMany(mappedBy = "scriptId")
@OneToMany(mappedBy = "scriptId", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JsonBackReference
private List<Paragraph> paragraphList = new ArrayList<>();
// private List<Paragraph> paragraphList = new ArrayList<>();
private List<Paragraph> paragraphList;

public void addParagraph(Paragraph paragraph) {
paragraphList.add(paragraph);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -17,7 +18,8 @@ public interface ScriptRepository extends JpaRepository<Script, Long> , CrudRepo

// Optional<Script> findByUserId(Long id);

List<Script> findByMemberId(Long id);
// @Query("SELECT * FROM umc3.script WHERE member_id = ? ")
// List<Script> findAllByMemberIdType(Long id);

// @SQLDelete(sql = "UPDATE script SET deleted = true WHERE scriptId = ?")
// Optional<Script> deleteScriptById(Long id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ public Script updateScript(Long id, String title) {
return toChangeScript;
}

/*
@Transactional
public List<Script> search(Long memberId) {
return scriptRepository.findByMemberId(memberId);
}
*/

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

@Transactional
public Script addParagraph(Long id, Long[] paragraphIdList){
Script addParagraphScript=em.find(Script.class, id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public void testFindUserIdByEmail() throws Exception {

String user_main="[email protected]";

Long id= memberRepository.findUserIdByEmail(user_main);
System.out.println(id);
// Long id= memberRepository.findUserIdByEmail(user_main);
//System.out.println(id);

}
}

0 comments on commit 56fa8f0

Please sign in to comment.