Skip to content

Commit

Permalink
Merge pull request #73 from 9oormthonUniv-seoultech/feat/#71
Browse files Browse the repository at this point in the history
Feat/#71 포토부스 찜 API 추가 & 수정
  • Loading branch information
JiinHong authored Nov 7, 2024
2 parents 9c4cb20 + dc90674 commit 2641377
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
@AllArgsConstructor
public enum PhotoBoothErrorCode implements BaseErrorCode {
PHOTOBOOTH_NOT_FOUND(HttpStatus.BAD_REQUEST, "400", "해당 포토부스가 존재하지 않습니다."),
PHOTOBOOTHBRAND_NOT_FOUND(HttpStatus.BAD_REQUEST, "400", "해당 포토부스 브랜드가 존재하지 않습니다.");
PHOTOBOOTHBRAND_NOT_FOUND(HttpStatus.BAD_REQUEST, "400", "해당 포토부스 브랜드가 존재하지 않습니다."),
PHOTOBOOTHLIKE_NOT_FOUND(HttpStatus.BAD_REQUEST, "400", "찜한 포토부스가 아닙니다."),
PHOTOBOOTHLIKE_FOUND(HttpStatus.BAD_REQUEST, "400", "이미 찜한 포토부스 입니다.");

private final HttpStatus httpStatus;
private final String code;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pocket.domain.port.photobooth;

import com.pocket.domain.entity.photobooth.PhotoBooth;

public interface PhotoBoothCheckLikePort {

Boolean checkLike(Long photoBoothId, String userEmail);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pocket.domain.port.photobooth;

import com.pocket.domain.entity.photobooth.PhotoBooth;

public interface PhotoBoothDeleteLikePort {

void deleteLike(Long photoBoothId, String userEmail);

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@Service
@RequiredArgsConstructor
public class PhotoBoothService implements PhotoBoothFindUseCase, PhotoBoothGetNameUseCase, PhotoBoothGetRatingUseCase, PhotoBoothSearchUseCase, PhotoBoothGetModalUseCase, PhotoBoothVisitedUseCase, PhotoBoothLikeUseCase, PhotoBoothGetLikeUseCase
public class PhotoBoothService implements PhotoBoothFindUseCase, PhotoBoothGetNameUseCase, PhotoBoothGetRatingUseCase, PhotoBoothSearchUseCase, PhotoBoothGetModalUseCase, PhotoBoothVisitedUseCase, PhotoBoothLikeUseCase, PhotoBoothGetLikeUseCase, PhotoBoothCheckLikeUseCase, PhotoBoothDeleteLikeUseCase
{

private final PhotoBoothFindPort photoBoothFindPort;
Expand All @@ -24,6 +24,8 @@ public class PhotoBoothService implements PhotoBoothFindUseCase, PhotoBoothGetNa
private final PhotoBoothVisitedPort photoBoothVisitedPort;
private final PhotoBoothLikePort photoBoothLikePort;
private final PhotoBoothGetLikePort photoBoothGetLikePort;
private final PhotoBoothCheckLikePort photoBoothCheckLikePort;
private final PhotoBoothDeleteLikePort photoBoothDeleteLikePort;

public PhotoBoothFindResponseDto findPhotoBoothResponse(Long id) {
return photoBoothFindPort.findById(id);
Expand Down Expand Up @@ -55,12 +57,22 @@ public List<PhotoBoothVisitedDto> getVisitedPhotoBooths(String userEmail) {
}

@Override
public void photoBoothLike(Long photoId, String userEmail) {
photoBoothLikePort.photoBoothLike(photoId, userEmail);
public void photoBoothLike(Long photoboothId, String userEmail) {
photoBoothLikePort.photoBoothLike(photoboothId, userEmail);
}

@Override
public List<PhotoBoothLikeDto> getLikedPhotos(String userEmail) {
return photoBoothGetLikePort.getLikedPhotos(userEmail);
}

@Override
public Boolean checkLike(Long photoBoothId, String userEmail) {
return photoBoothCheckLikePort.checkLike(photoBoothId, userEmail);
}

@Override
public void deleteLike(Long photoBoothId, String userEmail) {
photoBoothDeleteLikePort.deleteLike(photoBoothId, userEmail);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pocket.domain.usecase.photobooth;

public interface PhotoBoothCheckLikeUseCase {

Boolean checkLike(Long photoBoothId, String userEmail);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pocket.domain.usecase.photobooth;

public interface PhotoBoothDeleteLikeUseCase {

void deleteLike(Long photoBoothId, String userEmail);

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class PhotoBoothController implements PhotoBoothControllerDocs {
private final PhotoBoothVisitedUseCase photoBoothVisitedUseCase;
private final PhotoBoothLikeUseCase photoBoothLikeUseCase;
private final PhotoBoothGetLikeUseCase photoBoothGetLikeUseCase;
private final PhotoBoothCheckLikeUseCase photoBoothCheckLikeUseCase;
private final PhotoBoothDeleteLikeUseCase photoBoothDeleteLikeUseCase;

@GetMapping("{id}")
public ApplicationResponse<PhotoBoothFindResponseDto> getPhotoBoothById(@PathVariable("id") Long id) {
Expand Down Expand Up @@ -92,4 +94,22 @@ public ApplicationResponse<List<PhotoBoothLikeDto>> getPhotoBoothLike(
List<PhotoBoothLikeDto> response = photoBoothGetLikeUseCase.getLikedPhotos(user.email());
return ApplicationResponse.ok(response);
}

@GetMapping("/like/check/{id}")
public ApplicationResponse<Boolean> likePhotoBoothCheck(
@PathVariable("id") Long id,
@AuthenticationPrincipal UserInfoDTO user
) {
Boolean response = photoBoothCheckLikeUseCase.checkLike(id, user.email());
return ApplicationResponse.ok(response);
}

@DeleteMapping("/like/{id}")
public ApplicationResponse<String> deletePhotoBoothLike(
@PathVariable("id") Long id,
@AuthenticationPrincipal UserInfoDTO user
) {
photoBoothDeleteLikeUseCase.deleteLike(id, user.email());
return ApplicationResponse.ok("success");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,30 @@ ApplicationResponse<List<PhotoBoothLikeDto>> getPhotoBoothLike(
@AuthenticationPrincipal UserInfoDTO user
);

@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "400", description = "BAD REQUEST",
content = {@Content(schema = @Schema(implementation = ErrorResponse.class))}),
@ApiResponse(responseCode = "500", description = "INTERNAL SERVER ERROR",
content = {@Content(schema = @Schema(implementation = ErrorResponse.class))})
})
@Operation(summary = "포토부스 찜 여부 확인", description = "찜한 포토부스인지 확인하는 API")
ApplicationResponse<Boolean> likePhotoBoothCheck(
@PathVariable("id") Long id,
@AuthenticationPrincipal UserInfoDTO user
);

@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "400", description = "BAD REQUEST",
content = {@Content(schema = @Schema(implementation = ErrorResponse.class))}),
@ApiResponse(responseCode = "500", description = "INTERNAL SERVER ERROR",
content = {@Content(schema = @Schema(implementation = ErrorResponse.class))})
})
@Operation(summary = "포토부스 찜 삭제", description = "포토부스 찜 삭제하는 API")
ApplicationResponse<String> deletePhotoBoothLike(
@PathVariable("id") Long id,
@AuthenticationPrincipal UserInfoDTO user
);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.pocket.outbound.adapter.photobooth.adapter;

import com.pocket.core.aop.annotation.AdapterService;
import com.pocket.domain.port.photobooth.PhotoBoothCheckLikePort;
import com.pocket.outbound.entity.photobooth.JpaLike;
import com.pocket.outbound.repository.photobooth.LikeRepository;
import lombok.RequiredArgsConstructor;

import java.util.Optional;


@AdapterService
@RequiredArgsConstructor
public class PhotoBoothCheckLikeAdapter implements PhotoBoothCheckLikePort {

private final LikeRepository likeRepository;

@Override
public Boolean checkLike(Long photoBoothId, String userEmail) {
return likeRepository.findByUser_UserEmailAndPhotoBooth_Id(userEmail, photoBoothId).isPresent();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.pocket.outbound.adapter.photobooth.adapter;

import com.pocket.core.aop.annotation.AdapterService;
import com.pocket.core.exception.photobooth.PhotoBoothCustomException;
import com.pocket.core.exception.photobooth.PhotoBoothErrorCode;
import com.pocket.domain.port.photobooth.PhotoBoothDeleteLikePort;
import com.pocket.outbound.entity.photobooth.JpaLike;
import com.pocket.outbound.repository.photobooth.LikeRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

@AdapterService
@RequiredArgsConstructor
public class PhotoBoothDeleteLikeAdapter implements PhotoBoothDeleteLikePort {

private final LikeRepository likeRepository;

@Override
@Transactional
public void deleteLike(Long photoBoothId, String userEmail) {
Optional<JpaLike> entity = likeRepository.findByUser_UserEmailAndPhotoBooth_Id(userEmail, photoBoothId);
if (entity.isPresent()) {
likeRepository.delete(entity.get());
} else {
throw new PhotoBoothCustomException(PhotoBoothErrorCode.PHOTOBOOTHLIKE_NOT_FOUND);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import com.pocket.outbound.repository.photobooth.PhotoBoothRepository;
import lombok.RequiredArgsConstructor;

import java.util.Optional;

@AdapterService
@RequiredArgsConstructor
public class PhotoBoothLikeAdapter implements PhotoBoothLikePort {
Expand All @@ -25,13 +27,19 @@ public class PhotoBoothLikeAdapter implements PhotoBoothLikePort {

@Override
public void photoBoothLike(Long photoBoothId, String userEmail) {

Optional<JpaLike> entity = likeRepository.findByUser_UserEmailAndPhotoBooth_Id(userEmail, photoBoothId);
if (entity.isPresent()) {
throw new PhotoBoothCustomException(PhotoBoothErrorCode.PHOTOBOOTHLIKE_FOUND);
}
JpaUser jpaUser = userRepository.findByUserEmail(userEmail)
.orElseThrow(() -> new UserCustomException(UserErrorCode.NO_USER_INFO));

JpaPhotoBooth jpaPhotoBooth = photoBoothRepository.findById(photoBoothId)
.orElseThrow(() -> new PhotoBoothCustomException((PhotoBoothErrorCode.PHOTOBOOTH_NOT_FOUND)));

JpaLike jpaLike = JpaLike.createLike(jpaUser, jpaPhotoBooth);

likeRepository.save(jpaLike);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;

public interface LikeRepository extends JpaRepository<JpaLike, Long> {

List<JpaLike> findByUser_UserEmail(String userEmail);

Optional<JpaLike> findByUser_UserEmailAndPhotoBooth_Id(String userEmail, Long photoBoothId);

}

0 comments on commit 2641377

Please sign in to comment.