-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from Informatik-Projekt-Kurs/IPK-167-Backend-C…
…ompany-Setup Ipk 167 backend company setup
- Loading branch information
Showing
9 changed files
with
136 additions
and
25 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/java/com/MeetMate/_experiments/docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#Test Mongo Database | ||
version: '3' | ||
|
||
services: | ||
mongodb: | ||
image: mongo:latest | ||
container_name: mongodb | ||
restart: always | ||
ports: | ||
- "27017:27017" | ||
networks: | ||
- mongo-net | ||
volumes: | ||
- data:/data | ||
environment: | ||
MONGO_INITDB_ROOT_USERNAME: root | ||
MONGO_INITDB_ROOT_PASSWORD: pass | ||
|
||
mongo-express: | ||
image: mongo-express | ||
container_name: mongo-express | ||
restart: always | ||
ports: | ||
- "8082:8081" | ||
networks: | ||
- mongo-net | ||
depends_on: | ||
- mongodb | ||
environment: | ||
ME_CONFIG_MONGODB_ADMINUSERNAME: root | ||
ME_CONFIG_MONGODB_ADMINPASSWORD: pass | ||
ME_CONFIG_MONGODB_SERVER: mongodb | ||
|
||
volumes: | ||
data: { } | ||
|
||
networks: | ||
mongo-net: | ||
driver: bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/MeetMate/company/sequence/CompanySequence.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.MeetMate.company.sequence; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
|
||
@Document(collection = "company_sequence") | ||
@Data | ||
@AllArgsConstructor | ||
public class CompanySequence { | ||
@Id | ||
String id; | ||
long value; | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/MeetMate/company/sequence/SequenceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.MeetMate.company.sequence; | ||
|
||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
|
||
@Configuration | ||
public class SequenceConfig { | ||
|
||
@Bean | ||
public CommandLineRunner init(MongoTemplate mongoTemplate) { | ||
return args -> { | ||
if (!mongoTemplate.collectionExists(CompanySequence.class)) { | ||
mongoTemplate.createCollection(CompanySequence.class); | ||
mongoTemplate.insert(new CompanySequence("company_sequence", 0)); | ||
} | ||
}; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/MeetMate/company/sequence/SequenceService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.MeetMate.company.sequence; | ||
|
||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
import org.springframework.data.mongodb.core.query.Criteria; | ||
import org.springframework.data.mongodb.core.query.Query; | ||
import org.springframework.data.mongodb.core.query.Update; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class SequenceService { | ||
|
||
private final MongoTemplate mongoTemplate; | ||
|
||
@Transactional | ||
public void incrementId() { | ||
Query query = new Query(Criteria.where("_id").is("company_sequence")); | ||
Update update = new Update().inc("value", 1); | ||
mongoTemplate.updateFirst(query, update, CompanySequence.class); | ||
} | ||
|
||
public long getAndIncrementCurrentValue(){ | ||
Query query = new Query(Criteria.where("_id").is("company_sequence")); | ||
CompanySequence sequence = mongoTemplate.findOne(query, CompanySequence.class); | ||
long value = sequence.getValue(); | ||
incrementId(); | ||
return value; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#graphqls for graphql scema | ||
|
||
type Query { | ||
getCompany: Company | ||
getCompany(id: ID!): Company | ||
} | ||
|
||
type Mutation { | ||
|