-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
264 additions
and
141 deletions.
There are no files selected for viewing
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
91 changes: 91 additions & 0 deletions
91
...com/agiletestingdays/untangletestcode/unicornservice/adapter/driven/db/UnicornEntity.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,91 @@ | ||
package com.agiletestingdays.untangletestcode.unicornservice.adapter.driven.db; | ||
|
||
import com.agiletestingdays.untangletestcode.unicornservice.domain.Unicorn; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import java.time.Instant; | ||
import java.time.LocalDate; | ||
import java.time.ZoneOffset; | ||
import java.util.UUID; | ||
|
||
@Entity | ||
@Table(name = "unicorns") | ||
public class UnicornEntity { | ||
|
||
@Id private UUID id; | ||
private String name; | ||
private String maneColor; | ||
private Integer hornLength; | ||
private Integer hornDiameter; | ||
private Instant dateOfBirth; | ||
|
||
public UnicornEntity() {} | ||
|
||
public UnicornEntity(Unicorn unicorn) { | ||
this.id = unicorn.id(); | ||
this.name = unicorn.name(); | ||
this.maneColor = unicorn.maneColor().name(); | ||
this.hornLength = unicorn.hornLength(); | ||
this.hornDiameter = unicorn.hornDiameter(); | ||
this.dateOfBirth = unicorn.dateOfBirth().atStartOfDay().toInstant(ZoneOffset.UTC); | ||
} | ||
|
||
public UUID getId() { | ||
return id; | ||
} | ||
|
||
public void setId(UUID id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getManeColor() { | ||
return maneColor; | ||
} | ||
|
||
public void setManeColor(String maneColor) { | ||
this.maneColor = maneColor; | ||
} | ||
|
||
public Integer getHornLength() { | ||
return hornLength; | ||
} | ||
|
||
public void setHornLength(Integer hornLength) { | ||
this.hornLength = hornLength; | ||
} | ||
|
||
public Integer getHornDiameter() { | ||
return hornDiameter; | ||
} | ||
|
||
public void setHornDiameter(Integer hornDiameter) { | ||
this.hornDiameter = hornDiameter; | ||
} | ||
|
||
public Instant getDateOfBirth() { | ||
return dateOfBirth; | ||
} | ||
|
||
public void setDateOfBirth(Instant dateOfBirth) { | ||
this.dateOfBirth = dateOfBirth; | ||
} | ||
|
||
public Unicorn toUnicorn() { | ||
return new Unicorn( | ||
id, | ||
name, | ||
Unicorn.ManeColor.valueOf(maneColor), | ||
hornLength, | ||
hornDiameter, | ||
LocalDate.ofInstant(dateOfBirth, ZoneOffset.UTC)); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...agiletestingdays/untangletestcode/unicornservice/adapter/driven/db/UnicornRepository.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,12 @@ | ||
package com.agiletestingdays.untangletestcode.unicornservice.adapter.driven.db; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
import org.springframework.data.repository.ListCrudRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface UnicornRepository extends ListCrudRepository<UnicornEntity, UUID> { | ||
|
||
List<UnicornEntity> findAll(); | ||
} |
33 changes: 33 additions & 0 deletions
33
...iletestingdays/untangletestcode/unicornservice/adapter/driven/db/UnicornStoreAdapter.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.agiletestingdays.untangletestcode.unicornservice.adapter.driven.db; | ||
|
||
import com.agiletestingdays.untangletestcode.unicornservice.application.port.out.UnicornStore; | ||
import com.agiletestingdays.untangletestcode.unicornservice.domain.Unicorn; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class UnicornStoreAdapter implements UnicornStore { | ||
|
||
UnicornRepository repository; | ||
|
||
public UnicornStoreAdapter(UnicornRepository repository) { | ||
this.repository = repository; | ||
} | ||
|
||
@Override | ||
public Optional<Unicorn> findById(UUID id) { | ||
return repository.findById(id).map(UnicornEntity::toUnicorn); | ||
} | ||
|
||
@Override | ||
public List<Unicorn> getAll() { | ||
return repository.findAll().stream().map(UnicornEntity::toUnicorn).toList(); | ||
} | ||
|
||
@Override | ||
public Unicorn save(Unicorn unicorn) { | ||
return repository.save(new UnicornEntity(unicorn)).toUnicorn(); | ||
} | ||
} |
6 changes: 4 additions & 2 deletions
6
...ornservice/unicorn/UnicornController.java → ...apter/driving/http/UnicornController.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
3 changes: 2 additions & 1 deletion
3
...de/unicornservice/unicorn/UnicornDto.java → ...vice/adapter/driving/http/UnicornDto.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
13 changes: 13 additions & 0 deletions
13
...com/agiletestingdays/untangletestcode/unicornservice/application/port/in/ReadUnicorn.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,13 @@ | ||
package com.agiletestingdays.untangletestcode.unicornservice.application.port.in; | ||
|
||
import com.agiletestingdays.untangletestcode.unicornservice.domain.Unicorn; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
public interface ReadUnicorn { | ||
|
||
List<Unicorn> getAll(); | ||
|
||
Optional<Unicorn> getById(UUID id); | ||
} |
8 changes: 8 additions & 0 deletions
8
...om/agiletestingdays/untangletestcode/unicornservice/application/port/in/WriteUnicorn.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,8 @@ | ||
package com.agiletestingdays.untangletestcode.unicornservice.application.port.in; | ||
|
||
import com.agiletestingdays.untangletestcode.unicornservice.domain.Unicorn; | ||
|
||
public interface WriteUnicorn { | ||
|
||
void createNewUnicorn(Unicorn unicorn); | ||
} |
15 changes: 15 additions & 0 deletions
15
...m/agiletestingdays/untangletestcode/unicornservice/application/port/out/UnicornStore.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,15 @@ | ||
package com.agiletestingdays.untangletestcode.unicornservice.application.port.out; | ||
|
||
import com.agiletestingdays.untangletestcode.unicornservice.domain.Unicorn; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
public interface UnicornStore { | ||
|
||
Optional<Unicorn> findById(UUID id); | ||
|
||
List<Unicorn> getAll(); | ||
|
||
Unicorn save(Unicorn unicorn); | ||
} |
32 changes: 32 additions & 0 deletions
32
.../agiletestingdays/untangletestcode/unicornservice/application/service/UnicornService.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,32 @@ | ||
package com.agiletestingdays.untangletestcode.unicornservice.application.service; | ||
|
||
import com.agiletestingdays.untangletestcode.unicornservice.application.port.in.ReadUnicorn; | ||
import com.agiletestingdays.untangletestcode.unicornservice.application.port.in.WriteUnicorn; | ||
import com.agiletestingdays.untangletestcode.unicornservice.application.port.out.UnicornStore; | ||
import com.agiletestingdays.untangletestcode.unicornservice.domain.Unicorn; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class UnicornService implements ReadUnicorn, WriteUnicorn { | ||
|
||
private final UnicornStore store; | ||
|
||
public UnicornService(UnicornStore store) { | ||
this.store = store; | ||
} | ||
|
||
public List<Unicorn> getAll() { | ||
return store.getAll(); | ||
} | ||
|
||
public Optional<Unicorn> getById(UUID id) { | ||
return store.findById(id); | ||
} | ||
|
||
public void createNewUnicorn(Unicorn newUnicorn) { | ||
store.save(newUnicorn); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...tcode/unicornservice/unicorn/Unicorn.java → ...stcode/unicornservice/domain/Unicorn.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
59 changes: 0 additions & 59 deletions
59
.../java/com/agiletestingdays/untangletestcode/unicornservice/unicorn/UnicornRepository.java
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
...ain/java/com/agiletestingdays/untangletestcode/unicornservice/unicorn/UnicornService.java
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...etestingdays/untangletestcode/unicornservice/adapter/driven/db/UnicornRepositoryStub.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,7 @@ | ||
package com.agiletestingdays.untangletestcode.unicornservice.adapter.driven.db; | ||
|
||
import java.util.UUID; | ||
import org.stubit.springdata.ListCrudRepositoryStub; | ||
|
||
public class UnicornRepositoryStub extends ListCrudRepositoryStub<UnicornEntity, UUID> | ||
implements UnicornRepository {} |
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
Oops, something went wrong.