-
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] Shoot 생성 API 구현, 상태 변경 수정 (#64)
* feat : shootStatus 변경 수정 * feat : shootStatus 구현 * feat : Shoot 생성, 태그 추출 구현 * feat : ShootStatusService 분리 * feat : ShootRepository 정리 * feat : figmaService 수정
- Loading branch information
Showing
10 changed files
with
154 additions
and
37 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
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
42 changes: 37 additions & 5 deletions
42
src/main/java/gigedi/dev/domain/shoot/application/ShootStatusService.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,24 +1,56 @@ | ||
package gigedi.dev.domain.shoot.application; | ||
|
||
import jakarta.transaction.Transactional; | ||
import java.util.EnumSet; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import gigedi.dev.domain.auth.domain.Figma; | ||
import gigedi.dev.domain.shoot.dao.ShootStatusRepository; | ||
import gigedi.dev.domain.shoot.domain.Shoot; | ||
import gigedi.dev.domain.shoot.domain.ShootStatus; | ||
import gigedi.dev.domain.shoot.domain.Status; | ||
import gigedi.dev.domain.shoot.dto.response.GetShootResponse; | ||
import gigedi.dev.global.error.exception.CustomException; | ||
import gigedi.dev.global.error.exception.ErrorCode; | ||
import gigedi.dev.global.util.FigmaUtil; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ShootStatusService { | ||
private final ShootStatusRepository shootStatusRepository; | ||
private final FigmaUtil figmaUtil; | ||
private final ShootService shootService; | ||
|
||
@Transactional | ||
public ShootStatus getShootStatusByShootId(Long shootId) { | ||
return shootStatusRepository | ||
.findByShoot_ShootId(shootId) | ||
.orElseThrow(() -> new CustomException(ErrorCode.SHOOT_STATUS_NOT_FOUND)); | ||
public GetShootResponse updateShootStatus(Long shootId, Status newStatus) { | ||
final Figma figma = figmaUtil.getCurrentFigma(); | ||
validateStatus(newStatus); | ||
Shoot shoot = shootService.findValidShoot(shootId); | ||
ShootStatus shootStatus = | ||
shootStatusRepository | ||
.findByShoot_ShootIdAndFigma_FigmaId(shootId, figma.getFigmaId()) | ||
.orElseGet( | ||
() -> { | ||
ShootStatus newShootStatus = | ||
ShootStatus.createShootStatus(newStatus, figma, shoot); | ||
return shootStatusRepository.save(newShootStatus); | ||
}); | ||
|
||
if (shootStatus.getStatus() != newStatus) { | ||
shootStatus.updateStatus(newStatus); | ||
} | ||
return GetShootResponse.of( | ||
shoot, | ||
shootService.getUsersByStatus(shoot, Status.YET), | ||
shootService.getUsersByStatus(shoot, Status.DOING), | ||
shootService.getUsersByStatus(shoot, Status.DONE)); | ||
} | ||
|
||
private void validateStatus(Status status) { | ||
if (status == null || !EnumSet.allOf(Status.class).contains(status)) { | ||
throw new CustomException(ErrorCode.INVALID_STATUS); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/gigedi/dev/domain/shoot/application/ShootTagService.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 gigedi.dev.domain.shoot.application; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import gigedi.dev.domain.auth.domain.Figma; | ||
import gigedi.dev.domain.figma.application.FigmaService; | ||
import gigedi.dev.domain.shoot.dao.ShootTagRepository; | ||
import gigedi.dev.domain.shoot.domain.Shoot; | ||
import gigedi.dev.domain.shoot.domain.ShootTag; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ShootTagService { | ||
private final ShootTagRepository shootTagRepository; | ||
private final FigmaService figmaService; | ||
|
||
public void createShootTags(Shoot shoot, List<String> tags) { | ||
tags.forEach( | ||
tag -> { | ||
Figma figma = figmaService.findByTag(tag); | ||
if (figma != null) { | ||
ShootTag shootTag = ShootTag.createShootTag(shoot, figma); | ||
shootTagRepository.save(shootTag); | ||
} | ||
}); | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
src/main/java/gigedi/dev/domain/shoot/dao/ShootTagRepository.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,9 @@ | ||
package gigedi.dev.domain.shoot.dao; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import gigedi.dev.domain.shoot.domain.ShootTag; | ||
|
||
@Repository | ||
public interface ShootTagRepository extends JpaRepository<ShootTag, Long> {} |
3 changes: 3 additions & 0 deletions
3
src/main/java/gigedi/dev/domain/shoot/dto/request/CreateShootRequest.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,3 @@ | ||
package gigedi.dev.domain.shoot.dto.request; | ||
|
||
public record CreateShootRequest(String content) {} |
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,22 @@ | ||
package gigedi.dev.global.util; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class ShootUtil { | ||
private static final String SPACE_DELIMITER = "\\s+"; | ||
private static final String TAG_PREFIX = "@"; | ||
|
||
public static List<String> extractTags(String content) { | ||
|
||
if (content == null || content.isEmpty()) { | ||
return Collections.emptyList(); | ||
} | ||
return Arrays.stream(content.split(SPACE_DELIMITER)) | ||
.filter(word -> word.startsWith(TAG_PREFIX)) | ||
.map(word -> word.substring(1)) | ||
.collect(Collectors.toList()); | ||
} | ||
} |