Skip to content

Commit 5ab47bc

Browse files
author
bu2000
committed
complete user_survey_domain and separate userservice into userservice and authservice
1 parent 6dff7f5 commit 5ab47bc

15 files changed

Lines changed: 542 additions & 125 deletions
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.webservice.algorithmchef.controller;
2+
3+
import java.util.List;
4+
5+
import org.springframework.http.ResponseEntity;
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
import com.webservice.algorithmchef.dto.allergy.AllergyResponse;
10+
import com.webservice.algorithmchef.service.AllergyService;
11+
12+
import lombok.RequiredArgsConstructor;
13+
14+
@RestController
15+
@RequiredArgsConstructor
16+
public class AllergyController {
17+
18+
private final AllergyService allergyService;
19+
20+
@GetMapping("/allergies")
21+
public ResponseEntity<?> retrieveAll(){
22+
try {
23+
List<AllergyResponse> allergies = allergyService.retrieveAll();
24+
return ResponseEntity.ok(allergies);
25+
26+
}catch(IllegalArgumentException e) {
27+
return ResponseEntity.badRequest().body(e.getMessage());
28+
}
29+
}
30+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.webservice.algorithmchef.controller;
2+
3+
import org.springframework.http.HttpStatus;
4+
import org.springframework.http.ResponseEntity;
5+
import org.springframework.security.core.annotation.AuthenticationPrincipal;
6+
import org.springframework.security.core.userdetails.UserDetails;
7+
import org.springframework.transaction.annotation.Transactional;
8+
import org.springframework.web.bind.annotation.PatchMapping;
9+
import org.springframework.web.bind.annotation.PostMapping;
10+
import org.springframework.web.bind.annotation.RequestBody;
11+
import org.springframework.web.bind.annotation.RequestMapping;
12+
import org.springframework.web.bind.annotation.RestController;
13+
14+
import com.webservice.algorithmchef.dto.user.ChangePasswordRequest;
15+
import com.webservice.algorithmchef.dto.user.ChangePasswordResponse;
16+
import com.webservice.algorithmchef.dto.user.FindPasswordRequest;
17+
import com.webservice.algorithmchef.dto.user.FindPasswordResponse;
18+
import com.webservice.algorithmchef.dto.user.FindUserIdRequest;
19+
import com.webservice.algorithmchef.dto.user.FindUserIdResponse;
20+
import com.webservice.algorithmchef.dto.user.UserLoginRequest;
21+
import com.webservice.algorithmchef.dto.user.UserLoginResponse;
22+
import com.webservice.algorithmchef.dto.user.UserSignUpRequest;
23+
import com.webservice.algorithmchef.dto.user.UserSignUpResponse;
24+
import com.webservice.algorithmchef.service.AuthService;
25+
26+
import lombok.RequiredArgsConstructor;
27+
28+
@RestController
29+
@RequiredArgsConstructor
30+
@RequestMapping("/auth")
31+
public class AuthController {
32+
33+
private final AuthService authService;
34+
35+
@PostMapping("/login")
36+
public ResponseEntity<?> login(@RequestBody UserLoginRequest userLoginRequest){
37+
try {
38+
UserLoginResponse userLoginResponse = authService.login(userLoginRequest);
39+
return ResponseEntity.ok(userLoginResponse);
40+
}catch(IllegalArgumentException e) {
41+
return ResponseEntity.badRequest().body(e.getMessage());
42+
}
43+
}
44+
45+
@PostMapping("/signUp")
46+
public ResponseEntity<?> signUp(@RequestBody UserSignUpRequest userSignUpRequest){
47+
try {
48+
UserSignUpResponse userSignUpResponse = authService.signUp(userSignUpRequest);
49+
return ResponseEntity.status(HttpStatus.CREATED).body(userSignUpResponse);
50+
51+
}catch (IllegalArgumentException e) {
52+
return ResponseEntity.badRequest().body(e.getMessage());
53+
}
54+
}
55+
56+
@Transactional
57+
@PatchMapping("/findPassword")
58+
public ResponseEntity<?> findPassword(@RequestBody FindPasswordRequest fPasswordRequest){
59+
try {
60+
FindPasswordResponse pResponse = authService.findPassword(fPasswordRequest);
61+
return ResponseEntity.ok(pResponse);
62+
}catch(IllegalArgumentException e) {
63+
return ResponseEntity.badRequest().body(e.getMessage());
64+
}
65+
}
66+
67+
@PatchMapping("/update-tempPassword")
68+
public ResponseEntity<?> updateTempPasswod(@RequestBody ChangePasswordRequest cPasswordRequest,
69+
@AuthenticationPrincipal UserDetails userDetails){
70+
try {
71+
String userId = userDetails.getUsername();
72+
ChangePasswordResponse cResponse = authService.updateTempPassword(cPasswordRequest, userId);
73+
return ResponseEntity.ok(cResponse);
74+
}catch(IllegalArgumentException e) {
75+
return ResponseEntity.badRequest().body(e.getMessage());
76+
}
77+
}
78+
79+
@PostMapping("/findUserId")
80+
public ResponseEntity<?> findUserId(@RequestBody FindUserIdRequest fIdRequest){
81+
try {
82+
FindUserIdResponse idResponse = authService.findUserId(fIdRequest);
83+
return ResponseEntity.ok(idResponse);
84+
}catch(IllegalArgumentException e) {
85+
return ResponseEntity.badRequest().body(e.getMessage());
86+
}
87+
}
88+
89+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.webservice.algorithmchef.controller;
2+
3+
import java.util.List;
4+
5+
import org.springframework.http.ResponseEntity;
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
import com.webservice.algorithmchef.dto.healthgoal.HealthGoalResponse;
10+
import com.webservice.algorithmchef.service.HealthGoalService;
11+
12+
import lombok.RequiredArgsConstructor;
13+
14+
@RequiredArgsConstructor
15+
@RestController
16+
public class HealthGoalController {
17+
18+
private final HealthGoalService hGoalService;
19+
20+
@GetMapping("/healthGoals")
21+
public ResponseEntity<?> retrieveAll(){
22+
try {
23+
List<HealthGoalResponse> goals = hGoalService.retriveAll();
24+
return ResponseEntity.ok(goals);
25+
}catch (IllegalArgumentException e) {
26+
return ResponseEntity.badRequest().body(e.getMessage());
27+
}
28+
}
29+
30+
}

src/main/java/com/webservice/algorithmchef/controller/UserController.java

Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,87 +4,76 @@
44
import org.springframework.http.ResponseEntity;
55
import org.springframework.security.core.annotation.AuthenticationPrincipal;
66
import org.springframework.security.core.userdetails.UserDetails;
7-
import org.springframework.transaction.annotation.Transactional;
7+
import org.springframework.web.bind.annotation.GetMapping;
88
import org.springframework.web.bind.annotation.PatchMapping;
99
import org.springframework.web.bind.annotation.PostMapping;
1010
import org.springframework.web.bind.annotation.RequestBody;
1111
import org.springframework.web.bind.annotation.RequestMapping;
1212
import org.springframework.web.bind.annotation.RestController;
1313

14-
import com.webservice.algorithmchef.dto.user.ChangePasswordRequest;
15-
import com.webservice.algorithmchef.dto.user.ChangePasswordResponse;
16-
import com.webservice.algorithmchef.dto.user.FindPasswordRequest;
17-
import com.webservice.algorithmchef.dto.user.FindPasswordResponse;
18-
import com.webservice.algorithmchef.dto.user.FindUserIdRequest;
19-
import com.webservice.algorithmchef.dto.user.FindUserIdResponse;
20-
import com.webservice.algorithmchef.dto.user.UserLoginRequest;
21-
import com.webservice.algorithmchef.dto.user.UserLoginResponse;
22-
import com.webservice.algorithmchef.dto.user.UserSignUpRequest;
23-
import com.webservice.algorithmchef.dto.user.UserSignUpResponse;
14+
import com.webservice.algorithmchef.dto.user.mypage.MyPageResponse;
15+
import com.webservice.algorithmchef.dto.user.survey.SurveyRequest;
16+
import com.webservice.algorithmchef.dto.user.survey.MessageResponse;
17+
import com.webservice.algorithmchef.dto.user.survey.NudgeRequest;
2418
import com.webservice.algorithmchef.service.UserService;
2519

2620
import lombok.RequiredArgsConstructor;
2721

2822
@RestController
2923
@RequiredArgsConstructor
30-
@RequestMapping("/auth")
24+
@RequestMapping("/user")
3125
public class UserController {
3226

3327
private final UserService userService;
3428

35-
@PostMapping("/login")
36-
public ResponseEntity<?> login(@RequestBody UserLoginRequest userLoginRequest){
29+
@PostMapping("/survey")
30+
public ResponseEntity<?> makeSurvey(@RequestBody SurveyRequest sRequest,
31+
@AuthenticationPrincipal UserDetails userDetails){
3732
try {
38-
UserLoginResponse userLoginResponse = userService.login(userLoginRequest);
39-
return ResponseEntity.ok(userLoginResponse);
33+
String userId = userDetails.getUsername();
34+
MessageResponse sResponse = userService.makeOrUpdateSurvey(sRequest, userId);
35+
return ResponseEntity.status(HttpStatus.CREATED).body(sResponse);
4036
}catch(IllegalArgumentException e) {
4137
return ResponseEntity.badRequest().body(e.getMessage());
4238
}
4339
}
4440

45-
@PostMapping("/signUp")
46-
public ResponseEntity<?> signUp(@RequestBody UserSignUpRequest userSignUpRequest){
47-
try {
48-
UserSignUpResponse userSignUpResponse = userService.signUp(userSignUpRequest);
49-
return ResponseEntity.status(HttpStatus.CREATED).body(userSignUpResponse);
50-
51-
}catch (IllegalArgumentException e) {
52-
return ResponseEntity.badRequest().body(e.getMessage());
53-
}
54-
}
55-
56-
@Transactional
57-
@PatchMapping("/findPassword")
58-
public ResponseEntity<?> findPassword(@RequestBody FindPasswordRequest fPasswordRequest){
41+
@GetMapping("/mypage")
42+
public ResponseEntity<?> retrieveMyInformation(@AuthenticationPrincipal UserDetails userDetails){
5943
try {
60-
FindPasswordResponse pResponse = userService.findPassword(fPasswordRequest);
61-
return ResponseEntity.ok(pResponse);
44+
String userId = userDetails.getUsername();
45+
MyPageResponse pageResponse = userService.retrieveMyInformation(userId);
46+
return ResponseEntity.ok(pageResponse);
6247
}catch(IllegalArgumentException e) {
6348
return ResponseEntity.badRequest().body(e.getMessage());
6449
}
6550
}
6651

67-
@PatchMapping("/update-tempPassword")
68-
public ResponseEntity<?> updateTempPasswod(@RequestBody ChangePasswordRequest cPasswordRequest,
52+
@PatchMapping("/survey")
53+
public ResponseEntity<?> updateSurvey(@RequestBody SurveyRequest sRequest,
6954
@AuthenticationPrincipal UserDetails userDetails){
7055
try {
7156
String userId = userDetails.getUsername();
72-
ChangePasswordResponse cResponse = userService.updateTempPassword(cPasswordRequest, userId);
73-
return ResponseEntity.ok(cResponse);
74-
}catch(IllegalArgumentException e) {
57+
MessageResponse mResponse = userService.makeOrUpdateSurvey(sRequest, userId);
58+
return ResponseEntity.ok(mResponse);
59+
}catch (IllegalArgumentException e) {
60+
// TODO: handle exception
7561
return ResponseEntity.badRequest().body(e.getMessage());
7662
}
7763
}
7864

79-
@PostMapping("/findUserId")
80-
public ResponseEntity<?> findUserId(@RequestBody FindUserIdRequest fIdRequest){
65+
@PatchMapping("/postpone/register")
66+
public ResponseEntity<?> postponeNudge(@RequestBody NudgeRequest nRequest,
67+
@AuthenticationPrincipal UserDetails userDetails){
8168
try {
82-
FindUserIdResponse idResponse = userService.findUserId(fIdRequest);
83-
return ResponseEntity.ok(idResponse);
84-
}catch(IllegalArgumentException e) {
69+
String userId = userDetails.getUsername();
70+
MessageResponse mResponse = userService.postponeNudge(nRequest, userId);
71+
return ResponseEntity.ok(mResponse);
72+
}catch (IllegalArgumentException e) {
73+
// TODO: handle exception
8574
return ResponseEntity.badRequest().body(e.getMessage());
8675
}
76+
8777
}
8878

89-
9079
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.webservice.algorithmchef.dto.allergy;
2+
3+
import com.webservice.algorithmchef.model.Allergy;
4+
5+
import lombok.Getter;
6+
7+
@Getter
8+
public class AllergyResponse {
9+
10+
private Long id;
11+
private String name;
12+
13+
public AllergyResponse(Allergy allergy) {
14+
this.id = allergy.getId();
15+
this.name = allergy.getName();
16+
}
17+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.webservice.algorithmchef.dto.healthgoal;
2+
3+
import com.webservice.algorithmchef.model.HealthGoal;
4+
5+
import lombok.Getter;
6+
7+
@Getter
8+
public class HealthGoalResponse {
9+
private String name;
10+
private Long id;
11+
private String category;
12+
13+
public HealthGoalResponse(HealthGoal goal) {
14+
this.name = goal.getName();
15+
this.id = goal.getId();
16+
this.category = goal.getCategory();
17+
}
18+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.webservice.algorithmchef.dto.user.mypage;
2+
3+
import java.time.LocalDate;
4+
import java.time.LocalDateTime;
5+
import java.time.Period;
6+
import java.util.List;
7+
8+
import com.webservice.algorithmchef.model.User;
9+
10+
import lombok.Getter;
11+
12+
@Getter
13+
public class MyPageResponse {
14+
15+
private String userId;
16+
private LocalDateTime birthDate;
17+
private int age;
18+
private List<String> goals;
19+
private List<String> allergyList;
20+
private String dislikedIngredients;
21+
private String likedIngredients;
22+
private String preferredCuisine;
23+
private String spiceLevel;
24+
private boolean allowPushConsumption;
25+
private boolean allowPushComment;
26+
private boolean allowPushNudge;
27+
28+
public MyPageResponse(User user) {
29+
this.userId = user.getUserId();
30+
this.birthDate = user.getBirthDate();
31+
this.age = Period.between(birthDate.toLocalDate(), LocalDate.now()).getYears();
32+
this.goals = user.getUserHealthGoals().stream()
33+
.map(userHealthGoal -> userHealthGoal.getHealthGoal().getName())
34+
.toList();
35+
this.allergyList = user.getUserAllergyList().stream()
36+
.map(userAllergy -> userAllergy.getAllergy().getName())
37+
.toList();
38+
this.dislikedIngredients = user.getUserPreference().getDisLikedIngredients();
39+
this.likedIngredients = user.getUserPreference().getLikedIngredients();
40+
this.preferredCuisine = user.getUserPreference().getPreferredCuisine();
41+
this.spiceLevel = user.getUserPreference().getSpiceLevel();
42+
this.allowPushConsumption = user.getUserPreference().isAllowPushConsumption();
43+
this.allowPushComment = user.getUserPreference().isAllowPushComment();
44+
this.allowPushNudge = user.getUserPreference().isAllowPushNudge();
45+
}
46+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.webservice.algorithmchef.dto.user.survey;
2+
3+
import lombok.Getter;
4+
5+
@Getter
6+
public class MessageResponse {
7+
8+
private String message;
9+
10+
public MessageResponse(String userId, String message) {
11+
this.message = userId + message;
12+
}
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.webservice.algorithmchef.dto.user.survey;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
8+
@Getter
9+
@NoArgsConstructor
10+
public class NudgeRequest {
11+
12+
@JsonProperty("wants_register_nudge")
13+
private boolean wantsRegisterNudge;
14+
}

0 commit comments

Comments
 (0)