-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from CAUSOLDOUTMEN/feature/19-feat-userservice
✨️feat: User 객체 속성 개편 및 UserService 추가 구현 (#19)
- Loading branch information
Showing
16 changed files
with
354 additions
and
160 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
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,37 @@ | ||
package com.diareat.diareat.user.domain; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
import java.io.Serializable; | ||
|
||
@NoArgsConstructor | ||
@IdClass(Follow.PK.class) // 복합키를 위한 어노테이션 | ||
@Getter | ||
@Table(uniqueConstraints = { | ||
@UniqueConstraint(columnNames = {"to_user", "from_user"}) | ||
}) // 중복 팔로우 방지 | ||
@Entity | ||
public class Follow { | ||
|
||
@Id | ||
@Column(name = "to_user", insertable = false, updatable = false) | ||
private Long toUser; | ||
|
||
@Id | ||
@Column(name = "from_user", insertable = false, updatable = false) | ||
private Long fromUser; | ||
|
||
public static Follow makeFollow(Long toUser, Long fromUser) { | ||
Follow follow = new Follow(); | ||
follow.toUser = toUser; | ||
follow.fromUser = fromUser; | ||
return follow; | ||
} | ||
|
||
public static class PK implements Serializable { // 복합키를 위한 클래스 | ||
Long toUser; | ||
Long fromUser; | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
src/main/java/com/diareat/diareat/user/dto/FollowUserDto.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,14 @@ | ||
package com.diareat.diareat.user.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class FollowUserDto { | ||
|
||
private Long userId; | ||
private Long followUserId; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/diareat/diareat/user/dto/ResponseRankUserDto.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,22 @@ | ||
package com.diareat.diareat.user.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class ResponseRankUserDto { | ||
|
||
private Long userId; | ||
private String name; | ||
private String image; | ||
private double calorieScore; | ||
private double carbohydrateScore; | ||
private double proteinScore; | ||
private double fatScore; | ||
private double totalScore; | ||
|
||
public static ResponseRankUserDto of(Long userId, String name, String image, double calorieScore, double carbohydrateScore, double proteinScore, double fatScore, double totalScore) { | ||
return new ResponseRankUserDto(userId, name, image, calorieScore, carbohydrateScore, proteinScore, fatScore, totalScore); | ||
} | ||
} |
16 changes: 0 additions & 16 deletions
16
src/main/java/com/diareat/diareat/user/dto/ResponseResearchUserDto.java
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
src/main/java/com/diareat/diareat/user/dto/ResponseSearchUserDto.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,18 @@ | ||
package com.diareat.diareat.user.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class ResponseSearchUserDto { | ||
|
||
private Long userId; | ||
private String name; | ||
private String image; | ||
private boolean isFollow; // 유저가 이미 팔로우한 유저인지 확인 | ||
|
||
public static ResponseSearchUserDto of(Long userId, String name, String image, boolean isFollow) { | ||
return new ResponseSearchUserDto(userId, name, image, isFollow); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/diareat/diareat/user/dto/ResponseSimpleUserDto.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,17 @@ | ||
package com.diareat.diareat.user.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class ResponseSimpleUserDto { | ||
|
||
private String name; | ||
private String image; | ||
private double nutritionScore; | ||
|
||
public static ResponseSimpleUserDto of(String name, String image, double nutritionScore) { | ||
return new ResponseSimpleUserDto(name, image, nutritionScore); | ||
} | ||
} |
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/com/diareat/diareat/user/dto/ResponseUserNutritionDto.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 com.diareat.diareat.user.dto; | ||
|
||
import com.diareat.diareat.user.domain.User; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class ResponseUserNutritionDto { | ||
|
||
private int calorie; | ||
private int carbohydrate; | ||
private int protein; | ||
private int fat; | ||
|
||
public static ResponseUserNutritionDto of(int calorie, int carbohydrate, int protein, int fat) { | ||
return new ResponseUserNutritionDto(calorie, carbohydrate, protein, fat); | ||
} | ||
|
||
public static ResponseUserNutritionDto from(User user) { | ||
return new ResponseUserNutritionDto(user.getBaseNutrition().getKcal(), user.getBaseNutrition().getCarbohydrate(), user.getBaseNutrition().getProtein(), user.getBaseNutrition().getFat()); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/diareat/diareat/user/dto/SearchUserDto.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,18 @@ | ||
package com.diareat.diareat.user.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class SearchUserDto { | ||
|
||
private Long userId; | ||
private String inputName; | ||
|
||
public static SearchUserDto of(Long userId, String inputName) { | ||
return new SearchUserDto(userId, inputName); | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/diareat/diareat/user/dto/UpdateUserNutritionDto.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,21 @@ | ||
package com.diareat.diareat.user.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class UpdateUserNutritionDto { | ||
|
||
private Long userId; | ||
private int calorie; | ||
private int carbohydrate; | ||
private int protein; | ||
private int fat; | ||
|
||
public static UpdateUserNutritionDto of(Long userId, int calorie, int carbohydrate, int protein, int fat) { | ||
return new UpdateUserNutritionDto(userId, calorie, carbohydrate, protein, fat); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/diareat/diareat/user/repository/FollowRepository.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,16 @@ | ||
package com.diareat.diareat.user.repository; | ||
|
||
import com.diareat.diareat.user.domain.Follow; | ||
import com.diareat.diareat.user.domain.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.util.List; | ||
|
||
public interface FollowRepository extends JpaRepository<Follow, Follow.PK> { | ||
@Query(value = "select u from Follow f INNER JOIN User u ON f.toUser = u.id where f.fromUser = :userId") // 팔로우 목록 조회 | ||
List<User> findAllByFromUser(@Param("userId") Long userId); | ||
|
||
boolean existsByFromUserAndToUser(Long fromUser, Long toUser); // 팔로우 여부 확인 | ||
} |
Oops, something went wrong.