Skip to content

Commit

Permalink
Merge branch 'develop_back_core' into feat/announcement-B-#576
Browse files Browse the repository at this point in the history
  • Loading branch information
GaBaljaintheroom authored Jul 28, 2024
2 parents 787faf3 + 4f4ff26 commit d74a849
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import java.time.ZonedDateTime;
import org.springframework.http.ResponseEntity;
import site.timecapsulearchive.core.domain.capsuleskin.data.reqeust.CapsuleSkinCreateRequest;
import site.timecapsulearchive.core.domain.capsuleskin.data.response.CapsuleSkinDeleteResultResponse;
import site.timecapsulearchive.core.domain.capsuleskin.data.response.CapsuleSkinSearchPageResponse;
import site.timecapsulearchive.core.domain.capsuleskin.data.response.CapsuleSkinStatusResponse;
import site.timecapsulearchive.core.domain.capsuleskin.data.response.CapsuleSkinsSliceResponse;
import site.timecapsulearchive.core.global.common.response.ApiSpec;
import site.timecapsulearchive.core.global.error.ErrorResponse;

public interface CapsuleSkinApi {

Expand Down Expand Up @@ -74,7 +78,8 @@ ResponseEntity<ApiSpec<CapsuleSkinsSliceResponse>> getCapsuleSkins(
),
@ApiResponse(
responseCode = "500",
description = "외부 API 요청 실패"
description = "외부 API 요청 실패",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
)
})
ResponseEntity<ApiSpec<CapsuleSkinStatusResponse>> createCapsuleSkin(
Expand All @@ -100,17 +105,24 @@ ResponseEntity<ApiSpec<String>> updateCapsuleSkin(

@Operation(
summary = "캡슐 스킨 삭제",
description = "사용자가 소유한 캡슐 스킨을 삭제한다.",
description = "사용자가 소유한 캡슐 스킨을 삭제한다. 캡슐에 사용되는 경우 삭제되지 않는다.",
security = {@SecurityRequirement(name = "user_token")},
tags = {"capsule skin"}
)
@ApiResponses(value = {
@ApiResponse(
responseCode = "204",
responseCode = "200",
description = "처리 완료"
),
@ApiResponse(
responseCode = "404",
description = "캡슐 스킨을 찾을 수 없을 때 발생한다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
)
})
ResponseEntity<ApiSpec<String>> deleteCapsuleSkin(
ResponseEntity<ApiSpec<CapsuleSkinDeleteResultResponse>> deleteCapsuleSkin(
Long memberId,

@Parameter(in = ParameterIn.PATH, description = "캡슐 스킨 아이디", required = true)
Long capsuleSkinId
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import site.timecapsulearchive.core.domain.capsuleskin.data.dto.CapsuleSkinDeleteResultDto;
import site.timecapsulearchive.core.domain.capsuleskin.data.mapper.CapsuleSkinMapper;
import site.timecapsulearchive.core.domain.capsuleskin.data.reqeust.CapsuleSkinCreateRequest;
import site.timecapsulearchive.core.domain.capsuleskin.data.response.CapsuleSkinDeleteResultResponse;
import site.timecapsulearchive.core.domain.capsuleskin.data.response.CapsuleSkinSearchPageResponse;
import site.timecapsulearchive.core.domain.capsuleskin.data.response.CapsuleSkinStatusResponse;
import site.timecapsulearchive.core.domain.capsuleskin.data.response.CapsuleSkinsSliceResponse;
Expand Down Expand Up @@ -85,9 +87,18 @@ public ResponseEntity<ApiSpec<String>> updateCapsuleSkin(

@DeleteMapping(value = "/{capsule_skin_id}")
@Override
public ResponseEntity<ApiSpec<String>> deleteCapsuleSkin(
public ResponseEntity<ApiSpec<CapsuleSkinDeleteResultResponse>> deleteCapsuleSkin(
@AuthenticationPrincipal final Long memberId,
@PathVariable(name = "capsule_skin_id") final Long capsuleSkinId
) {
return null;
CapsuleSkinDeleteResultDto capsuleSkinDeleteResultDto = capsuleSkinService.deleteCapsuleSkin(
memberId, capsuleSkinId);

return ResponseEntity.ok(
ApiSpec.success(
SuccessCode.SUCCESS,
CapsuleSkinDeleteResultResponse.createOf(capsuleSkinDeleteResultDto)
)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package site.timecapsulearchive.core.domain.capsuleskin.data.dto;

import lombok.Getter;

@Getter
public enum CapsuleSkinDeleteResult {
FAIL, SUCCESS
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package site.timecapsulearchive.core.domain.capsuleskin.data.dto;

public record CapsuleSkinDeleteResultDto(
CapsuleSkinDeleteResult capsuleSkinDeleteResult,
String message
) {

public static CapsuleSkinDeleteResultDto fail() {
return new CapsuleSkinDeleteResultDto(CapsuleSkinDeleteResult.FAIL, "캡슐 스킨이 존재하지 않거나 캡슐에 사용되고 있습니다.");
}

public static CapsuleSkinDeleteResultDto success() {
return new CapsuleSkinDeleteResultDto(CapsuleSkinDeleteResult.SUCCESS, "캡슐 스킨 삭제에 성공했습니다.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package site.timecapsulearchive.core.domain.capsuleskin.data.response;

import site.timecapsulearchive.core.domain.capsuleskin.data.dto.CapsuleSkinDeleteResult;
import site.timecapsulearchive.core.domain.capsuleskin.data.dto.CapsuleSkinDeleteResultDto;

public record CapsuleSkinDeleteResultResponse(
CapsuleSkinDeleteResult capsuleSkinDeleteResult,
String message
) {

public static CapsuleSkinDeleteResultResponse createOf(
CapsuleSkinDeleteResultDto capsuleSkinDeleteResultDto) {
return new CapsuleSkinDeleteResultResponse(
capsuleSkinDeleteResultDto.capsuleSkinDeleteResult(),
capsuleSkinDeleteResultDto.message()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@Entity
@Table(name = "capsule_skin")
@Getter
@SQLDelete(sql = "UPDATE `capsule_skin` SET deleted_at = now() WHERE caspuel_skin_id = ?")
@SQLDelete(sql = "UPDATE `capsule_skin` SET deleted_at = now() WHERE capsule_skin_id = ?")
@Where(clause = "deleted_at is null")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class CapsuleSkin extends BaseEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ Slice<CapsuleSkinSummaryDto> findCapsuleSkinSliceByCreatedAtAndMemberId(
);

boolean existByImageUrlAndMemberId(String imageUrl, Long memberId);

boolean existRelatedCapsule(Long memberId, Long capsuleSkinId);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package site.timecapsulearchive.core.domain.capsuleskin.repository;

import static site.timecapsulearchive.core.domain.capsule.entity.QCapsule.capsule;
import static site.timecapsulearchive.core.domain.capsuleskin.entity.QCapsuleSkin.capsuleSkin;

import com.querydsl.core.types.Projections;
Expand Down Expand Up @@ -52,4 +53,16 @@ public boolean existByImageUrlAndMemberId(String imageUrl, Long memberId) {

return count != null;
}

@Override
public boolean existRelatedCapsule(final Long memberId, final Long capsuleSkinId) {
Integer count = jpaQueryFactory
.selectOne()
.from(capsuleSkin)
.join(capsule).on(capsule.capsuleSkin.id.eq(capsuleSkin.id))
.where(capsuleSkin.id.eq(capsuleSkinId).and(capsuleSkin.member.id.eq(memberId)))
.fetchOne();

return count != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ void deleteByMemberId(
@Param("memberId") Long memberId,
@Param("deletedAt") ZonedDateTime deletedAt
);

void delete(CapsuleSkin capsuleSkin);

Optional<CapsuleSkin> findCapsuleSkinByMemberIdAndId(Long memberId, Long capsuleSkinId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionTemplate;
import site.timecapsulearchive.core.domain.capsuleskin.data.dto.CapsuleSkinCreateDto;
import site.timecapsulearchive.core.domain.capsuleskin.data.dto.CapsuleSkinDeleteResultDto;
import site.timecapsulearchive.core.domain.capsuleskin.data.dto.CapsuleSkinSummaryDto;
import site.timecapsulearchive.core.domain.capsuleskin.data.mapper.CapsuleSkinMapper;
import site.timecapsulearchive.core.domain.capsuleskin.data.response.CapsuleSkinStatusResponse;
Expand Down Expand Up @@ -74,4 +75,21 @@ public CapsuleSkin findCapsuleSkinById(final Long capsuleSkinId) {
return capsuleSkinRepository.findCapsuleSkinById(capsuleSkinId)
.orElseThrow(CapsuleSkinNotFoundException::new);
}

@Transactional
public CapsuleSkinDeleteResultDto deleteCapsuleSkin(
final Long memberId,
final Long capsuleSkinId
) {
boolean existRelatedCapsule = capsuleSkinRepository.existRelatedCapsule(memberId, capsuleSkinId);
if (existRelatedCapsule) {
return CapsuleSkinDeleteResultDto.fail();
}

CapsuleSkin capsuleSkin = capsuleSkinRepository.findCapsuleSkinByMemberIdAndId(memberId, capsuleSkinId)
.orElseThrow(CapsuleSkinNotFoundException::new);
capsuleSkinRepository.delete(capsuleSkin);

return CapsuleSkinDeleteResultDto.success();
}
}

0 comments on commit d74a849

Please sign in to comment.