Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.example.gp_backend_data.card.controller;

import com.example.gp_backend_data.card.domain.dto.response.CardCreateResponse;
import com.example.gp_backend_data.card.domain.dto.response.CardshareResponse;
import com.example.gp_backend_data.card.service.CardService;
import jakarta.persistence.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/share")
@RequiredArgsConstructor
public class ShareCardController {

private final CardService cardService;

@GetMapping("/{sharingId}/cards")
public List<CardshareResponse> getSharedCards(
@PathVariable UUID sharingId,
@RequestParam(defaultValue = "10") int count,
@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "createdAt") String sortBy) {

try {
return cardService.getSharedCards(sharingId, count, page, sortBy);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("400 Bad Request: " + e.getMessage());
} catch (EntityNotFoundException e) {
throw new EntityNotFoundException("404 Not Found: " + e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.gp_backend_data.card.domain.dto.response;

import com.example.gp_backend_data.card.domain.entity.Cardlink;
import lombok.Builder;
import lombok.Getter;

Expand All @@ -13,4 +14,5 @@ public class CardlinkResponse {
private String content;
// private int positionStart;
// private String contentLength;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.gp_backend_data.card.domain.dto.response;

import com.example.gp_backend_data.card.domain.entity.Card;
import lombok.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CardshareResponse {
private UUID cardId;
private UUID sharingId;
private String title;
//private String color;
private List<CardlinkResponse> cardlinks;
private String aiSummary;
//private String userSummary;
private LocalDateTime createdAt;

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ public interface CardRepository extends JpaRepository<Card, byte[]> {
// List<Card> findTodayCreatedCards();
@Query("SELECT c FROM Card c WHERE c.createdAt >= :start AND c.createdAt < :end")
List<Card> findCardsCreatedBetween(@Param("start") LocalDateTime start, @Param("end") LocalDateTime end);
@Query("SELECT c FROM Card c WHERE c.spaceId = :spaceId ORDER BY c.createdAt DESC")
Page<Card> findBySpaceIdOrderByCreatedAtDesc(@Param("spaceId") byte[] spaceId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.example.gp_backend_data.card.domain.dto.request.CardCreateRequest;
import com.example.gp_backend_data.card.domain.dto.request.CardUpdateRequest;
import com.example.gp_backend_data.card.domain.dto.response.CardlinkResponse;
import com.example.gp_backend_data.card.domain.dto.response.CardCreateResponse;
import com.example.gp_backend_data.card.domain.dto.response.CardListResponse;
import com.example.gp_backend_data.card.domain.dto.response.CardResponse;
import com.example.gp_backend_data.card.domain.dto.response.*;
import com.example.gp_backend_data.card.domain.entity.Card;
import com.example.gp_backend_data.card.repository.CardlinkRepository;
import com.example.gp_backend_data.card.repository.CardRepository;
Expand Down Expand Up @@ -144,6 +141,53 @@ public List<CardCreateResponse> getCardsBySpace(UUID spaceId, int count, int pag
.collect(Collectors.toList());
}

//공유된 스페이스의 지식카드 목록 조회
@Transactional(readOnly = true)
public List<CardshareResponse> getSharedCards(UUID sharingId, int count, int page, String sortBy) {
if (!"createdAt".equals(sortBy)) {
throw new IllegalArgumentException("400 Bad Request: Invalid sortBy value");
}

Space space = spaceRepository.findBySharingIdAndIsShared(uuidHelper.convertUUIDToByteArray(sharingId), true)
.orElseThrow(() -> new EntityNotFoundException("Shared space not found."));

Pageable pageable = PageRequest.of(page - 1, count);
Page<Card> cards = cardRepository.findBySpaceIdOrderByCreatedAtDesc(space.getSpaceId(), pageable);


if (page == 1 && cards.isEmpty()) {
throw new EntityNotFoundException("404 Not Found: No cards available for this spaceId");
}

if (cards.isEmpty()) {
throw new ResponseStatusException(NO_CONTENT, "No more items available");
}

return cards.getContent().stream()
.map(card -> {
List<CardlinkResponse> cardlinks = cardlinkRepository.findByCard_CardId(card.getCardId()).stream()
.map(cardlink -> CardlinkResponse.builder()
.cardlinkId(uuidHelper.convertByteArrayToUUID(cardlink.getCardlinkId()))
.chatId(uuidHelper.convertByteArrayToUUID(cardlink.getChatId()))
.content(cardlink.getContent())
//.positionStart(cardlink.getPositionStart())
//.contentLength(cardlink.getContentLength())
.build())
.toList();
return CardshareResponse.builder()
.cardId(uuidHelper.convertByteArrayToUUID(card.getCardId()))
.sharingId(sharingId)
.title(card.getTitle())
//.color(uuidHelper.convertBytesToHex(card.getColor()))
.cardlinks(cardlinks)
.aiSummary(card.getAiSummary())
.createdAt(card.getCreatedAt())
.build();
})
.collect(Collectors.toList());

}

//지식카드 정보 수정
@Transactional
public CardResponse updateCard(UUID cardId, CardUpdateRequest request) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.gp_backend_data.graph.controller;

import com.example.gp_backend_data.graph.domain.dto.response.GraphResponse;
import com.example.gp_backend_data.graph.domain.dto.response.GraphShareResponse;
import com.example.gp_backend_data.graph.service.GraphService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

@RestController
@RequestMapping("/share")
@RequiredArgsConstructor
public class ShareGraphController {

private final GraphService graphService;

@GetMapping("/{sharingId}/graphs")
public ResponseEntity<GraphShareResponse> getShareGraph(@PathVariable UUID sharingId) {
GraphShareResponse response = graphService.getSharedGraph(sharingId);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.gp_backend_data.graph.domain.dto.response;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.*;

import java.util.UUID;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class GraphShareResponse {
private UUID graphId;
private UUID sharingId;
private JsonNode items;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import com.example.gp_backend_data.graph.domain.dto.request.GraphRequest;
import com.example.gp_backend_data.graph.domain.dto.response.GraphResponse;
import com.example.gp_backend_data.graph.domain.dto.response.GraphShareResponse;
import com.example.gp_backend_data.graph.domain.entity.Graph;
import com.example.gp_backend_data.graph.repository.GraphRepository;
import com.example.gp_backend_data.space.domain.entity.Space;
import com.example.gp_backend_data.space.repository.SpaceRepository;
import com.example.gp_backend_data.utils.UUIDHelper;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.persistence.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
Expand All @@ -19,6 +23,7 @@
@Transactional
public class GraphService {
private final GraphRepository graphRepository;
private final SpaceRepository spaceRepository;
private final ObjectMapper objectMapper;
private final UUIDHelper uuidHelper;

Expand All @@ -41,6 +46,28 @@ public GraphResponse getGraphBySpaceId(UUID spaceId) {
}
}

//공유된 스페이스의 그래프 조회
@Transactional
public GraphShareResponse getSharedGraph(UUID sharingId) {

Space space = spaceRepository.findBySharingIdAndIsShared(uuidHelper.convertUUIDToByteArray(sharingId), true)
.orElseThrow(() -> new EntityNotFoundException("Shared space not found."));

Graph graph = graphRepository.findBySpaceId(space.getSpaceId())
.orElseThrow(() -> new EntityNotFoundException("Graph not found for shared space."));

try {
return new GraphShareResponse(
uuidHelper.convertByteArrayToUUID(graph.getGraphId()),
sharingId,
objectMapper.readTree(graph.getData())
);
} catch (Exception e) {
throw new RuntimeException("Error parsing graph data", e);
}
}


private Graph createNewGraphForSpace(byte[] spaceIdBytes) {
try {
UUID newGraphId = UUID.randomUUID();
Expand Down Expand Up @@ -90,5 +117,7 @@ public GraphResponse updateGraph(UUID graphId, GraphRequest request) {
}

return new GraphResponse(uuidHelper.convertByteArrayToUUID(graph.getGraphId()), uuidHelper.convertByteArrayToUUID(graph.getSpaceId()), request.getItems());

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public interface SpaceRepository extends JpaRepository<Space, byte[]> {
List<Space> findAllByUserId(byte[] userId, Sort sort);
Optional<Space> findBySpaceIdAndUserId(byte[] spaceId, byte[] userId);
List<Space> findByUserId(byte[] userId);
Optional<Space> findBySharingIdAndIsShared(byte[] sharingId, boolean isShared);
}
Loading