Skip to content

Commit

Permalink
[feat] farmclub 도메인 엔티티 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
MinchoGreenT committed Mar 18, 2024
1 parent 72cf6fb commit 7853bc5
Show file tree
Hide file tree
Showing 29 changed files with 386 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.modernfarmer.farmusspring.domain.farmclub.entity;

import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary;
import com.modernfarmer.farmusspring.global.common.BaseEntity;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.joda.time.LocalDate;

import java.util.ArrayList;
import java.util.List;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
@SuperBuilder
@Entity(name = "farm_club")
public class FarmClub extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "farm_club_id")
private Long id;

@Column(nullable = false)
private String veggieInfoId;

@Column(nullable = false)
private String name;

@Column(nullable = false)
private String description;

@Column(nullable = false)
private String difficulty;

@Column(nullable = false)
private int maxUser;

@Column(nullable = false)
private LocalDate startedAt;

@OneToMany(mappedBy = "farmClub")
@Builder.Default
private List<UserFarmClub> userFarmClubs = new ArrayList<>();

@OneToMany(mappedBy = "farmClub")
@Builder.Default
private List<Diary> diaries = new ArrayList<>();

public static FarmClub createFarmClub(String veggieInfoId, String name, String description, String difficulty, int maxUser, LocalDate startedAt){
return FarmClub.builder()
.veggieInfoId(veggieInfoId)
.name(name)
.description(description)
.difficulty(difficulty)
.maxUser(maxUser)
.startedAt(startedAt)
.build();
}

public void addUserFarmClub(UserFarmClub userFarmClub){
this.userFarmClubs.add(userFarmClub);
}

public void addDiary(Diary diary){
this.diaries.add(diary);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.modernfarmer.farmusspring.domain.farmclub.entity;

import com.modernfarmer.farmusspring.global.common.BaseEntity;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.SuperBuilder;

import java.util.ArrayList;
import java.util.List;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
@SuperBuilder
@Entity(name = "mission_post")
public class MissionPost extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "mission_post_id")
private Long id;

@Column(nullable = false)
private String content;

@Column(nullable = false)
private Long step_num;

@Column(nullable = false)
private String image;

@OneToMany(mappedBy = "missionPost", cascade = CascadeType.REMOVE)
@Builder.Default
private List<MissionPostLike> missionPostLikes = new ArrayList<>();

@OneToMany(mappedBy = "missionPost", cascade = CascadeType.REMOVE)
@Builder.Default
private List<MissionPostComment> missionPostComments = new ArrayList<>();

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_farm_club_id")
private UserFarmClub userFarmClub;

public static MissionPost createMissionPost(String content, Long step_num, String image, UserFarmClub userFarmClub){
MissionPost newMissionPost = MissionPost.builder()
.content(content)
.step_num(step_num)
.image(image)
.userFarmClub(userFarmClub)
.build();

userFarmClub.addMissionPost(newMissionPost);

return newMissionPost;
}

public void addLike(MissionPostLike missionPostLike) {
missionPostLikes.add(missionPostLike);
}

public void addComment(MissionPostComment missionPostComment) {
missionPostComments.add(missionPostComment);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.modernfarmer.farmusspring.domain.farmclub.entity;

import com.modernfarmer.farmusspring.domain.user.entity.User;
import com.modernfarmer.farmusspring.global.common.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
@SuperBuilder
@Entity(name = "mission_post_comment")
public class MissionPostComment extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "mission_post_comment_id")
private Long id;

@Column(nullable = false)
private String comment;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "mission_post_id")
private MissionPost missionPost;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

public static MissionPostComment createMissionPostComment(String comment, MissionPost missionPost, User user){
MissionPostComment newMissionPostComment = MissionPostComment.builder()
.comment(comment)
.missionPost(missionPost)
.user(user)
.build();

missionPost.addComment(newMissionPostComment);
user.addMissionPostComment(newMissionPostComment);

return newMissionPostComment;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.modernfarmer.farmusspring.domain.farmclub.entity;

import com.modernfarmer.farmusspring.domain.user.entity.User;
import com.modernfarmer.farmusspring.global.common.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
@SuperBuilder
@Entity(name = "mission_post_like")
public class MissionPostLike extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "mission_post_like_id")
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "mission_post_id")
private MissionPost missionPost;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

