-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Dto 설정, FeelingPostController 생성 -#10 #11
Changes from all commits
0d226db
c40fa5d
686821b
473e684
7252996
5f0db4a
6d6b125
13a67f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.gdschanyang.todayfeelingbackend2.controller; | ||
|
||
|
||
import com.gdschanyang.todayfeelingbackend2.service.FeelingPostService; | ||
import com.gdschanyang.todayfeelingbackend2.web.dto.FeelingPostResponseDto; | ||
import com.gdschanyang.todayfeelingbackend2.web.dto.FeelingPostSaveRequestDto; | ||
import com.gdschanyang.todayfeelingbackend2.web.dto.FeelingPostUpdateRequestDto; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
|
||
@RequiredArgsConstructor | ||
@Controller | ||
public class FeelingPostController { | ||
|
||
private final FeelingPostService feelingPostService; | ||
|
||
@GetMapping("/api/feelingpost") | ||
public void save(@RequestBody FeelingPostSaveRequestDto requestDto) { | ||
feelingPostService.save(requestDto); | ||
} | ||
|
||
@PutMapping("/api/feelingpost/{id}") | ||
public void update(@PathVariable Long id, @RequestBody FeelingPostUpdateRequestDto requestDto) { | ||
feelingPostService.update(id, requestDto); | ||
} | ||
|
||
@GetMapping("/api/feelingpost/{id}") | ||
public FeelingPostResponseDto findById(@PathVariable Long id) { | ||
return feelingPostService.findById(id); | ||
} | ||
|
||
@DeleteMapping("/api/feelingpost/{id}") | ||
public void delete(@PathVariable Long id) { | ||
feelingPostService.delete(id); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.gdschanyang.todayfeelingbackend2.controller; | ||
|
||
import com.gdschanyang.todayfeelingbackend2.service.FeelingPostService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
|
||
|
||
@RequiredArgsConstructor | ||
@Controller | ||
public class IndexController { | ||
|
||
private final FeelingPostService feelingPostService; | ||
|
||
@GetMapping("/") | ||
public String home() { | ||
return "home"; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.gdschanyang.todayfeelingbackend2.domain; | ||
|
||
import lombok.Getter; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import javax.persistence.EntityListeners; | ||
import javax.persistence.MappedSuperclass; | ||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@MappedSuperclass | ||
@EntityListeners(AuditingEntityListener.class) | ||
public abstract class BaseTimeEntity { | ||
|
||
@CreatedDate | ||
private LocalDateTime createdDate; | ||
|
||
@LastModifiedDate | ||
private LocalDateTime modifiedDate; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.gdschanyang.todayfeelingbackend2.domain.hearts; | ||
|
||
import com.gdschanyang.todayfeelingbackend2.domain.BaseTimeEntity; | ||
import com.gdschanyang.todayfeelingbackend2.domain.posts.ClinicPost; | ||
import com.gdschanyang.todayfeelingbackend2.domain.user.User; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
|
||
@Getter | ||
@Entity | ||
public class ClinicHeart extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "CLINICHEART_ID") | ||
private Long id; | ||
|
||
// 2. ClinicHeart : User = n : 1 | ||
@ManyToOne | ||
@JoinColumn(name = "USER_ID") | ||
private User user; | ||
|
||
// 3. ClinicHeart : ClinicPost = n : 1 | ||
@ManyToOne | ||
@JoinColumn(name = "CLINICPOST_ID") | ||
private ClinicPost clinicPost; | ||
|
||
@Builder | ||
public ClinicHeart() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 빈 생성자를 만드셨는데 ClinicHeart가 생성될때 user와 clinicpost 값을 받아야 하므로 두 필드를 받는 생성자를 만드셔야 합니다. @builder There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 앗 넵!! 클리닉부분에 살짝 미스가 났습니다 바로 수정하겠습니다! |
||
this.user.addClinicHeart(this); | ||
this.clinicPost.addClinicPost(this); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.gdschanyang.todayfeelingbackend2.domain.hearts; | ||
|
||
import com.gdschanyang.todayfeelingbackend2.domain.BaseTimeEntity; | ||
import com.gdschanyang.todayfeelingbackend2.domain.posts.FeelingPost; | ||
import com.gdschanyang.todayfeelingbackend2.domain.user.User; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
|
||
@Getter | ||
@Entity | ||
public class FeelingHeart extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "FEELINGHEART_ID") | ||
private Long id; | ||
|
||
// 2. FeelingHeart : User = n : 1 | ||
@ManyToOne | ||
@JoinColumn(name = "USER_ID") | ||
private User user; | ||
|
||
// 3. FeelingHeart : FeelingPost = n : 1 | ||
@ManyToOne | ||
@JoinColumn(name = "FEELINGPOST_ID") | ||
private FeelingPost feelingPost; | ||
|
||
@Builder | ||
public FeelingHeart() { | ||
this.user.addFeelingHeart(this); | ||
this.feelingPost.addFeelingPost(this); | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.gdschanyang.todayfeelingbackend2.domain.posts; | ||
|
||
import com.gdschanyang.todayfeelingbackend2.domain.BaseTimeEntity; | ||
import com.gdschanyang.todayfeelingbackend2.domain.hearts.ClinicHeart; | ||
import com.gdschanyang.todayfeelingbackend2.domain.user.User; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@Entity | ||
public class ClinicPost extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "CLINICPOST_ID") | ||
private Long id; | ||
|
||
@Column(length = 500, nullable = false) | ||
private String title; | ||
|
||
// 글 작성은 필수 | ||
@Column(columnDefinition = "TEXT", nullable = false) | ||
private String content; | ||
|
||
// 1. ClinicPost : User = n : 1 | ||
@ManyToOne | ||
@JoinColumn(name = "USER_ID") | ||
private User user; | ||
|
||
// 3. ClinicPost : ClinicHeart = 1 : n | ||
@OneToMany(mappedBy = "clinicPost") | ||
private List<ClinicHeart> clinicHearts = new ArrayList<ClinicHeart>(); | ||
|
||
@Builder | ||
public ClinicPost(Long id, String title, String content) { | ||
this.id = id; | ||
this.title = title; | ||
this.content = content; | ||
this.user.addClinicPost(this); | ||
} | ||
|
||
public void addClinicPost(ClinicHeart clinicHeart){ | ||
this.clinicHearts.add(clinicHeart); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.gdschanyang.todayfeelingbackend2.domain.posts; | ||
|
||
|
||
public enum Feeling { | ||
POSITIVE, | ||
NEGATIVE | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.gdschanyang.todayfeelingbackend2.domain.posts; | ||
|
||
|
||
import com.gdschanyang.todayfeelingbackend2.domain.BaseTimeEntity; | ||
import com.gdschanyang.todayfeelingbackend2.domain.hearts.FeelingHeart; | ||
import com.gdschanyang.todayfeelingbackend2.domain.user.User; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@Entity | ||
public class FeelingPost extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "FEELINGPOST_ID") | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private Feeling feeling; | ||
|
||
// 글 작성은 선택적 | ||
@Column(columnDefinition = "TEXT") | ||
private String content; | ||
|
||
// 1. FeelingPost : User = n : 1 | ||
@ManyToOne | ||
@JoinColumn(name = "USER_ID") | ||
private User user; | ||
|
||
// 3. FeelingPost : FeelingHeart = 1 : n | ||
@OneToMany(mappedBy = "feelingPost") | ||
private List<FeelingHeart> feelingHearts = new ArrayList<FeelingHeart>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new ArrayList<>(); 로 <>안의 제네릭을 생략할 수 있습니다 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵!! 바로 수정하여 pr 보내겠습니다 |
||
|
||
// 삭제 여부 T:삭제 F:삭제X | ||
@Column(nullable = false) | ||
private char delFlag; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DB에서는 String으로 보여지는게 맞지만 어플리케이션 내 객체로는 boolean이 맞습니다. JPA가 DB에 종속적이지 않은 객체 중심 개발을 위해 만들어진 것이므로 Boolean으로 사용하시는게 좋을 것 같습니다 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵! 슬랙에 올려주신 것 참고하여 수정했습니다 감사합니다 :) |
||
|
||
@Builder | ||
public FeelingPost(Long id, Feeling feeling, String content) { | ||
this.id = id; | ||
this.feeling = feeling; | ||
this.content = content; | ||
this.user.addFeelingPost(this); | ||
} | ||
|
||
public void addFeelingPost(FeelingHeart feelingHeart){ | ||
this.feelingHearts.add(feelingHeart); | ||
} | ||
|
||
public void update(String content) { | ||
this.content = content; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.gdschanyang.todayfeelingbackend2.domain.user; | ||
|
||
|
||
import com.gdschanyang.todayfeelingbackend2.domain.BaseTimeEntity; | ||
import com.gdschanyang.todayfeelingbackend2.domain.hearts.ClinicHeart; | ||
import com.gdschanyang.todayfeelingbackend2.domain.hearts.FeelingHeart; | ||
import com.gdschanyang.todayfeelingbackend2.domain.posts.ClinicPost; | ||
import com.gdschanyang.todayfeelingbackend2.domain.posts.FeelingPost; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@Entity | ||
public class User { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "USER_ID") | ||
private Long id; | ||
|
||
@Column(name = "USER_NAME", nullable = false) | ||
private String name; | ||
|
||
// 1. User : FeelingPost = 1 : n -> 한 유저가 여러 감정글 작성 | ||
@OneToMany(mappedBy = "user") | ||
private List<FeelingPost> feelingPosts = new ArrayList<FeelingPost>(); | ||
|
||
// 1. User : ClinicPost = 1 : n -> 한 유저가 여러 클리닉글 작성 | ||
@OneToMany(mappedBy = "user") | ||
private List<ClinicPost> clinicPosts = new ArrayList<ClinicPost>(); | ||
|
||
// 2. User : FeelingHeart = 1 : n | ||
@OneToMany(mappedBy = "user") | ||
private List<FeelingHeart> feelingHearts = new ArrayList<FeelingHeart>(); | ||
|
||
// 2. User : ClinicHeart = 1 : n | ||
@OneToMany(mappedBy = "user") | ||
private List<ClinicHeart> clinicHearts = new ArrayList<ClinicHeart>(); | ||
|
||
public void addFeelingPost(FeelingPost feelingPost) { | ||
this.feelingPosts.add(feelingPost); | ||
} | ||
|
||
public void addFeelingHeart(FeelingHeart feelingHeart){ | ||
this.feelingHearts.add(feelingHeart); | ||
} | ||
public void addClinicPost(ClinicPost clinicPost) { | ||
this.clinicPosts.add(clinicPost); | ||
} | ||
public void addClinicHeart(ClinicHeart clinicHeart){ | ||
this.clinicHearts.add((clinicHeart)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.gdschanyang.todayfeelingbackend2.repository; | ||
|
||
import com.gdschanyang.todayfeelingbackend2.domain.posts.FeelingPost; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface FeelingPostRepository extends JpaRepository<FeelingPost, Long> { | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.gdschanyang.todayfeelingbackend2.repository; | ||
|
||
import com.gdschanyang.todayfeelingbackend2.domain.user.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface UserRepository extends JpaRepository<User, Long> { | ||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이건 왜 있는건가요? 저희는 REST API여서 이런 API는 사용하지 않습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아하 넵 수정하겠습니다!