mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
72 lines
2.1 KiB
Go
72 lines
2.1 KiB
Go
package services
|
|
|
|
import (
|
|
"github.com/emilybache/gildedrose-refactoring-kata/lib"
|
|
"github.com/emilybache/gildedrose-refactoring-kata/models"
|
|
)
|
|
|
|
type SulfurasItemUpdateService struct {
|
|
logger lib.Logger
|
|
}
|
|
|
|
func NewSulfurasItemUpdateService(logger lib.Logger) SulfurasItemUpdateService {
|
|
return SulfurasItemUpdateService{
|
|
logger: logger,
|
|
}
|
|
}
|
|
|
|
func (this SulfurasItemUpdateService) UpdateQuality(item *models.Item) error {
|
|
item.Mutex.Lock()
|
|
defer item.Mutex.Unlock()
|
|
|
|
itemModel := item.Model
|
|
|
|
if itemModel.Name != "Aged Brie" && itemModel.Name != "Backstage passes to a TAFKAL80ETC concert" {
|
|
if itemModel.Quality > 0 {
|
|
if itemModel.Name != "Sulfuras, Hand of Ragnaros" {
|
|
itemModel.Quality = itemModel.Quality - 1
|
|
}
|
|
}
|
|
} else {
|
|
if itemModel.Quality < 50 {
|
|
itemModel.Quality = itemModel.Quality + 1
|
|
if itemModel.Name == "Backstage passes to a TAFKAL80ETC concert" {
|
|
if itemModel.SellIn < 11 {
|
|
if itemModel.Quality < 50 {
|
|
itemModel.Quality = itemModel.Quality + 1
|
|
}
|
|
}
|
|
if itemModel.SellIn < 6 {
|
|
if itemModel.Quality < 50 {
|
|
itemModel.Quality = itemModel.Quality + 1
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if itemModel.Name != "Sulfuras, Hand of Ragnaros" {
|
|
itemModel.SellIn = itemModel.SellIn - 1
|
|
}
|
|
|
|
if itemModel.SellIn < 0 {
|
|
if itemModel.Name != "Aged Brie" {
|
|
if itemModel.Name != "Backstage passes to a TAFKAL80ETC concert" {
|
|
if itemModel.Quality > 0 {
|
|
if itemModel.Name != "Sulfuras, Hand of Ragnaros" {
|
|
itemModel.Quality = itemModel.Quality - 1
|
|
}
|
|
}
|
|
} else {
|
|
itemModel.Quality = itemModel.Quality - itemModel.Quality
|
|
}
|
|
} else {
|
|
if itemModel.Quality < 50 {
|
|
itemModel.Quality = itemModel.Quality + 1
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|