Skip to content

Commit

Permalink
[fix] 버그 수정, 오타 수정, 컨벤션 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
isanghaessi committed Aug 12, 2023
1 parent c0f9935 commit bd3b4f5
Show file tree
Hide file tree
Showing 33 changed files with 177 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ public MindCountByUserSequenceAndRelationshipSequenceAndUseYnCommand(
this.useYn = useYn;
}

public Mono<MindCountResult> execute(
CustomMindRepository customMindRepository
) {
result = customMindRepository.countByRelationshipSequenceAndUseYn(
public Mono<MindCountResult> execute(CustomMindRepository customMindRepository) {
result = customMindRepository.countByUserSequenceAndRelationshipSequenceAndUseYn(
userSequence,
relationshipSequence,
useYn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,31 @@
import org.springframework.data.domain.Sort;
import reactor.core.publisher.Flux;

public class MindFindAllByRelationshipSequenceWithOrderCommand {
public class MindFindAllByUserSequenceAndRelationshipSequenceWithOrderAndUseYnCommand {
private final String userSequence;
private final String relationshipSequence;
private final Sort sort;
private final YnType useYn;

private Flux<Mind> result;

public MindFindAllByRelationshipSequenceWithOrderCommand(
public MindFindAllByUserSequenceAndRelationshipSequenceWithOrderAndUseYnCommand(
String userSequence,
String relationshipSequence,
Sort sort
Sort sort,
YnType useYn
) {
this.userSequence = userSequence;
this.relationshipSequence = relationshipSequence;
this.sort = sort;
this.useYn = useYn;
}

public Flux<Mind> execute(MindRepository mindRepository) {
result = mindRepository.findAllByUserSequenceAndRelationshipSequenceAndUseYn(
userSequence,
relationshipSequence,
YnType.Y,
useYn,
sort
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,28 @@
import com.beside.startrail.mind.repository.MindRepository;
import reactor.core.publisher.Mono;

public class MindFindOneByUserSequenceAndSequenceCommand {
public class MindFindOneByUserSequenceAndSequenceAndUseYnCommand {
private final String userSequence;
private final String sequence;
private final YnType useYn;

private Mono<Mind> result;

public MindFindOneByUserSequenceAndSequenceCommand(String userSequence, String sequence) {
public MindFindOneByUserSequenceAndSequenceAndUseYnCommand(
String userSequence,
String sequence,
YnType useYn
) {
this.userSequence = userSequence;
this.sequence = sequence;
this.useYn = useYn;
}

public Mono<Mind> execute(MindRepository mindRepository) {
result = mindRepository.findOneByUserSequenceAndSequenceAndUseYn(
userSequence,
sequence,
YnType.Y
useYn
);

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.beside.startrail.mind.document.Mind;
import com.beside.startrail.mind.repository.MindRepository;
import java.util.List;
import org.springframework.transaction.annotation.Transactional;
import reactor.core.publisher.Flux;

public class MindSaveAllCommand {
Expand All @@ -14,7 +13,6 @@ public MindSaveAllCommand(List<Mind> minds) {
this.minds = minds;
}

@Transactional
public Flux<Mind> execute(MindRepository mindRepository) {
result = mindRepository.saveAll(minds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public MindCountHandler(
@Override
protected Mono<ServerResponse> signedHandle(ServerRequest serverRequest) {
return MindService
.countByUserSequenceAndUseYn(super.jwtPayloadProto.getSequence(), YnType.Y)
.countByUserSequence(super.jwtPayloadProto.getSequence(), YnType.Y)
.execute(customMindRepository)
.map(MindProtoUtil::toMindCountResponseProto)
.flatMap(mindCountResponseProto ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.beside.startrail.mind.service.MindService;
import io.micrometer.common.util.StringUtils;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -39,15 +40,17 @@ public MindDeleteHandler(

@Override
protected Mono<ServerResponse> signedHandle(ServerRequest serverRequest) {
AtomicReference<String> key = new AtomicReference<>("");
String sequence = serverRequest.pathVariable("sequence");

return MindService
.getBySequence(
super.jwtPayloadProto.getSequence(),
sequence
sequence,
YnType.Y
)
.execute(mindRepository)
.doOnNext(mind -> key = mind.getItem().getImageLink())
.doOnNext(mind -> key.set(mind.getItem().getImageLink()))
.doOnNext(mind ->
Optional.ofNullable(
ImageService.delete(
Expand Down Expand Up @@ -76,10 +79,14 @@ protected Mono<ServerResponse> signedHandle(ServerRequest serverRequest) {
.build()
)
.onErrorMap(throwable -> {
if (!StringUtils.isBlank(key)) {
ImageService
.delete(bucketName, key)
.execute(imageRepository);
if (!StringUtils.isBlank(key.get())) {
Optional.ofNullable(
ImageService
.delete(bucketName, key.get())
)
.map(imageDeleteCommand ->
imageDeleteCommand.execute(imageRepository)
);
}

return throwable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.beside.startrail.common.handler.AbstractSignedHandler;
import com.beside.startrail.common.protocolbuffer.ProtocolBufferUtil;
import com.beside.startrail.common.protocolbuffer.mind.MindProtoUtil;
import com.beside.startrail.common.type.YnType;
import com.beside.startrail.mind.repository.MindRepository;
import com.beside.startrail.mind.service.MindService;
import com.beside.startrail.mind.type.SortOrderType;
Expand Down Expand Up @@ -37,7 +38,8 @@ protected Mono<ServerResponse> signedHandle(ServerRequest serverRequest) {
.getByRelationshipSequenceWithOrder(
super.jwtPayloadProto.getSequence(),
mindGetRequestProto.getRelationshipSequence(),
SortOrderType.valueOf(mindGetRequestProto.getSort().name())
SortOrderType.valueOf(mindGetRequestProto.getSort().name()),
YnType.Y
)
)
.flatMapMany(mindFindAllByRelationshipSequenceCommand ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.beside.startrail.common.handler.AbstractSignedHandler;
import com.beside.startrail.common.protocolbuffer.ProtocolBufferUtil;
import com.beside.startrail.common.protocolbuffer.mind.MindProtoUtil;
import com.beside.startrail.common.type.YnType;
import com.beside.startrail.mind.repository.MindRepository;
import com.beside.startrail.mind.service.MindService;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -31,7 +32,8 @@ protected Mono<ServerResponse> signedHandle(ServerRequest serverRequest) {
return MindService
.getBySequence(
super.jwtPayloadProto.getSequence(),
sequence
sequence,
YnType.Y
)
.execute(mindRepository)
.map(MindProtoUtil::toMindResponseProto)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.beside.startrail.mind.service.MindService;
import io.micrometer.common.util.StringUtils;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
Expand All @@ -26,8 +27,6 @@ public class MindPostHandler extends AbstractSignedTransactionalHandler {
private final MindRepository mindRepository;
private final ImageRepository imageRepository;

private String key;

public MindPostHandler(
@Value("${sign.attributeName}") String attributeName,
@Value("${objectStorage.bucketName}") String bucketName,
Expand All @@ -45,6 +44,8 @@ public MindPostHandler(

@Override
protected Mono<ServerResponse> signedTransactionalHandle(ServerRequest serverRequest) {
AtomicReference<String> key = new AtomicReference<>("");

return serverRequest
.bodyToMono(String.class)
.flatMap(body ->
Expand All @@ -68,7 +69,7 @@ protected Mono<ServerResponse> signedTransactionalHandle(ServerRequest serverReq
.map(imageSaveCommand ->
imageSaveCommand
.execute(imageRepository)
.doOnNext(imageLink -> key = imageLink)
.doOnNext(key::set)
.mapNotNull(imageLink ->
MindProtoUtil.toMindWithImageLink(
mindRequestProto,
Expand Down Expand Up @@ -104,10 +105,17 @@ protected Mono<ServerResponse> signedTransactionalHandle(ServerRequest serverReq
.bodyValue(body)
)
.onErrorMap(throwable -> {
if (!StringUtils.isBlank(key)) {
ImageService
.delete(bucketName, key)
.execute(imageRepository);
if (!StringUtils.isBlank(key.get())) {
Optional.ofNullable(
ImageService
.delete(
bucketName,
ImageService.getKey(key.get())
)
)
.map(imageDeleteCommand ->
imageDeleteCommand.execute(imageRepository)
);
}

return throwable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
import com.beside.startrail.common.type.YnType;
import com.beside.startrail.image.repository.ImageRepository;
import com.beside.startrail.image.service.ImageService;
import com.beside.startrail.mind.document.Item;
import com.beside.startrail.mind.document.Mind;
import com.beside.startrail.mind.repository.MindRepository;
import com.beside.startrail.mind.service.MindService;
import io.micrometer.common.util.StringUtils;
import com.google.common.collect.Lists;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import protobuf.mind.MindPutRequestProto;
Expand All @@ -24,8 +29,6 @@ public class MindPutHandler extends AbstractSignedTransactionalHandler {
private final MindRepository mindRepository;
private final ImageRepository imageRepository;

private String key;

public MindPutHandler(
@Value("${sign.attributeName}") String attributeName,
@Value("${objectStorage.bucketName}") String bucketName,
Expand All @@ -40,6 +43,8 @@ public MindPutHandler(

@Override
protected Mono<ServerResponse> signedTransactionalHandle(ServerRequest serverRequest) {
AtomicReference<List<String>> keys = new AtomicReference<>(Lists.newArrayList());

return serverRequest
.bodyToMono(String.class)
.flatMap(body ->
Expand All @@ -48,6 +53,30 @@ protected Mono<ServerResponse> signedTransactionalHandle(ServerRequest serverReq
MindPutRequestProto.newBuilder()
)
)
.flatMap(mindPutRequestProto ->
MindService
.getBySequence(
super.jwtPayloadProto.getSequence(),
mindPutRequestProto.getSequence(),
YnType.Y
)
.execute(mindRepository)
.map(Mind::getItem)
.map(Item::getImageLink)
.map(imageLink ->
Optional.ofNullable(
ImageService
.delete(
bucketName,
ImageService.getKey(imageLink)
)
)
.map(imageDeleteCommand ->
imageDeleteCommand.execute(imageRepository)
)
)
.thenReturn(mindPutRequestProto)
)
.flatMap(mindPutRequestProto ->
Optional.ofNullable(
ImageService.create(
Expand All @@ -60,7 +89,9 @@ protected Mono<ServerResponse> signedTransactionalHandle(ServerRequest serverReq
.map(imageSaveCommand ->
imageSaveCommand
.execute(imageRepository)
.doOnNext(imageLink -> key = imageLink)
.doOnNext(imageLink ->
keys.get().add(ImageService.getKey(imageLink))
)
.mapNotNull(imageLink ->
MindProtoUtil.toMindWithImageLink(
mindPutRequestProto,
Expand Down Expand Up @@ -99,10 +130,19 @@ protected Mono<ServerResponse> signedTransactionalHandle(ServerRequest serverReq
.build()
)
.onErrorMap(throwable -> {
if (!StringUtils.isBlank(key)) {
ImageService
.delete(bucketName, key)
.execute(imageRepository);
if (!CollectionUtils.isEmpty(keys.get())) {
keys
.get()
.stream()
.map(ImageService::getKey)
.forEach((key) ->
Optional.ofNullable(
ImageService
.delete(bucketName, key)
).map(imageDeleteCommand ->
imageDeleteCommand.execute(imageRepository)
)
);
}

return throwable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ public class MindCountResult {
private int total;
private int given;
private int taken;

public static MindCountResult makeDefault() {
return MindCountResult
.builder()
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public interface CustomMindRepository {
Mono<MindCountResult> countByUserSequenceAndUseYn(String userSequence, YnType useYn);

Mono<MindCountResult> countByRelationshipSequenceAndUseYn(
Mono<MindCountResult> countByUserSequenceAndRelationshipSequenceAndUseYn(
String userSequence,
String relationshipSequence,
YnType useYn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Mono<MindCountResult> countByUserSequenceAndUseYn(
}

@Override
public Mono<MindCountResult> countByRelationshipSequenceAndUseYn(
public Mono<MindCountResult> countByUserSequenceAndRelationshipSequenceAndUseYn(
String userSequence,
String relationshipSequence,
YnType useYn
Expand All @@ -68,10 +68,10 @@ public Mono<MindCountResult> countByRelationshipSequenceAndUseYn(

return Mono.from(
reactiveMongoTemplate.aggregate(
aggregation,
Mind.class,
MindCountResult.class
)
aggregation,
Mind.class,
MindCountResult.class
)
);
}
}
Loading

0 comments on commit bd3b4f5

Please sign in to comment.