Skip to content

Commit

Permalink
Merge pull request #18 from Leets-Official/feat/#11/지원서-코멘트-작성
Browse files Browse the repository at this point in the history
[feat] #12 지원서 코멘트 작성
  • Loading branch information
ay-eonii authored Jan 27, 2024
2 parents 15d3c64 + 7e15d3f commit d3ade28
Show file tree
Hide file tree
Showing 13 changed files with 241 additions and 13 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ COPY ${JAR_FILE} /app.jar

EXPOSE 8080

ENTRYPOINT ["java", "-Dspring.profiles.active=prod", "-jar", "/app.jar"]
#ENTRYPOINT ["java", "-Dspring.profiles.active=prod", "-jar", "/app.jar"]
ENTRYPOINT ["java", "-jar", "/app.jar"]
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package land.leets.domain.admin.presentation.dto;

import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class AdminDetailsResponse {
@NotBlank
private String name;
}
28 changes: 28 additions & 0 deletions src/main/java/land/leets/domain/comment/domain/Comment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package land.leets.domain.comment.domain;

import jakarta.persistence.*;
import land.leets.domain.admin.domain.Admin;
import land.leets.domain.shared.BaseTimeEntity;
import lombok.*;

@Entity(name = "comments")
@Builder
@Getter
@Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class Comment extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
private Long applicationId;

@Column(nullable = false)
private String content;

@OneToOne
private Admin admin;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package land.leets.domain.comment.domain.repository;

