-
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.
- Loading branch information
Showing
8 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/main/java/com/nice/petudio/api/controller/gift/GiftController.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,26 @@ | ||
package com.nice.petudio.api.controller.gift; | ||
|
||
import com.nice.petudio.api.controller.gift.dto.GiftGenerateResponse; | ||
import com.nice.petudio.api.controller.gift.service.GiftCodeGenerator; | ||
import com.nice.petudio.api.controller.gift.service.GiftCommandService; | ||
import com.nice.petudio.api.controller.gift.service.GiftQueryService; | ||
import com.nice.petudio.api.dto.ApiResponse; | ||
import com.nice.petudio.common.auth.admin.Admin; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1") | ||
@RequiredArgsConstructor | ||
public class GiftController { | ||
private final GiftCommandService giftCommandService; | ||
private final GiftQueryService giftQueryService; | ||
|
||
@Admin | ||
@PostMapping("/gift/generate") | ||
public ApiResponse<GiftGenerateResponse> generateGift() { | ||
return ApiResponse.success(giftCommandService.generateGift()); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/nice/petudio/api/controller/gift/dto/GiftGenerateResponse.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,7 @@ | ||
package com.nice.petudio.api.controller.gift.dto; | ||
|
||
public record GiftGenerateResponse(String giftCode) { | ||
public static GiftGenerateResponse from(String giftCode) { | ||
return new GiftGenerateResponse(giftCode); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/nice/petudio/api/controller/gift/service/GiftCodeGenerator.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.nice.petudio.api.controller.gift.service; | ||
|
||
import java.util.UUID; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Slf4j | ||
public class GiftCodeGenerator { | ||
|
||
public String generate() { | ||
String giftCode = UUID.randomUUID().toString(); | ||
giftCode = giftCode.toUpperCase(); | ||
giftCode = giftCode.replace("-", ""); | ||
|
||
log.info(String.format("[GIFT CODE 생성] %s", giftCode)); | ||
return giftCode; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/nice/petudio/api/controller/gift/service/GiftCommandService.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,24 @@ | ||
package com.nice.petudio.api.controller.gift.service; | ||
|
||
import com.nice.petudio.api.controller.gift.dto.GiftGenerateResponse; | ||
import com.nice.petudio.domain.gift.Gift; | ||
import com.nice.petudio.domain.gift.repository.GiftRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class GiftCommandService { | ||
private final GiftRepository giftRepository; | ||
private final GiftCodeGenerator giftCodeGenerator; | ||
|
||
public GiftGenerateResponse generateGift() { | ||
String giftCode = giftCodeGenerator.generate(); | ||
Gift gift = Gift.newInstance(giftCode); | ||
|
||
giftRepository.save(gift); | ||
return GiftGenerateResponse.from(giftCode); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/nice/petudio/api/controller/gift/service/GiftQueryService.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,11 @@ | ||
package com.nice.petudio.api.controller.gift.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class GiftQueryService { | ||
} |
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
3 changes: 2 additions & 1 deletion
3
src/main/java/com/nice/petudio/domain/gift/repository/GiftRepository.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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
package com.nice.petudio.domain.gift.repository; | ||
|
||
import com.nice.petudio.domain.concept.Concept; | ||
import com.nice.petudio.domain.gift.Gift; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface GiftRepository extends GiftRepositoryCustom, JpaRepository<Concept, Long> { | ||
public interface GiftRepository extends GiftRepositoryCustom, JpaRepository<Gift, Long> { | ||
} |
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