Skip to content

Commit

Permalink
Merge pull request #173 from jjikky/refactor/objet-create-update
Browse files Browse the repository at this point in the history
오브제 수정 삭제 sharers 데이터 타입 변경
  • Loading branch information
JiHongKim98 authored Sep 2, 2024
2 parents 6a234b7 + c45170c commit 807489a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
import com.example.daobe.user.domain.User;
import com.example.daobe.user.domain.repository.UserRepository;
import com.example.daobe.user.exception.UserException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
Expand All @@ -55,7 +52,6 @@ public class ObjetService {
private final ChatService chatRoomService;
private final ObjetCallRepository objetCallRepository;
private final ApplicationEventPublisher eventPublisher;
private final ObjectMapper objectMapper = new ObjectMapper();

@Transactional
public ObjetCreateResponseDto create(Long userId, ObjetCreateRequestDto request) {
Expand All @@ -75,7 +71,7 @@ public ObjetCreateResponseDto create(Long userId, ObjetCreateRequestDto request)
.build();
objetRepository.save(objet);

List<Long> sharerIds = parseSharerData(request.sharers());
List<Long> sharerIds = request.sharers();
sharerIds.add(userId);

List<ObjetSharer> objetSharers = manageSharers(objet, sharerIds, userId);
Expand All @@ -97,7 +93,7 @@ public ObjetCreateResponseDto update(Long userId, Long objetId, ObjetUpdateReque
}

Set<Long> currentSharerIds = getCurrentSharerIds(findObjet);
List<Long> newSharerIds = parseSharerData(request.sharers());
List<Long> newSharerIds = request.sharers();
manageAndSyncSharers(findObjet, currentSharerIds, newSharerIds, userId);

objetRepository.save(findObjet);
Expand Down Expand Up @@ -199,15 +195,6 @@ private Set<Long> getCurrentSharerIds(Objet findObjet) {
.collect(Collectors.toSet());
}

private List<Long> parseSharerData(String sharers) {
try {
return objectMapper.readValue(sharers, new TypeReference<>() {
});
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}

private List<ObjetSharer> manageSharers(Objet objet, List<Long> sharerIds, Long userId) {
return sharerIds.stream()
.map(sharerId -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.example.daobe.objet.application.dto;

import java.util.List;

public record ObjetCreateRequestDto(
String sharers,
List<Long> sharers,
String name,
String description,
String type,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.example.daobe.objet.application.dto;

import java.util.List;
import lombok.Builder;

@Builder
public record ObjetUpdateRequestDto(
Long objetId,
String sharers,
List<Long> sharers,
String name,
String description,
String objetImage
Expand Down

0 comments on commit 807489a

Please sign in to comment.