Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

문화 생성 기능 추가함 #53

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package likelion.MZConnent.api.culture;

import likelion.MZConnent.domain.culture.Culture;
import likelion.MZConnent.domain.culture.CultureCategory;
import likelion.MZConnent.dto.culture.request.CreateCultureRequest;
import likelion.MZConnent.repository.culture.CultureCategoryRepository;
import likelion.MZConnent.repository.culture.CultureRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;
import java.util.Random;

// 문화 추가용
@RestController
@Slf4j
@RequiredArgsConstructor
public class CreateCultureController {
private final CultureRepository cultureRepository;
private final CultureCategoryRepository cultureCategoryRepository;

@PostMapping("/api/cultures")
public ResponseEntity<Culture> createCulture(@RequestBody CreateCultureRequest request) {

log.info("culture request: {}", request);

CultureCategory cultureCategory = cultureCategoryRepository.findById(request.getCultureCategoryId()).orElseThrow(()-> new IllegalArgumentException("해당하는 카테고리가 존재하지 않습니다."));

Culture newCulture = Culture.builder()
.name(request.getName())
.summary(request.getSummary())
.content(request.getContent())
.cultureImageUrl(request
.getCultureImageUrl())
.recommendedMember(request.getRecommendedMember())
.cultureCategory(cultureCategory)
.build();

Culture savedCulture = cultureRepository.save(newCulture);

return ResponseEntity.ok(savedCulture);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class SecurityConfig {
private final String[] adminUrl = {"/admin/**"};
private final String[] permitAllUrl = {"/error",
"/api/auth/login", "/api/auth/logout", // 회원
"/api/categories/culture", // 문화
"/api/categories/culture", "/api/cultures", // 문화
"/api/clubs", "/api/clubs/*/join", // 동아리
"/api/clubs/*",
"/swagger", "/swagger-ui.html", "/swagger-ui/**", "/api-docs", "/api-docs/**", "/v3/api-docs/**", //swagger
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/likelion/MZConnent/domain/culture/Culture.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Culture {
private Long cultureId;

@Column(nullable = false)
private int interestCount;
private int interestCount = 0;

@Column(columnDefinition = "TEXT", nullable = false)
private String content;
Expand All @@ -33,7 +33,7 @@ public class Culture {
private String summary;

@Column(nullable = false)
private int clubCount;
private int clubCount = 0;

@Column(length = 100, nullable = false)
private String recommendedMember;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,4 @@ public class CultureCategory {

@Column(length = 255, nullable = false)
private String name;

@OneToMany(mappedBy = "cultureCategory", cascade = CascadeType.ALL)
private List<SelfIntroduction> selfIntroductions = new ArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package likelion.MZConnent.dto.culture.request;

import jakarta.persistence.Column;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import likelion.MZConnent.domain.culture.CultureCategory;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

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

private String summary;

private String content;

private String cultureImageUrl;

private String recommendedMember;

private Long cultureCategoryId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public ResponseEntity<ApiResponseJson> handleHttpMessageNotReadableException(Ex
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(RuntimeException.class)
public ResponseEntity<ApiResponseJson> handleRuntimeException(RuntimeException e) {
log.info("error: {}", e);
return new ResponseEntity<>( new ApiResponseJson(HttpStatus.INTERNAL_SERVER_ERROR, "서버에 오류가 발생했습니다."),
HttpStatus.INTERNAL_SERVER_ERROR);
}
Expand Down
Loading