Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] feat: 엔티티 설계 #15

Merged
merged 5 commits into from
Jul 18, 2023
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
60 changes: 60 additions & 0 deletions backend/src/main/java/com/now/naaga/game/domain/Game.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.now.naaga.game.domain;

import com.now.naaga.member.domain.Member;
import com.now.naaga.place.domain.Place;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import java.util.Objects;

@Entity
public class Game {

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

@Enumerated(EnumType.STRING)
private GameStatus gameStatus;

@ManyToOne
@JoinColumn(name = "member_id")
private Member member;

@ManyToOne
@JoinColumn(name = "place_id")
private Place place;

@Override
public boolean equals(final Object o) {

if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final Game game = (Game) o;
return Objects.equals(id, game.id);
}

@Override
public int hashCode() {
return Objects.hash(id);
}

@Override
public String toString() {
return "Game{" +
"id=" + id +
", gameStatus=" + gameStatus +
", memberId=" + member.getId() +
", placeId=" + place.getId() +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.now.naaga.game.domain;

public enum GameStatus {

IN_PROGRESSING,
DONE,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.now.naaga.game.repository;

import com.now.naaga.game.domain.Game;
import org.springframework.data.jpa.repository.JpaRepository;

public interface GameRepository extends JpaRepository<Game, Long> {

}
60 changes: 60 additions & 0 deletions backend/src/main/java/com/now/naaga/member/domain/Member.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.now.naaga.member.domain;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import java.util.Objects;

@Entity
public class Member {

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

private String email;

private String password;

protected Member() {
}

public Long getId() {
return id;
}

public String getEmail() {
return email;
}

public String getPassword() {
return password;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final Member member = (Member) o;
return Objects.equals(id, member.id);
}

@Override
public int hashCode() {
return Objects.hash(id);
}

@Override
public String toString() {
return "Member{" +
"id=" + id +
", email='" + email + '\'' +
", password='" + password + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.now.naaga.member.persistence.repository;

import com.now.naaga.member.domain.Member;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MemberRepository extends JpaRepository<Member, Long> {

}
62 changes: 62 additions & 0 deletions backend/src/main/java/com/now/naaga/place/domain/Place.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.now.naaga.place.domain;

import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import java.util.Objects;

@Entity
public class Place {

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

@Embedded
private Position position;

private String imageUrl;

protected Place() {
}

public Long getId() {
return id;
}

public Position getPosition() {
return position;
}

public String getImageUrl() {
return imageUrl;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final Place place = (Place) o;
return Objects.equals(id, place.id);
}

@Override
public int hashCode() {
return Objects.hash(id);
}

@Override
public String toString() {
return "Place{" +
"id=" + id +
", position=" + position +
", imageUrl='" + imageUrl + '\'' +
'}';
}
}
58 changes: 58 additions & 0 deletions backend/src/main/java/com/now/naaga/place/domain/Position.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.now.naaga.place.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import java.math.BigDecimal;
import java.util.Objects;

@Embeddable
public class Position {

@Column(precision = 9, scale = 6)
private BigDecimal latitude;

@Column(precision = 9, scale = 6)
private BigDecimal longitude;

protected Position() {
}

public Position(final BigDecimal latitude, final BigDecimal longitude) {
this.latitude = latitude;
this.longitude = longitude;
}

public BigDecimal getLatitude() {
return latitude;
}

public BigDecimal getLongitude() {
return longitude;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final Position position = (Position) o;
return Objects.equals(latitude, position.latitude)
&& Objects.equals(longitude, position.longitude);
}

@Override
public int hashCode() {
return Objects.hash(latitude, longitude);
}

@Override
public String toString() {
return "Position{" +
"latitude=" + latitude +
", longitude=" + longitude +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.now.naaga.place.persistence.repository;

import com.now.naaga.place.domain.Place;
import org.springframework.data.jpa.repository.JpaRepository;

public interface PlaceRepository extends JpaRepository<Place, Long> {

}
9 changes: 8 additions & 1 deletion backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@

spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb;MODE=MySQL
spring.datasource.username=sa
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57Dialect