-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Fix ErrorType * feat: WishCoupon Patch Api * feat: Fix for exception * chore: Change isContainApiPath * feat: Fix to use record * feat: Fix setter method * feat: Fix to record * chore: Fix code style
- Loading branch information
Showing
9 changed files
with
176 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/com/universe/uni/controller/WishCouponController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.universe.uni.controller; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.universe.uni.dto.request.UpdateWishCouponRequestDto; | ||
import com.universe.uni.dto.response.UpdateWishCouponResponseDto; | ||
import com.universe.uni.service.WishCouponService; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/wish") | ||
public class WishCouponController { | ||
|
||
private final WishCouponService wishCouponService; | ||
|
||
@PatchMapping | ||
@ResponseStatus(HttpStatus.OK) | ||
public UpdateWishCouponResponseDto updateWishCoupon( | ||
@RequestBody UpdateWishCouponRequestDto requestDto | ||
) { | ||
return wishCouponService.uploadWishCoupon(requestDto); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/java/com/universe/uni/dto/request/UpdateWishCouponRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.universe.uni.dto.request; | ||
|
||
public record UpdateWishCouponRequestDto(String gameType, String content) { | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/universe/uni/dto/response/UpdateWishCouponResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.universe.uni.dto.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
|
||
import lombok.Builder; | ||
|
||
@JsonPropertyOrder({"id", "image", "content", "isVisible", "isUsed", "usedAt", "gameType"}) | ||
@Builder | ||
public record UpdateWishCouponResponseDto( | ||
Long id, | ||
String image, | ||
String content, | ||
@JsonProperty("isVisible") boolean visible, | ||
@JsonProperty("isUsed") boolean used, | ||
String usedAt, | ||
String gameType | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/com/universe/uni/repository/WishCouponRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.universe.uni.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.universe.uni.domain.GameType; | ||
import com.universe.uni.domain.entity.WishCoupon; | ||
|
||
public interface WishCouponRepository extends JpaRepository<WishCoupon, Long> { | ||
|
||
List<WishCoupon> findByGameTypeAndIsVisibleFalseAndIsUsedFalseAndUsedAtIsNull(GameType gameType); | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/universe/uni/service/WishCouponService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.universe.uni.service; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.universe.uni.domain.GameType; | ||
import com.universe.uni.domain.entity.WishCoupon; | ||
import com.universe.uni.dto.request.UpdateWishCouponRequestDto; | ||
import com.universe.uni.dto.response.UpdateWishCouponResponseDto; | ||
import com.universe.uni.exception.BadRequestException; | ||
import com.universe.uni.exception.dto.ErrorType; | ||
import com.universe.uni.repository.WishCouponRepository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class WishCouponService { | ||
|
||
private final WishCouponRepository wishCouponRepository; | ||
|
||
@Transactional | ||
public UpdateWishCouponResponseDto uploadWishCoupon(UpdateWishCouponRequestDto requestDto) { | ||
GameType gameType = GameType.valueOf(requestDto.gameType()); | ||
List<WishCoupon> wishCouponList = wishCouponRepository.findByGameTypeAndIsVisibleFalseAndIsUsedFalseAndUsedAtIsNull( | ||
gameType); | ||
|
||
if (wishCouponList.isEmpty()) { | ||
throw new BadRequestException(ErrorType.INVALID_REQUEST_METHOD); | ||
} | ||
|
||
WishCoupon wishCoupon = wishCouponList.get(0); | ||
|
||
wishCoupon.updateContent(requestDto.content()); | ||
wishCoupon.makeVisible(); | ||
|
||
return fromWishCoupon(wishCoupon); | ||
} | ||
|
||
private UpdateWishCouponResponseDto fromWishCoupon(WishCoupon wishCoupon) { | ||
String usedAt = wishCoupon.getUsedAt() != null ? wishCoupon.getUsedAt().toString() : null; | ||
|
||
return UpdateWishCouponResponseDto.builder() | ||
.id(wishCoupon.getId()) | ||
.image(wishCoupon.getImage()) | ||
.content(wishCoupon.getContent()) | ||
.visible(wishCoupon.isVisible()) | ||
.used(wishCoupon.isUsed()) | ||
.usedAt(usedAt) | ||
.gameType(String.valueOf(wishCoupon.getGameType())) | ||
.build(); | ||
} | ||
} |