-
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.
Browse files
Browse the repository at this point in the history
Feat/#25 Album Register API
- Loading branch information
Showing
35 changed files
with
663 additions
and
78 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
core/src/main/java/com/pocket/core/aop/annotation/AdapterService.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,14 @@ | ||
package com.pocket.core.aop.annotation; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({ElementType.TYPE, ElementType.METHOD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Service | ||
public @interface AdapterService { | ||
} |
14 changes: 14 additions & 0 deletions
14
core/src/main/java/com/pocket/core/aop/annotation/DomainService.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,14 @@ | ||
package com.pocket.core.aop.annotation; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({ElementType.TYPE, ElementType.METHOD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Service | ||
public @interface DomainService { | ||
} |
32 changes: 32 additions & 0 deletions
32
core/src/main/java/com/pocket/core/util/DistanceCalculator.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,32 @@ | ||
package com.pocket.core.util; | ||
|
||
public class DistanceCalculator { | ||
|
||
private static final double EARTH_RADIUS_KM = 6371.0; | ||
|
||
/** | ||
* 두 지점 간의 거리를 계산합니다. (단위: 킬로미터) | ||
* | ||
* @param lat1 첫 번째 지점의 위도 | ||
* @param lon1 첫 번째 지점의 경도 | ||
* @param lat2 두 번째 지점의 위도 | ||
* @param lon2 두 번째 지점의 경도 | ||
* @return 두 지점 간의 거리 (킬로미터) | ||
*/ | ||
public static double haversineDistance(double lat1, double lon1, double lat2, double lon2) { | ||
// 위도와 경도를 라디안으로 변환 | ||
double dLat = Math.toRadians(lat2 - lat1); | ||
double dLon = Math.toRadians(lon2 - lon1); | ||
|
||
double radLat1 = Math.toRadians(lat1); | ||
double radLat2 = Math.toRadians(lat2); | ||
|
||
// Haversine 공식 적용 | ||
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + | ||
Math.cos(radLat1) * Math.cos(radLat2) * | ||
Math.sin(dLon / 2) * Math.sin(dLon / 2); | ||
double c = 2 * Math.asin(Math.sqrt(a)); | ||
|
||
return EARTH_RADIUS_KM * c; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
domain/src/main/java/com/pocket/domain/dto/image/AlbumRegisterRequestDto.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,15 @@ | ||
package com.pocket.domain.dto.image; | ||
|
||
import java.util.List; | ||
|
||
public record AlbumRegisterRequestDto( | ||
Long photoboothId, | ||
String year, | ||
String month, | ||
String date, | ||
List<String> hashtag, | ||
String memo, | ||
String imageName, // 이미지 이름 | ||
String prefix // S3 버킷 내에 저장할 경로 | ||
) { | ||
} |
7 changes: 7 additions & 0 deletions
7
domain/src/main/java/com/pocket/domain/dto/photobooth/NearPhotoBoothInfo.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.pocket.domain.dto.photobooth; | ||
|
||
public record NearPhotoBoothInfo( | ||
Long id, | ||
String name | ||
) { | ||
} |
16 changes: 16 additions & 0 deletions
16
domain/src/main/java/com/pocket/domain/entity/album/HashTag.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,16 @@ | ||
package com.pocket.domain.entity.album; | ||
|
||
import jakarta.persistence.Embeddable; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Embeddable | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class HashTag { | ||
|
||
private String content; | ||
} |
16 changes: 16 additions & 0 deletions
16
domain/src/main/java/com/pocket/domain/entity/album/Memo.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,16 @@ | ||
package com.pocket.domain.entity.album; | ||
|
||
import jakarta.persistence.Embeddable; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Embeddable | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class Memo { | ||
|
||
private 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
10 changes: 10 additions & 0 deletions
10
domain/src/main/java/com/pocket/domain/port/album/AlbumRegisterPort.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,10 @@ | ||
package com.pocket.domain.port.album; | ||
|
||
import com.pocket.domain.dto.image.AlbumRegisterRequestDto; | ||
import com.pocket.domain.entity.User; | ||
|
||
public interface AlbumRegisterPort { | ||
|
||
String registerPhoto(AlbumRegisterRequestDto albumRegisterRequestDto, String name); | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
domain/src/main/java/com/pocket/domain/port/photobooth/PhotoBoothFindPort.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,9 +1,15 @@ | ||
package com.pocket.domain.port.photobooth; | ||
|
||
import com.pocket.domain.dto.photobooth.NearPhotoBoothInfo; | ||
import com.pocket.domain.dto.photobooth.PhotoBoothFindResponseDto; | ||
import com.pocket.domain.entity.photobooth.PhotoBoothBrand; | ||
|
||
import java.util.List; | ||
|
||
public interface PhotoBoothFindPort { | ||
|
||
PhotoBoothFindResponseDto findById(Long id); | ||
|
||
List<NearPhotoBoothInfo> getPhotoboothWithin2Km(double currentLat, double currentLon, PhotoBoothBrand brand); | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
domain/src/main/java/com/pocket/domain/service/album/AlbumService.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.pocket.domain.service.album; | ||
|
||
import com.pocket.core.aop.annotation.DomainService; | ||
import com.pocket.domain.dto.image.AlbumRegisterRequestDto; | ||
import com.pocket.domain.port.album.AlbumRegisterPort; | ||
import com.pocket.domain.usecase.image.AlbumRegisterUseCase; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@DomainService | ||
@RequiredArgsConstructor | ||
public class AlbumService implements AlbumRegisterUseCase { | ||
|
||
private final AlbumRegisterPort albumRegisterPort; | ||
|
||
public String registerPhotoResponse(AlbumRegisterRequestDto albumRegisterRequestDto, String name) { | ||
return albumRegisterPort.registerPhoto(albumRegisterRequestDto, name); | ||
} | ||
|
||
} |
10 changes: 9 additions & 1 deletion
10
domain/src/main/java/com/pocket/domain/service/photobooth/PhotoBoothFindService.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,19 +1,27 @@ | ||
package com.pocket.domain.service.photobooth; | ||
|
||
import com.pocket.domain.dto.photobooth.NearPhotoBoothInfo; | ||
import com.pocket.domain.dto.photobooth.PhotoBoothFindResponseDto; | ||
import com.pocket.domain.entity.photobooth.PhotoBoothBrand; | ||
import com.pocket.domain.port.photobooth.PhotoBoothFindPort; | ||
import com.pocket.domain.usecase.photobooth.PhotoBoothFindUseCase; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class PhotoBoothFindService implements PhotoBoothFindUseCase { | ||
|
||
private final PhotoBoothFindPort photoBoothFindPort; | ||
|
||
public PhotoBoothFindResponseDto getPhotoBoothFindResponse(Long id) { | ||
public PhotoBoothFindResponseDto findPhotoBoothResponse(Long id) { | ||
return photoBoothFindPort.findById(id); | ||
} | ||
|
||
public List<NearPhotoBoothInfo> findNearPhotoBooth(double lat, double lon, PhotoBoothBrand brand) { | ||
return photoBoothFindPort.getPhotoboothWithin2Km(lat, lon, brand); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
domain/src/main/java/com/pocket/domain/usecase/image/AlbumRegisterUseCase.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 com.pocket.domain.usecase.image; | ||
|
||
import com.pocket.domain.dto.image.AlbumRegisterRequestDto; | ||
|
||
public interface AlbumRegisterUseCase { | ||
|
||
String registerPhotoResponse(AlbumRegisterRequestDto requestDto, String name); | ||
|
||
} |
8 changes: 7 additions & 1 deletion
8
domain/src/main/java/com/pocket/domain/usecase/photobooth/PhotoBoothFindUseCase.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,9 +1,15 @@ | ||
package com.pocket.domain.usecase.photobooth; | ||
|
||
import com.pocket.domain.dto.photobooth.NearPhotoBoothInfo; | ||
import com.pocket.domain.dto.photobooth.PhotoBoothFindResponseDto; | ||
import com.pocket.domain.entity.photobooth.PhotoBoothBrand; | ||
|
||
import java.util.List; | ||
|
||
public interface PhotoBoothFindUseCase { | ||
|
||
PhotoBoothFindResponseDto getPhotoBoothFindResponse(Long id); | ||
PhotoBoothFindResponseDto findPhotoBoothResponse(Long id); | ||
|
||
List<NearPhotoBoothInfo> findNearPhotoBooth(double lat, double lon, PhotoBoothBrand brand); | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
inbounds/src/main/java/com/pocket/inbounds/album/presentation/AlbumContollerDocs.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.pocket.inbounds.album.presentation; | ||
|
||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
|
||
@Tag(name = "Album", description = "Album API") | ||
public interface AlbumContollerDocs { | ||
} |
30 changes: 30 additions & 0 deletions
30
inbounds/src/main/java/com/pocket/inbounds/album/presentation/AlbumController.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 com.pocket.inbounds.album.presentation; | ||
|
||
import com.pocket.core.exception.common.ApplicationResponse; | ||
import com.pocket.domain.dto.image.AlbumRegisterRequestDto; | ||
import com.pocket.domain.dto.user.UserInfoDTO; | ||
import com.pocket.domain.usecase.image.AlbumRegisterUseCase; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/album") | ||
public class AlbumController implements AlbumContollerDocs{ | ||
|
||
private final AlbumRegisterUseCase albumRegisterUseCase; | ||
|
||
@PostMapping | ||
public ApplicationResponse<String> postPhoto( | ||
@RequestBody AlbumRegisterRequestDto requestDto, | ||
@AuthenticationPrincipal UserInfoDTO user) { | ||
|
||
String url = albumRegisterUseCase.registerPhotoResponse(requestDto, user.name()); | ||
return ApplicationResponse.ok(url);// presigned Url을 리턴해줘야 함. | ||
} | ||
|
||
} |
38 changes: 20 additions & 18 deletions
38
inbounds/src/main/java/com/pocket/inbounds/photobooth/presentation/PhotoBoothController.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,36 +1,38 @@ | ||
package com.pocket.inbounds.photobooth.presentation; | ||
|
||
|
||
import com.pocket.core.exception.common.ApplicationResponse; | ||
import com.pocket.domain.dto.photobooth.NearPhotoBoothInfo; | ||
import com.pocket.domain.dto.photobooth.PhotoBoothFindResponseDto; | ||
import com.pocket.domain.entity.photobooth.PhotoBoothBrand; | ||
import com.pocket.domain.usecase.photobooth.PhotoBoothFindUseCase; | ||
import com.pocket.inbounds.photobooth.response.PhotoBoothResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/v1/photobooth") | ||
public class PhotoBoothController implements PhotoBoothControllerDocs { | ||
|
||
private final PhotoBoothFindUseCase photoBoothFindUseCase; | ||
|
||
@GetMapping("{id}") | ||
public ApplicationResponse<PhotoBoothFindResponseDto> getPhotoBoothById(@PathVariable("id") Long id) { | ||
|
||
@GetMapping("/api/v1/photobooth/{id}") | ||
public ApplicationResponse<PhotoBoothResponse> getPhotoBooth(@PathVariable("id") Long id) { | ||
PhotoBoothFindResponseDto dto = photoBoothFindUseCase.getPhotoBoothFindResponse(id); | ||
PhotoBoothFindResponseDto response = photoBoothFindUseCase.findPhotoBoothResponse(id); | ||
return ApplicationResponse.ok(response); | ||
} | ||
|
||
// 여기서 dto를 response로 변환 | ||
PhotoBoothResponse response = new PhotoBoothResponse( | ||
dto.name(), | ||
dto.road(), | ||
dto.x(), | ||
dto.y(), | ||
dto.photoBoothBrand() | ||
); | ||
@GetMapping() | ||
public ApplicationResponse<List<NearPhotoBoothInfo>> getAllPhotoBooth( | ||
@RequestParam("lat") double lat, | ||
@RequestParam("lon") double lon, | ||
@RequestParam(value = "brand", required = false) PhotoBoothBrand brand | ||
) { | ||
|
||
return ApplicationResponse.ok(response); | ||
List<NearPhotoBoothInfo> responses = photoBoothFindUseCase.findNearPhotoBooth(lat, lon, brand); | ||
return ApplicationResponse.ok(responses); | ||
} | ||
|
||
} |
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
Oops, something went wrong.