Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.webservice.algorithmchef.controller;

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.webservice.algorithmchef.dto.allergy.AllergyResponse;
import com.webservice.algorithmchef.service.AllergyService;

import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
public class AllergyController {

private final AllergyService allergyService;

@GetMapping("/allergies")
public ResponseEntity<?> retrieveAll(){
try {
List<AllergyResponse> allergies = allergyService.retrieveAll();
return ResponseEntity.ok(allergies);

}catch(IllegalArgumentException e) {
return ResponseEntity.badRequest().body(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.webservice.algorithmchef.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PatchMapping;
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;

import com.webservice.algorithmchef.dto.user.ChangePasswordRequest;
import com.webservice.algorithmchef.dto.user.ChangePasswordResponse;
import com.webservice.algorithmchef.dto.user.FindPasswordRequest;
import com.webservice.algorithmchef.dto.user.FindPasswordResponse;
import com.webservice.algorithmchef.dto.user.FindUserIdRequest;
import com.webservice.algorithmchef.dto.user.FindUserIdResponse;
import com.webservice.algorithmchef.dto.user.UserLoginRequest;
import com.webservice.algorithmchef.dto.user.UserLoginResponse;
import com.webservice.algorithmchef.dto.user.UserSignUpRequest;
import com.webservice.algorithmchef.dto.user.UserSignUpResponse;
import com.webservice.algorithmchef.service.AuthService;

import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/auth")
public class AuthController {

private final AuthService authService;

@PostMapping("/login")
public ResponseEntity<?> login(@RequestBody UserLoginRequest userLoginRequest){
try {
UserLoginResponse userLoginResponse = authService.login(userLoginRequest);
return ResponseEntity.ok(userLoginResponse);
}catch(IllegalArgumentException e) {
return ResponseEntity.badRequest().body(e.getMessage());
}
}

@PostMapping("/signUp")
public ResponseEntity<?> signUp(@RequestBody UserSignUpRequest userSignUpRequest){
try {
UserSignUpResponse userSignUpResponse = authService.signUp(userSignUpRequest);
return ResponseEntity.status(HttpStatus.CREATED).body(userSignUpResponse);

}catch (IllegalArgumentException e) {
return ResponseEntity.badRequest().body(e.getMessage());
}
}

@Transactional
@PatchMapping("/findPassword")
public ResponseEntity<?> findPassword(@RequestBody FindPasswordRequest fPasswordRequest){
try {
FindPasswordResponse pResponse = authService.findPassword(fPasswordRequest);
return ResponseEntity.ok(pResponse);
}catch(IllegalArgumentException e) {
return ResponseEntity.badRequest().body(e.getMessage());
}
}

@PatchMapping("/update-tempPassword")
public ResponseEntity<?> updateTempPasswod(@RequestBody ChangePasswordRequest cPasswordRequest,
@AuthenticationPrincipal UserDetails userDetails){
try {
String userId = userDetails.getUsername();
ChangePasswordResponse cResponse = authService.updateTempPassword(cPasswordRequest, userId);
return ResponseEntity.ok(cResponse);
}catch(IllegalArgumentException e) {
return ResponseEntity.badRequest().body(e.getMessage());
}
}

@PostMapping("/findUserId")
public ResponseEntity<?> findUserId(@RequestBody FindUserIdRequest fIdRequest){
try {
FindUserIdResponse idResponse = authService.findUserId(fIdRequest);
return ResponseEntity.ok(idResponse);
}catch(IllegalArgumentException e) {
return ResponseEntity.badRequest().body(e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.webservice.algorithmchef.controller;

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.webservice.algorithmchef.dto.healthgoal.HealthGoalResponse;
import com.webservice.algorithmchef.service.HealthGoalService;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@RestController
public class HealthGoalController {

private final HealthGoalService hGoalService;

@GetMapping("/healthGoals")
public ResponseEntity<?> retrieveAll(){
try {
List<HealthGoalResponse> goals = hGoalService.retriveAll();
return ResponseEntity.ok(goals);
}catch (IllegalArgumentException e) {
return ResponseEntity.badRequest().body(e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,87 +4,76 @@
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
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;

import com.webservice.algorithmchef.dto.user.ChangePasswordRequest;
import com.webservice.algorithmchef.dto.user.ChangePasswordResponse;
import com.webservice.algorithmchef.dto.user.FindPasswordRequest;
import com.webservice.algorithmchef.dto.user.FindPasswordResponse;
import com.webservice.algorithmchef.dto.user.FindUserIdRequest;
import com.webservice.algorithmchef.dto.user.FindUserIdResponse;
import com.webservice.algorithmchef.dto.user.UserLoginRequest;
import com.webservice.algorithmchef.dto.user.UserLoginResponse;
import com.webservice.algorithmchef.dto.user.UserSignUpRequest;
import com.webservice.algorithmchef.dto.user.UserSignUpResponse;
import com.webservice.algorithmchef.dto.user.mypage.MyPageResponse;
import com.webservice.algorithmchef.dto.user.survey.SurveyRequest;
import com.webservice.algorithmchef.dto.user.survey.MessageResponse;
import com.webservice.algorithmchef.dto.user.survey.NudgeRequest;
import com.webservice.algorithmchef.service.UserService;

import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/auth")
@RequestMapping("/user")
public class UserController {

private final UserService userService;

@PostMapping("/login")
public ResponseEntity<?> login(@RequestBody UserLoginRequest userLoginRequest){
@PostMapping("/survey")
public ResponseEntity<?> makeSurvey(@RequestBody SurveyRequest sRequest,
@AuthenticationPrincipal UserDetails userDetails){
try {
UserLoginResponse userLoginResponse = userService.login(userLoginRequest);
return ResponseEntity.ok(userLoginResponse);
String userId = userDetails.getUsername();
MessageResponse sResponse = userService.makeOrUpdateSurvey(sRequest, userId);
return ResponseEntity.status(HttpStatus.CREATED).body(sResponse);
}catch(IllegalArgumentException e) {
return ResponseEntity.badRequest().body(e.getMessage());
}
}

@PostMapping("/signUp")
public ResponseEntity<?> signUp(@RequestBody UserSignUpRequest userSignUpRequest){
try {
UserSignUpResponse userSignUpResponse = userService.signUp(userSignUpRequest);
return ResponseEntity.status(HttpStatus.CREATED).body(userSignUpResponse);

}catch (IllegalArgumentException e) {
return ResponseEntity.badRequest().body(e.getMessage());
}
}

@Transactional
@PatchMapping("/findPassword")
public ResponseEntity<?> findPassword(@RequestBody FindPasswordRequest fPasswordRequest){
@GetMapping("/mypage")
public ResponseEntity<?> retrieveMyInformation(@AuthenticationPrincipal UserDetails userDetails){
try {
FindPasswordResponse pResponse = userService.findPassword(fPasswordRequest);
return ResponseEntity.ok(pResponse);
String userId = userDetails.getUsername();
MyPageResponse pageResponse = userService.retrieveMyInformation(userId);
return ResponseEntity.ok(pageResponse);
}catch(IllegalArgumentException e) {
return ResponseEntity.badRequest().body(e.getMessage());
}
}

@PatchMapping("/update-tempPassword")
public ResponseEntity<?> updateTempPasswod(@RequestBody ChangePasswordRequest cPasswordRequest,
@PatchMapping("/survey")
public ResponseEntity<?> updateSurvey(@RequestBody SurveyRequest sRequest,
@AuthenticationPrincipal UserDetails userDetails){
try {
String userId = userDetails.getUsername();
ChangePasswordResponse cResponse = userService.updateTempPassword(cPasswordRequest, userId);
return ResponseEntity.ok(cResponse);
}catch(IllegalArgumentException e) {
MessageResponse mResponse = userService.makeOrUpdateSurvey(sRequest, userId);
return ResponseEntity.ok(mResponse);
}catch (IllegalArgumentException e) {
// TODO: handle exception
return ResponseEntity.badRequest().body(e.getMessage());
}
}

@PostMapping("/findUserId")
public ResponseEntity<?> findUserId(@RequestBody FindUserIdRequest fIdRequest){
@PatchMapping("/postpone/register")
public ResponseEntity<?> postponeNudge(@RequestBody NudgeRequest nRequest,
@AuthenticationPrincipal UserDetails userDetails){
try {
FindUserIdResponse idResponse = userService.findUserId(fIdRequest);
return ResponseEntity.ok(idResponse);
}catch(IllegalArgumentException e) {
String userId = userDetails.getUsername();
MessageResponse mResponse = userService.postponeNudge(nRequest, userId);
return ResponseEntity.ok(mResponse);
}catch (IllegalArgumentException e) {
// TODO: handle exception
return ResponseEntity.badRequest().body(e.getMessage());
}

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.webservice.algorithmchef.dto.allergy;

import com.webservice.algorithmchef.model.Allergy;

import lombok.Getter;

@Getter
public class AllergyResponse {

private Long id;
private String name;

public AllergyResponse(Allergy allergy) {
this.id = allergy.getId();
this.name = allergy.getName();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.webservice.algorithmchef.dto.healthgoal;

import com.webservice.algorithmchef.model.HealthGoal;

import lombok.Getter;

@Getter
public class HealthGoalResponse {
private String name;
private Long id;
private String category;

public HealthGoalResponse(HealthGoal goal) {
this.name = goal.getName();
this.id = goal.getId();
this.category = goal.getCategory();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.webservice.algorithmchef.dto.user.mypage;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.util.List;

import com.webservice.algorithmchef.model.User;

import lombok.Getter;

@Getter
public class MyPageResponse {

private String userId;
private LocalDateTime birthDate;
private int age;
private List<String> goals;
private List<String> allergyList;
private String dislikedIngredients;
private String likedIngredients;
private String preferredCuisine;
private String spiceLevel;
private boolean allowPushConsumption;
private boolean allowPushComment;
private boolean allowPushNudge;

public MyPageResponse(User user) {
this.userId = user.getUserId();
this.birthDate = user.getBirthDate();
this.age = Period.between(birthDate.toLocalDate(), LocalDate.now()).getYears();
this.goals = user.getUserHealthGoals().stream()
.map(userHealthGoal -> userHealthGoal.getHealthGoal().getName())
.toList();
this.allergyList = user.getUserAllergyList().stream()
.map(userAllergy -> userAllergy.getAllergy().getName())
.toList();
this.dislikedIngredients = user.getUserPreference().getDisLikedIngredients();
this.likedIngredients = user.getUserPreference().getLikedIngredients();
this.preferredCuisine = user.getUserPreference().getPreferredCuisine();
this.spiceLevel = user.getUserPreference().getSpiceLevel();
this.allowPushConsumption = user.getUserPreference().isAllowPushConsumption();
this.allowPushComment = user.getUserPreference().isAllowPushComment();
this.allowPushNudge = user.getUserPreference().isAllowPushNudge();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.webservice.algorithmchef.dto.user.survey;

import lombok.Getter;

@Getter
public class MessageResponse {

private String message;

public MessageResponse(String userId, String message) {
this.message = userId + message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.webservice.algorithmchef.dto.user.survey;

import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class NudgeRequest {

@JsonProperty("wants_register_nudge")
private boolean wantsRegisterNudge;
}
Loading