Skip to content

Commit

Permalink
Merge pull request #47 from LIKELION-TEAM4-HACKATHON/feature/get-regi…
Browse files Browse the repository at this point in the history
…on-category

feat: 지역 카테고리 조회 기능 구현
  • Loading branch information
oosedus authored Jul 25, 2024
2 parents 6ee7193 + 5b07032 commit 33e7be7
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 5 deletions.
Binary file modified .gradle/8.8/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/8.8/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
15 changes: 11 additions & 4 deletions src/main/java/likelion/MZConnent/api/club/ClubController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
import likelion.MZConnent.domain.member.Member;
import likelion.MZConnent.dto.club.request.CreateClubRequest;
import likelion.MZConnent.dto.club.response.CreateClubResponse;
import likelion.MZConnent.dto.club.response.RegionCategoryResponse;
import likelion.MZConnent.jwt.principle.UserPrinciple;
import likelion.MZConnent.repository.member.MemberRepository;
import likelion.MZConnent.service.club.ClubService;
import likelion.MZConnent.service.club.RegionCategoryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequiredArgsConstructor
public class ClubController {
private final ClubService clubService;
private final MemberRepository memberRepository;
private final RegionCategoryService regionCategoryService;

@PostMapping("/api/clubs")
public ResponseEntity<CreateClubResponse> createClub(@Valid @RequestBody CreateClubRequest request, @AuthenticationPrincipal UserPrinciple userPrinciple, BindingResult bindingResult) {
Expand All @@ -39,4 +39,11 @@ public ResponseEntity<CreateClubResponse> createClub(@Valid @RequestBody CreateC
CreateClubResponse response = clubService.createClub(request, member);
return ResponseEntity.ok(response);
}

@GetMapping("/api/categories/region")
public ResponseEntity<RegionCategoryResponse> getAllRegionCategories() {
RegionCategoryResponse all = regionCategoryService.getAllRegionCategories();
log.info("전체 지역 카테고리: {}", all.getRegionCategories());
return ResponseEntity.ok(all);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class SecurityConfig {
"/swagger", "/swagger-ui.html", "/swagger-ui/**", "/api-docs", "/api-docs/**", "/v3/api-docs/**", //swagger
};
private final String[] anonymousUrl = {
"/api/auth/signup"
"/api/auth/signup", "/api/categories/region"
};


Expand Down
18 changes: 18 additions & 0 deletions src/main/java/likelion/MZConnent/dto/club/RegionCategoryDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package likelion.MZConnent.dto.club;

import likelion.MZConnent.domain.club.RegionCategory;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class RegionCategoryDto {
private Long regionCategoryId;
private String name;

public RegionCategoryDto(RegionCategory regionCategory) {
this.regionCategoryId = regionCategory.getRegionId();
this.name = regionCategory.getName();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package likelion.MZConnent.dto.club.response;

import likelion.MZConnent.domain.club.RegionCategory;
import likelion.MZConnent.dto.club.RegionCategoryDto;
import likelion.MZConnent.dto.culture.CultureCategoryDto;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class RegionCategoryResponse {
List<RegionCategoryDto> regionCategories = new ArrayList<>();

public RegionCategoryResponse(List<RegionCategory> regionCategory) {
this.regionCategories = regionCategory.stream()
.map(RegionCategoryDto::new)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package likelion.MZConnent.service.club;

import likelion.MZConnent.domain.club.RegionCategory;
import likelion.MZConnent.dto.club.RegionCategoryDto;
import likelion.MZConnent.dto.club.response.RegionCategoryResponse;
import likelion.MZConnent.repository.club.RegionCategoryRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class RegionCategoryService {
private final RegionCategoryRepository regionCategoryRepository;

public RegionCategoryResponse getAllRegionCategories() {
List<RegionCategory> regionCategories = regionCategoryRepository.findAll();

return new RegionCategoryResponse(regionCategories);
}
}

0 comments on commit 33e7be7

Please sign in to comment.