-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
36 changes: 35 additions & 1 deletion
36
src/main/java/com/m3pro/groundflip/controller/CommunityController.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 |
---|---|---|
@@ -1 +1,35 @@ | ||
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@RequiredArgsConstructorpublic class CommunityController { private final CommunityService communityService; @GetMapping("/api/groups")//그룹 검색 public List<ListResponseCommunity> getCommunitys(@RequestParam String searchKeyword) { return communityService.findCommunityByName(searchKeyword); } @GetMapping("/api/groups/{groupId}")//그룹 정보 api인데 아직 미완성 public ResponseGetGroup findGroupById(@PathVariable Long groupId) { return communityService.findCommunityById(groupId); }} | ||
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<ListResponseCommunity> getCommunitys(@RequestParam String searchKeyword) { | ||
return communityService.findCommunityByName(searchKeyword); | ||
} | ||
|
||
@GetMapping("/api/groups/{groupId}")//그룹 정보 api인데 아직 미완성 | ||
public ResponseGetGroup findGroupById(@PathVariable Long groupId) { | ||
return communityService.findCommunityById(groupId); | ||
} | ||
|
||
} |
15 changes: 14 additions & 1 deletion
15
src/main/java/com/m3pro/groundflip/repository/CommunityRepository.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 |
---|---|---|
@@ -1 +1,14 @@ | ||
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<Community, Long> { List<Community> findByNameLike(String name);} | ||
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<Community, Long> { | ||
|
||
List<Community> findByNameLike(String name); | ||
} |
35 changes: 34 additions & 1 deletion
35
src/main/java/com/m3pro/groundflip/service/CommunityService.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 |
---|---|---|
@@ -1 +1,34 @@ | ||
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@RequiredArgsConstructorpublic class CommunityService { private final CommunityRepository communityRepository; //그룹 검색 api public List<ListResponseCommunity> findCommunityByName(String name){ List<Community> 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); }} | ||
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<ListResponseCommunity> findCommunityByName(String name){ | ||
List<Community> 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); | ||
} | ||
} |