Skip to content

Commit

Permalink
Merge pull request #2 from 9oormthon-univ/feature/#1
Browse files Browse the repository at this point in the history
[FEAT] entity 생성
  • Loading branch information
haeun1107 authored Nov 18, 2024
2 parents 90930aa + d02829e commit f7cc896
Show file tree
Hide file tree
Showing 11 changed files with 298 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package danpoong.soenter.domain.enterprise;

import danpoong.soenter.base.ApiResponse;
import danpoong.soenter.domain.enterprise.entity.Enterprise;
import danpoong.soenter.domain.enterprise.entity.Region;
import lombok.RequiredArgsConstructor;
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;

@RestController
@RequiredArgsConstructor
@RequestMapping("/enterprises")
public class EnterpriseController {

private final EnterpriseService enterpriseService;

@GetMapping("/{region}")
public ApiResponse<List<Enterprise>> getEnterprisesByRegion(@PathVariable("region") Region region) {
return enterpriseService.getEnterprisesByRegion(region);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package danpoong.soenter.domain.enterprise;

import danpoong.soenter.base.ApiResponse;
import danpoong.soenter.domain.enterprise.entity.Enterprise;
import danpoong.soenter.domain.enterprise.entity.Region;
import danpoong.soenter.domain.enterprise.repository.EnterpriseRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@RequiredArgsConstructor
@Transactional
public class EnterpriseService {

private final EnterpriseRepository enterpriseRepository;

public ApiResponse<List<Enterprise>> getEnterprisesByRegion(Region region) {
try {
List<Enterprise> enterprises = enterpriseRepository.findAllByRegion(region);
return ApiResponse.onSuccess(enterprises);
} catch (Exception e) {
return ApiResponse.onFailure("500", "지역별 기업 정보를 가져오는 데 실패했습니다.", null);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package danpoong.soenter.domain.enterprise.entity;

import jakarta.persistence.*;
import lombok.*;

@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Table(name = "enterprise")
public class Enterprise {

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

@Enumerated(EnumType.STRING)
@Column
private Region region;

@Column
private Boolean is_cooperative;

@Column
private String certificationNumber;

@Column(nullable = false)
private String name;

@Column
private String businessRegistrationNumber;

@Column
private String socialPurpose;

@Column
private String type;

@Column
private String representativeName;

@Column
private String representativePhone;

@Column
private String city;

@Column
private String district;

@Column
private double latitude;

@Column
private double longitude;

@Column
private String website;

@Column
private Integer certificationYear;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package danpoong.soenter.domain.enterprise.entity;

public enum Region {
경기,
// todo: 나중에 서울 강원 다 추가하면 될듯
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package danpoong.soenter.domain.enterprise.entity;

public enum Type {
사회서비스제공형,
일자리제공형,
지역사회공헌형,
기타
}
30 changes: 30 additions & 0 deletions src/main/java/danpoong/soenter/domain/enterprise/entity/Visit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package danpoong.soenter.domain.enterprise.entity;

import danpoong.soenter.domain.user.entity.User;
import jakarta.persistence.*;
import lombok.*;

import java.time.LocalDate;

@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Table(name = "visit")
public class Visit {

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

@ManyToOne
@JoinColumn(name = "userId", nullable = false)
private User user;

@ManyToOne
@JoinColumn(name = "enterpriseId", nullable = false)
private Enterprise enterprise;

private LocalDate visitDate;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package danpoong.soenter.domain.enterprise.repository;

import danpoong.soenter.domain.enterprise.entity.Enterprise;
import danpoong.soenter.domain.enterprise.entity.Region;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface EnterpriseRepository extends JpaRepository<Enterprise, Long> {
List<Enterprise> findAllByRegion(Region region);
}
27 changes: 27 additions & 0 deletions src/main/java/danpoong/soenter/domain/likes/entity/Likes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package danpoong.soenter.domain.likes.entity;

import danpoong.soenter.domain.enterprise.entity.Enterprise;
import danpoong.soenter.domain.user.entity.User;
import jakarta.persistence.*;
import lombok.*;

@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Table(name = "likes")
public class Likes {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long likeId;

@ManyToOne
@JoinColumn(name = "userId", nullable = false)
private User user;

@ManyToOne
@JoinColumn(name = "enterpriseId", nullable = false)
private Enterprise enterprise;

}
44 changes: 44 additions & 0 deletions src/main/java/danpoong/soenter/domain/review/entity/Review.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package danpoong.soenter.domain.review.entity;

import danpoong.soenter.domain.enterprise.entity.Enterprise;
import danpoong.soenter.domain.user.entity.User;
import jakarta.persistence.*;
import lombok.*;

import java.time.LocalDate;
import java.util.List;

@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Table(name = "review")
public class Review {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long reviewId;

@ManyToOne
@JoinColumn(name = "userId", nullable = false)
private User user;

@ManyToOne
@JoinColumn(name = "enterpriseId", nullable = false)
private Enterprise enterprise;

@Column
private String title;

@Column
private String content;

@Column
private Integer tagNum;

@Column
private LocalDate createAt;

@OneToMany(mappedBy = "review", cascade = CascadeType.ALL, orphanRemoval = true)
private List<TagList> tagList;
}
23 changes: 23 additions & 0 deletions src/main/java/danpoong/soenter/domain/review/entity/TagList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package danpoong.soenter.domain.review.entity;

import jakarta.persistence.*;
import lombok.*;

@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Table(name = "tagList")
public class TagList {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long tagId;

@ManyToOne
@JoinColumn(name = "reviewId", nullable = false)
private Review review;

@Column
private Integer tagNum;
}
32 changes: 32 additions & 0 deletions src/main/java/danpoong/soenter/domain/user/entity/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package danpoong.soenter.domain.user.entity;

import jakarta.persistence.*;
import lombok.*;

@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Table(name = "users")
public class User {

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

@Column(nullable = false)
private String name;

@Column(nullable = false)
private String email;

private String password;

@Column
private String socialType;

@Column
private String socialId; // 로그인한 소셜 타입의 식별자 값 (일반 로그인 : null)

}

0 comments on commit f7cc896

Please sign in to comment.