-
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
15 changed files
with
255 additions
and
98 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: 0 additions & 33 deletions
33
src/main/java/gyeongdan/article/controller/TypeTestController.java
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
src/main/java/gyeongdan/article/repository/ArticleJpaRepository.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 |
---|---|---|
@@ -1,10 +1,17 @@ | ||
package gyeongdan.article.repository; | ||
|
||
import gyeongdan.article.domain.Article; | ||
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.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Repository | ||
public interface ArticleJpaRepository extends JpaRepository<Article, Long> { | ||
|
||
List<Article> findTop10ByPublishedAtBetweenOrderByViewCountDesc(LocalDateTime startOfWeek, LocalDateTime endOfDay); | ||
} |
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
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
49 changes: 49 additions & 0 deletions
49
src/main/java/gyeongdan/user/controller/UserTypeController.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,49 @@ | ||
package gyeongdan.user.controller; | ||
|
||
import gyeongdan.user.domain.UserType; | ||
import gyeongdan.user.dto.UserTypeRecord; | ||
import gyeongdan.user.dto.UserTypeTestResult; | ||
import gyeongdan.user.service.UserManageService; | ||
import gyeongdan.util.CommonResponse; | ||
import gyeongdan.util.annotation.LoginAuthenticated; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/usertype") | ||
@RequiredArgsConstructor | ||
public class UserTypeController { | ||
|
||
private final UserManageService userManageService; | ||
|
||
|
||
|
||
@LoginAuthenticated | ||
@PostMapping("/save") | ||
public ResponseEntity<?> saveUserTypeTestResult( | ||
@RequestBody UserTypeTestResult userTypeTestResult | ||
) { | ||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
Long userId = Long.valueOf(authentication.getName()); | ||
|
||
userManageService.saveUserType(userId, userTypeTestResult); | ||
|
||
return ResponseEntity.ok(new CommonResponse<>(null, "유저 타입 테스트 결과 저장 성공", true)); | ||
} | ||
|
||
@LoginAuthenticated | ||
@GetMapping | ||
public ResponseEntity<?> getUserType() { | ||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
Long userId = Long.valueOf(authentication.getName()); | ||
UserTypeRecord userType = userManageService.getUserType(userId); | ||
return ResponseEntity.ok(new CommonResponse<>(userType, "유저 타입 테스트 결과 조회 성공", true)); | ||
} | ||
} |
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,50 @@ | ||
package gyeongdan.user.domain; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum UserTypeEnum { | ||
ISSUE_FINDER("이슈파인더"), | ||
LIFESTYLE_CONSUMER("라이프스타일소비자"), | ||
ENTERTAINER("엔터테이너"), | ||
TECH_SPECIALIST("테크전문가"), | ||
PROFESSIONALS("전문가"); | ||
|
||
private final String name; | ||
|
||
public static UserTypeEnum from(String name) { | ||
for (UserTypeEnum userType : UserTypeEnum.values()) { | ||
if (userType.name.equals(name)) { | ||
return userType; | ||
} | ||
} | ||
throw new IllegalArgumentException("Invalid name: " + name); | ||
} | ||
|
||
public static UserTypeEnum fromWeights(Long issueFinder, Long lifestyleConsumer, Long entertainer, | ||
Long techSpecialist, Long professionals) { | ||
long maxWeight = issueFinder; | ||
UserTypeEnum strongestUserType = ISSUE_FINDER; | ||
|
||
if (lifestyleConsumer > maxWeight) { | ||
maxWeight = lifestyleConsumer; | ||
strongestUserType = LIFESTYLE_CONSUMER; | ||
} | ||
if (entertainer > maxWeight) { | ||
maxWeight = entertainer; | ||
strongestUserType = ENTERTAINER; | ||
} | ||
if (techSpecialist > maxWeight) { | ||
maxWeight = techSpecialist; | ||
strongestUserType = TECH_SPECIALIST; | ||
} | ||
if (professionals > maxWeight) { | ||
maxWeight = professionals; | ||
strongestUserType = PROFESSIONALS; | ||
} | ||
|
||
return strongestUserType; | ||
} | ||
} |
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,19 @@ | ||
package gyeongdan.user.dto; | ||
|
||
import gyeongdan.user.domain.UserTypeEnum; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
public class UserTypeRecord { | ||
|
||
private Long userTypeIssueFinder; | ||
private Long userTypeLifestyleConsumer; | ||
private Long userTypeEntertainer; | ||
private Long userTypeTechSpecialist; | ||
private Long userTypeProfessionals; | ||
private UserTypeEnum userType; | ||
} |
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 gyeongdan.user.dto; | ||
|
||
import gyeongdan.user.domain.UserTypeEnum; | ||
import lombok.Data; | ||
import lombok.Getter; | ||
|
||
@Data | ||
@Getter | ||
public class UserTypeTestResult { | ||
|
||
private Long userTypeIssueFinder; | ||
private Long userTypeLifestyleConsumer; | ||
private Long userTypeEntertainer; | ||
private Long userTypeTechSpecialist; | ||
private Long userTypeProfessionals; | ||
private UserTypeEnum userType; | ||
} |
8 changes: 6 additions & 2 deletions
8
...cle/repository/UserTypeJpaRepository.java → ...ser/repository/UserTypeJpaRepository.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 |
---|---|---|
@@ -1,12 +1,16 @@ | ||
package gyeongdan.article.repository; | ||
package gyeongdan.user.repository; | ||
|
||
import gyeongdan.article.domain.UserType; | ||
import gyeongdan.user.domain.UserType; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface UserTypeJpaRepository extends JpaRepository<UserType, Long> { | ||
|
||
Optional<UserType> findByuserId(Long user_id); | ||
|
||
Optional<List<UserType>> findByUserId(Long userId); | ||
} |
Oops, something went wrong.