Skip to content

Commit

Permalink
Merge pull request #39 from kakao-tech-campus-2nd-step3/weekly/5
Browse files Browse the repository at this point in the history
merge: 5주차 작업 master에 반영
  • Loading branch information
peeerr authored Oct 4, 2024
2 parents b808c2b + 632740d commit bde557f
Show file tree
Hide file tree
Showing 64 changed files with 1,654 additions and 288 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/master_weekly_cicd.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: master 브랜치 merge 시 CI/CD 파이프라인
name: master 및 weekly 브랜치 merge 시 CI/CD 파이프라인

on:
push:
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/com/potatocake/everymoment/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.potatocake.everymoment.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.customizers.OpenApiCustomizer;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {

@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.info(new Info().title("API").version("1.0"))
.components(new Components()
.addSecuritySchemes("bearerAuth", new SecurityScheme()
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT")
)
);
}

@Bean
public GroupedOpenApi publicApi() {
return GroupedOpenApi.builder()
.group("public-api")
.pathsToMatch("/**")
.addOpenApiCustomizer(addSecurityItemToAllEndpointsExceptLogin())
.build();
}

private OpenApiCustomizer addSecurityItemToAllEndpointsExceptLogin() {
return openApi -> {
SecurityRequirement securityRequirement = new SecurityRequirement().addList("bearerAuth");
openApi.getPaths().forEach((path, item) -> {
if (!"/api/members/login".equals(path)) {
item.readOperations().forEach(operation -> {
operation.addSecurityItem(securityRequirement);
});
}
});
};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.potatocake.everymoment.controller;

import com.potatocake.everymoment.dto.SuccessResponse;
import com.potatocake.everymoment.dto.request.CategoryCreateRequest;
import com.potatocake.everymoment.dto.response.CategoryResponse;
import com.potatocake.everymoment.security.MemberDetails;
import com.potatocake.everymoment.service.CategoryService;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@RequestMapping("/api/categories")
@RestController
public class CategoryController {

private final CategoryService categoryService;

@GetMapping
public ResponseEntity<SuccessResponse<CategoryResponse>> getCategories(
@AuthenticationPrincipal MemberDetails memberDetails) {
List<CategoryResponse> categories = categoryService.getCategories(memberDetails.getId());

return ResponseEntity.ok()
.body(SuccessResponse.ok(categories));
}

@PostMapping
public ResponseEntity<SuccessResponse> addCategory(@RequestBody @Valid CategoryCreateRequest request,
@AuthenticationPrincipal MemberDetails memberDetails) {
categoryService.addCategory(memberDetails.getId(), request);

return ResponseEntity.ok()
.body(SuccessResponse.ok());
}

@PatchMapping("/{categoryId}")
public ResponseEntity<SuccessResponse> updateCategory(@PathVariable Long categoryId,
@RequestBody @Valid CategoryCreateRequest request,
@AuthenticationPrincipal MemberDetails memberDetails) {
categoryService.updateCategory(categoryId, memberDetails.getId(), request);

return ResponseEntity.ok()
.body(SuccessResponse.ok());
}

@DeleteMapping("/{categoryId}")
public ResponseEntity<SuccessResponse> deleteCategory(@PathVariable Long categoryId,
@AuthenticationPrincipal MemberDetails memberDetails) {
categoryService.deleteCategory(categoryId, memberDetails.getId());

return ResponseEntity.ok()
.body(SuccessResponse.ok());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.potatocake.everymoment.controller;

import com.potatocake.everymoment.dto.SuccessResponse;
import com.potatocake.everymoment.dto.request.CommentRequest;
import com.potatocake.everymoment.security.MemberDetails;
import com.potatocake.everymoment.service.CommentService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PatchMapping;
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.RestController;

@RequiredArgsConstructor
@RestController
@RequestMapping("/api/comments")
public class CommentController {

private final CommentService commentService;

//댓글 수정
@PatchMapping("/{commentId}")
public ResponseEntity<SuccessResponse<Void>> updateComment(
@AuthenticationPrincipal MemberDetails memberDetails,
@PathVariable Long commentId,
@RequestBody CommentRequest commentRequest) {
Long memberId = memberDetails.getId();

commentService.updateComment(memberId, commentId, commentRequest);

return ResponseEntity.ok()
.body(SuccessResponse.ok());
}

//댓글 삭제
@DeleteMapping("/{commentId}")
public ResponseEntity<SuccessResponse<Void>> deleteComment(
@AuthenticationPrincipal MemberDetails memberDetails,
@PathVariable Long commentId) {
Long memberId = memberDetails.getId();

commentService.deleteComment(memberId, commentId);

return ResponseEntity.ok()
.body(SuccessResponse.ok());
}
}
Loading

0 comments on commit bde557f

Please sign in to comment.