Skip to content

Commit

Permalink
feat : post 요청에 대해 적절한 반환값을 돌려주도록 변경
Browse files Browse the repository at this point in the history
(CC-120)
  • Loading branch information
j2noo committed Aug 7, 2024
1 parent 8cd2236 commit 26a451b
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ai.softeer.caecae.global.enums.SuccessCode;
import ai.softeer.caecae.racinggame.domain.dto.request.RegisterRacingGameInfoRequestDto;
import ai.softeer.caecae.racinggame.domain.dto.response.RacingGameInfoResponseDto;
import ai.softeer.caecae.racinggame.domain.dto.response.RegisterRacingGameInfoResponseDto;
import ai.softeer.caecae.racinggame.service.RacingGameInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -34,8 +35,8 @@ public ResponseEntity<SuccessResponse<RacingGameInfoResponseDto>> getRacingGameI
* @return
*/
@PostMapping("/racing/period")
public ResponseEntity<SuccessResponse<Object>> registerRacingGame(@RequestBody RegisterRacingGameInfoRequestDto req) {
racingGameService.registerRacingGameInfo(req);
return SuccessResponse.of(SuccessCode.RACING_GAME_CREATED);
public ResponseEntity<SuccessResponse<RegisterRacingGameInfoResponseDto>> registerRacingGame(@RequestBody RegisterRacingGameInfoRequestDto req) {
RegisterRacingGameInfoResponseDto res = racingGameService.registerRacingGameInfo(req);
return SuccessResponse.of(SuccessCode.RACING_GAME_CREATED, res);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public abstract class BaseResponse {
// 커스텀 응답 코드 종류
// TODO : 커스텀 응답코드 문서화
private int responseCode;

// 응답 정보를 담은 메시지
private String message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.time.LocalDateTime;

// 레이싱게임 정보(기간, 인원수)를 등록하는 requestDto
@Builder
public record RegisterRacingGameInfoRequestDto(
LocalDateTime startTime,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ai.softeer.caecae.racinggame.domain.dto.response;

import lombok.Builder;

import java.time.LocalDateTime;

// 레이싱게임 정보(기간, 인원수)를 등록하는 requestDto
@Builder
public record RegisterRacingGameInfoResponseDto(
LocalDateTime startTime,
LocalDateTime endTime,
int numberOfWinners
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import lombok.Builder;

// 사용자가 레이싱게임 결과를 등록하기 위한 RequestDto
// 사용자가 레이싱게임 결과를 등록하기 위한 ResponseDto
@Builder
public record RegisterRacingGameResultResponseDto(
// 시용자가 커스텀옵션을 이전에 선택하였는지 여부
Boolean isOptionSelected
Boolean isOptionSelected,
double distance
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ public Boolean isOptionSelected() {
public void updateDistance(double distance) {
this.distance = distance;
}

// 엔티티의 커스텀 옵션 정보를 저장하는 메서드
public void setSelection(Integer selection) {
this.selection = selection;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ public class RacingGameInfoRepository {
private final RedisTemplate<String, Object> redisTemplate;

// 레디스에 저장하는 로직
public void save(RacingGameInfo gameInfo) {
public RacingGameInfo save(RacingGameInfo gameInfo) {
redisTemplate.opsForValue().set(KEY, gameInfo);
return gameInfo;
}

// 레디스에 저장된 객체를 가져오는 로직
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ai.softeer.caecae.global.enums.ErrorCode;
import ai.softeer.caecae.racinggame.domain.dto.request.RegisterRacingGameInfoRequestDto;
import ai.softeer.caecae.racinggame.domain.dto.response.RacingGameInfoResponseDto;
import ai.softeer.caecae.racinggame.domain.dto.response.RegisterRacingGameInfoResponseDto;
import ai.softeer.caecae.racinggame.domain.entity.RacingGameInfo;
import ai.softeer.caecae.racinggame.domain.exception.RacingGameException;
import ai.softeer.caecae.racinggame.repository.RacingGameInfoRepository;
Expand Down Expand Up @@ -40,17 +41,22 @@ public RacingGameInfoResponseDto getRacingGameInfo() {
*
* @param req 입력한 레이싱게임 정보
*/
public void registerRacingGameInfo(RegisterRacingGameInfoRequestDto req) {
public RegisterRacingGameInfoResponseDto registerRacingGameInfo(RegisterRacingGameInfoRequestDto req) {
RacingGameInfo racingGameInfo = RacingGameInfo.builder()
.startTime(req.startTime())
.endTime(req.endTime())
.numberOfWinners(req.numberOfWinners())
.build();

// TODO : 존재하면 저장하지 않거나 업데이트 하거나 에러를 던져야할 지 논의하기. 현재는 덮어씌워짐
racingGameInfoRepository.save(racingGameInfo);
RacingGameInfo saved = racingGameInfoRepository.save(racingGameInfo);
log.info("saved racingGameInfo: {}", racingGameInfo.getStartTime(), racingGameInfo.getEndTime());

return RegisterRacingGameInfoResponseDto.builder()
.startTime(saved.getStartTime())
.endTime(saved.getEndTime())
.numberOfWinners(saved.getNumberOfWinners())
.build();
}

/**
Expand Down

0 comments on commit 26a451b

Please sign in to comment.