Skip to content

Commit

Permalink
docs: 📝 auth api 문서 추가 (#62)
Browse files Browse the repository at this point in the history
* feat: 몇가지 소소한 수정

* refactor: ♻️ user 디렉토리 구조 수정 (#53)

* hotfix: conflict solve (#55)

* refactor: ♻️ user 디렉토리 구조 수정

* hotfix: conflict solve

* hotfix: 🚑 build error 해결 (#57)

* refactor: ♻️ user 디렉토리 구조 수정

* hotfix: conflict solve

* hotfix: 🚑 sever restart

* fix: 루틴 삭제 기능 수정

* fix: 루틴 삭제 기능 수정

* docs: 📝 auth api 문서 추가 (#61)

* hotfix: server restart

* docs: 📝 auth api 문서 추가

---------

Co-authored-by: gzhan0226 <[email protected]>
  • Loading branch information
LEEJaeHyeok97 and gzhan0226 authored Sep 28, 2024
1 parent 29e084a commit eee170c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.goormdari.domain.routine.application;

import com.amazonaws.services.kms.model.AlreadyExistsException;
import com.amazonaws.services.kms.model.NotFoundException;
import com.goormdari.domain.routine.domain.Routine;
import com.goormdari.domain.routine.dto.request.CompleteRoutineRequest;
Expand All @@ -23,16 +22,10 @@ public class RoutineService {
private final RoutineRepository routineRepository;
private final UserRepository userRepository;

private final S3Service s3Service;
@Transactional
public Message completeRoutine (Long userId, CompleteRoutineRequest completeRoutineRequest, String imgURL) {
User user = userRepository.findById(userId)
.orElseThrow(()->new NotFoundException("User Not Found"));

if(routineRepository.findByRoutineIndexAndUserId(userId, completeRoutineRequest.routineIndex())!= null) {
throw new IllegalStateException("Routine already completed for given index");
}

Routine routine = Routine.builder()
.user(user)
.routineImg(imgURL)
Expand All @@ -54,7 +47,6 @@ public Message deleteRoutineByUserIdAndRoutineIndex (Long userId, Long routineIn
.orElseThrow(()->new NotFoundException("User Not Found"));
Routine routine = routineRepository.findByRoutineIndexAndUserId(userId,routineIndex);
routineRepository.deleteById(routine.getId());
s3Service.deleteImageOnS3(routine.getRoutineImg());
user.updateCurrentStep(user.getCurrentStep()-1);
return Message.builder()
.message("루틴 삭제 성공")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package com.goormdari.domain.user.presentation;

import com.goormdari.domain.user.dto.request.AddUserRequest;
import com.goormdari.domain.user.dto.response.FindCurrentStepResponse;
import com.goormdari.domain.user.dto.response.JwtResponse;
import com.goormdari.domain.user.dto.request.LoginRequest;
import com.goormdari.domain.user.service.UserService;

import com.goormdari.global.payload.ErrorResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand All @@ -14,31 +22,30 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "Authorization", description = "Authorization API")
@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
public class AuthController {

private final UserService userService;

/**
* 회원가입 후 JWT 토큰 발급
*
* @param addUserRequest 회원가입 요청 데이터
* @return JWT 응답
*/
@Operation(summary = "회원가입 후 로그인", description = "회원가입과 로그인을 수행합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "회원가입 성공 ", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = JwtResponse.class))}),
@ApiResponse(responseCode = "400", description = "회원가입 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
})
@PostMapping("/signup")
public ResponseEntity<JwtResponse> registerUser(@Valid @RequestBody AddUserRequest addUserRequest) {
JwtResponse jwtResponse = userService.signupAndLogin(addUserRequest);
return ResponseEntity.status(HttpStatus.CREATED).body(jwtResponse);
}

/**
* 로그인 후 JWT 토큰 발급
*
* @param loginRequest 로그인 요청 데이터
* @return JWT 응답
*/
@Operation(summary = "로그인", description = "로그인을 수행합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "로그인 성공 ", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = JwtResponse.class))}),
@ApiResponse(responseCode = "400", description = "로그인 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
})
@PostMapping("/login")
public ResponseEntity<JwtResponse> authenticateUser(@Valid @RequestBody LoginRequest loginRequest) {
JwtResponse jwtResponse = userService.loginAndGetToken(loginRequest);
Expand Down

0 comments on commit eee170c

Please sign in to comment.