-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat] 한판승부 생성하기 API 구현 #33
Changes from 5 commits
b59f1ec
4ce55d7
54a44f1
7e7972e
82e2f29
c1d60ce
f93f6e4
3971fe6
1c71ef3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.universe.uni.controller; | ||
|
||
import javax.validation.Valid; | ||
|
||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.universe.uni.dto.CreateShortGameRequestDto; | ||
import com.universe.uni.dto.CreateShortGameResponseDto; | ||
import com.universe.uni.service.GameService; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api") | ||
public class ShortGameController { | ||
|
||
private final GameService gameService; | ||
|
||
@PostMapping("/game/short") | ||
public CreateShortGameResponseDto createShortGame(@RequestBody @Valid final CreateShortGameRequestDto createShortGameRequestDto) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 나 |
||
return gameService.createShortGame(createShortGameRequestDto); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
import java.util.Objects; | ||
|
||
public enum GameResult { | ||
WIN, LOSE, DRAW; | ||
WIN, LOSE, DRAW, UNDECIDED; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 고뇌의 흔적이 보입니다... |
||
|
||
public static GameResult findMatchResultBy(String gameResultName) { | ||
return Arrays.stream(values()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,4 +41,9 @@ public class Game { | |
|
||
@Column(name = "finish_at") | ||
private LocalDateTime finishAt; | ||
|
||
public Game(Couple couple) { | ||
this.couple = couple; | ||
this.enable = Boolean.TRUE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그냥 true랑 다른 게 있나용???? |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.universe.uni.dto; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class CreateShortGameRequestDto { | ||
|
||
@NotNull | ||
private Long missionCategoryId; | ||
|
||
@NotNull | ||
private String wishContent; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.universe.uni.dto; | ||
|
||
import com.universe.uni.domain.entity.RoundMission; | ||
import com.universe.uni.domain.entity.ShortGame; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class CreateShortGameResponseDto { | ||
private ShortGameVO shortGame; | ||
private RoundMissionVO roundMission; | ||
|
||
public static CreateShortGameResponseDto of(ShortGame shortGame, RoundMission roundMission) { | ||
return new CreateShortGameResponseDto(new ShortGameVO(shortGame), new RoundMissionVO(roundMission)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.universe.uni.dto; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
||
import com.universe.uni.domain.GameResult; | ||
import com.universe.uni.domain.entity.MissionCategory; | ||
import com.universe.uni.domain.entity.MissionContent; | ||
import com.universe.uni.domain.entity.RoundMission; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class RoundMissionVO { | ||
private long roundMissionId; | ||
private MissionContent missionContent; | ||
private GameResult result; | ||
private GameResult finalResult; | ||
private LocalDateTime updatedAt; | ||
|
||
public RoundMissionVO(RoundMission roundMission){ | ||
this.roundMissionId = roundMission.getId(); | ||
this.missionContent = roundMission.getMissionContent(); | ||
this.result = roundMission.getResult(); | ||
this.finalResult = roundMission.getFinalResult(); | ||
this.updatedAt = roundMission.getUpdatedAt(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.universe.uni.dto; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import com.universe.uni.domain.entity.ShortGame; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class ShortGameVO { | ||
private Long id; | ||
private Boolean enable; | ||
private LocalDateTime finishAt; | ||
|
||
public ShortGameVO(ShortGame shortGame) { | ||
this.id = shortGame.getId(); | ||
this.enable = shortGame.getEnable(); | ||
this.finishAt = shortGame.getFinishAt(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.universe.uni.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.universe.uni.domain.entity.Couple; | ||
import com.universe.uni.domain.entity.Game; | ||
|
||
public interface GameRepository extends JpaRepository<Game, Long> { | ||
|
||
boolean existsByCoupleAndEnable(Couple couple, boolean enable); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.universe.uni.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.universe.uni.domain.entity.MissionCategory; | ||
|
||
public interface MissionCategoryRepository extends JpaRepository<MissionCategory, Long> { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.universe.uni.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.universe.uni.domain.entity.MissionCategory; | ||
import com.universe.uni.domain.entity.MissionContent; | ||
|
||
public interface MissionContentRepository extends JpaRepository<MissionContent, Long> { | ||
List<MissionContent> findByMissionCategory(MissionCategory missionCategory); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.universe.uni.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.universe.uni.domain.entity.RoundGame; | ||
|
||
public interface RoundGameRepository extends JpaRepository<RoundGame, Long> { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.universe.uni.repository; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.universe.uni.domain.entity.RoundGame; | ||
import com.universe.uni.domain.entity.RoundMission; | ||
import com.universe.uni.domain.entity.User; | ||
|
||
public interface RoundMissionRepository extends JpaRepository<RoundMission, Long> { | ||
Optional<RoundMission> findByRoundGameAndUser(RoundGame roundGame, User user); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
package com.universe.uni.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.universe.uni.domain.entity.Couple; | ||
import com.universe.uni.domain.entity.User; | ||
|
||
public interface UserRepository extends JpaRepository<User, Long> { | ||
List<User> findByCouple(Couple couple); | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
game관련이면
/api/game
으로 둬도 될거같은디There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
애초에 컨트롤러 명 자체도 shortGame 이기 때문에 별도의 /game 에 대한 endpoint 를 다루지 않는다면
컨트롤러 이름과 매칭되는 역할과 endpoint Path 를 주면 좋을 것 같아요:)