public static MissionPostLike createMissionPostLike(MissionPost missionPost, User user){
MissionPostLike newMissionPostLike = MissionPostLike.builder()
.missionPost(missionPost)
.user(user)
.build();

missionPost.addLike(newMissionPostLike);
user.addMissionPostLike(newMissionPostLike);

return newMissionPostLike;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.modernfarmer.farmusspring.domain.farmclub.entity;

import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie;
import com.modernfarmer.farmusspring.global.common.BaseEntity;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.SuperBuilder;

import java.util.ArrayList;
import java.util.List;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
@SuperBuilder
@Entity(name = "user_farm_club")
public class UserFarmClub extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "user_farm_club_id")
private Long id;

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

@Column(nullable = false)
private int currentStep;

@Column(nullable = false)
private String currentStepName;

@OneToMany(mappedBy = "userFarmClub", cascade = CascadeType.REMOVE)
@Builder.Default
private List<MissionPost> missionPosts = new ArrayList<>();

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "farm_club_id")
private FarmClub farmClub;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "my_veggie_id")
private MyVeggie myVeggie;

public static UserFarmClub createUserFarmClub(Long userId, int currentStep, String currentStepName, FarmClub farmClub, MyVeggie myVeggie){
UserFarmClub newUserFarmClub = UserFarmClub.builder()
.userId(userId)
.currentStep(currentStep)
.currentStepName(currentStepName)
.farmClub(farmClub)
.myVeggie(myVeggie)
.build();

farmClub.addUserFarmClub(newUserFarmClub);
myVeggie.setUserFarmClub(newUserFarmClub);

return newUserFarmClub;
}

public void updateCurrentStep(int currentStep, String currentStepName){
this.currentStep = currentStep;
this.currentStepName = currentStepName;
}

public void addMissionPost(MissionPost missionPost){
this.missionPosts.add(missionPost);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.modernfarmer.farmusspring.domain.myveggiegarden.controller;

public class TestController {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.modernfarmer.farmusspring.domain.myveggiegarden.dto;

public class TestDto {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.modernfarmer.farmusspring.domain.myvegetablegarden.entity;
package com.modernfarmer.farmusspring.domain.myveggiegarden.entity;


import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub;
import com.modernfarmer.farmusspring.global.common.BaseEntity;
import jakarta.persistence.*;
import lombok.*;
Expand Down Expand Up @@ -37,8 +38,8 @@ public class Diary extends BaseEntity {
private String state;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "my_vegetable_id")
private MyVegetable myVegetable;
@JoinColumn(name = "my_veggie_id")
private MyVeggie myVeggie;

@OneToMany(mappedBy = "diary", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
@Builder.Default
Expand All @@ -48,18 +49,20 @@ public class Diary extends BaseEntity {
@Builder.Default
private List<DiaryLike> diaryLikes = new ArrayList<>();

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "farm_club_id")
private FarmClub farmClub;


public static Diary createDiary(String content, Boolean isOpen, String image, String state, MyVegetable myVegetable){
public static Diary createDiary(String content, Boolean isOpen, String image, String state, MyVeggie myVeggie){
Diary newDiary = Diary.builder()
.content(content)
.isOpen(isOpen)
.image(image)
.state(state)
.myVegetable(myVegetable)
.myVeggie(myVeggie)
.build();

myVegetable.addDiary(newDiary);
myVeggie.addDiary(newDiary);

return newDiary;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.modernfarmer.farmusspring.domain.myvegetablegarden.entity;
package com.modernfarmer.farmusspring.domain.myveggiegarden.entity;

import com.modernfarmer.farmusspring.domain.user.entity.User;
import com.modernfarmer.farmusspring.global.common.BaseEntity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.modernfarmer.farmusspring.domain.myvegetablegarden.entity;
package com.modernfarmer.farmusspring.domain.myveggiegarden.entity;

import com.modernfarmer.farmusspring.domain.user.entity.User;
import com.modernfarmer.farmusspring.global.common.BaseEntity;
Expand Down
Loading

0 comments on commit 7853bc5

Please sign in to comment.