-
Notifications
You must be signed in to change notification settings - Fork 11
simulations v0.7

By default, branches in Git have nothing to do with each other. However, when you tell a local branch to "track" a remote branch, you create a connection between these two branches. Your local branch now has a "counterpart" on the remote server.
$ git checkout --track origin/dev
Branch dev set up to track remote branch dev from origin.
Switched to a new branch 'dev'
The git
fetchcommand downloads commits, files, and refs from a remote repository into your local repo.
Fetching is what you do when you want to see what everybody else has been working on. It lets you see how the central history has progressed, but it doesn’t force you to actually merge the changes into your repository. Git isolates fetched content from existing local content; it has absolutely no effect on your local development work.
git pull is actually an alias to 2 commands: git fetch + git merge
# Update your local repo with the latest code:
git fetch --all --prune
# Merge the changes (you already did a pull)`
git merge origin master
repo by enchufin with the social domain done and ready to add upstream.

remote repo, albertprofe, is adding commits day after day. Thus remote repo, enchufin. is a lot of commits behind.

Important
So, in this case, enchufin is going to:
-
update/sync his local repo with the upstream updates (
git checkout & pull) - solving the conflicts with merge local IntellJIdea tool on a new branch (
AlbertProfe-master) - create remote repo branch (
AlbertProfe-master) -
pushto remote enchufin repo branch (AlbertProfe-master) - and after that enchufin will make a pull-request to albertprofe with
socialdomain with no conflicts.
And albertprofe will:
- accept the
pull-requestwith no conflicts - update his local repo
First at all, enchufin will download the project to local:


First at all: checkout
git checkout -b <new-branch> <existing-branch>
By default git checkout -b will base the new-branch off the current HEAD. An optional additional branch parameter can be passed to git checkout. In the above example, <existing-branch> is passed which then bases new-branch off of existing-branch instead of the current HEAD.
And then, git pull
git pull https://github.com/AlbertProfe/simulations.git master
Then with IntellJIdea tool enchufin will resolve Git conflicts and then merge-commit.



After that, enchufin will make a pull-request:

The pull-request in this case will have no conflict! (on github cloud)


AlbertProfe merged commit f1812d4 into AlbertProfe:master now
Last step, update local project albertprofe:



- new dependencies: JPA and H2
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Annotations:
-
@OneToMany: Establishes one-to-many relationship. Example:Playercan have multipleSimulation. Used in JPA/Hibernate. Annotation: @OneToMany(mappedBy = "Player").mappedBy: Indicates the field on the inverse side of a bidirectional relationship. Specifies the field in the owning side that maps the relationship. Example: In a bidirectional OneToMany, mappedBy points to the field in the ManyToOne side. -
@ManyToOne: Specifies many-to-one relationship. Multiple instances are associated with one instance of another entity. Example: Manysimulationbelong to oneplayer. -
@JoinColumn: Customizes join column. Example: Specifies foreign key column in @ManyToOne or @OneToOne relationships. Annotation: @JoinColumn(name = "PLAYER_FK"). -
@JsonIgnore: Excludes field from serialization/deserialization. Example: Hides sensitive or irrelevant data in JSON responses. Annotation: @JsonIgnore.
package com.example.demo.model;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.List;
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Player {
@Id
private String id;
private String player;
private int age;
private boolean active;
@OneToMany(mappedBy = "player", cascade = CascadeType.ALL)
private List<Simulation> simulations = new ArrayList<>();
@OneToMany(mappedBy = "player", cascade = CascadeType.ALL)
private List<Subscription> subscriptions = new ArrayList<>();
@OneToMany(mappedBy = "player", cascade = CascadeType.ALL)
private List<Payment> payments = new ArrayList<>();
@OneToMany(mappedBy = "player", cascade = CascadeType.ALL)
private List<Card> cards = new ArrayList<>();
@OneToMany(mappedBy = "player", cascade = CascadeType.ALL)
private List<Social> socials = new ArrayList<>();
public void addSimulation(Simulation simulation) {
this.getSimulations().add(simulation);
//if (simulation.getId() != null) simulation.getId().getSimulations().remove(simulation);
simulation.setPlayer(this);
}
public void addSocial(Social social) {
this.getSocials().add(social);
social.setPlayer(this);
}
public void addCard(Card card) {
this.getCards().add(card);
card.setPlayer(this);
}
public void addPayment(Payment payment) {
this.getPayments().add(payment);
//if (simulation.getId() != null) simulation.getId().getSimulations().remove(simulation);
payment.setPlayer(this);
}
public void addSubscription(Subscription subscription) {
this.getSubscriptions().add(subscription);
//if (subscription.getId() != null) subscription.getId().getSubscriptions().remove(subscription);
subscription.setPlayer(this);
}
}package com.example.demo.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.List;
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Social {
@Id
private String id;
private String name;
private boolean isActive;
private int numberDays;
private String socialUrl;
private String icon;
@JsonIgnore
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="PLAYER_FK")
private Player player;
}datasource
server.port=8089
#H2 DATASOURCE
spring.datasource.url=jdbc:h2:mem:0f74afd0-eefb-4b37-af9f-64249cb2ffa2
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
#DDL
spring.jpa.hibernate.ddl-auto=create-droppackage com.example.demo.repository;
import com.example.demo.model.Social;
import org.springframework.data.repository.CrudRepository;
public interface SocialRepository extends CrudRepository<Social, String> {}Fake data for social object
Runner
Player & Social
http://localhost:8089/h2-console/
http://localhost:8089/api/v1/player/players
http://localhost:8089/api/v1/social/socials

React - Spring Boot - API Rest - H2 DataBase - Axios - React_router_dom - JPA