Skip to content

Commit

Permalink
FEAT:"게임 기능 추가"
Browse files Browse the repository at this point in the history
  • Loading branch information
tioon committed Dec 19, 2023
1 parent b8898b0 commit 7e6aa8f
Show file tree
Hide file tree
Showing 35 changed files with 228 additions and 143 deletions.
2 changes: 2 additions & 0 deletions Gserver/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-websocket'
implementation 'org.mapstruct:mapstruct:1.4.2.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'
runtimeOnly 'com.h2database:h2'


}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public enum ErrorCode {
NOT_EXIST_PARTICIPATION(400,"AU_004", "해당 플레이어가 존재하지 않습니다."),
NOT_EXIST_HOST(400,"AU_005", "방장이 존재하지 않습니다."),
NOT_EXIST_QUESTION(500,"AU_006", "기본 질문이 존재하지 않습니다."),
EMPTY_ROOM(500,"AU_007","해당 방의 플레이어가 존재하지 않습니다.")
EMPTY_ROOM(500,"AU_007","해당 방의 플레이어가 존재하지 않습니다."),
ALREADY_GAME_START(400,"AU_008","이미 게임 진행 중인 방입니다."),
NOT_EXIT_ROOM(400,"AU_009","게임 진행중엔 나갈 수 없습니다.")
;

private final int status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
@ControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(Exception.class)
/*@ExceptionHandler(Exception.class)
protected ResponseEntity<String> handleException(Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body("서버에 예상치 못한 에러가 발생하였습니다.");
}
}*/

@ExceptionHandler(CustomException.class)
protected ResponseEntity<ErrorResponse> handleCustomException(CustomException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.example.Gserver.Main.domain.game.Dto.RequestDto.*;
import com.example.Gserver.Main.domain.game.Dto.ResponseDto.AnswersResponseDto;
import com.example.Gserver.Main.domain.game.Dto.ResponseDto.CorrectResultResponseDto;
import com.example.Gserver.Main.domain.game.Dto.ResponseDto.ItResponseDto;
import com.example.Gserver.Main.domain.game.Dto.ResponseDto.QuestionResponseDto;
import com.example.Gserver.Main.domain.game.Service.GameService;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -17,7 +18,7 @@


@RestController
@RequestMapping("/Room")
@RequestMapping("/Game")
public class GameController {

GameService gameService;
Expand Down Expand Up @@ -51,8 +52,8 @@ public ResponseEntity<List<AnswersResponseDto>> GetAnswer(@RequestBody RoundDto

@RequestMapping(value = "ChangeIt",method = RequestMethod.POST)
@ApiOperation(value="술래 체인지", notes="방넘버(String)")
public ResponseEntity<ItChangeDto> ChangeIt(@RequestBody RoomDto roomDTO){
ItChangeDto itChangeDto = gameService.changeIt(roomDTO);
public ResponseEntity<ItResponseDto> ChangeIt(@RequestBody RoomDto roomDTO){
ItResponseDto itChangeDto = gameService.changeIt(roomDTO);

return new ResponseEntity<>(itChangeDto, HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.example.Gserver.Main.domain.game.Dto.RequestDto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.validation.constraints.NotNull;

@Getter
@Setter

@AllArgsConstructor
public class CustomQuestionDto {
@NotNull
String roomNumber;
String roomId;

@NotNull
String question;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@


import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
public class ParticipationAnswerDto {
String roomNumber;
String roomId;
Long playerId;
int roundCount;
String answer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@Getter
@Setter
public class ParticipationAnswerListDto {
String roomNumber;
String roomId;
Long playerId;
int answerRound;
Long[] playerIdList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@Setter
public class ParticipationDto {
@NotNull
String roomNumber;
String roomId;

@NotNull
int playerId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
@Setter
public class RoomDto {
@NotNull
String roomNumber;
String roomId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
@Setter
public class RoomRequestDto {
@NotNull
String roomNumber;
String roomId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
@Getter
@Setter
public class RoundDto {
String roomNumber;
String roomId;
int round;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.Gserver.Main.domain.game.Dto.ResponseDto;


import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.validation.constraints.NotNull;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class ItResponseDto {
Long playerId;

String nickName;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.Gserver.Main.domain.game.Dto.ResponseDto;


import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

Expand All @@ -9,10 +10,9 @@

@Getter
@Setter
@AllArgsConstructor
public class QuestionResponseDto {
@NotNull
String roomNumber;
String roomId;

@NotNull
String question;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,53 @@


import com.example.Gserver.Main.domain.game.Dto.RequestDto.CustomQuestionDto;
import com.example.Gserver.Main.domain.game.Dto.RequestDto.ItChangeDto;
import com.example.Gserver.Main.domain.game.Dto.RequestDto.ParticipationAnswerDto;
import com.example.Gserver.Main.domain.game.Dto.ResponseDto.CorrectResultResponseDto;
import com.example.Gserver.Main.domain.game.Dto.ResponseDto.ItResponseDto;
import com.example.Gserver.Main.domain.game.Dto.ResponseDto.QuestionResponseDto;
import com.example.Gserver.Main.domain.game.Model.CustomQuestion;
import com.example.Gserver.Main.domain.game.Model.DefaultQuestion;
import com.example.Gserver.Main.domain.game.Model.PlayerAnswer;
import com.example.Gserver.Main.domain.participate.Dto.ResponseDto.ParticipationResponseDto;
import com.example.Gserver.Main.domain.participate.Model.Player;
import com.example.Gserver.Main.domain.room.Model.Room;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

@Mapper
@Mapper(componentModel = "spring")
public interface GameMapper {

@Mapping(target = "player", source = "player")
@Mapping(target = "roundCount", source = "participationAnswerDto.roundCount")
@Mapping(target = "answerRound", source = "participationAnswerDto.roundCount")
@Mapping(target = "answer", source = "participationAnswerDto.answer")
PlayerAnswer toPlaterAnswer (Player player, ParticipationAnswerDto participationAnswerDto);
PlayerAnswer toPlayerAnswer (Player player, ParticipationAnswerDto participationAnswerDto);


@Mapping(target = "room", source = "room")
@Mapping(target = "customQuestion", source = "customQuestionDto.question")
CustomQuestion toCustomQuestion (Room room, CustomQuestionDto customQuestionDto);
@Mappings({
@Mapping(target = "room", source = "room"),
@Mapping(target = "customQuestion", source = "customQuestionDto.question")
})
CustomQuestion toCustomQuestion(Room room,CustomQuestionDto customQuestionDto);




@Mapping(target = "roomNumber", source = "room.roomNumber")
@Mapping(target = "question", source = "question")
QuestionResponseDto toQuestionResponse (Room room , String question);

@Mapping(target = "roomNumber", source = "roomID")
@Mapping(target = "nickName", source = "participation.nickName")
ParticipationResponseDto toParticipationResponse (Room room);
@Mappings({
@Mapping(target = "roomId", source = "room.roomId"),
@Mapping(target = "question", source = "defaultQuestion.defaultQuestion")
})
QuestionResponseDto toQuestionResponse (Room room , DefaultQuestion defaultQuestion);


QuestionResponseDto toQuestionResponse(Room room, String question);

@Mapping(target = "correctAnswer", source = "correctAnswer")
CorrectResultResponseDto toCorrectResultResponse (int correctAnswer);
CorrectResultResponseDto toCorrectResultResponse (Integer correctAnswer);


@Mapping(target = "playerId", source = "playerId")
@Mapping(target = "nickName", source = "nickName")
ItChangeDto toItChangeDto (Long playerId, String nickName);
@Mapping(target = "playerId", source = "player.playerId")
@Mapping(target = "nickName", source = "player.nickName")
ItResponseDto toItResponseDto (Player player);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@


import com.example.Gserver.Main.domain.room.Model.Room;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;



@Entity
@Data
@Table
@NoArgsConstructor
@AllArgsConstructor
public class CustomQuestion {


Expand All @@ -25,4 +31,5 @@ public class CustomQuestion {
@Column(name="CUSTOM_QUESTION")
private String customQuestion;


}
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
package com.example.Gserver.Main.domain.game.Model;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.Id;

import javax.persistence.*;

@Entity
@Table
@AllArgsConstructor
@Getter
@Setter
@NoArgsConstructor
public class DefaultQuestion {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "DEFAULT_QUESTION_ID")
private int id;
private int defaultQuestionId;

@Column(name = "DEFAULT_QUESTION")
private String question;
private String defaultQuestion;

public DefaultQuestion(String question) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import javax.persistence.*;
import java.io.Serializable;
import java.util.stream.DoubleStream;

@Entity
@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public interface DefaultQuestionRepo extends JpaRepository<DefaultQuestion,Strin

int countBy();

String findQuestionById(int randomNumber);
DefaultQuestion findByDefaultQuestionId(int defaultQuestionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
@Repository
public interface PlayerAnswerRepo extends JpaRepository<PlayerAnswer,Long> {

List<PlayerAnswer> findByPlayerAndRoundCount(Player player, int roundCount);


PlayerAnswer findByPlayerAndAnswerRound(Player currentPlayer, int answerRound);
Expand Down
Loading

0 comments on commit 7e6aa8f

Please sign in to comment.