-
Notifications
You must be signed in to change notification settings - Fork 1
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: 사진 서비스 중 앨범 기능 구현
- Loading branch information
Showing
20 changed files
with
362 additions
and
32 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
11 changes: 11 additions & 0 deletions
11
photo-service/src/main/java/kr/mafoo/photo/annotation/RequestMemberId.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,11 @@ | ||
package kr.mafoo.photo.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.PARAMETER, ElementType.TYPE_PARAMETER}) | ||
public @interface RequestMemberId { | ||
} |
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
21 changes: 21 additions & 0 deletions
21
photo-service/src/main/java/kr/mafoo/photo/config/MemberIdParameterResolver.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,21 @@ | ||
package kr.mafoo.photo.config; | ||
|
||
import kr.mafoo.photo.annotation.RequestMemberId; | ||
import org.springframework.core.MethodParameter; | ||
import org.springframework.web.reactive.BindingContext; | ||
import org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import reactor.core.publisher.Mono; | ||
|
||
public class MemberIdParameterResolver implements HandlerMethodArgumentResolver { | ||
@Override | ||
public boolean supportsParameter(MethodParameter parameter) { | ||
return parameter.getParameterAnnotation(RequestMemberId.class) != null; | ||
} | ||
|
||
@Override | ||
public Mono<Object> resolveArgument(MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange) { | ||
String memberId = exchange.getRequest().getHeaders().getFirst("X-MEMBER-ID"); | ||
return Mono.justOrEmpty(memberId); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
photo-service/src/main/java/kr/mafoo/photo/config/WebExceptionHandler.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,17 @@ | ||
package kr.mafoo.photo.config; | ||
|
||
import kr.mafoo.photo.controller.dto.response.ErrorResponse; | ||
import kr.mafoo.photo.exception.DomainException; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
|
||
@ControllerAdvice | ||
public class WebExceptionHandler { | ||
@ExceptionHandler(DomainException.class) | ||
public ResponseEntity<ErrorResponse> handleDomainException(DomainException exception) { | ||
return ResponseEntity | ||
.badRequest() | ||
.body(ErrorResponse.fromErrorCode(exception.getErrorCode())); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
photo-service/src/main/java/kr/mafoo/photo/config/WebFluxConfig.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 kr.mafoo.photo.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.reactive.config.EnableWebFlux; | ||
import org.springframework.web.reactive.config.WebFluxConfigurer; | ||
import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer; | ||
|
||
@EnableWebFlux | ||
@Configuration | ||
public class WebFluxConfig implements WebFluxConfigurer { | ||
@Override | ||
public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) { | ||
configurer.addCustomResolver(new MemberIdParameterResolver()); | ||
} | ||
} |
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
3 changes: 2 additions & 1 deletion
3
photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/AlbumUpdateRequest.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,13 +1,14 @@ | ||
package kr.mafoo.photo.controller.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import kr.mafoo.photo.domain.AlbumType; | ||
|
||
@Schema(description = "앨범 수정 요청") | ||
public record AlbumUpdateRequest( | ||
@Schema(description = "앨범 이름", example = "시금치파슷하") | ||
String name, | ||
|
||
@Schema(description = "앨범 타입", example = "TYPE_A") | ||
String type | ||
AlbumType type | ||
) { | ||
} |
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
20 changes: 20 additions & 0 deletions
20
photo-service/src/main/java/kr/mafoo/photo/controller/dto/response/ErrorResponse.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,20 @@ | ||
package kr.mafoo.photo.controller.dto.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import kr.mafoo.photo.exception.ErrorCode; | ||
|
||
@Schema(description = "에러 응답") | ||
public record ErrorResponse( | ||
@Schema(description = "에러 코드", example = "ME0001") | ||
String code, | ||
|
||
@Schema(description = "에러 메시지", example = "사용자를 찾을 수 없습니다") | ||
String message | ||
) { | ||
public static ErrorResponse fromErrorCode(ErrorCode errorCode) { | ||
return new ErrorResponse( | ||
errorCode.getCode(), | ||
errorCode.getMessage() | ||
); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
photo-service/src/main/java/kr/mafoo/photo/domain/AlbumEntity.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,83 @@ | ||
package kr.mafoo.photo.domain; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.annotation.Transient; | ||
import org.springframework.data.domain.Persistable; | ||
import org.springframework.data.relational.core.mapping.Column; | ||
import org.springframework.data.relational.core.mapping.Table; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@Table("album") | ||
public class AlbumEntity implements Persistable<String> { | ||
@Id | ||
@Column("id") | ||
private String albumId; | ||
|
||
@Column("name") | ||
private String name; | ||
|
||
@Column("type") | ||
private AlbumType type; | ||
|
||
@Column("owner_member_id") | ||
private String ownerMemberId; | ||
|
||
@CreatedDate | ||
@Column("created_at") | ||
private LocalDateTime createdAt; | ||
|
||
@LastModifiedDate | ||
@Column("updated_at") | ||
private LocalDateTime updatedAt; | ||
|
||
@Transient | ||
private boolean isNew = false; | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) return true; | ||
if (obj == null || getClass() != obj.getClass()) return false; | ||
|
||
AlbumEntity that = (AlbumEntity) obj; | ||
return albumId.equals(that.albumId); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return albumId.hashCode(); | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return albumId; | ||
} | ||
|
||
public AlbumEntity updateName(String newName) { | ||
this.name = newName; | ||
return this; | ||
} | ||
|
||
public AlbumEntity updateType(AlbumType newType) { | ||
this.type = newType; | ||
return this; | ||
} | ||
|
||
public static AlbumEntity newAlbum(String albumId, String albumName, AlbumType albumType, String ownerMemberId) { | ||
AlbumEntity album = new AlbumEntity(); | ||
album.albumId = albumId; | ||
album.name = albumName; | ||
album.type = albumType; | ||
album.ownerMemberId = ownerMemberId; | ||
album.isNew = true; | ||
return album; | ||
} | ||
} |
12 changes: 6 additions & 6 deletions
12
photo-service/src/main/java/kr/mafoo/photo/domain/AlbumType.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,10 +1,10 @@ | ||
package kr.mafoo.photo.domain; | ||
|
||
public enum AlbumType { | ||
TYPE_A, | ||
TYPE_B, | ||
TYPE_C, | ||
TYPE_D, | ||
TYPE_E, | ||
TYPE_F, | ||
HEART, | ||
FIRE, | ||
BASKETBALL, | ||
BUILDING, | ||
STARFALL, | ||
SMILE_FACE | ||
} |
7 changes: 7 additions & 0 deletions
7
photo-service/src/main/java/kr/mafoo/photo/exception/AlbumNotFoundException.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 kr.mafoo.photo.exception; | ||
|
||
public class AlbumNotFoundException extends DomainException { | ||
public AlbumNotFoundException() { | ||
super(ErrorCode.ALBUM_NOT_FOUND); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
photo-service/src/main/java/kr/mafoo/photo/exception/DomainException.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,13 @@ | ||
package kr.mafoo.photo.exception; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class DomainException extends RuntimeException { | ||
private final ErrorCode errorCode; | ||
|
||
public DomainException(ErrorCode errorCode) { | ||
super(errorCode.getMessage()); | ||
this.errorCode = errorCode; | ||
} | ||
} |
Oops, something went wrong.