diff --git a/src/main/java/com/m3pro/groundflip/controller/CommunityController.java b/src/main/java/com/m3pro/groundflip/controller/CommunityController.java index d62b0bec..9cb60647 100644 --- a/src/main/java/com/m3pro/groundflip/controller/CommunityController.java +++ b/src/main/java/com/m3pro/groundflip/controller/CommunityController.java @@ -1 +1 @@ -package com.m3pro.groundflip.controller; import org.springframework.web.bind.annotation.RestController; import com.m3pro.groundflip.service.CommunityService; import lombok.RequiredArgsConstructor; @RestController @RequiredArgsConstructor public class CommunityController { private final CommunityService communityService; } \ No newline at end of file +package com.m3pro.groundflip.controller; import java.util.List; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import com.m3pro.groundflip.domain.dto.community.ListResponseCommunity; import com.m3pro.groundflip.domain.dto.community.ResponseGetGroup; import com.m3pro.groundflip.domain.entity.Community; import com.m3pro.groundflip.service.CommunityService; import lombok.RequiredArgsConstructor; @RestController @RequiredArgsConstructor public class CommunityController { private final CommunityService communityService; @GetMapping("/api/groups")//그룹 검색 public List getCommunitys(@RequestParam String searchKeyword) { return communityService.findCommunityByName(searchKeyword); } @GetMapping("/api/groups/{groupId}")//그룹 정보 api인데 아직 미완성 public ResponseGetGroup findGroupById(@PathVariable Long groupId) { return communityService.findCommunityById(groupId); } } \ No newline at end of file diff --git a/src/main/java/com/m3pro/groundflip/domain/dto/community/ListResponseCommunity.java b/src/main/java/com/m3pro/groundflip/domain/dto/community/ListResponseCommunity.java new file mode 100644 index 00000000..e1a8545c --- /dev/null +++ b/src/main/java/com/m3pro/groundflip/domain/dto/community/ListResponseCommunity.java @@ -0,0 +1,23 @@ +package com.m3pro.groundflip.domain.dto.community; + +import com.m3pro.groundflip.domain.entity.Community; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@AllArgsConstructor +@NoArgsConstructor +@Data +@Builder +public class ListResponseCommunity { + private String name; + + public static ListResponseCommunity from(Community community) { + return ListResponseCommunity.builder() + .name(community.getName()) + .build(); + } + +} diff --git a/src/main/java/com/m3pro/groundflip/domain/dto/community/ResponseGetGroup.java b/src/main/java/com/m3pro/groundflip/domain/dto/community/ResponseGetGroup.java new file mode 100644 index 00000000..17025801 --- /dev/null +++ b/src/main/java/com/m3pro/groundflip/domain/dto/community/ResponseGetGroup.java @@ -0,0 +1,33 @@ +package com.m3pro.groundflip.domain.dto.community; + +import com.m3pro.groundflip.domain.entity.Community; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@AllArgsConstructor +@NoArgsConstructor +@Data +@Builder +public class ResponseGetGroup { + private String name; + private String pixelColor; + private String profileImageUrl; + private String backgroundImageUrl; + private int groupRanking; + private int memberCount; + + public static ResponseGetGroup from(Community community, int groupRanking, int memberCount){ + return ResponseGetGroup.builder() + .name(community.getName()) + .pixelColor(community.getPixelColor()) + .profileImageUrl(community.getProfileImageUrl()) + .backgroundImageUrl(community.getBackgroundImageUrl()) + .groupRanking(groupRanking) + .memberCount(memberCount) + .build(); + } + +} diff --git a/src/main/java/com/m3pro/groundflip/repository/CommunityRepository.java b/src/main/java/com/m3pro/groundflip/repository/CommunityRepository.java index 195ff5c2..eb7700c7 100644 --- a/src/main/java/com/m3pro/groundflip/repository/CommunityRepository.java +++ b/src/main/java/com/m3pro/groundflip/repository/CommunityRepository.java @@ -1 +1 @@ -package com.m3pro.groundflip.repository; import org.springframework.data.jpa.repository.JpaRepository; import com.m3pro.groundflip.domain.entity.Community; public interface CommunityRepository extends JpaRepository { } \ No newline at end of file +package com.m3pro.groundflip.repository; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import com.m3pro.groundflip.domain.entity.Community; public interface CommunityRepository extends JpaRepository { List findByNameLike(String name); } \ No newline at end of file diff --git a/src/main/java/com/m3pro/groundflip/service/CommunityService.java b/src/main/java/com/m3pro/groundflip/service/CommunityService.java index 3ff312e1..24c1d34a 100644 --- a/src/main/java/com/m3pro/groundflip/service/CommunityService.java +++ b/src/main/java/com/m3pro/groundflip/service/CommunityService.java @@ -1 +1 @@ -package com.m3pro.groundflip.service; import org.springframework.stereotype.Service; import lombok.RequiredArgsConstructor; @Service @RequiredArgsConstructor public class CommunityService { } \ No newline at end of file +package com.m3pro.groundflip.service; import java.util.List; import org.springframework.stereotype.Service; import com.m3pro.groundflip.domain.dto.community.ListResponseCommunity; import com.m3pro.groundflip.domain.dto.community.ResponseGetGroup; import com.m3pro.groundflip.domain.entity.Community; import com.m3pro.groundflip.repository.CommunityRepository; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; @Service @RequiredArgsConstructor public class CommunityService { private final CommunityRepository communityRepository; //그룹 검색 api public List findCommunityByName(String name){ List community = communityRepository.findByNameLike("%"+name+"%"); return community.stream().map(ListResponseCommunity::from).toList(); } // 그룹 정보 get api인데 일단 검색만 하면 되는걸 깜빡하고 작성해버렸습니다. // 랭킹, 멤버카운트는 더미로 0을 넣어놨습니다. 나중에 계산해서 값을 넣을 수 있을 듯 합니다. public ResponseGetGroup findCommunityById(Long id){ Community community = communityRepository.findById(id) .orElseThrow(() -> new IllegalArgumentException("Community not found")); return ResponseGetGroup.from(community, 0,0); } } \ No newline at end of file