Skip to content

Commit

Permalink
M3-129 Fat : 그룹 검색 api 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
tkdals802 committed Jun 26, 2024
1 parent ec8e288 commit a0b25f1
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
package com.m3pro.groundflip.controller;import org.springframework.web.bind.annotation.RestController;import com.m3pro.groundflip.service.CommunityService;import lombok.RequiredArgsConstructor;@RestController@RequiredArgsConstructorpublic class CommunityController { private final CommunityService communityService;}
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); }}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -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<Community, Long> {}
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);}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
package com.m3pro.groundflip.service;import org.springframework.stereotype.Service;import lombok.RequiredArgsConstructor;@Service@RequiredArgsConstructorpublic class CommunityService {}
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); }}
Expand Down

0 comments on commit a0b25f1

Please sign in to comment.