import land.leets.domain.comment.domain.Comment;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface CommentRepository extends JpaRepository<Comment, Long> {
List<Comment> findAllByApplicationId(Long applicationId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package land.leets.domain.comment.presentation;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import land.leets.domain.auth.AuthDetails;
import land.leets.domain.comment.presentation.dto.CommentRequest;
import land.leets.domain.comment.presentation.dto.CommentResponse;
import land.leets.domain.comment.usecase.CreateComment;
import land.leets.domain.comment.usecase.GetComments;
import land.leets.global.error.ErrorResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;

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

private final CreateComment createComment;
private final GetComments getComments;

@Operation(summary = "(관리자) 댓글 작성", description = "지원서에 댓글을 작성합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "400", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "403", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "404", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "500", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PostMapping
public CommentResponse create(@AuthenticationPrincipal AuthDetails authDetails,
@RequestBody CommentRequest request) {
return createComment.execute(authDetails, request);
}

@Operation(summary = "(관리자) 댓글 조회", description = "지원서 댓글을 조회합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "400", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "403", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "404", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "500", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@GetMapping("/{applicationId}")
public List<CommentResponse> get(@PathVariable Long applicationId) {
return getComments.execute(applicationId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package land.leets.domain.comment.presentation.dto;

import jakarta.validation.constraints.NotBlank;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class CommentRequest {
@NotBlank
private Long applicationId;

@NotBlank
private String content;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package land.leets.domain.comment.presentation.dto;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import land.leets.domain.admin.presentation.dto.AdminDetailsResponse;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.time.LocalDateTime;

@Getter
@AllArgsConstructor
public class CommentResponse {
@NotBlank
private String content;

@NotBlank
private LocalDateTime createdAt;

@NotBlank
private LocalDateTime updatedAt;

@NotNull
private AdminDetailsResponse admin;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package land.leets.domain.comment.presentation.mapper;

import land.leets.domain.comment.domain.Comment;
import land.leets.domain.comment.presentation.dto.CommentResponse;
import org.mapstruct.BeanMapping;
import org.mapstruct.Mapper;
import org.mapstruct.NullValuePropertyMappingStrategy;
import org.mapstruct.ReportingPolicy;

@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface CommentMapper {
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
CommentResponse mappingCommentToDto(Comment comment);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package land.leets.domain.comment.usecase;

import land.leets.domain.auth.AuthDetails;
import land.leets.domain.comment.presentation.dto.CommentRequest;
import land.leets.domain.comment.presentation.dto.CommentResponse;

public interface CreateComment {
CommentResponse execute(AuthDetails authDetails, CommentRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package land.leets.domain.comment.usecase;

import land.leets.domain.admin.domain.Admin;
import land.leets.domain.admin.domain.repository.AdminRepository;
import land.leets.domain.admin.exception.AdminNotFoundException;
import land.leets.domain.auth.AuthDetails;
import land.leets.domain.comment.domain.Comment;
import land.leets.domain.comment.domain.repository.CommentRepository;
import land.leets.domain.comment.presentation.dto.CommentRequest;
import land.leets.domain.comment.presentation.dto.CommentResponse;
import land.leets.domain.comment.presentation.mapper.CommentMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class CreateCommentImpl implements CreateComment {
private final CommentRepository commentRepository;
private final AdminRepository adminRepository;
private final CommentMapper commentMapper;

@Override
public CommentResponse execute(AuthDetails authDetails, CommentRequest request) {
Admin admin = adminRepository.findById(authDetails.getUid()).orElseThrow(AdminNotFoundException::new);
Comment comment = Comment.builder()
.applicationId(request.getApplicationId())
.content(request.getContent())
.admin(admin)
.build();
Comment save = commentRepository.save(comment);
return commentMapper.mappingCommentToDto(save);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package land.leets.domain.comment.usecase;

import land.leets.domain.comment.presentation.dto.CommentResponse;

import java.util.List;

public interface GetComments {
List<CommentResponse> execute(Long applicationId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package land.leets.domain.comment.usecase;

import land.leets.domain.comment.domain.Comment;
import land.leets.domain.comment.domain.repository.CommentRepository;
import land.leets.domain.comment.presentation.dto.CommentResponse;
import land.leets.domain.comment.presentation.mapper.CommentMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class GetCommentsImpl implements GetComments {
private final CommentRepository commentRepository;
private final CommentMapper commentMapper;

@Override
public List<CommentResponse> execute(Long applicationId) {
List<Comment> comments = commentRepository.findAllByApplicationId(applicationId);
return comments.stream()
.map(commentMapper::mappingCommentToDto)
.toList();
}
}
27 changes: 15 additions & 12 deletions src/main/java/land/leets/global/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import land.leets.domain.auth.exception.PermissionDeniedException;
import land.leets.domain.shared.AuthRole;
import land.leets.global.filter.ExceptionHandleFilter;
import land.leets.global.jwt.*;
import land.leets.global.jwt.JwtFilter;
import land.leets.global.jwt.JwtProvider;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -52,7 +53,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.authorizeHttpRequests()
.requestMatchers(CorsUtils::isCorsRequest).permitAll()

.requestMatchers(HttpMethod.GET,"/health-check").permitAll()
.requestMatchers(HttpMethod.GET, "/health-check").permitAll()

.requestMatchers("/v3/api-docs/**", "/swagger-ui/**").permitAll()

Expand All @@ -61,23 +62,25 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers("/oauth2/authorization/*").permitAll()

.requestMatchers("/user/login", "/admin/login").permitAll()
.requestMatchers("/user/refresh","/admin/refresh").permitAll()
.requestMatchers("/user/refresh", "/admin/refresh").permitAll()

.requestMatchers("/user/me").hasAuthority(AuthRole.ROLE_USER.getRole())
.requestMatchers("/admin/me").hasAuthority(AuthRole.ROLE_ADMIN.getRole())

.requestMatchers("/interview").permitAll()
.requestMatchers(HttpMethod.GET,"/application").hasAuthority(AuthRole.ROLE_ADMIN.getRole())
.requestMatchers(HttpMethod.POST,"/application").hasAuthority(AuthRole.ROLE_USER.getRole())
.requestMatchers(HttpMethod.PATCH,"/application").hasAuthority(AuthRole.ROLE_USER.getRole())
.requestMatchers(HttpMethod.GET,"/application/me").hasAuthority(AuthRole.ROLE_USER.getRole())
.requestMatchers(HttpMethod.GET,"/application/**").hasAuthority(AuthRole.ROLE_ADMIN.getRole())
.requestMatchers(HttpMethod.PATCH,"/application/**").hasAuthority(AuthRole.ROLE_ADMIN.getRole())
.requestMatchers(HttpMethod.GET, "/application").hasAuthority(AuthRole.ROLE_ADMIN.getRole())
.requestMatchers(HttpMethod.POST, "/application").hasAuthority(AuthRole.ROLE_USER.getRole())
.requestMatchers(HttpMethod.PATCH, "/application").hasAuthority(AuthRole.ROLE_USER.getRole())
.requestMatchers(HttpMethod.GET, "/application/me").hasAuthority(AuthRole.ROLE_USER.getRole())
.requestMatchers(HttpMethod.GET, "/application/**").hasAuthority(AuthRole.ROLE_ADMIN.getRole())
.requestMatchers(HttpMethod.PATCH, "/application/**").hasAuthority(AuthRole.ROLE_ADMIN.getRole())

.requestMatchers(HttpMethod.GET,"/interview").permitAll()
.requestMatchers(HttpMethod.PATCH,"/interview/**").hasAuthority(AuthRole.ROLE_ADMIN.getRole())
.requestMatchers(HttpMethod.GET, "/interview").permitAll()
.requestMatchers(HttpMethod.PATCH, "/interview/**").hasAuthority(AuthRole.ROLE_ADMIN.getRole())

.requestMatchers(HttpMethod.POST,"/mail/**").hasAuthority(AuthRole.ROLE_ADMIN.getRole())
.requestMatchers("/comments/**").hasAuthority(AuthRole.ROLE_ADMIN.getRole())

.requestMatchers(HttpMethod.POST, "/mail/**").hasAuthority(AuthRole.ROLE_ADMIN.getRole())

.anyRequest().authenticated();

Expand Down

0 comments on commit d3ade28

Please sign in to comment.