team-forAdhd / forAdhd-server

For ADHD 서버
1 stars 2 forks source link

게시글 탭 구현 #29

Closed newoceanwave closed 3 months ago

newoceanwave commented 5 months ago

💻 구현 내용

(24. 07. 10 추가)

🛠️ 개발 오류 사항

🗣️ For 리뷰어

(24. 07. 10 추가)

to-do

jkde7721 commented 5 months ago

일단 코드 전반적으로 리뷰 남기겠습니다

p1

예외 처리 방법

22 해당 PR의 For Reviewer 부분에 저희 프로젝트에서의 예외 처리 방법에 대해 코멘트 달아두었습니다.

현재 로그인한 유저의 ID를 얻는 방법

엔티티 내 createdAt, lastModifiedAt 필드

p2

Mapper 클래스의 의존 계층

@RequiredArgsConstructor
@RequestMapping("/api/v1/user")
@RestController
public class UserController {

    private final UserService userService;
    private final UserTokenService userTokenService;
    private final UserEmailAuthService userEmailAuthService;
    private final UserMapper userMapper;

    //...
}

현재 제 코드를 보시면 Controller 계층에서 Mapper 클래스를 의존하고 있습니다.

@Setter의 사용

일부 엔티티 연관관계 매핑 부재

DTO 클래스의 Request, Response 분리

Service 클래스 레벨의 @Transactional 선언

도메인이 다른 Repository 의존

p3

@Table, @Column 어노테이션의 name 속성 지정

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity
@Table(name = "comment")
public class Comment {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "comment_id")
    private Long commentId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "post_id", referencedColumnName = "post_id")
    private GeneralPost postId; // 이 댓글이 속한 게시글 id

    @Column(name = "writer_id")
    private String writerId;

    @Column(name = "content", columnDefinition = "TEXT")
    private String content;

    @Column(name = "created_at", columnDefinition = "TIMESTAMP")
    private LocalDateTime createdAt;

    @Column(name = "last_modified_at", columnDefinition = "TIMESTAMP")
    private LocalDateTime lastModifiedAt;

    @Column(name = "anonymous", columnDefinition = "TINYINT(1)")
    private boolean anonymous;

    @Column(name = "like_count", columnDefinition = "BIGINT")
    private long likeCount;
}

p4

코드 컨벤션 관련

p5

서비스 인터페이스 사용

현재 서현님 구현에서는 Service 인터페이스를 정의한 후 ServiceImpl을 구현하여 작성한 반면 저는 바로 Service 클래스를 사용하였습니다. 이거는 인터페이스로 구체적인 클래스에 의존하지 않도록하는 서현님 방법이 더 좋은 것 같아 제 코드를 수정하겠습니다.


게시글 및 댓글 작성 시 유저 role을 받아와 guest인 경우 custom exception 발생시키는 것도 곧 추가하도록 하겠습니다. => 이거는 SercurityConfig 클래스 보시면 securityFilterChain 메소드 내에서 각 role에 따라 가능한 api 요청을 지정하고 있어 컨트롤러 단에서 별도의 작업을 하실 필요는 없습니다. 좀더 자세히 설명드리면 SecurityFilterExceptionTranslationFilter에서 권한이 없는 api 요청을 한 경우 AccessDeniedException 예외를 발생시키며 해당 예외는 AccessDeniedHandler의 구현체인 JwtAuthorizationFailureHandler(우리 프로젝트에서 직접 정의)가 처리하고 있습니다.

기능 구현하시느라 수고 많으셨습니다...! 다만 기존 코드들을 조금더 살펴보고 코드를 작성하셨으면 좋았을 것 같다는 아쉬움은 조금 듭니다. 또한 pr 날려주신 코드 실행시켜 보면 Mapper 뿐만 아니라 다른 부분에서도 오류가 나고 있습니다. 다음 PR은 모든 api가 정상 동작하는 상태로 날려주세요. 제가 코멘트 남긴 부분에서 이해되지 않는 부분은 댓글 달아주시고 자세한 설명은 수요일날 전달드릴께요 추가로 구현하시면서 변경된 DB 테이블이나 API 스펙 모두 erdcloud, postman에도 적용 부탁드려요. 또한 포스트맨 내 게시글 api 관련 각 요청에 Add Example로 요청, 응답 JSON도 작성해주시면 좋을 것 같습니다.

gitguardian[bot] commented 3 months ago

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | | | -------------- | ------------------ | ------------------------------ | ---------------- | --------------- | -------------------- | | [10222351](https://dashboard.gitguardian.com/workspace/523651/incidents/10222351?occurrence=160328925) | Triggered | Generic Password | be08d17ef30a52eaf1b686b344af2a848e84d3f2 | src/test/java/com/project/foradhd/domain/user/web/mapper/UserMapperTest.java | [View secret](https://github.com/team-forAdhd/forAdhd-server/commit/be08d17ef30a52eaf1b686b344af2a848e84d3f2#diff-7298240abfa4cea7237be80620f60647a6039156406cf82b3c45f91038d1079eL57) |
🛠 Guidelines to remediate hardcoded secrets
1. Understand the implications of revoking this secret by investigating where it is used in your code. 2. Replace and store your secret safely. [Learn here](https://blog.gitguardian.com/secrets-api-management?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment) the best practices. 3. Revoke and [rotate this secret](https://docs.gitguardian.com/secrets-detection/secrets-detection-engine/detectors/generics/generic_password#revoke-the-secret?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment). 4. If possible, [rewrite git history](https://blog.gitguardian.com/rewriting-git-history-cheatsheet?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment). Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data. To avoid such incidents in the future consider - following these [best practices](https://blog.gitguardian.com/secrets-api-management/?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment) for managing and storing secrets including API keys and other credentials - install [secret detection on pre-commit](https://docs.gitguardian.com/ggshield-docs/integrations/git-hooks/pre-commit?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment) to catch secret before it leaves your machine and ease remediation.

🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.