Skip to content

Commit

Permalink
Merge pull request #59 from 9oormthonUniv-seoultech/feat/#58
Browse files Browse the repository at this point in the history
Feat/#58 Album API
  • Loading branch information
Jeongh00 authored Nov 6, 2024
2 parents 8a6ad3a + bba2fcd commit 368efb2
Show file tree
Hide file tree
Showing 41 changed files with 804 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.pocket.core.exception.album;

import com.pocket.core.exception.common.BaseErrorCode;
import lombok.Getter;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

@Getter
@ResponseStatus(HttpStatus.BAD_REQUEST)
public class AlbumCustomException extends RuntimeException {

private final BaseErrorCode errorCode;

public AlbumCustomException(BaseErrorCode errorCode) {
this.errorCode = errorCode;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.pocket.core.exception.album;

import com.pocket.core.exception.common.ApiResponse;
import com.pocket.core.exception.common.BaseErrorCode;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
@AllArgsConstructor
public enum AlbumErrorCode implements BaseErrorCode {
ALBUM_NOT_FOUND(HttpStatus.BAD_REQUEST, "400", "해당 앨범이 존재하지 않습니다.");

private final HttpStatus httpStatus;
private final String code;
private final String message;

@Override
public ApiResponse<Void> getErrorResponse() {
return ApiResponse.onFailure(code, message);
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.pocket.core.exception.common;

import com.pocket.core.exception.jwt.SecurityCustomException;
import com.pocket.core.exception.jwt.SecurityErrorCode;
import com.pocket.core.exception.photobooth.PhotoBoothCustomException;
import com.pocket.core.exception.photobooth.PhotoBoothErrorCode;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
Expand All @@ -18,4 +20,13 @@ public ResponseEntity<ApplicationResponse<String>> handlePhotoBoothNotFound(Phot
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(SecurityCustomException.class)
public ResponseEntity<ApplicationResponse<String>> handleSecurityException(SecurityCustomException ex) {
ApplicationResponse<String> response = new ApplicationResponse<>(
new ApplicationResult(Integer.parseInt(ex.getErrorCode().getCode()), ex.getErrorCode().getMessage()),
null
);
return new ResponseEntity<>(response, ex.getErrorCode().getHttpStatus());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
@Getter
@AllArgsConstructor
public enum PhotoBoothErrorCode implements BaseErrorCode {
PHOTOBOOTH_NOT_FOUND(HttpStatus.BAD_REQUEST, "400", "해당 포토부스가 존재하지 않습니다.");
PHOTOBOOTH_NOT_FOUND(HttpStatus.BAD_REQUEST, "400", "해당 포토부스가 존재하지 않습니다."),
PHOTOBOOTHBRAND_NOT_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,14 @@
package com.pocket.domain.dto.album;

import java.util.List;

public record AlbumHashtagResponseDto(
String photoUrl,
List<String> hashtags,
Integer year,
Integer month,
Integer date,
String memo,
boolean isLiked
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pocket.domain.dto.album;

public record AlbumResponseDto(
Long albumId,
String photoUrl,
boolean like
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.pocket.domain.dto.album;

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

public record NearAlbumInfo(
String photoUrl,
double x,
double y
) {
}
12 changes: 6 additions & 6 deletions domain/src/main/java/com/pocket/domain/entity/image/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public class Image extends BaseEntity {
@Column(name = "image_url")
private String imageUrl;

private String year;
private String month;
private String date;
private Integer year;
private Integer month;
private Integer date;

public Image(ImageType type) {
this.type = type;
Expand All @@ -34,9 +34,9 @@ public Image(ImageType type) {
public void makeAlbumImage(AlbumRegisterRequestDto dto, String filePath) {
this.type = ImageType.PHOTO;
this.imageUrl = filePath;
this.year = dto.year();
this.month = dto.month();
this.date = dto.date();
this.year = Integer.parseInt(dto.year());
this.month = Integer.parseInt(dto.month());
this.date = Integer.parseInt(dto.date());
}

public void makeReviewImage(String filePath) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.pocket.domain.entity.photobooth;

public enum PhotoBoothBrand {
import com.pocket.core.exception.photobooth.PhotoBoothCustomException;
import com.pocket.core.exception.photobooth.PhotoBoothErrorCode;

public enum PhotoBoothBrand {
LIFE4CUT("인생네컷"),
PHOTOISM("포토이즘"),
PHOTOGRAY("포토그레이"),
Expand All @@ -14,14 +16,22 @@ public enum PhotoBoothBrand {
PHOTOSIGNATURE("포토시그니처"),
UNKNOWN("존재하지 않음");

final private String name;
private final String koreanName;

PhotoBoothBrand(String name) {
this.name = name;
PhotoBoothBrand(String koreanName) {
this.koreanName = koreanName;
}

public String getName() {
return this.name;
public String getKoreanName() {
return koreanName;
}

}
public static PhotoBoothBrand fromKoreanName(String koreanName) {
for (PhotoBoothBrand brand : PhotoBoothBrand.values()) {
if (brand.getKoreanName().equals(koreanName)) {
return brand;
}
}
throw new PhotoBoothCustomException(PhotoBoothErrorCode.PHOTOBOOTHBRAND_NOT_FOUND);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pocket.domain.port.album;

public interface AlbumDeletePort {

void deleteAlbum(Long albumId);

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

import com.pocket.domain.dto.album.AlbumResponseDto;

import java.util.List;

public interface AlbumFavoritePort {

List<AlbumResponseDto> getFavoriteAlbums(String userEmail);

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

import com.pocket.domain.dto.album.AlbumResponseDto;

import java.util.List;

public interface AlbumGetByBrandPort {

List<AlbumResponseDto> getAlbumByBrand(String brandName, String userEmail);

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

import com.pocket.domain.dto.album.AlbumResponseDto;

import java.util.List;

public interface AlbumGetByDatePort {

List<AlbumResponseDto> getAlbumByDate(Integer year, Integer month, String userEmail);

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

import com.pocket.domain.dto.album.NearAlbumInfo;

import java.util.List;

public interface AlbumGetByLocationPort {

List<NearAlbumInfo> getAlbumByLocation(double currentLat, double currentLon, String userEmail);

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

import com.pocket.domain.dto.album.AlbumHashtagResponseDto;

import java.util.List;

public interface AlbumHashtagPort {

List<AlbumHashtagResponseDto> getAlbumByHashtag(String hashtag, String userEmail);

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

public interface AlbumLikePort {

void likeAlbum(Long albumId);

}
Original file line number Diff line number Diff line change
@@ -1,20 +1,101 @@
package com.pocket.domain.service.album;

import com.pocket.core.aop.annotation.DomainService;
import com.pocket.domain.dto.album.AlbumRegisterRequestDto;
import com.pocket.domain.dto.album.AlbumRegisterResponseDto;
import com.pocket.domain.port.album.AlbumRegisterPort;
import com.pocket.domain.usecase.album.AlbumRegisterUseCase;
import com.pocket.domain.dto.album.*;
import com.pocket.domain.port.album.*;
import com.pocket.domain.port.file.FileDownloadPort;
import com.pocket.domain.usecase.album.*;
import lombok.RequiredArgsConstructor;

import java.util.List;
import java.util.stream.Collectors;

@DomainService
@RequiredArgsConstructor
public class AlbumService implements AlbumRegisterUseCase {
public class AlbumService implements AlbumRegisterUseCase, AlbumLikeUseCase, AlbumGetByDateUseCase, AlbumGetByBrandUseCase, AlbumGetByLocationUseCase, AlbumDeleteUseCase, AlbumHashtagUseCase, AlbumFavoriteUseCase
{

private final FileDownloadPort fileDownloadPort;
private final AlbumRegisterPort albumRegisterPort;
private final AlbumLikePort albumLikePort;
private final AlbumGetByDatePort albumGetByDatePort;
private final AlbumGetByBrandPort albumGetByBrandPort;
private final AlbumGetByLocationPort albumGetByLocationPort;
private final AlbumDeletePort albumDeletePort;
private final AlbumHashtagPort albumHashtagPort;
private final AlbumFavoritePort albumFavoritePort;

public AlbumRegisterResponseDto registerPhotoResponse(AlbumRegisterRequestDto albumRegisterRequestDto, String name) {
return albumRegisterPort.registerPhoto(albumRegisterRequestDto, name);
}

@Override
public void likeAlbum(Long albumId) {
albumLikePort.likeAlbum(albumId);
}

@Override
public List<AlbumResponseDto> getAlbumByDate(Integer year, Integer month, String userEmail) {
List<AlbumResponseDto> albumResponseDtos = albumGetByDatePort.getAlbumByDate(year, month, userEmail);

return albumResponseDtos.stream()
.map(dto -> {
String presignedUrl = dto.photoUrl().isEmpty() ? "" : fileDownloadPort.getDownloadPresignedUrl(dto.photoUrl());
return new AlbumResponseDto(dto.albumId(), presignedUrl, dto.like());
})
.collect(Collectors.toList());
}


@Override
public List<AlbumResponseDto> getAlbumByBrand(String brandName, String userEmail) {
List<AlbumResponseDto> albumResponseDtos = albumGetByBrandPort.getAlbumByBrand(brandName, userEmail);

return albumResponseDtos.stream()
.map(dto -> {
String presignedUrl = dto.photoUrl().isEmpty() ? "" : fileDownloadPort.getDownloadPresignedUrl(dto.photoUrl());
return new AlbumResponseDto(dto.albumId(), presignedUrl, dto.like());
})
.collect(Collectors.toList());
}

public List<NearAlbumInfo> getAlbumByLocation(double currentLat, double currentLon, String userEmail) {
List<NearAlbumInfo> nearAlbumInfos = albumGetByLocationPort.getAlbumByLocation(currentLat, currentLon, userEmail);

return nearAlbumInfos.stream()
.map(dto -> {
String presignedUrl = dto.photoUrl().isEmpty() ? "" : fileDownloadPort.getDownloadPresignedUrl(dto.photoUrl());
return new NearAlbumInfo(presignedUrl, dto.x(), dto.y());
})
.collect(Collectors.toList());
}

public void deleteAlbum(Long albumId) {
albumDeletePort.deleteAlbum(albumId);
}

@Override
public List<AlbumHashtagResponseDto> getAlbumByHashtag(String hashtag, String userEmail) {
List<AlbumHashtagResponseDto> albumHashtagResponseDtos = albumHashtagPort.getAlbumByHashtag(hashtag, userEmail);

return albumHashtagResponseDtos.stream()
.map(dto -> {
String presignedUrl = dto.photoUrl().isEmpty() ? "" : fileDownloadPort.getDownloadPresignedUrl(dto.photoUrl());
return new AlbumHashtagResponseDto(presignedUrl, dto.hashtags(), dto.year(), dto.month(), dto.date(), dto.memo(), dto.isLiked());
})
.collect(Collectors.toList());
}


@Override
public List<AlbumResponseDto> getFavoriteAlbums(String userEmail) {
List<AlbumResponseDto> albumResponseDtos = albumFavoritePort.getFavoriteAlbums(userEmail);

return albumResponseDtos.stream()
.map(dto -> {
String presignedUrl = dto.photoUrl().isEmpty() ? "" : fileDownloadPort.getDownloadPresignedUrl(dto.photoUrl());
return new AlbumResponseDto(dto.albumId(), presignedUrl, dto.like());
})
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pocket.domain.usecase.album;

public interface AlbumDeleteUseCase {

void deleteAlbum(Long albumId);

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

import com.pocket.domain.dto.album.AlbumResponseDto;

import java.util.List;

public interface AlbumFavoriteUseCase {

List<AlbumResponseDto> getFavoriteAlbums(String userEmail);

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

import com.pocket.domain.dto.album.AlbumResponseDto;

import java.util.List;

public interface AlbumGetByBrandUseCase {

List<AlbumResponseDto> getAlbumByBrand(String brandName, String userEmail);

}
Loading

0 comments on commit 368efb2

Please sign in to comment.