-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from UMC-Edison/feature/55
- Loading branch information
Showing
13 changed files
with
657 additions
and
3 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
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
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
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
43 changes: 43 additions & 0 deletions
43
project/src/main/java/com/edison/project/domain/space/controller/SpaceController.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,43 @@ | ||
package com.edison.project.domain.space.controller; | ||
|
||
import com.edison.project.common.response.ApiResponse; | ||
import com.edison.project.common.status.SuccessStatus; | ||
import com.edison.project.domain.space.dto.SpaceInfoResponseDto; | ||
import com.edison.project.domain.space.dto.SpaceResponseDto; | ||
import com.edison.project.domain.space.service.SpaceService; | ||
import com.edison.project.global.security.CustomUserPrincipal; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/spaces") | ||
public class SpaceController { | ||
|
||
private final SpaceService spaceService; | ||
|
||
public SpaceController(SpaceService spaceService) { | ||
this.spaceService = spaceService; | ||
} | ||
|
||
@GetMapping("/convert") // 스페이스로 변환 | ||
public ResponseEntity<?> convertSpaces( | ||
@AuthenticationPrincipal CustomUserPrincipal userPrincipal, Pageable pageable) { | ||
ResponseEntity<ApiResponse> response = spaceService.processSpaces(userPrincipal, pageable); | ||
List<SpaceResponseDto> spaces = (List<SpaceResponseDto>) response.getBody().getResult(); | ||
return ApiResponse.onSuccess(SuccessStatus._OK, spaces); | ||
} | ||
|
||
@GetMapping("/cluster") // 클러스터의 중심, 반지름 반환 | ||
public ResponseEntity<?> clusterSpaces() { | ||
ResponseEntity<ApiResponse> response = spaceService.getSpaceInfo(); | ||
List<SpaceInfoResponseDto> spaceInfoList = (List<SpaceInfoResponseDto>) response.getBody().getResult(); | ||
return ApiResponse.onSuccess(SuccessStatus._OK, spaceInfoList); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
project/src/main/java/com/edison/project/domain/space/dto/SpaceInfoResponseDto.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,35 @@ | ||
package com.edison.project.domain.space.dto; | ||
|
||
public class SpaceInfoResponseDto { | ||
private int groupId; | ||
private double centerX; | ||
private double centerY; | ||
private double radius; | ||
|
||
// 기본 생성자 추가 | ||
public SpaceInfoResponseDto() { | ||
} | ||
|
||
public SpaceInfoResponseDto(int groupId, double centerX, double centerY, double radius) { | ||
this.groupId = groupId; | ||
this.centerX = centerX; | ||
this.centerY = centerY; | ||
this.radius = radius; | ||
} | ||
|
||
public int getGroupId() { | ||
return groupId; | ||
} | ||
|
||
public double getCenterX() { | ||
return centerX; | ||
} | ||
|
||
public double getCenterY() { | ||
return centerY; | ||
} | ||
|
||
public double getRadius() { | ||
return radius; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
project/src/main/java/com/edison/project/domain/space/dto/SpaceResponseDto.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,54 @@ | ||
package com.edison.project.domain.space.dto; | ||
|
||
import com.edison.project.domain.bubble.entity.Bubble; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
||
@JsonIgnoreProperties ({"hibernateLazyInitializer", "handler"}) | ||
public class SpaceResponseDto { | ||
private Long id; | ||
private String content; | ||
private double x; | ||
private double y; | ||
private Integer group = 0; | ||
|
||
// 올바른 생성자 추가 | ||
public SpaceResponseDto(Bubble bubble, double x, double y, Integer group) { | ||
this.id = bubble.getBubbleId(); | ||
this.x = x; | ||
this.y = y; | ||
this.group = group; | ||
} | ||
|
||
// Getters and Setters | ||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public double getX() { | ||
return x; | ||
} | ||
|
||
public void setX(double x) { | ||
this.x = x; | ||
} | ||
|
||
public double getY() { | ||
return y; | ||
} | ||
|
||
public void setY(double y) { | ||
this.y = y; | ||
} | ||
|
||
public int getGroup() { | ||
return this.group != null ? this.group : 0; // ✅ null이면 0 반환 | ||
} | ||
|
||
public void setGroup(int group) { | ||
this.group = group; | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
project/src/main/java/com/edison/project/domain/space/entity/Space.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,95 @@ | ||
package com.edison.project.domain.space.entity; | ||
|
||
import com.edison.project.domain.bubble.entity.Bubble; | ||
import jakarta.persistence.*; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Table(name = "spaces") | ||
public class Space { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private String content; | ||
private double x; | ||
private double y; | ||
|
||
// ✅ Bubble과의 관계 설정 (ManyToOne) | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "bubble_id", nullable = false) // 🚨 `NOT NULL` 적용 | ||
private Bubble bubble; | ||
|
||
@Column(name = "group_id") | ||
private Integer group; | ||
|
||
@Column(nullable = false) // member_id 추가 | ||
private Long memberId; | ||
|
||
// ✅ 기본 생성자 (JPA 필수) | ||
public Space() {} | ||
|
||
// ✅ memberId와 Bubble 포함한 생성자 | ||
public Space(String content, double x, double y, int group, Bubble bubble, Long memberId) { | ||
this.content = content; | ||
this.x = x; | ||
this.y = y; | ||
this.group = group; | ||
this.bubble = bubble; // ✅ `bubble_id` 설정 | ||
this.memberId = memberId; | ||
} | ||
|
||
// ✅ Getter & Setter | ||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public String getContent() { | ||
return content; | ||
} | ||
|
||
public void setContent(String content) { | ||
this.content = content; | ||
} | ||
|
||
public double getX() { | ||
return x; | ||
} | ||
|
||
public void setX(double x) { | ||
this.x = x; | ||
} | ||
|
||
public double getY() { | ||
return y; | ||
} | ||
|
||
public void setY(double y) { | ||
this.y = y; | ||
} | ||
|
||
public Bubble getBubble() { // ✅ Bubble 관련 Getter 추가 | ||
return bubble; | ||
} | ||
|
||
public void setBubble(Bubble bubble) { // ✅ Bubble 관련 Setter 추가 | ||
this.bubble = bubble; | ||
} | ||
|
||
public int getGroup() { | ||
return this.group != null ? this.group : 0; // ✅ null이면 0 반환 | ||
} | ||
|
||
public void setGroup(int group) { // ✅ 변경된 필드명 반영 | ||
this.group = group; | ||
} | ||
|
||
public Long getMemberId() { | ||
return memberId; | ||
} | ||
|
||
public void setMemberId(Long memberId) { | ||
this.memberId = memberId; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
project/src/main/java/com/edison/project/domain/space/repository/SpaceRepository.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 com.edison.project.domain.space.repository; | ||
|
||
import com.edison.project.domain.space.entity.Space; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public interface SpaceRepository extends JpaRepository<Space, Long> { | ||
@Query("SELECT s FROM Space s JOIN FETCH s.bubble WHERE s.bubble.bubbleId = :bubbleId AND s.memberId = :memberId") | ||
List<Space> findByBubble_BubbleIdAndMemberId(@Param("bubbleId") Long bubbleId, @Param("memberId") Long memberId); | ||
|
||
@Query("SELECT s FROM Space s WHERE s.memberId = :memberId") | ||
List<Space> findByMemberId(@Param("memberId") Long memberId); | ||
|
||
} | ||
|
12 changes: 12 additions & 0 deletions
12
project/src/main/java/com/edison/project/domain/space/service/SpaceService.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,12 @@ | ||
package com.edison.project.domain.space.service; | ||
|
||
import com.edison.project.common.response.ApiResponse; | ||
import com.edison.project.global.security.CustomUserPrincipal; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
public interface SpaceService { | ||
|
||
ResponseEntity<ApiResponse> processSpaces(CustomUserPrincipal userPrincipal, Pageable pageable); | ||
ResponseEntity<ApiResponse> getSpaceInfo(); | ||
} |
Oops, something went wrong.