Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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,18 @@
package com.sequence.anonymous.user.application;

import com.sequence.anonymous.user.domain.College;
import com.sequence.anonymous.user.domain.repository.CollegeRepository;
import com.sequence.anonymous.user.domain.repository.TagRepository;
import com.sequence.anonymous.user.domain.tag.Tag;

import java.util.List;

public class CollegeService {

private CollegeRepository collegeRepository;


public List<College> printAll(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

함수의 기능상 printAll()보다 findAll()이 더 적합한 것 같습니다!

return collegeRepository.findAll();
}
Comment on lines +16 to +18
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Controller <-> Service간에 데이터를 전달할 때는 entity 보다는 dto를 사용하는 것이 좋습니다~

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package com.sequence.anonymous.user.application;

import com.sequence.anonymous.user.domain.repository.TagRepository;
import com.sequence.anonymous.user.domain.tag.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@RequiredArgsConstructor
@Service
public class TagService {

private final TagRepository tagRepository;
}


public List<Tag> printAll(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

함수의 기능상 printAll()보다 findAll()이 더 적합한 것 같습니다!

return tagRepository.findAll(); }
}
Comment on lines +17 to +19
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Controller <-> Service간에 데이터를 전달할 때는 entity 보다는 dto를 사용하는 것이 좋습니다~

23 changes: 23 additions & 0 deletions src/main/java/com/sequence/anonymous/user/domain/College.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.sequence.anonymous.user.domain;


import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;

@Getter
@Entity
public class College {

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

@Column(unique = true, insertable = false, updatable = false, length = 10)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

컬럼 조건을 상세하게 지정해주셨네요 👍👍

@NotNull
private String name;

protected College() {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.sequence.anonymous.user.domain.dto;

import com.sequence.anonymous.user.domain.College;
import com.sequence.anonymous.user.domain.tag.Tag;
import lombok.Getter;

@Getter
public class CollegeResponse {

private final Long id;
private final String collegeName;


public CollegeResponse(College college){

this.id = college.getId();
this.collegeName = college.getName();

}


}
Comment on lines +7 to +22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요즘 dto를 만들 때는 record를 사용하시면 편리합니다~

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.sequence.anonymous.user.domain.dto;

import com.sequence.anonymous.user.domain.tag.Tag;
import lombok.Getter;

@Getter
public class TagResponse {

private final Long id;
private final String user;


public TagResponse(Tag tag){
this.id = tag.getId();
this.user = tag.getName();
}


}
Comment on lines +6 to +19
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요즘 dto를 만들 때는 record를 사용하시면 편리합니다~

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.sequence.anonymous.user.domain.repository;

import com.sequence.anonymous.user.domain.College;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CollegeRepository extends JpaRepository<College, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.sequence.anonymous.user.presentation;


import com.sequence.anonymous.user.application.CollegeService;
import com.sequence.anonymous.user.domain.College;
import com.sequence.anonymous.user.domain.tag.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/api/colleges")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

스펙상 rest api 앞에는 /api가 붙지 않습니다~

public class CollegeController {

private final CollegeService collegeService;

@GetMapping("/")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rest api 규칙 중 마지막에 /가 붙지 않는 규칙이 있습니다.

public ResponseEntity<List<College>> findAll(){

List<College> college = collegeService.printAll();
return ResponseEntity.status(HttpStatus.CREATED).body((List<College>) college);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HttpStatus.CREATED 보다 HttpStatus.OK 가 더 적합한 것 같습니다~

}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
package com.sequence.anonymous.user.presentation;

import com.sequence.anonymous.user.application.TagService;
import com.sequence.anonymous.user.domain.dto.TagResponse;
import com.sequence.anonymous.user.domain.tag.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/tags")
@RequestMapping("/api/personality-tags")
public class TagController {

private final TagService tagService;

@GetMapping("/")
public ResponseEntity<List<Tag>>findAll(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

커밋 전 idea의 포메팅 기능 이용을 부탁드립니다!


List<Tag> tag = tagService.printAll();
return ResponseEntity.status(HttpStatus.CREATED).body((List<Tag>) tag);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HttpStatus.CREATED 보다 HttpStatus.OK 가 더 적합한 것 같습니다~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(List)를 통해 형변환이 이루어지고 있는데,
불필요한 코드 같습니다!

}
}