-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
82 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/modernfarmer/server/farmususer/user/entity/Motivation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package modernfarmer.server.farmususer.user.entity; | ||
|
||
import lombok.*; | ||
import org.hibernate.annotations.OnDelete; | ||
import org.hibernate.annotations.OnDeleteAction; | ||
|
||
import javax.persistence.*; | ||
import javax.validation.constraints.NotNull; | ||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
|
||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Entity | ||
@Table(name = "motivation") | ||
public class Motivation extends BaseEntity{ | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "motivation_id", nullable = false) | ||
private Long id; | ||
|
||
|
||
@Column(name = "motivation_reason", nullable = false, length = 40) | ||
private String motivationReason; | ||
|
||
@OneToMany(mappedBy = "motivation", fetch = FetchType.LAZY) | ||
private Set<UserMotivation> userMotivations = new LinkedHashSet<>(); | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/modernfarmer/server/farmususer/user/repository/MotivationRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package modernfarmer.server.farmususer.user.repository; | ||
|
||
|
||
import modernfarmer.server.farmususer.user.entity.Motivation; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface MotivationRepository extends JpaRepository<Motivation, Long> { | ||
|
||
@Query("select m.id from Motivation as m where m.motivationReason = :motivationReason") | ||
Long getMotivationId(@Param("motivationReason") String motivationReason); | ||
|
||
|
||
Optional<Motivation> findByMotivationReason(String motivationReason); | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters