Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
wldns2577 committed Nov 25, 2023
2 parents b82b150 + 1b6f44e commit 6f81f38
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ public enum BaseResponseStatus implements BaseResponseStatusImpl {
*/
INPUT_INVALID_VALUE(HttpStatus.BAD_REQUEST, "REQUEST_ERROR_001", "잘못된 요청입니다."),
INVALID_ENUM(HttpStatus.BAD_REQUEST, "REQUEST_ERROR_002", "Enum 타입으로 변경할 수 없습니다."),
CANNOT_FIND_USER(HttpStatus.NOT_FOUND, "REQUEST_ERROR_003", "요청한 사용자를 찾을 수 없습니다."),

// Product
CRAWLING_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "PRODUCT_ERROR_001", "크롤링 서버와의 연결에 실패했습니다."),
PRODUCT_INDEX_OUT_OF_RANGE(HttpStatus.BAD_REQUEST, "PRODUCT_ERROR_002", "제품 리스트의 끝입니다."),


/**
* 500 : 응답 실패
*/
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/dev/neordinary/zero/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package dev.neordinary.zero.controller;

import dev.neordinary.zero.base.BaseResponse;
import dev.neordinary.zero.dto.*;
import dev.neordinary.zero.service.NoteService;
import dev.neordinary.zero.service.UserService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RequiredArgsConstructor
Expand All @@ -17,23 +17,23 @@ public class UserController {
private final NoteService noteService;

@PostMapping("")
public UserResponse.UserJoinRes join(@RequestBody UserRequest.UserJoin userJoin) {
return userService.join(userJoin);
public ResponseEntity<BaseResponse> join(@RequestBody UserRequest.UserJoin userJoin) {
return BaseResponse.toResponseEntityContainsResult(userService.join(userJoin));
}

@GetMapping("/{userId}")
public UserResponse.UserBeverageRes showUserBeverage(@PathVariable Long userId) {
return userService.showUserBeverage(userId);
public ResponseEntity<BaseResponse> showUserBeverage(@PathVariable Long userId) {
return BaseResponse.toResponseEntityContainsResult(userService.showUserBeverage(userId));
}

@PostMapping("/{userId}/note")
public NoteResponse.NoteJoinRes createNote(@PathVariable Long userId, @RequestBody NoteRequest.NoteJoin noteJoin) {
return noteService.createNote(userId, noteJoin);
public ResponseEntity<BaseResponse> createNote(@PathVariable Long userId, @RequestBody NoteRequest.NoteJoin noteJoin) {
return BaseResponse.toResponseEntityContainsResult(noteService.createNote(userId, noteJoin));
}

@GetMapping("/{userId}/purpose")
public int getPurpose(@PathVariable Long userId) {
return userService.getPurpose(userId);
public ResponseEntity<BaseResponse> getPurpose(@PathVariable Long userId) {
return BaseResponse.toResponseEntityContainsResult(userService.getPurpose(userId));
}

// @PostMapping("/api/v2/user")
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/dev/neordinary/zero/service/NoteService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.neordinary.zero.service;

import dev.neordinary.zero.base.BaseException;
import dev.neordinary.zero.base.BaseResponseStatus;
import dev.neordinary.zero.converter.NoteConverter;
import dev.neordinary.zero.domain.NoteEntity;
import dev.neordinary.zero.domain.NoteRepository;
Expand All @@ -18,7 +20,7 @@ public class NoteService {
private final UserRepository userRepository;

public NoteResponse.NoteJoinRes createNote(Long userId, NoteRequest.NoteJoin noteJoin) {
UserEntity currentUser = userRepository.findById(userId).orElseThrow(() -> null);
UserEntity currentUser = userRepository.findById(userId).orElseThrow(() -> new BaseException(BaseResponseStatus.CANNOT_FIND_USER));
NoteEntity newNote = NoteConverter.toNote(noteJoin, currentUser);
return NoteConverter.toNoteDto(noteRepository.save(newNote));
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/dev/neordinary/zero/service/UserService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package dev.neordinary.zero.service;

import dev.neordinary.zero.base.BaseException;
import dev.neordinary.zero.base.BaseResponse;
import dev.neordinary.zero.base.BaseResponseStatus;
import dev.neordinary.zero.converter.UserConverter;
import dev.neordinary.zero.domain.UserEntity;
import dev.neordinary.zero.domain.UserRepository;
Expand All @@ -23,12 +26,12 @@ public UserResponse.UserJoinRes join(UserRequest.UserJoin userJoin) {

@Transactional
public UserResponse.UserBeverageRes showUserBeverage(Long userId) {
UserEntity userEntity = userRepository.findById(userId).orElseThrow(() -> null);
UserEntity userEntity = userRepository.findById(userId).orElseThrow(() -> new BaseException(BaseResponseStatus.CANNOT_FIND_USER));
return UserConverter.toUserBeverageDto(userEntity);
}

public int getPurpose(Long userId) {
UserEntity userEntity = userRepository.findById(userId).orElseThrow(() -> null);
UserEntity userEntity = userRepository.findById(userId).orElseThrow(() -> new BaseException(BaseResponseStatus.CANNOT_FIND_USER));
return userEntity.getMaxSugar().intValue();
}

Expand Down

0 comments on commit 6f81f38

Please sign in to comment.