Skip to content
Merged
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 @@ -35,6 +35,7 @@ public void init() {
new LabQueryService(fakeLabRepository)
);


fakeLabRepository.save(Lab.builder()
.name("Lab A")
.loc("8500")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ public class AboutCommandService {

public Long createAbout(Category category, String content) {
About about = About.create(category, content);
return aboutRepository.save(about).getId();
About savedAbout = aboutRepository.save(about);
return savedAbout.getId();
}
Comment on lines 16 to 20
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

카테고리 유니크 제약 사전 검증/예외 변환 필요

DB 레벨에서 category가 unique인데, 사전 검증 없이 생성 시 DataIntegrityViolationException으로 터질 수 있습니다. 도메인 친화적 예외로 변환하거나, 생성 전에 존재 여부를 체크하세요.

간단한 선행 체크 예시:

   public Long createAbout(Category category, String content) {
+    if (aboutRepository.findByCategory(category).isPresent()) {
+      // TODO: 도메인 전용 예외(예: AboutAlreadyExistsException)로 치환
+      throw new IllegalStateException("이미 존재하는 카테고리: " + category);
+    }
     About about = About.create(category, content);
     About savedAbout = aboutRepository.save(about);
     return savedAbout.getId();
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public Long createAbout(Category category, String content) {
About about = About.create(category, content);
return aboutRepository.save(about).getId();
About savedAbout = aboutRepository.save(about);
return savedAbout.getId();
}
public Long createAbout(Category category, String content) {
if (aboutRepository.findByCategory(category).isPresent()) {
// TODO: 도메인 전용 예외(예: AboutAlreadyExistsException)로 치환
throw new IllegalStateException("이미 존재하는 카테고리: " + category);
}
About about = About.create(category, content);
About savedAbout = aboutRepository.save(about);
return savedAbout.getId();
}
🤖 Prompt for AI Agents
aics-domain/src/main/java/kgu/developers/domain/about/application/command/AboutCommandService.java
lines 16-20: the createAbout method can trigger a
DataIntegrityViolationException when the category column is unique; perform a
pre-check (e.g., aboutRepository.existsByCategory(category)) and throw a
domain-friendly DuplicateCategoryException if true, or alternatively wrap the
save call in a try/catch catching DataIntegrityViolationException and rethrowing
a domain-specific exception; ensure the repository has an existsByCategory
method and the new DuplicateCategoryException is defined and used consistently.


public void updateAbout(Category category, String content) {
About about = aboutRepository.findByCategory(category)
.orElseThrow(AboutNotFoundException::new);
about.updateContent(content);
aboutRepository.save(about);
}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
package kgu.developers.domain.about.domain;

import static jakarta.persistence.EnumType.STRING;
import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import kgu.developers.common.domain.BaseTimeEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = PROTECTED)
public class About extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = IDENTITY)
private Long id;
public class About{

@Column(nullable = false, unique = true)
@Enumerated(STRING)
private Long id;
private Category category;

@Column(nullable = false, columnDefinition = "text")
private String content;

public static About create(Category category, String content) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package kgu.developers.domain.about.infrastructure;

import static jakarta.persistence.EnumType.STRING;
import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

import jakarta.persistence.*;
import kgu.developers.common.domain.BaseTimeEntity;
import kgu.developers.domain.about.domain.About;
import kgu.developers.domain.about.domain.Category;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Table(name ="\"about\"")
@Builder
@Getter
@AllArgsConstructor
@NoArgsConstructor(access = PROTECTED)
public class AboutJpaEntity extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = IDENTITY)
private Long id;

@Column(nullable = false, unique = true)
@Enumerated(STRING)
private Category category;

@Column(nullable = false, columnDefinition = "text")
private String content;


public About toDomain(){
return About.builder()
.id(this.id)
.category(this.category)
.content(this.content)
.build();
}
public static AboutJpaEntity toEntity(About about){
return AboutJpaEntity.builder()
.id(about.getId())
.category(about.getCategory())
.content(about.getContent())
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ public class AboutRepositoryImpl implements AboutRepository {

@Override
public About save(About about) {
return jpaAboutRepository.save(about);
AboutJpaEntity entity = AboutJpaEntity.toEntity(about);
AboutJpaEntity savedEntity = jpaAboutRepository.save(entity);
return savedEntity.toDomain();

}

@Override
public Optional<About> findByCategory(Category category) {
return jpaAboutRepository.findByCategory(category);
Optional<AboutJpaEntity> optionalEntity = jpaAboutRepository.findByCategory(category);
return optionalEntity.map(AboutJpaEntity::toDomain);
}

@Override
public Optional<About> findById(Long id) {
return jpaAboutRepository.findById(id);
Optional<AboutJpaEntity> optionalEntity = jpaAboutRepository.findById(id);
return optionalEntity.map(AboutJpaEntity::toDomain);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

import org.springframework.data.jpa.repository.JpaRepository;

import kgu.developers.domain.about.domain.About;
import kgu.developers.domain.about.domain.Category;

public interface JpaAboutRepository extends JpaRepository<About, Long> {
Optional<About> findByCategory(Category category);
public interface JpaAboutRepository extends JpaRepository<AboutJpaEntity, Long> {
Optional<AboutJpaEntity> findByCategory(Category category);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public void updateClub(Club club, String name, String description, String site,
club.updateName(name);
club.updateDescription(description);
club.updateSite(site);

club.updateFileId(fileId);
clubRepository.save(club);
}

public void deleteClubById(Long id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package kgu.developers.domain.club.infrastructure;

import jakarta.persistence.*;
import kgu.developers.common.domain.BaseTimeEntity;
import kgu.developers.domain.club.domain.Club;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

@Entity
@Table(name = "\"club\"")
@Builder
@Getter
@AllArgsConstructor
@NoArgsConstructor(access = PROTECTED)
public class ClubJpaEntity extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = IDENTITY)
private Long id;

@Column(nullable = false, unique = true, length = 16)
private String name;

@Column(nullable = false, length = 100)
private String description;

@Column(length = 50)
private String site;

private Long fileId;


public Club toDomain() {
return Club.builder()
.id(id)
.name(name)
.description(description)
.site(site)
.fileId(fileId)
.build();
}
public static ClubJpaEntity toEntity(Club club) {
return ClubJpaEntity.builder()
.id(club.getId())
.name(club.getName())
.description(club.getDescription())
.site(club.getSite())
.fileId(club.getFileId())
.build();
}

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

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.springframework.stereotype.Repository;

Expand All @@ -16,17 +17,24 @@ public class ClubRepositoryImpl implements ClubRepository {

@Override
public Club save(Club club) {
return jpaClubRepository.save(club);
ClubJpaEntity entity = ClubJpaEntity.toEntity(club);
ClubJpaEntity savedEntity = jpaClubRepository.save(entity);

return savedEntity.toDomain();
}

@Override
public List<Club> findAll() {
return jpaClubRepository.findAll();
List<ClubJpaEntity> entities = jpaClubRepository.findAll();
return entities.stream()
.map(ClubJpaEntity::toDomain)
.collect(Collectors.toList());
}

@Override
public Optional<Club> findById(Long id) {
return jpaClubRepository.findById(id);
Optional<ClubJpaEntity> optionalEntity = jpaClubRepository.findById(id);
return optionalEntity.map(ClubJpaEntity::toDomain);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

import org.springframework.data.jpa.repository.JpaRepository;

import kgu.developers.domain.club.domain.Club;

public interface JpaClubRepository extends JpaRepository<Club, Long> {
public interface JpaClubRepository extends JpaRepository<ClubJpaEntity, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void updateLab(Lab lab, String name, String loc, String site, String advi
lab.updateSite(site);
lab.updateAdvisor(advisor);
lab.updateFileId(fileId);
labRepository.save(lab);
}

public void deleteLabById(Long id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,19 @@
package kgu.developers.domain.lab.domain;

import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import kgu.developers.common.domain.BaseTimeEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = PROTECTED)
public class Lab extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = IDENTITY)
private Long id;
public class Lab{

@Column(nullable = false, length = 16)
private Long id;
private String name;

@Column(nullable = false, length = 10)
private String loc;

@Column(nullable = false, length = 50)
private String site;

@Column(nullable = false, length = 16)
private String advisor;

@Column(name = "file_id")
private Long fileId;

public static Lab create(String name, String loc, String site, String advisor, Long fileId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import org.springframework.data.jpa.repository.JpaRepository;

import kgu.developers.domain.lab.domain.Lab;

public interface JpaLabRepository extends JpaRepository<Lab, Long> {
List<Lab> findAllByOrderByName();
public interface JpaLabRepository extends JpaRepository<LabJpaEntity, Long> {
List<LabJpaEntity> findAllByOrderByName();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package kgu.developers.domain.lab.infrastructure;

import jakarta.persistence.*;
import kgu.developers.common.domain.BaseTimeEntity;
import kgu.developers.domain.lab.domain.Lab;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;


@Entity
@Table(name = "\"lab\"")
@Builder
@Getter
@AllArgsConstructor
@NoArgsConstructor(access = PROTECTED)
public class LabJpaEntity extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = IDENTITY)
private Long id;

@Column(nullable = false, length = 16)
private String name;

@Column(nullable = false, length = 10)
private String loc;

@Column(nullable = false, length = 50)
private String site;

@Column(nullable = false, length = 16)
private String advisor;

private Long fileId;

public Lab toDomain(){
return Lab.builder()
.id(id)
.name(name)
.loc(loc)
.site(site)
.advisor(advisor)
.fileId(fileId)
.build();
}
public static LabJpaEntity toEntity(Lab lab) {
return LabJpaEntity.builder()
.id(lab.getId())
.name(lab.getName())
.loc(lab.getLoc())
.site(lab.getSite())
.advisor(lab.getAdvisor())
.fileId(lab.getFileId())
.build();
}
}
Loading