Skip to content

Commit

Permalink
Merge pull request #19 from CSID-DGU/develop
Browse files Browse the repository at this point in the history
Test: CI/CD ํ…Œ์ŠคํŠธ์šฉ
  • Loading branch information
saokiritoni authored Nov 4, 2024
2 parents 8c821a6 + 892f264 commit fcf8f85
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/main/java/dongguk/osori/TestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
public class TestController {
@GetMapping("/")
public String home() {
return "CI/CD ์„ฑ๊ณต!";
return "CI/CD test";
}
}
40 changes: 29 additions & 11 deletions src/main/java/dongguk/osori/domain/follow/FollowController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
import dongguk.osori.domain.follow.service.FollowService;
import dongguk.osori.domain.user.entity.User;
import dongguk.osori.domain.user.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@RequiredArgsConstructor
Expand All @@ -22,7 +24,11 @@ public class FollowController {
private final FollowService followService;
private final UserService userService;

// ๋‚ด ํŒ”๋กœ์ž‰ ๋ชฉ๋ก ๋ฐ ํŒ”๋กœ์ž‰ ์ˆ˜ ์กฐํšŒ
@Operation(summary = "๋‚ด ํŒ”๋กœ์ž‰ ๋ชฉ๋ก ๋ฐ ํŒ”๋กœ์ž‰ ์ˆ˜ ์กฐํšŒ", description = "๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ํŒ”๋กœ์ž‰ ๋ชฉ๋ก๊ณผ ํŒ”๋กœ์ž‰ ์ˆ˜๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "ํŒ”๋กœ์ž‰ ๋ชฉ๋ก ๋ฐ ์ˆ˜ ์กฐํšŒ ์„ฑ๊ณต"),
@ApiResponse(responseCode = "401", description = "์ธ์ฆ๋˜์ง€ ์•Š์€ ์‚ฌ์šฉ์ž")
})
@GetMapping("/following")
public ResponseEntity<MyFollowResponse> getMyFollowingList(@SessionAttribute(name = "userId", required = false) Long userId) {
if (userId == null) {
Expand All @@ -35,7 +41,11 @@ public ResponseEntity<MyFollowResponse> getMyFollowingList(@SessionAttribute(nam
return ResponseEntity.ok(response);
}

// ๋‚ด ํŒ”๋กœ์›Œ ๋ชฉ๋ก ๋ฐ ํŒ”๋กœ์›Œ ์ˆ˜ ์กฐํšŒ
@Operation(summary = "๋‚ด ํŒ”๋กœ์›Œ ๋ชฉ๋ก ๋ฐ ํŒ”๋กœ์›Œ ์ˆ˜ ์กฐํšŒ", description = "๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ํŒ”๋กœ์›Œ ๋ชฉ๋ก๊ณผ ํŒ”๋กœ์›Œ ์ˆ˜๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "ํŒ”๋กœ์›Œ ๋ชฉ๋ก ๋ฐ ์ˆ˜ ์กฐํšŒ ์„ฑ๊ณต"),
@ApiResponse(responseCode = "401", description = "์ธ์ฆ๋˜์ง€ ์•Š์€ ์‚ฌ์šฉ์ž")
})
@GetMapping("/followers")
public ResponseEntity<MyFollowResponse> getMyFollowerList(@SessionAttribute(name = "userId", required = false) Long userId) {
if (userId == null) {
Expand All @@ -48,8 +58,12 @@ public ResponseEntity<MyFollowResponse> getMyFollowerList(@SessionAttribute(name
return ResponseEntity.ok(response);
}


// ์ด๋ฉ”์ผ๋กœ ํŒ”๋กœ์šฐ
@Operation(summary = "์ด๋ฉ”์ผ๋กœ ์‚ฌ์šฉ์ž ํŒ”๋กœ์šฐ", description = "์ด๋ฉ”์ผ๋กœ ์‚ฌ์šฉ์ž๋ฅผ ๊ฒ€์ƒ‰ํ•ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "ํŒ”๋กœ์šฐ ์„ฑ๊ณต"),
@ApiResponse(responseCode = "401", description = "์ธ์ฆ๋˜์ง€ ์•Š์€ ์‚ฌ์šฉ์ž"),
@ApiResponse(responseCode = "404", description = "ํ•ด๋‹น ์ด๋ฉ”์ผ์˜ ์‚ฌ์šฉ์ž๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Œ")
})
@PostMapping()
public ResponseEntity<Void> followUserByEmail(@SessionAttribute(name = "userId", required = false) Long userId, @RequestBody FollowRequestDto followRequestDto) {
if (userId == null) {
Expand All @@ -65,8 +79,11 @@ public ResponseEntity<Void> followUserByEmail(@SessionAttribute(name = "userId",
return ResponseEntity.ok().build();
}


// ์–ธํŒ”๋กœ์šฐ
@Operation(summary = "์–ธํŒ”๋กœ์šฐ", description = "์‚ฌ์šฉ์ž๋ฅผ ์–ธํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "์–ธํŒ”๋กœ์šฐ ์„ฑ๊ณต"),
@ApiResponse(responseCode = "401", description = "์ธ์ฆ๋˜์ง€ ์•Š์€ ์‚ฌ์šฉ์ž")
})
@DeleteMapping()
public ResponseEntity<Void> unfollowUser(@SessionAttribute(name = "userId", required = false) Long userId,
@RequestBody UnfollowRequestDto unfollowRequestDto) {
Expand All @@ -77,9 +94,11 @@ public ResponseEntity<Void> unfollowUser(@SessionAttribute(name = "userId", requ
return ResponseEntity.ok().build();
}


// ํŒ”๋กœ์›Œ ๋Š๊ธฐ
// TODO: ํŒ”๋กœ์›Œ ๋Š๊ธฐ์™€ ์–ธํŒ”๋กœ์šฐ ํ†ตํ•ฉ ๋ฐฉ์•ˆ ๊ณ ๋ ค
@Operation(summary = "ํŒ”๋กœ์›Œ ๋Š๊ธฐ", description = "ํŒ”๋กœ์›Œ๋ฅผ ๋Š์Šต๋‹ˆ๋‹ค. (์ฐจ๋‹จ ๊ธฐ๋Šฅ)")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "ํŒ”๋กœ์›Œ ๋Š๊ธฐ ์„ฑ๊ณต"),
@ApiResponse(responseCode = "401", description = "์ธ์ฆ๋˜์ง€ ์•Š์€ ์‚ฌ์šฉ์ž")
})
@DeleteMapping("/block")
public ResponseEntity<Void> blockFollower(@SessionAttribute(name = "userId", required = false) Long userId,
@RequestBody BlockFollowerRequestDto blockFollowerRequestDto) {
Expand All @@ -89,5 +108,4 @@ public ResponseEntity<Void> blockFollower(@SessionAttribute(name = "userId", req
followService.blockFollower(userId, blockFollowerRequestDto.getFollowerId());
return ResponseEntity.ok().build();
}

}
35 changes: 30 additions & 5 deletions src/main/java/dongguk/osori/domain/goal/GoalController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import dongguk.osori.domain.goal.dto.GoalDto;
import dongguk.osori.domain.goal.entity.Goal;
import dongguk.osori.domain.goal.service.GoalService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -22,7 +25,11 @@ public class GoalController {

private final GoalService goalService;

// ๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ๋ชฉํ‘œ ์กฐํšŒ
@Operation(summary = "๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ๋ชฉํ‘œ ์กฐํšŒ", description = "์„ธ์…˜์˜ userId๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ๋ชฉํ‘œ ๋ชฉ๋ก์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "๋ชฉํ‘œ ๋ชฉ๋ก ์กฐํšŒ ์„ฑ๊ณต"),
@ApiResponse(responseCode = "401", description = "์ธ์ฆ๋˜์ง€ ์•Š์€ ์‚ฌ์šฉ์ž")
})
@GetMapping
public ResponseEntity<List<Goal>> getUserGoals(HttpSession session) {
Long userId = (Long) session.getAttribute("userId");
Expand All @@ -33,7 +40,11 @@ public ResponseEntity<List<Goal>> getUserGoals(HttpSession session) {
return ResponseEntity.ok(goals);
}

// ๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ๋ชฉํ‘œ ์ƒ์„ฑ
@Operation(summary = "๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ๋ชฉํ‘œ ์ƒ์„ฑ", description = "๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ์ƒˆ๋กœ์šด ๋ชฉํ‘œ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "๋ชฉํ‘œ ์ƒ์„ฑ ์„ฑ๊ณต"),
@ApiResponse(responseCode = "401", description = "์ธ์ฆ๋˜์ง€ ์•Š์€ ์‚ฌ์šฉ์ž")
})
@PostMapping
public ResponseEntity<Goal> createGoal(@RequestBody GoalDto goalDto, HttpSession session) {
Long userId = (Long) session.getAttribute("userId");
Expand All @@ -44,7 +55,12 @@ public ResponseEntity<Goal> createGoal(@RequestBody GoalDto goalDto, HttpSession
return ResponseEntity.ok(createdGoal);
}

// ๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ๋ชฉํ‘œ ์ˆ˜์ •
@Operation(summary = "๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ๋ชฉํ‘œ ์ˆ˜์ •", description = "๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ๊ธฐ์กด ๋ชฉํ‘œ๋ฅผ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "๋ชฉํ‘œ ์ˆ˜์ • ์„ฑ๊ณต"),
@ApiResponse(responseCode = "401", description = "์ธ์ฆ๋˜์ง€ ์•Š์€ ์‚ฌ์šฉ์ž"),
@ApiResponse(responseCode = "404", description = "๋ชฉํ‘œ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Œ")
})
@PatchMapping("/{goalId}")
public ResponseEntity<Goal> updateGoal(@PathVariable("goalId") Long goalId, @RequestBody GoalDto goalDto, HttpSession session) {
Long userId = (Long) session.getAttribute("userId");
Expand All @@ -56,7 +72,11 @@ public ResponseEntity<Goal> updateGoal(@PathVariable("goalId") Long goalId, @Req
.orElseGet(() -> ResponseEntity.notFound().build());
}

// ๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ๋ชฉํ‘œ ์‚ญ์ œ
@Operation(summary = "๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ๋ชฉํ‘œ ์‚ญ์ œ", description = "๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ๊ธฐ์กด ๋ชฉํ‘œ๋ฅผ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "๋ชฉํ‘œ ์‚ญ์ œ ์„ฑ๊ณต"),
@ApiResponse(responseCode = "401", description = "์ธ์ฆ๋˜์ง€ ์•Š์€ ์‚ฌ์šฉ์ž")
})
@DeleteMapping("/{goalId}")
public ResponseEntity<Void> deleteGoal(@PathVariable("goalId") Long goalId, HttpSession session) {
Long userId = (Long) session.getAttribute("userId");
Expand All @@ -67,7 +87,12 @@ public ResponseEntity<Void> deleteGoal(@PathVariable("goalId") Long goalId, Http
return ResponseEntity.noContent().build();
}

// ๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ๋ชฉํ‘œ ๋‹ฌ์„ฑ ์—ฌ๋ถ€ ์ˆ˜์ •
@Operation(summary = "๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ๋ชฉํ‘œ ๋‹ฌ์„ฑ ์—ฌ๋ถ€ ์ˆ˜์ •", description = "๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ๋ชฉํ‘œ ๋‹ฌ์„ฑ ์ƒํƒœ๋ฅผ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "๋ชฉํ‘œ ๋‹ฌ์„ฑ ์ƒํƒœ ์ˆ˜์ • ์„ฑ๊ณต"),
@ApiResponse(responseCode = "401", description = "์ธ์ฆ๋˜์ง€ ์•Š์€ ์‚ฌ์šฉ์ž"),
@ApiResponse(responseCode = "404", description = "๋ชฉํ‘œ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Œ")
})
@PatchMapping("/{goalId}/completion")
public ResponseEntity<Goal> updateGoalCompletion(@PathVariable("goalId") Long goalId, @RequestBody GoalCompletionDto goalCompletionDto, HttpSession session) {
Long userId = (Long) session.getAttribute("userId");
Expand Down
91 changes: 50 additions & 41 deletions src/main/java/dongguk/osori/domain/user/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import dongguk.osori.domain.user.dto.*;
import dongguk.osori.domain.user.service.EmailService;
import dongguk.osori.domain.user.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -21,39 +24,33 @@ public class UserController {
private final UserService userService;
private final EmailService emailService;


// ์ด๋ฉ”์ผ ์ธ์ฆ ์ฝ”๋“œ ์ „์†ก
@Operation(summary = "์ด๋ฉ”์ผ ์ธ์ฆ ์ฝ”๋“œ ์ „์†ก", description = "ํšŒ์›๊ฐ€์ž…์„ ์œ„ํ•ด ์ด๋ฉ”์ผ๋กœ ์ธ์ฆ ์ฝ”๋“œ๋ฅผ ์ „์†กํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "์ธ์ฆ ์ฝ”๋“œ ์ „์†ก ์„ฑ๊ณต"),
@ApiResponse(responseCode = "400", description = "์ž˜๋ชป๋œ ์ด๋ฉ”์ผ ์ž…๋ ฅ")
})
@PostMapping("/signup/send-email")
public ResponseEntity<String> sendSignupEmail(@RequestBody Map<String,String> request) {
String email = request.get("email"); // ์ด๋ฉ”์ผ ์ฃผ์†Œ ์ถ”์ถœ
public ResponseEntity<String> sendSignupEmail(@RequestBody Map<String, String> request) {
String email = request.get("email");
if (email == null || email.isEmpty()) {
return ResponseEntity.status(400).body("์ด๋ฉ”์ผ์ด ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.");
}
emailService.sendEmail(email);
return ResponseEntity.ok("์ธ์ฆ ์ฝ”๋“œ๊ฐ€ ์ด๋ฉ”์ผ๋กœ ์ „์†ก๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
}

// // ์ด๋ฉ”์ผ ์ธ์ฆ ์ฝ”๋“œ ํ™•์ธ
// @PostMapping("/signup/verify-code")
// public ResponseEntity<String> verifyEmailCode(@RequestBody EmailVerificationDto verificationDto) {
// boolean isVerified = emailService.verifyAuthCode(verificationDto.getEmail(), verificationDto.getCode());
//
// if (isVerified) {
// return ResponseEntity.ok("์ด๋ฉ”์ผ ์ธ์ฆ์ด ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
// } else {
// return ResponseEntity.status(400).body("์ž˜๋ชป๋œ ์ธ์ฆ ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.");
// }
// }

// ํšŒ์›๊ฐ€์ž…
@Operation(summary = "ํšŒ์›๊ฐ€์ž…", description = "์ด๋ฉ”์ผ ์ธ์ฆ์„ ์™„๋ฃŒํ•œ ์‚ฌ์šฉ์ž๊ฐ€ ํšŒ์›๊ฐ€์ž…์„ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "ํšŒ์›๊ฐ€์ž… ์„ฑ๊ณต"),
@ApiResponse(responseCode = "400", description = "์ด๋ฉ”์ผ ์ธ์ฆ ์‹คํŒจ ๋˜๋Š” ์ž˜๋ชป๋œ ์š”์ฒญ"),
@ApiResponse(responseCode = "500", description = "์„œ๋ฒ„ ์—๋Ÿฌ")
})
@PostMapping("/signup")
public ResponseEntity<String> signup(@RequestBody SignupUserDto signupUserDto) {
try {
// ์ด๋ฉ”์ผ ์ธ์ฆ์ด ์™„๋ฃŒ๋œ ์‚ฌ์šฉ์ž๋งŒ ํšŒ์›๊ฐ€์ž… ๊ฐ€๋Šฅ
if (!emailService.verifyAuthCode(signupUserDto.getEmail(), signupUserDto.getAuthCode())) {
return ResponseEntity.status(400).body("์ด๋ฉ”์ผ ์ธ์ฆ์ด ์™„๋ฃŒ๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.");
}

userService.signup(signupUserDto);
return ResponseEntity.ok("ํšŒ์›๊ฐ€์ž…์ด ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
} catch (IllegalArgumentException e) {
Expand All @@ -63,19 +60,27 @@ public ResponseEntity<String> signup(@RequestBody SignupUserDto signupUserDto) {
}
}

// ์œ ์ € ํ”„๋กœํ•„ ์ •๋ณด ์กฐํšŒ
@Operation(summary = "์œ ์ € ํ”„๋กœํ•„ ์กฐํšŒ", description = "๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ํ”„๋กœํ•„ ์ •๋ณด๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "ํ”„๋กœํ•„ ์กฐํšŒ ์„ฑ๊ณต"),
@ApiResponse(responseCode = "401", description = "์ธ์ฆ๋˜์ง€ ์•Š์€ ์‚ฌ์šฉ์ž")
})
@GetMapping("/profile")
public ResponseEntity<UserProfileDto> getUserProfile(HttpSession session) {
Long userId = (Long) session.getAttribute("userId");

if (userId == null) {
return ResponseEntity.status(401).build();
}
UserProfileDto userDto = userService.getUserProfile(userId);
return ResponseEntity.ok(userDto);
}

// ๋กœ๊ทธ์ธ
@Operation(summary = "๋กœ๊ทธ์ธ", description = "์ด๋ฉ”์ผ๊ณผ ๋น„๋ฐ€๋ฒˆํ˜ธ๋กœ ๋กœ๊ทธ์ธํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "๋กœ๊ทธ์ธ ์„ฑ๊ณต"),
@ApiResponse(responseCode = "401", description = "๋กœ๊ทธ์ธ ์‹คํŒจ"),
@ApiResponse(responseCode = "500", description = "์„œ๋ฒ„ ์—๋Ÿฌ")
})
@PostMapping("/login")
public ResponseEntity<String> login(@RequestBody LoginRequestDto loginRequest, HttpSession session) {
try {
Expand All @@ -92,22 +97,28 @@ public ResponseEntity<String> login(@RequestBody LoginRequestDto loginRequest, H
}
}

// ๋กœ๊ทธ์•„์›ƒ ์‹œ ์„ธ์…˜ ๋ฌดํšจํ™”
@Operation(summary = "๋กœ๊ทธ์•„์›ƒ", description = "์‚ฌ์šฉ์ž๋ฅผ ๋กœ๊ทธ์•„์›ƒํ•˜๊ณ  ์„ธ์…˜์„ ๋ฌดํšจํ™”ํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "๋กœ๊ทธ์•„์›ƒ ์„ฑ๊ณต")
})
@PostMapping("/logout")
public ResponseEntity<Void> logout(HttpSession session) {
session.invalidate();
return ResponseEntity.ok().build();
}

// ์œ ์ € ํ”„๋กœํ•„ ์ˆ˜์ •
@Operation(summary = "์œ ์ € ํ”„๋กœํ•„ ์ˆ˜์ •", description = "๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ํ”„๋กœํ•„ ์ •๋ณด๋ฅผ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "ํ”„๋กœํ•„ ์ˆ˜์ • ์„ฑ๊ณต"),
@ApiResponse(responseCode = "400", description = "์ž˜๋ชป๋œ ์š”์ฒญ"),
@ApiResponse(responseCode = "500", description = "์„œ๋ฒ„ ์—๋Ÿฌ")
})
@PatchMapping("/profile")
public ResponseEntity<String> updateUserProfile(@RequestBody UserProfileEditDto userProfileEditDto, HttpSession session) {
Long userId = (Long) session.getAttribute("userId");

if (userId == null) {
return ResponseEntity.status(401).body("๋กœ๊ทธ์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.");
}

try {
userService.updateUserProfile(userId, userProfileEditDto);
return ResponseEntity.ok("ํ”„๋กœํ•„ ์ˆ˜์ •์ด ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
Expand All @@ -119,20 +130,21 @@ public ResponseEntity<String> updateUserProfile(@RequestBody UserProfileEditDto
}
}


// ํ˜„์žฌ ๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ
@Operation(summary = "ํ˜„์žฌ ๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ", description = "๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ์šฉ ์—”๋“œํฌ์ธํŠธ๋กœ, ํ˜„์žฌ ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ๋งž๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ ์„ฑ๊ณต"),
@ApiResponse(responseCode = "400", description = "์ž˜๋ชป๋œ ๋น„๋ฐ€๋ฒˆํ˜ธ"),
@ApiResponse(responseCode = "500", description = "์„œ๋ฒ„ ์—๋Ÿฌ")
})
@PostMapping("/verify-password")
public ResponseEntity<String> verifyPassword(@RequestBody PasswordDto passwordDto, HttpSession session) {
Long userId = (Long) session.getAttribute("userId");

if (userId == null) {
return ResponseEntity.status(401).body("๋กœ๊ทธ์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.");
}

if (passwordDto.getPassword() == null || passwordDto.getPassword().isEmpty()) {
return ResponseEntity.status(400).body("๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์ž…๋ ฅ๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.");
}

try {
boolean isVerified = userService.verifyPassword(userId, passwordDto);
if (isVerified) {
Expand All @@ -146,36 +158,33 @@ public ResponseEntity<String> verifyPassword(@RequestBody PasswordDto passwordDt
}
}

// ๋น„๋ฐ€๋ฒˆํ˜ธ ๋ณ€๊ฒฝ
@Operation(summary = "๋น„๋ฐ€๋ฒˆํ˜ธ ๋ณ€๊ฒฝ", description = "ํ˜„์žฌ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธ ํ›„ ์ƒˆ๋กœ์šด ๋น„๋ฐ€๋ฒˆํ˜ธ๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "๋น„๋ฐ€๋ฒˆํ˜ธ ๋ณ€๊ฒฝ ์„ฑ๊ณต"),
@ApiResponse(responseCode = "400", description = "์ž˜๋ชป๋œ ์š”์ฒญ ๋˜๋Š” ํ˜„์žฌ ๋น„๋ฐ€๋ฒˆํ˜ธ ๋ถˆ์ผ์น˜"),
@ApiResponse(responseCode = "500", description = "์„œ๋ฒ„ ์—๋Ÿฌ")
})
@PatchMapping("/password")
public ResponseEntity<String> updatePassword(@RequestBody Map<String, String> request, HttpSession session) {
Long userId = (Long) session.getAttribute("userId");

if (userId == null) {
return ResponseEntity.status(401).body("๋กœ๊ทธ์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.");
}

String currentPassword = request.get("currentPassword");
String newPassword = request.get("newPassword");

if (currentPassword == null || newPassword == null || currentPassword.isEmpty() || newPassword.isEmpty()) {
return ResponseEntity.status(400).body("๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์ž…๋ ฅ๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.");
}

try {
// ํ˜„์žฌ ๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ
boolean isVerified = userService.verifyPassword(userId, new PasswordDto(currentPassword));
if (!isVerified) {
return ResponseEntity.status(400).body("ํ˜„์žฌ ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์ผ์น˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.");
}

// ๋น„๋ฐ€๋ฒˆํ˜ธ ๋ณ€๊ฒฝ
userService.updatePassword(userId, new PasswordDto(newPassword));
return ResponseEntity.ok("๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์„ฑ๊ณต์ ์œผ๋กœ ๋ณ€๊ฒฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
} catch (Exception e) {
log.error("Unexpected error during password update", e);
return ResponseEntity.status(500).body("์„œ๋ฒ„ ์—๋Ÿฌ ๋ฐœ์ƒ. ๋‚˜์ค‘์— ๋‹ค์‹œ ์‹œ๋„ํ•ด์ฃผ์„ธ์š”.");
}
}
}

}

0 comments on commit fcf8f85

Please sign in to comment.