Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -37,7 +37,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.oidcUserService(customOidcUserService);

http.authorizeHttpRequests()
.anyRequest().authenticated();
.anyRequest().permitAll();
Copy link
Member

Choose a reason for hiding this comment

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

insomnia 사용하실 때만 임시로만 부탁드리겠습니다


return http.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.sequence.anonymous.user.application;

import com.sequence.anonymous.user.domain.College;
import com.sequence.anonymous.user.domain.repository.CollegeRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
@RequiredArgsConstructor
Comment on lines +8 to +9
Copy link
Member

Choose a reason for hiding this comment

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

Ctrl + Alt + L 단축키 사용하셔서 포매팅 부탁드립니다~

@Service
public class CollegeService {

private final CollegeRepository collegeRepository;


public List<College> 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> 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를 사용하는 것이 좋습니다~

31 changes: 31 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,31 @@
package com.sequence.anonymous.user.domain;


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

import java.util.ArrayList;
import java.util.List;

@Getter
@Entity
@Table(name = "College")
Copy link
Member

Choose a reason for hiding this comment

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

보통 데이터베이스 테이블 이름, 컬럼과 같은 곳에는 소문자만을 사용하는 것이 기본 컨벤션입니다.

public class College {

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

@Column(unique = true, 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.

학교의 이름은 어플리케이션에서 수정할 일이 없으므로
insertable = false, updatable = false 추가를 부탁드립니다~

@NotNull
private String name;

@OneToMany(mappedBy = "college")
private List<Department> departments = new ArrayList<>();

protected College() {
}

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

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

import java.util.ArrayList;
import java.util.List;

@Entity
public class Department {

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

@ManyToOne
Copy link
Member

Choose a reason for hiding this comment

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

@ManyToOne 과 같이 @manyto 로 시작하는 친구들에게는 LAZY를 설정해주시는 것이 좋습니다.

@JoinColumn(name = "college_id")
private College college;

@Column(unique = true, insertable = false, updatable = false, length = 10)
@NotNull
private String name;

protected Department() {
}

@ManyToMany
@JoinTable(schema = "College")
private List<College> users = new ArrayList<>();
Comment on lines +28 to +30
Copy link
Member

Choose a reason for hiding this comment

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

collages가 조금 더 적합한 네이밍일 것 같습니다~

}
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,10 @@
package com.sequence.anonymous.user.domain.repository;

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

@Repository
public interface CollegeRepository extends JpaRepository<College, Long> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.sequence.anonymous.user.domain.tag.Tag;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface TagRepository extends JpaRepository<Tag, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.sequence.anonymous.user.presentation;


import com.sequence.anonymous.user.application.CollegeService;
import com.sequence.anonymous.user.domain.College;
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("/colleges")
public class CollegeController {

private final CollegeService collegeService;

@GetMapping("")
public ResponseEntity<List<College>> findAll(){

List<College> college = collegeService.findAll();
return ResponseEntity.status(HttpStatus.OK).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.

ResponseEntity.ok(body)를 사용하시면 조금 더 간결하고 편리하게 사용하실 수 있을 것 같습니다~

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

import com.sequence.anonymous.user.application.TagService;
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("/tags")
@RequestMapping("/personality-tags")
public class TagController {
private final TagService tagService;

@GetMapping("")
public ResponseEntity<List<Tag>> findAll() {

private final TagService tagService;
List<Tag> tag = tagService.findAll();
return ResponseEntity.status(HttpStatus.OK).body(tag);
Copy link
Member

Choose a reason for hiding this comment

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

ResponseEntity.ok(body)를 사용하시면 조금 더 간결하고 편리하게 사용하실 수 있을 것 같습니다~

}
}