-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from kakao-tech-campus-2nd-step3/weekly/5
merge: 5주차 작업 master에 반영
- Loading branch information
Showing
64 changed files
with
1,654 additions
and
288 deletions.
There are no files selected for viewing
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,4 +1,4 @@ | ||
name: master 브랜치 merge 시 CI/CD 파이프라인 | ||
name: master 및 weekly 브랜치 merge 시 CI/CD 파이프라인 | ||
|
||
on: | ||
push: | ||
|
51 changes: 51 additions & 0 deletions
51
src/main/java/com/potatocake/everymoment/config/SwaggerConfig.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 |
---|---|---|
@@ -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); | ||
}); | ||
} | ||
}); | ||
}; | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/com/potatocake/everymoment/controller/CategoryController.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 |
---|---|---|
@@ -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()); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/potatocake/everymoment/controller/CommentController.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 |
---|---|---|
@@ -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()); | ||
} | ||
} |
Oops, something went wrong.